Skip to content

Parse a new "arguments" keyword in new IaC v1.4 config#206

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
mainfrom
gaspard.barbier/iac-add-arguments-to-config
Jul 13, 2026
Merged

Parse a new "arguments" keyword in new IaC v1.4 config#206
gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
mainfrom
gaspard.barbier/iac-add-arguments-to-config

Conversation

@barbiergaspard

@barbiergaspard barbiergaspard commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Motivation

As seen in the linked Jira ticket, there is customer demand for adding arguments to the rule-configs. Currently, the rule-configs only allow to change which files and severities are read or ignored by a certain rules. Rule-specific arguments management would allow customers to fine-tune how they use the different rules.

JIRA Ticket : https://datadoghq.atlassian.net/browse/K9CODESEC-1940

Changes

This PR adds support for rule-specific arguments in IaC rule configs.
It bumps the emitted IaC config schema version to v1.4, parses and unparses an arguments block under iac.rule-configs.<rule-id>, stores those arguments on IacRuleConfig, and passes them to the policy input so rules can use customer-provided values at evaluation time.
It also adds/updates tests for:

  • Parsing and round-tripping arguments in rule configs.
  • Validating that arguments is accepted in the right config section.
  • E2E coverage for a Terraform rule using configurable required_tags.
  • support of argument override, which means processing the override before OPA evaluation

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).
    These changes have been tested on a real repository (except for the override support)

QA Instruction

You can verify that all tests currently pass. You can verify that if you tweak the values in TestV14_RuleConfig_Arguments_ArePassedToRule as well as in TestParseUnparseRoundTripV14 for the arguments, those tests should fail.

If you wish to go further, you can clone my branch of the datadoc-iac-scanner-default-rules repo, linked to this PR with a POC for arguments in 2 rules, and use the -q flag to specify a path to the rules directory. Arguments have been implemented for the cicd-github-unpinned-actions-full-length-commit-sha and the dockerfile-use-only-an-allowed-registry-in-the-from-image rules. You can test those changes by looking up which repo contains violations of those rules, and using the "allow" argument to reduce the number of findings.

Blast Radius

This change impacts only Datadog IaC Scanner configuration parsing and rule evaluation. It does not affect external services or infrastructure.

The main compatibility surface is the IaC config schema: existing configs should continue to work, while newly generated configs now use schema version v1.4.

Additional Notes

This PR introduces generic argument plumbing only. Each rule still needs to explicitly read and use the arguments it supports.

I submit this contribution under the Apache-2.0 license.

barbiergaspard commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/iac-add-arguments-to-config branch from 9c11854 to d441bb4 Compare June 22, 2026 12:57
@datadog-official

datadog-official Bot commented Jun 22, 2026

Copy link
Copy Markdown

🎯 Code Coverage (details)
Patch Coverage: 28.57%
Overall Coverage: 49.62% (-0.05%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 8eeff26 | Docs | Datadog PR Page | Give us feedback!

@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/iac-add-arguments-to-config branch 3 times, most recently from 4ce283c to 120ef4c Compare June 23, 2026 07:44
@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/query-path-flag branch from fced47c to c1a0cdc Compare June 23, 2026 07:44
@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/iac-add-arguments-to-config branch from 120ef4c to d32f8f8 Compare June 23, 2026 07:51
@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/query-path-flag branch from c1a0cdc to ab97dfd Compare June 23, 2026 07:51
@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/iac-add-arguments-to-config branch from d32f8f8 to 7b56423 Compare June 23, 2026 10:35
@barbiergaspard
barbiergaspard marked this pull request as ready for review June 23, 2026 13:44
@barbiergaspard
barbiergaspard requested a review from a team as a code owner June 23, 2026 13:44
@barbiergaspard

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7b5642387b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread pkg/config/config_validation_test.go Outdated
Comment thread pkg/config/config_validation_test.go Outdated
@barbiergaspard
barbiergaspard marked this pull request as draft June 23, 2026 13:54
@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/iac-add-arguments-to-config branch from 7b56423 to b8cb162 Compare June 24, 2026 07:09
@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/query-path-flag branch from ab97dfd to 8637be8 Compare June 24, 2026 13:39
@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/iac-add-arguments-to-config branch from b8cb162 to 16344df Compare June 24, 2026 13:39
@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/query-path-flag branch from 8637be8 to fd6d7a5 Compare June 24, 2026 14:53
@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/iac-add-arguments-to-config branch from 16344df to adf4194 Compare June 24, 2026 14:53
@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/query-path-flag branch from fd6d7a5 to fb2dff3 Compare June 25, 2026 07:44
@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/iac-add-arguments-to-config branch 3 times, most recently from 30a3d63 to 85756c2 Compare June 25, 2026 08:48
@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/query-path-flag branch 2 times, most recently from 39aba83 to da03d70 Compare June 25, 2026 10:22
@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/iac-add-arguments-to-config branch from 85756c2 to 0767aa5 Compare June 25, 2026 10:22
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/query-path-flag branch from da03d70 to f4324d9 Compare June 26, 2026 13:49
@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/iac-add-arguments-to-config branch from 380edfd to b815bee Compare June 30, 2026 13:01
@chatgpt-codex-connector

This comment was marked as resolved.

@barbiergaspard
barbiergaspard marked this pull request as ready for review June 30, 2026 13:15
@robertohuertasm-datadog

Copy link
Copy Markdown

@barbiergaspard While reviewing this change, I noticed a potential issue around how override arguments are resolved for aggregate rules. I used AI to help review this, so I may be missing some domain context; please treat this as something to validate rather than a definitive blocker.

Bug: single-override arguments are injected globally across all aggregate branches

The argument-lookup logic has a cross-contamination problem for aggregate rules with multiple overrides.

What happens today

lookupRuleArguments runs once, before Rego evaluation, resolves a single map[string]any, and injects it as input.arguments for the entire query. The relevant path for override-sourced arguments is lookupRuleConfigArgumentsForOverrideIDs:

// inspector.go ~785
if rc, found := lookupRuleConfig(ruleConfigs, *overrideID, ""); found && rc.Arguments != nil {
    if matched != nil {
        return nil, false, fmt.Errorf("multiple override argument configs match aggregated rule %s", queryID)
    }
    matched = rc.Arguments
}

When exactly one override ID has arguments in its rule config, those arguments are returned without error and injected globally. Every branch in the Rego evaluation — AWS, Azure, GCP, etc. — then sees the same input.arguments.

The overrideKey that identifies which branch produced a finding is only read after evaluation in vulnerability_builder.go (line ~160). By that point the cross-contamination has already occurred.

Concrete impact

Given an aggregate rule with overrides aws-sg-id and azure-nsg-id, and a rule config that attaches arguments: {allowed_ports: [443]} to aws-sg-id only:

  1. lookupRuleConfigArgumentsForOverrideIDs matches on aws-sg-id → returns {allowed_ports: [443]}
  2. That is injected as input.arguments for the whole evaluation
  3. The Azure NSG branch also reads input.arguments.allowed_ports, even though no arguments were configured for it
  4. Azure/GCP results are evaluated under AWS-specific arguments

The ambiguity guard doesn't help

The error on "multiple override argument configs" (line ~787) actually makes things worse: it prevents the correct fix (per-override arguments) while still silently allowing single-override cross-contamination.

Two clean remedies

Option A — restrict to aggregate-level only: Reject arguments configured under any individual override ID at lookup time and require them to be on the aggregate rule ID. Cross-contamination becomes impossible by construction.

Option B — key arguments by override: Instead of a flat input.arguments, inject input.arguments[overrideKey] so each Rego branch selects only its own arguments. Requires updating the Rego interface contract but is the most expressive fix.

@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/iac-add-arguments-to-config branch from b815bee to 3d9d724 Compare July 1, 2026 08:41
@barbiergaspard

barbiergaspard commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@robertohuertasm-datadog Yes, this bug was a real issue. Looking into it, I have a better understanding of how overrides work, and if my understanding is correct, overrides should not contain arguments. so I removed my last commit, that was related to overrides. Just to be sure we are on the same page, here is my current understanding of the overrides :

  • overrides are defined in the default rules repo and are linked to an override key
  • the override key is returned in the result of the rego query when relevant
  • the override is then processed by the scanner to produce findings

Since the override key depends on the result of the scan, and the result of the scan depends on arguments, we can't have arguments in the override or that would lead to circular dependancies. This is why I removed the override commit.

I also added a commit to fix some e2e tests

@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/iac-add-arguments-to-config branch from 2fd85fd to c4b827a Compare July 1, 2026 11:22
@barbiergaspard

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c4b827a2ad

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread pkg/engine/inspector.go
Comment on lines +544 to +545
queryID, legacyQueryID := queryIDsFromMetadata(ctx, &qCtx.Query.Metadata)
if rc, found := lookupRuleConfig(c.ruleConfigs, queryID, legacyQueryID); found {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Apply rule arguments to override IDs

When a rule has Datadog metadata overrides, configs are keyed by the effective override ID: the builder later resolves vulnerability.QueryID from overrideKey (pkg/engine/vulnerability_builder.go:170), and ConvertRule stores override IDs in metadata (pkg/engine/source/datadog.go:255-270). This lookup only checks the base metadata ID before evaluation, so rule-configs:<override-id>: arguments: is ignored and the rule sees no input.arguments, even though severity/path configs for the same override ID still work after decode.

Useful? React with 👍 / 👎.

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.

The override values depend on the rule's overrideKey, which depends on the result of the query. This results depends on the arguments. Arguments are not and should not be included in overrides

Comment thread test/e2e/v14_test.go Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

NIT: Shouldn't this be v1.4 features?

@robertohuertasm-datadog robertohuertasm-datadog left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM! 🚀

@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/iac-add-arguments-to-config branch 2 times, most recently from 1a59a55 to 6a630a1 Compare July 6, 2026 08:05
@barbiergaspard barbiergaspard mentioned this pull request Jul 6, 2026
5 tasks
@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/iac-add-arguments-to-config branch from 6a630a1 to 1cc8ea0 Compare July 7, 2026 14:41
Bump all tests to version 1.4. This implies renaming functions as
well as files.

Add a new TestV14_RuleConfig_Arguments_ArePassedToRule to the
e2e tests.
@barbiergaspard
barbiergaspard force-pushed the gaspard.barbier/iac-add-arguments-to-config branch from 1cc8ea0 to 8eeff26 Compare July 7, 2026 15:38
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit c45c6ac into main Jul 13, 2026
21 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the gaspard.barbier/iac-add-arguments-to-config branch July 13, 2026 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants