1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use github_actions_models::{
common::expr::ExplicitExpr,
workflow::job::{Container, DockerCredentials},
};
use super::{Audit, AuditLoadError, Job, audit_meta};
use crate::{
audit::AuditError,
finding::{Confidence, Severity, location::Locatable as _},
state::AuditState,
};
pub(crate) struct HardcodedContainerCredentials;
audit_meta!(
HardcodedContainerCredentials,
"hardcoded-container-credentials",
"hardcoded credential in GitHub Actions container configurations"
);
#[async_trait::async_trait]
impl Audit for HardcodedContainerCredentials {
fn new(_state: &AuditState) -> Result<Self, AuditLoadError>
where
Self: Sized,
{
Ok(Self)
}
async fn audit_workflow<'doc>(
&self,
workflow: &'doc crate::models::workflow::Workflow,
_config: &crate::config::Config,
) -> Result<Vec<crate::finding::Finding<'doc>>, AuditError> {
let mut findings = vec![];
for job in workflow.jobs() {
let Job::NormalJob(job) = &job else {
continue;
};
if let Some(Container::Container {
image: _,
credentials:
Some(DockerCredentials {
username: _,
password: Some(password),
}),
..
}) = &job.container
{
// If the password doesn't parse as an expression, it's hardcoded.
if ExplicitExpr::from_curly(password).is_none() {
findings.push(
Self::finding()
.severity(Severity::High)
.confidence(Confidence::High)
.add_location(
job.location()
.primary()
.with_keys(["container".into(), "credentials".into()])
.annotated("container registry password is hard-coded"),
)
.build(workflow)?,
)
}
}
for (service, config) in job.services.iter() {
if let Container::Container {
image: _,
credentials:
Some(DockerCredentials {
username: _,
password: Some(password),
}),
..
} = &config
&& ExplicitExpr::from_curly(password).is_none()
{
findings.push(
Self::finding()
.severity(Severity::High)
.confidence(Confidence::High)
.add_location(
job.location()
.primary()
.with_keys([
"services".into(),
service.as_str().into(),
"credentials".into(),
])
.annotated(format!(
"service {service}: container registry password is \
hard-coded"
)),
)
.build(workflow)
.map_err(Self::err)?,
)
}
}
}
Ok(findings)
}
}