-
-
Notifications
You must be signed in to change notification settings - Fork 116
Feature: Require or recommend the timeout-minutes property for all jobs #1023 #1067
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 all commits
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,62 @@ | ||||||
| use anyhow::Result; | ||||||
|
|
||||||
| use crate::{ | ||||||
| finding::{ | ||||||
| Confidence, Finding, Persona, Severity, | ||||||
| location::{Locatable as _, SymbolicLocation}, | ||||||
| }, | ||||||
| models::workflow::JobExt as _, | ||||||
| state::AuditState, | ||||||
| }; | ||||||
|
|
||||||
| use super::{Audit, AuditLoadError, audit_meta}; | ||||||
|
|
||||||
| pub(crate) struct TimeoutMinutes; | ||||||
|
|
||||||
| impl TimeoutMinutes { | ||||||
| fn build_finding<'doc>( | ||||||
| &self, | ||||||
| location: SymbolicLocation<'doc>, | ||||||
| annotation: &str, | ||||||
| job: &super::NormalJob<'doc>, | ||||||
| ) -> Result<Finding<'doc>> { | ||||||
| let mut annotated_location = location; | ||||||
| annotated_location = annotated_location.annotated(annotation); | ||||||
| Self::finding() | ||||||
| .severity(Severity::Medium) | ||||||
| .confidence(Confidence::High) | ||||||
| .add_location(annotated_location) | ||||||
| .persona(Persona::Pedantic) | ||||||
| .build(job.parent()) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| audit_meta!( | ||||||
| TimeoutMinutes, | ||||||
| "timeout-minutes", | ||||||
| "missing timeout-minutes on jobs" | ||||||
| ); | ||||||
|
|
||||||
| impl Audit for TimeoutMinutes { | ||||||
| fn new(_state: &AuditState<'_>) -> Result<Self, AuditLoadError> { | ||||||
| Ok(Self) | ||||||
| } | ||||||
|
|
||||||
| fn audit_normal_job<'doc>( | ||||||
| &self, | ||||||
| job: &super::NormalJob<'doc>, | ||||||
| ) -> anyhow::Result<Vec<Finding<'doc>>> { | ||||||
| let mut findings = vec![]; | ||||||
|
|
||||||
| // Check if timeout-minutes is missing | ||||||
| if job.timeout_minutes.is_none() { | ||||||
| findings.push(self.build_finding( | ||||||
| job.location().primary(), | ||||||
| "job is missing timeout-minutes", | ||||||
|
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.
Suggested change
|
||||||
| job, | ||||||
| )?); | ||||||
| } | ||||||
|
|
||||||
| Ok(findings) | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,13 @@ | |
| //! audits. | ||
|
|
||
| use std::{ | ||
| collections::{BTreeMap, btree_map}, | ||
| collections::{btree_map, BTreeMap}, | ||
| fmt::Display, | ||
| process::ExitCode, | ||
| str::FromStr, | ||
| }; | ||
|
|
||
| use anyhow::{Context, anyhow}; | ||
| use anyhow::{anyhow, Context}; | ||
| use camino::{Utf8Path, Utf8PathBuf}; | ||
| use indexmap::IndexMap; | ||
| use serde::Serialize; | ||
|
|
@@ -352,6 +352,7 @@ impl AuditRegistry { | |
| register_audit!(audit::self_hosted_runner::SelfHostedRunner); | ||
| register_audit!(audit::known_vulnerable_actions::KnownVulnerableActions); | ||
| register_audit!(audit::unpinned_uses::UnpinnedUses); | ||
| register_audit!(audit::timeout_minutes::TimeoutMinutes); | ||
|
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. Move this to the end, please -- right now these are declared in order of introduction, not alphabetically. |
||
| register_audit!(audit::insecure_commands::InsecureCommands); | ||
| register_audit!(audit::github_env::GitHubEnv); | ||
| register_audit!(audit::cache_poisoning::CachePoisoning); | ||
|
|
||
|
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. This should probably be moved under |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| name: Test Workflow | ||
| on: push | ||
|
|
||
| jobs: | ||
| test-job: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - run: echo "Hello World" |
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.
This approach looks right to me! Let's do the same for each step in the job as well 🙂