Skip to content

[CICD Coverage #1] Create specific CICD parsing#42

Open
ChouraquiBen wants to merge 12 commits intomainfrom
benjamin.chouraqui/add-cicd-coverage-0
Open

[CICD Coverage #1] Create specific CICD parsing#42
ChouraquiBen wants to merge 12 commits intomainfrom
benjamin.chouraqui/add-cicd-coverage-0

Conversation

@ChouraquiBen
Copy link
Copy Markdown
Contributor

@ChouraquiBen ChouraquiBen commented Mar 16, 2026

Motivation

There are only few rules to scan github-actions, which are not enough to cover the flaws hackers may use to attack a codebase. This series of PRs aims to extend the CICD scan coverage.

This first PR changes the go code to add the required features for the rules to be added:

  • Adding comment to the documents sent to be scanned by the rego rules
  • Adding bash expressions parsing
  • Adding specific github-actions parsing
  • Enabling dependabot configuration files to be scanned on the cicd platform.

To do so, other changes had to be performed:

  • Enabled CGO to have tree-sitter parsing that requires it
  • As a side effect of enabling CGO, removed vendor usage that does not support CGO

Not supported

  • Powershell
  • Heredocs
  • Functions / loops

Author Checklist

  • I have reviewed my own PR.
  • I have added or updated relevant unit tests where necessary. If no tests are added, I've explained why.
  • All new and existing tests pass.
  • I have tested my changes on staging (if applicable).
  • I have updated any relevant documentation (if applicable).

QA Instruction

Blast Radius

iac-scanning - CICD findings

Additional Notes

If you need to share anything else along with your PR, please do it here.

I submit this contribution under the Apache-2.0 license.

@ChouraquiBen ChouraquiBen requested a review from a team as a code owner March 16, 2026 10:38
@datadog-datadog-prod-us1-2

This comment has been minimized.

@ChouraquiBen ChouraquiBen force-pushed the benjamin.chouraqui/add-cicd-coverage-0 branch 6 times, most recently from 077d971 to 3847b7c Compare March 16, 2026 15:49
run: go mod vendor
- name: Build datadog-iac-scanner
run: |
CGO_ENABLED=1
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tree-sitter uses c packages, thus the need of CGO enabled

cicdOnRegex = regexp.MustCompile(`\s*on:\s*`)
cicdJobsRegex = regexp.MustCompile(`\s*jobs:\s*`)
cicdStepsRegex = regexp.MustCompile(`\s*steps:\s*`)
dependabotVersionRegex = regexp.MustCompile(`\s*version:\s*`)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check dependabot config files usual patterns to be able to notice one

switch returnType {
case "cdkTf":
return terraform
case dependabot:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return dependabot config files as part of the cicd platform. This is a choice made not to confuse customers as dependabot can be considered a part of cicd although, it is not a github action

${{ runner.OS }}-
- name: Get Modules
run: |
go mod vendor
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mod vendor does not support CGO dependencies

@@ -0,0 +1,328 @@
/*
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parser aims to parse expressions specific to github actions

}

// ParsedCommand represents a parsed shell command
type ParsedCommand struct {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create all the structures related to gh-actions and shell parsing

documents = convertKeysToString(documents)

// Enhance documents with parsed run blocks
p.enhanceWithParsedRuns(ctx, documents)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add shell parsing

p.enhanceWithParsedRuns(ctx, documents)

// Enhance documents with parsed expressions
p.enhanceWithParsedExpressions(ctx, documents)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add gh action Expression parsing

@ChouraquiBen ChouraquiBen force-pushed the benjamin.chouraqui/add-cicd-coverage-0 branch 9 times, most recently from dc90c53 to 2d72075 Compare March 23, 2026 13:46
@ChouraquiBen ChouraquiBen force-pushed the benjamin.chouraqui/add-cicd-coverage-0 branch from 2d72075 to faa31e1 Compare March 24, 2026 10:48
@ChouraquiBen ChouraquiBen force-pushed the benjamin.chouraqui/add-cicd-coverage-0 branch 2 times, most recently from 8edfdd2 to 8fe4424 Compare March 26, 2026 10:11
@ChouraquiBen ChouraquiBen force-pushed the benjamin.chouraqui/add-cicd-coverage-0 branch 2 times, most recently from 890bb12 to a3f73bb Compare March 27, 2026 10:35
@ChouraquiBen ChouraquiBen force-pushed the benjamin.chouraqui/add-cicd-coverage-0 branch from a3f73bb to 9f2e68a Compare March 27, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants