-
-
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
Open
aldur
wants to merge
14
commits into
zizmorcore:main
Choose a base branch
from
aldur:feat/secrets_outside_env
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3e9f0ad
feat: Audit secrets outside an environment
aldur 13f9213
Add TODO
aldur acaaef1
Make name more generic
aldur 992b15b
Add snapshot test
aldur 1d5b2df
Switch to `audit_step` and handle expressions
aldur 6b963b6
Add `environment` to `use-trusted-publishing.yml`
aldur 13c8cf3
Merge branch 'main' into feat/secrets_outside_env
aldur 2ae5791
Fix `merge`
aldur cf1b0e5
Update to `Audit` from `main`
aldur 0132617
Update integration tests and snaps
aldur 5a3bfe6
Merge branch 'main' into feat/secrets_outside_env
aldur f328751
Make this a pedantic audit
aldur 96c90ac
Rename to `secret_without_env`
aldur b5dab62
Whitelist `secrets.github_token`
aldur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| use github_actions_models::{ | ||
| common::{expr::LoE, Env, EnvValue}, | ||
| workflow::job::StepBody, | ||
| }; | ||
|
|
||
| use super::{audit_meta, Audit}; | ||
| use crate::{finding::Confidence, models::Job}; | ||
|
|
||
| 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: super::AuditState) -> anyhow::Result<Self> | ||
| where | ||
| Self: Sized, | ||
| { | ||
| Ok(Self) | ||
| } | ||
|
|
||
| fn audit_raw<'w>( | ||
aldur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| &self, | ||
| input: &'w super::AuditInput, | ||
| ) -> anyhow::Result<Vec<crate::finding::Finding<'w>>> { | ||
| let mut findings = vec![]; | ||
|
|
||
| if let super::AuditInput::Workflow(w) = input { | ||
| for job in w.jobs() { | ||
| if let Job::NormalJob(j) = job { | ||
| if j.environment().is_some() { | ||
| continue; | ||
| } | ||
|
|
||
| for step in j.steps() { | ||
| let body = &step.body; | ||
| let eenv: &Env; | ||
|
|
||
| match body { | ||
| StepBody::Uses { uses: _, with } => { | ||
| eenv = with; | ||
| } | ||
| StepBody::Run { | ||
| run: _, | ||
| shell: _, | ||
| env, | ||
| working_directory: _, | ||
| } => match env { | ||
| LoE::Expr(_) => { | ||
| // TODO: Implement this. | ||
| panic!("We don't handle Expr yet!") | ||
aldur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| LoE::Literal(env) => eenv = env, | ||
| }, | ||
| } | ||
|
|
||
| for v in eenv.values() { | ||
| if let EnvValue::String(s) = v { | ||
| if s.contains("secrets") { | ||
| findings.push( | ||
| Self::finding() | ||
| .add_location(step.location().primary()) | ||
| .confidence(Confidence::High) | ||
| .severity(crate::finding::Severity::High) | ||
| .build(input)?, | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Ok(findings) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
tests/integration/test-data/secrets-outside-environment.yml
aldur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| name: Action | ||
| on: push | ||
| jobs: | ||
| build: | ||
| name: Job | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Docker setup | ||
| uses: actions_repo/actions/docker@main | ||
| with: | ||
| username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
| password: ${{ secrets.DOCKERHUB_PASSWORD }} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.