Repository navigation
Fix dynamic secret selection false positives in strict linting #80581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f0e277a
45f22a6
e6d6da4
1a530e7
3c4e3c9
db5c641
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,11 +16,12 @@ import ( | |
| // secrets context instead of the named secrets a job or step actually needs. | ||
| func OverprovisionedSecretsRule() Rule { | ||
| return Rule{ | ||
| ID: "overprovisioned-secrets", | ||
| Description: "Detect secrets: inherit and expressions that materialize the whole secrets context", | ||
| Severity: Error, | ||
| Targets: ActionsAST | AWAST, | ||
| Check: checkOverprovisionedSecrets, | ||
| ID: "overprovisioned-secrets", | ||
| ThreatRuleID: "CTR-017", | ||
| Description: "Detect secrets: inherit and expressions that materialize the whole secrets context", | ||
| Severity: Error, | ||
| Targets: ActionsAST | AWAST, | ||
| Check: checkOverprovisionedSecrets, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -93,19 +94,7 @@ func overprovisionedSecretsDiagnostics(ctx context.Context, input Input) ([]Diag | |
| } | ||
|
|
||
| blocks, err := aw.ExecutionBlocks(ctx, input.Document) | ||
| failures := []error{err} | ||
| // engine.env and sandbox.agent.env are copied into the agent execution step | ||
| // environment but are not execution blocks. | ||
| if input.Document != nil { | ||
| if engine, ok := input.Document.Frontmatter["engine"].(map[string]any); ok { | ||
| failures = append(failures, walkExpressionScalars(ctx, engine["env"], "engine.env", visit)) | ||
| } | ||
| if sandbox, ok := input.Document.Frontmatter["sandbox"].(map[string]any); ok { | ||
| if agent, ok := sandbox["agent"].(map[string]any); ok { | ||
| failures = append(failures, walkExpressionScalars(ctx, agent["env"], "sandbox.agent.env", visit)) | ||
| } | ||
| } | ||
| } | ||
| failures := []error{err, walkOverprovisionedSecretsEnv(ctx, input.Document, visit)} | ||
| for _, block := range blocks { | ||
| if secrets, ok := block.Fields["secrets"].(string); ok && strings.EqualFold(strings.TrimSpace(secrets), "inherit") { | ||
| if uses, ok := block.Fields["uses"].(string); ok { | ||
|
|
@@ -124,6 +113,23 @@ func overprovisionedSecretsDiagnostics(ctx context.Context, input Input) ([]Diag | |
| return diagnostics, errors.Join(failures...) | ||
| } | ||
|
|
||
| func walkOverprovisionedSecretsEnv(ctx context.Context, document *aw.Document, visit func(string, string) error) error { | ||
| // engine.env and sandbox.agent.env are copied into the agent execution step | ||
| // environment but are not execution blocks. | ||
| var failures []error | ||
| if document != nil { | ||
| if engine, ok := document.Frontmatter["engine"].(map[string]any); ok { | ||
| failures = append(failures, walkExpressionScalars(ctx, engine["env"], "engine.env", visit)) | ||
| } | ||
| if sandbox, ok := document.Frontmatter["sandbox"].(map[string]any); ok { | ||
| if agent, ok := sandbox["agent"].(map[string]any); ok { | ||
| failures = append(failures, walkExpressionScalars(ctx, agent["env"], "sandbox.agent.env", visit)) | ||
| } | ||
| } | ||
| } | ||
| return errors.Join(failures...) | ||
| } | ||
|
|
||
| // isCompilerCallWorkflowFallback reports whether job has the exact shape of a | ||
| // compiler-generated call-workflow fan-out job: call-<worker> needing | ||
| // safe_outputs, gated on call_workflow_name, and calling the local worker file. | ||
|
|
@@ -174,7 +180,8 @@ func inheritDiagnostic(path, uses string) Diagnostic { | |
| } | ||
|
|
||
| // materializesSecretsContext reports whether node evaluates the secrets | ||
| // context as a whole: any reference other than secrets.NAME or secrets['NAME']. | ||
| // context as a whole rather than selecting one property. Dynamic indexes select | ||
| // one secret too, but their expressions are still visited for whole-context use. | ||
| func materializesSecretsContext(node actionlint.ExprNode) bool { | ||
| found := false | ||
| actionlint.VisitExprNode(node, func(child, parent actionlint.ExprNode, entering bool) { | ||
|
|
@@ -191,7 +198,7 @@ func materializesSecretsContext(node actionlint.ExprNode) bool { | |
| return | ||
| } | ||
| case *actionlint.IndexAccessNode: | ||
| if _, literal := parent.Index.(*actionlint.StringNode); literal && parent.Operand == child { | ||
| if parent.Operand == child { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Computed selectors are now fingerprinted for safe-update checks, redacted, and bounded by explicit
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Computed secret references are now included in step secret classification, so env bindings are rejected when the step writes to |
||
| return | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CTR-017 suppressions no longer suppress
overprovisioned-secrets; added strict-mode regression coverage in3c4e3c96.