-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MVP HardcodedContainerCredentials check
- Loading branch information
Showing
3 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,101 @@ | ||
use std::ops::Deref; | ||
|
||
use github_actions_models::{ | ||
common::Expression, | ||
workflow::{ | ||
job::{Container, DockerCredentials}, | ||
Job, | ||
}, | ||
}; | ||
|
||
use crate::{ | ||
finding::{Confidence, Severity}, | ||
models::AuditConfig, | ||
}; | ||
|
||
use super::WorkflowAudit; | ||
|
||
pub(crate) struct HardcodedContainerCredentials<'a> { | ||
pub(crate) _config: AuditConfig<'a>, | ||
} | ||
|
||
impl<'a> WorkflowAudit<'a> for HardcodedContainerCredentials<'a> { | ||
fn ident() -> &'static str | ||
where | ||
Self: Sized, | ||
{ | ||
"hardcoded-container-credentials" | ||
} | ||
|
||
fn new(config: crate::models::AuditConfig<'a>) -> anyhow::Result<Self> | ||
where | ||
Self: Sized, | ||
{ | ||
Ok(Self { _config: config }) | ||
} | ||
|
||
fn audit<'w>( | ||
&self, | ||
workflow: &'w crate::models::Workflow, | ||
) -> anyhow::Result<Vec<crate::finding::Finding<'w>>> { | ||
let mut findings = vec![]; | ||
|
||
for job in workflow.jobs() { | ||
let Job::NormalJob(normal) = job.deref() else { | ||
continue; | ||
}; | ||
|
||
if let Some(Container::Container { | ||
image: _, | ||
credentials: | ||
Some(DockerCredentials { | ||
username: _, | ||
password: Some(password), | ||
}), | ||
.. | ||
}) = &normal.container | ||
{ | ||
// If the password doesn't parse as an expression, it's hardcoded. | ||
if Expression::from_curly(password.into()).is_none() { | ||
findings.push( | ||
Self::finding() | ||
.severity(Severity::High) | ||
.confidence(Confidence::High) | ||
.add_location( | ||
job.location() | ||
.annotated("container registry password is hard-coded"), | ||
) | ||
.build(workflow)?, | ||
) | ||
} | ||
} | ||
|
||
for (service, config) in normal.services.iter() { | ||
if let Container::Container { | ||
image: _, | ||
credentials: | ||
Some(DockerCredentials { | ||
username: _, | ||
password: Some(password), | ||
}), | ||
.. | ||
} = &config | ||
{ | ||
if Expression::from_curly(password.into()).is_none() { | ||
findings.push( | ||
Self::finding() | ||
.severity(Severity::High) | ||
.confidence(Confidence::High) | ||
.add_location(job.location().annotated(format!( | ||
"service {service}: container registry password is hard-coded" | ||
))) | ||
.build(workflow)?, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
Ok(findings) | ||
} | ||
} |
This file contains 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 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