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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//! DOCKER007: Shell entrypoint detection (F061)
//!
//! **Rule**: Detect Dockerfiles that use shell as entrypoint
//!
//! **Why this matters**:
//! Using shell as ENTRYPOINT defeats the purpose of containerization.
//! Containers should run a single process, not a shell.
//!
//! ## Examples
//!
//! ❌ **BAD** (shell entrypoint):
//! ```dockerfile
//! ENTRYPOINT ["/bin/sh"]
//! ENTRYPOINT ["/bin/bash"]
//! ```
//!
//! ✅ **GOOD** (direct process):
//! ```dockerfile
//! ENTRYPOINT ["/app"]
//! ENTRYPOINT ["python", "app.py"]
//! ```
use crate::linter::{Diagnostic, LintResult, Severity, Span};
/// Shell paths that indicate shell entrypoint
const SHELL_PATHS: &[&str] = &[
"/bin/sh",
"/bin/bash",
"/bin/ash",
"/bin/dash",
"/bin/zsh",
"sh",
"bash",
"ash",
"dash",
"zsh",
];
/// Check for shell entrypoints in Dockerfiles
pub fn check(source: &str) -> LintResult {
let mut result = LintResult::new();
for (line_num, line) in source.lines().enumerate() {
let trimmed = line.trim();
// Check ENTRYPOINT directive
if trimmed.starts_with("ENTRYPOINT ") {
let rest = trimmed.strip_prefix("ENTRYPOINT ").unwrap_or("");
// Check exec form: ENTRYPOINT ["sh", ...] or ENTRYPOINT ["/bin/sh", ...]
if rest.starts_with('[') {
for shell in SHELL_PATHS {
let patterns = [
format!("[\"{}\"]", shell),
format!("[\"{}\"", shell),
format!("['{}'", shell),
];
for pattern in &patterns {
if rest.contains(pattern) {
let span =
Span::new(line_num + 1, 1, line_num + 1, trimmed.len().min(80));
let diag = Diagnostic::new(
"DOCKER007",
Severity::Warning,
format!(
"Shell entrypoint '{}' detected - consider using direct process (F061)",
shell
),
span,
);
result.add(diag);
break;
}
}
}
}
// Check shell form: ENTRYPOINT /bin/sh
else {
for shell in SHELL_PATHS {
if rest.trim() == *shell || rest.starts_with(&format!("{} ", shell)) {
let span = Span::new(line_num + 1, 1, line_num + 1, trimmed.len().min(80));
let diag = Diagnostic::new(
"DOCKER007",
Severity::Warning,
format!(
"Shell entrypoint '{}' detected - consider using direct process (F061)",
shell
),
span,
);
result.add(diag);
break;
}
}
}
}
}
result
}
#[cfg(test)]
mod tests {
use super::*;
/// F061: Detects shell entrypoints
#[test]
fn test_F061_shell_entrypoint_exec_form() {
let dockerfile = r#"FROM debian:12-slim
ENTRYPOINT ["/bin/sh"]"#;
let result = check(dockerfile);
assert_eq!(
result.diagnostics.len(),
1,
"F061: Should detect /bin/sh entrypoint"
);
assert_eq!(result.diagnostics[0].code, "DOCKER007");
}
#[test]
fn test_F061_shell_entrypoint_bash() {
let dockerfile = r#"FROM debian:12-slim
ENTRYPOINT ["/bin/bash"]"#;
let result = check(dockerfile);
assert_eq!(
result.diagnostics.len(),
1,
"F061: Should detect /bin/bash entrypoint"
);
}
#[test]
fn test_F061_shell_entrypoint_shell_form() {
let dockerfile = r#"FROM debian:12-slim
ENTRYPOINT /bin/sh"#;
let result = check(dockerfile);
assert_eq!(
result.diagnostics.len(),
1,
"F061: Should detect shell form entrypoint"
);
}
#[test]
fn test_F061_no_warning_direct_process() {
let dockerfile = r#"FROM debian:12-slim
ENTRYPOINT ["/app"]"#;
let result = check(dockerfile);
assert_eq!(
result.diagnostics.len(),
0,
"F061: Should not flag direct process entrypoint"
);
}
#[test]
fn test_F061_no_warning_python() {
let dockerfile = r#"FROM python:3.12-slim
ENTRYPOINT ["python", "app.py"]"#;
let result = check(dockerfile);
assert_eq!(
result.diagnostics.len(),
0,
"F061: Should not flag python entrypoint"
);
}
}