-
-
Notifications
You must be signed in to change notification settings - Fork 118
feat: Audit secrets outside an environment #637
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
base: main
Are you sure you want to change the base?
Changes from 12 commits
3e9f0ad
13f9213
acaaef1
992b15b
1d5b2df
6b963b6
13c8cf3
2ae5791
cf1b0e5
0132617
5a3bfe6
f328751
96c90ac
b5dab62
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 |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| use github_actions_models::{ | ||
| common::{Env, EnvValue, expr::LoE}, | ||
| workflow::job::StepBody, | ||
| }; | ||
|
|
||
| use super::{Audit, audit_meta}; | ||
| use crate::{finding::Confidence, models::StepCommon, AuditState, AuditLoadError, Persona}; | ||
|
|
||
| pub(crate) struct SecretsOutsideEnvironment; | ||
|
|
||
| audit_meta!( | ||
| SecretsOutsideEnvironment, | ||
| "secrets-outside-environment", | ||
| "secrets used without an environment to gate them" | ||
| ); | ||
|
|
||
| impl Audit for SecretsOutsideEnvironment { | ||
| fn new(_state: &AuditState<'_>) -> Result<Self, AuditLoadError> | ||
| where | ||
| Self: Sized, | ||
| { | ||
| Ok(Self) | ||
| } | ||
|
|
||
| fn audit_step<'w>( | ||
| &self, | ||
| step: &crate::models::Step<'w>, | ||
| ) -> anyhow::Result<Vec<crate::finding::Finding<'w>>> { | ||
| let mut findings = vec![]; | ||
|
|
||
| if step.parent.environment().is_some() { | ||
| return Ok(findings); | ||
| } | ||
|
|
||
| let eenv: &Env; | ||
| match &step.body { | ||
| StepBody::Uses { uses: _, with } => { | ||
| eenv = with; | ||
| } | ||
| StepBody::Run { | ||
| run: _, | ||
|
Member
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. Note: I'm okay with skipping
Author
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. Makes sense! I naively thought that wouldn't be required, would this be an example?
Member
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. Yep, exactly 🙂 |
||
| shell: _, | ||
| env, | ||
| working_directory: _, | ||
| } => match env { | ||
| LoE::Expr(e) => { | ||
| Self::check_secrets_access(e.as_bare(), step, &mut findings)?; | ||
|
Member
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. I think this check needs to be a little more discerning: Without that, we'll end up with (admittedly goofy) false positives like: with:
yolo: ${{ 'secrets' }}Writing the AST walker is currently a bit annoying/manual; if you want to wait until I add a
Author
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. I like that! It will also increase the audit confidence. I am ok with waiting for the |
||
| return Ok(findings); | ||
| } | ||
| LoE::Literal(env) => eenv = env, | ||
| }, | ||
| } | ||
|
|
||
| for v in eenv.values() { | ||
| if let EnvValue::String(s) = v { | ||
| Self::check_secrets_access(s, step, &mut findings)? | ||
| } | ||
| } | ||
|
|
||
| Ok(findings) | ||
| } | ||
| } | ||
|
|
||
| impl SecretsOutsideEnvironment { | ||
| fn check_secrets_access<'w>( | ||
| s: &str, | ||
| step: &crate::models::Step<'w>, | ||
| findings: &mut Vec<crate::finding::Finding<'w>>, | ||
| ) -> anyhow::Result<()> { | ||
| if s.contains("secrets") { | ||
|
||
| findings.push( | ||
| Self::finding() | ||
| .add_location(step.location().primary()) | ||
| .confidence(Confidence::High) | ||
| .severity(crate::finding::Severity::High) | ||
| .persona(Persona::Pedantic) | ||
| .build(step.workflow())?, | ||
| ); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| --- | ||
| source: tests/integration/snapshot.rs | ||
| expression: "zizmor().input(input_under_test(\"secrets-outside-environment.yml\")).run()?" | ||
| --- | ||
| error[secrets-outside-environment]: secrets used without an environment to gate them | ||
| --> @@INPUT@@:7:9 | ||
| | | ||
| 7 | - uses: actions_repo/actions/docker@13c8cf37e54dd9488afe8c067575444cc58bf155 | ||
| | _________^ | ||
| 8 | | with: | ||
| 9 | | # NOT OK: Anyone with write access can exfiltrate this secret. | ||
| 10 | | password: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
| | |______________________________________________________^ this step | ||
| | | ||
| = note: audit confidence → High | ||
|
|
||
| 1 finding: 0 unknown, 0 informational, 0 low, 0 medium, 1 high |
aldur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| on: push | ||
| permissions: {} | ||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions_repo/actions/docker@13c8cf37e54dd9488afe8c067575444cc58bf155 | ||
| with: | ||
| # NOT OK: Anyone with write access can exfiltrate this secret. | ||
| password: ${{ secrets.DOCKERHUB_PASSWORD }} |
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.
I'm trying to make new audit names a bit shorter, so some ideas here:
secret-outside-envsecret-without-envsecret-missing-envsecret-no-env(shortest, but maybe not easy to understand)Curious if you have any other naming thoughts as well 🙂
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.
Picked number 2 and fixed in
96c90ac.