-
-
Notifications
You must be signed in to change notification settings - Fork 124
Check for timeout-minutes in jobs and steps
#1347
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
joewallwork
wants to merge
10
commits into
zizmorcore:main
Choose a base branch
from
joewallwork:1023_timeout
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 all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e3bdefb
Feature: Require or recommend the timeout-minutes property for all jo…
EmmanuelBerkowicz f0c3711
Merge branch 'zizmorcore:main' into main
EmmanuelBerkowicz 73484d1
Apply @woodruffw suggestions from #1067
joewallwork 7b9571a
Merge branch 'main' into 1023_timeout
joewallwork b87f936
Rework TimeoutMinutes like ConcurrencyLimits
joewallwork 8c77d42
Account for steps as well as the job
joewallwork 1b53931
Update test workflow
joewallwork a8dcfb5
Update test data and snapshots
joewallwork e3dced0
Neater approach using a labelled match arm
joewallwork f9a4803
Separate out audit_step
joewallwork 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,113 @@ | ||
| use super::{Audit, AuditLoadError, audit_meta}; | ||
| use crate::{ | ||
| audit::AuditError, | ||
| config::Config, | ||
| finding::{ | ||
| Confidence, Finding, Persona, Severity, | ||
| location::Locatable as _, | ||
| }, | ||
| models::workflow::JobExt as _, | ||
| state::AuditState, | ||
| }; | ||
|
|
||
| pub(crate) struct TimeoutMinutes; | ||
|
|
||
| audit_meta!( | ||
| TimeoutMinutes, | ||
| "timeout-minutes", | ||
| "missing timeout-minutes" | ||
| ); | ||
|
|
||
| #[async_trait::async_trait] | ||
| impl Audit for TimeoutMinutes { | ||
| fn new(_state: &AuditState) -> Result<Self, AuditLoadError> { | ||
| Ok(Self) | ||
| } | ||
|
|
||
| async fn audit_normal_job<'doc>( | ||
| &self, | ||
| job: &super::NormalJob<'doc>, | ||
| _config: &Config, | ||
| ) -> anyhow::Result<Vec<Finding<'doc>>, AuditError> { | ||
| let mut findings = vec![]; | ||
|
|
||
| // Check if timeout-minutes is set in the job | ||
| match &job.timeout_minutes { | ||
| None => 'label: { | ||
| // If not, check if it's set in any of the job's steps | ||
| for step in job.steps() { | ||
| match &step.timeout_minutes { | ||
| Some(_) => { | ||
| // If so, the job doesn't need to set it | ||
| break 'label; | ||
| } | ||
| None => {} | ||
| } | ||
| } | ||
| findings.push( | ||
| Self::finding() | ||
| .confidence(Confidence::High) | ||
| .severity(Severity::Medium) | ||
| .persona(Persona::Pedantic) | ||
| .add_location( | ||
| job | ||
| .location() | ||
| .primary() | ||
| .annotated("job missing timeout-minutes"), | ||
| ) | ||
| .build(job.parent())?, | ||
| ); | ||
| }, | ||
| _ => {} | ||
| } | ||
|
|
||
| Ok(findings) | ||
| } | ||
|
|
||
| async fn audit_step<'doc>( | ||
| &self, | ||
| step: &super::Step<'doc>, | ||
| _config: &Config, | ||
| ) -> anyhow::Result<Vec<Finding<'doc>>, AuditError> { | ||
| let mut findings = vec![]; | ||
|
|
||
| // Check if timeout-minutes is set in the step | ||
| match &step.timeout_minutes { | ||
| None => 'label: { | ||
| // If not, check if it's set by its parent job | ||
| let job = &step.parent; | ||
| match &job.timeout_minutes { | ||
| None => { | ||
| // If not, check if it's set in any of the job's other steps | ||
| for other_step in job.steps() { | ||
| match &other_step.timeout_minutes { | ||
| Some(_) => { | ||
| // If so, this job should set it, too | ||
| findings.push( | ||
| Self::finding() | ||
| .confidence(Confidence::High) | ||
| .severity(Severity::Medium) | ||
| .persona(Persona::Pedantic) | ||
| .add_location( | ||
| step | ||
| .location() | ||
| .primary() | ||
| .annotated("step missing timeout-minutes"), | ||
| ) | ||
| .build(step)?, | ||
| ); | ||
| break 'label; | ||
| } | ||
| None => {} | ||
| } | ||
| } | ||
| }, | ||
| _ => {} | ||
| } | ||
| }, | ||
| _ => {} | ||
| } | ||
|
|
||
| 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
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
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
3 changes: 2 additions & 1 deletion
3
crates/zizmor/tests/integration/snapshots/integration__config__disablement.snap
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 |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| --- | ||
| source: crates/zizmor/tests/integration/config.rs | ||
| assertion_line: 183 | ||
| expression: "zizmor().input(input_under_test(\"config-scenarios/disablement\")).setenv(\"RUST_LOG\",\n\"zizmor::audit=debug\").output(OutputMode::Both).run()?" | ||
| --- | ||
| 🌈 zizmor v@@VERSION@@ | ||
| DEBUG audit{input=Workflow(file://@@INPUT@@/.github/workflows/hackme.yml)}: zizmor::audit: skipping: template-injection is disabled in config for group Group("@@INPUT@@") | ||
| No findings to report. Good job! (1 suppressed) | ||
| No findings to report. Good job! (2 suppressed) |
3 changes: 2 additions & 1 deletion
3
...izmor/tests/integration/snapshots/integration__config__discovers_config_in_dotgithub.snap
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 |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| --- | ||
| source: crates/zizmor/tests/integration/config.rs | ||
| assertion_line: 116 | ||
| expression: "zizmor().input(input_under_test(\"config-scenarios/config-in-dotgithub\")).setenv(\"RUST_LOG\",\n\"zizmor::config=debug\").output(OutputMode::Both).run()?" | ||
| --- | ||
| 🌈 zizmor v@@VERSION@@ | ||
| DEBUG zizmor::config: discovering config for local input `@@INPUT@@` | ||
| DEBUG zizmor::config: attempting config discovery in `@@INPUT@@` | ||
| DEBUG zizmor::config: found config candidate at `@@INPUT@@/.github/zizmor.yml` | ||
| No findings to report. Good job! (1 ignored, 2 suppressed) | ||
| No findings to report. Good job! (1 ignored, 3 suppressed) |
3 changes: 2 additions & 1 deletion
3
...gration/snapshots/integration__config__discovers_config_in_dotgithub_from_file_input.snap
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 |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| --- | ||
| source: crates/zizmor/tests/integration/config.rs | ||
| assertion_line: 133 | ||
| expression: "zizmor().input(input_under_test(\"config-scenarios/config-in-dotgithub/.github/workflows/hackme.yml\")).setenv(\"RUST_LOG\",\n\"zizmor::config=debug\").output(OutputMode::Both).run()?" | ||
| --- | ||
| 🌈 zizmor v@@VERSION@@ | ||
| DEBUG zizmor::config: discovering config for local input `@@INPUT@@` | ||
| DEBUG zizmor::config: attempting config discovery in `@@TEST_PREFIX@@/config-scenarios/config-in-dotgithub/.github/workflows` | ||
| DEBUG zizmor::config: found config candidate at `@@TEST_PREFIX@@/config-scenarios/config-in-dotgithub/.github/zizmor.yml` | ||
| No findings to report. Good job! (1 ignored, 2 suppressed) | ||
| No findings to report. Good job! (1 ignored, 3 suppressed) |
3 changes: 2 additions & 1 deletion
3
crates/zizmor/tests/integration/snapshots/integration__config__discovers_config_in_root.snap
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 |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| --- | ||
| source: crates/zizmor/tests/integration/config.rs | ||
| assertion_line: 10 | ||
| expression: "zizmor().input(input_under_test(\"config-scenarios/config-in-root\")).setenv(\"RUST_LOG\",\n\"zizmor::config=debug\").output(OutputMode::Both).run()?" | ||
| --- | ||
| 🌈 zizmor v@@VERSION@@ | ||
| DEBUG zizmor::config: discovering config for local input `@@INPUT@@` | ||
| DEBUG zizmor::config: attempting config discovery in `@@INPUT@@` | ||
| DEBUG zizmor::config: found config candidate at `@@INPUT@@/zizmor.yml` | ||
| No findings to report. Good job! (1 ignored, 2 suppressed) | ||
| No findings to report. Good job! (1 ignored, 3 suppressed) |
3 changes: 2 additions & 1 deletion
3
...s/integration/snapshots/integration__config__discovers_config_in_root_from_child_dir.snap
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 |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| --- | ||
| source: crates/zizmor/tests/integration/config.rs | ||
| assertion_line: 46 | ||
| expression: "zizmor().input(input_under_test(\"config-scenarios/config-in-root/.github/workflows\")).setenv(\"RUST_LOG\",\n\"zizmor::config=debug\").output(OutputMode::Both).run()?" | ||
| --- | ||
| 🌈 zizmor v@@VERSION@@ | ||
| DEBUG zizmor::config: discovering config for local input `@@INPUT@@` | ||
| DEBUG zizmor::config: attempting config discovery in `@@INPUT@@` | ||
| DEBUG zizmor::config: found config candidate at `@@TEST_PREFIX@@/config-scenarios/config-in-root/zizmor.yml` | ||
| No findings to report. Good job! (1 ignored, 2 suppressed) | ||
| No findings to report. Good job! (1 ignored, 3 suppressed) |
3 changes: 2 additions & 1 deletion
3
.../integration/snapshots/integration__config__discovers_config_in_root_from_file_input.snap
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 |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| --- | ||
| source: crates/zizmor/tests/integration/config.rs | ||
| assertion_line: 27 | ||
| expression: "zizmor().input(input_under_test(\"config-scenarios/config-in-root/.github/workflows/hackme.yml\")).setenv(\"RUST_LOG\",\n\"zizmor::config=debug\").output(OutputMode::Both).run()?" | ||
| --- | ||
| 🌈 zizmor v@@VERSION@@ | ||
| DEBUG zizmor::config: discovering config for local input `@@INPUT@@` | ||
| DEBUG zizmor::config: attempting config discovery in `@@TEST_PREFIX@@/config-scenarios/config-in-root/.github/workflows` | ||
| DEBUG zizmor::config: found config candidate at `@@TEST_PREFIX@@/config-scenarios/config-in-root/zizmor.yml` | ||
| No findings to report. Good job! (1 ignored, 2 suppressed) | ||
| No findings to report. Good job! (1 ignored, 3 suppressed) |
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
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
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
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
3 changes: 2 additions & 1 deletion
3
crates/zizmor/tests/integration/snapshots/integration__e2e__menagerie.snap
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 |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| --- | ||
| source: crates/zizmor/tests/integration/e2e.rs | ||
| assertion_line: 65 | ||
| expression: "zizmor().output(OutputMode::Both).input(input_under_test(\"e2e-menagerie\")).run()?" | ||
| --- | ||
| 🌈 zizmor v@@VERSION@@ | ||
| INFO audit: zizmor: 🌈 completed @@INPUT@@/.github/dummy-action-2/action.yml | ||
| INFO audit: zizmor: 🌈 completed @@INPUT@@/.github/workflows/another-dummy.yml | ||
| INFO audit: zizmor: 🌈 completed @@INPUT@@/.github/workflows/dummy.yml | ||
| INFO audit: zizmor: 🌈 completed @@INPUT@@/dummy-action-1/action.yaml | ||
| No findings to report. Good job! (2 suppressed) | ||
| No findings to report. Good job! (4 suppressed) |
Oops, something went wrong.
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.
The logic here seems pretty deeply nested 🙂 -- maybe we could do this in a "bubble up" style instead, i.e. use
audit_stepand then check the step's parent (the job) if a timeout is missing?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.
Good suggestion. I separated out
audit_stepin f9a4803 but the logic is still quite complex. I wanted to make sure that we don't get reports for both the job and the step when neither settimeout-minutes. Is there a simpler way?