Skip to content

Commit de40df9

Browse files
authored
fix(misconf): disable DS016 check for image history analyzer (#7540)
Signed-off-by: nikpivkin <[email protected]>
1 parent efdb68d commit de40df9

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

pkg/fanal/analyzer/imgconf/dockerfile/dockerfile.go

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import (
1616
"github.com/aquasecurity/trivy/pkg/misconf"
1717
)
1818

19+
var disabledChecks = []string{
20+
"DS016", // See https://github.com/aquasecurity/trivy/issues/7368
21+
}
22+
1923
const analyzerVersion = 1
2024

2125
func init() {
@@ -27,6 +31,7 @@ type historyAnalyzer struct {
2731
}
2832

2933
func newHistoryAnalyzer(opts analyzer.ConfigAnalyzerOptions) (analyzer.ConfigAnalyzer, error) {
34+
opts.MisconfScannerOption.DisabledCheckIDs = append(opts.MisconfScannerOption.DisabledCheckIDs, disabledChecks...)
3035
s, err := misconf.NewScanner(detection.FileTypeDockerfile, opts.MisconfScannerOption)
3136
if err != nil {
3237
return nil, xerrors.Errorf("misconfiguration scanner error: %w", err)

pkg/fanal/analyzer/imgconf/dockerfile/dockerfile_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,47 @@ func Test_historyAnalyzer_Analyze(t *testing.T) {
284284
Config: nil,
285285
},
286286
},
287+
{
288+
name: "DS016 check not detected",
289+
input: analyzer.ConfigAnalysisInput{
290+
Config: &v1.ConfigFile{
291+
Config: v1.Config{
292+
Healthcheck: &v1.HealthConfig{
293+
Test: []string{"CMD-SHELL", "curl --fail http://localhost:3000 || exit 1"},
294+
Interval: time.Second * 10,
295+
Timeout: time.Second * 3,
296+
},
297+
},
298+
History: []v1.History{
299+
{
300+
// duplicate command from another layer
301+
CreatedBy: `/bin/sh -c #(nop) CMD [\"/bin/bash\"]`,
302+
EmptyLayer: true,
303+
},
304+
{
305+
CreatedBy: "/bin/sh -c #(nop) ADD file:e4d600fc4c9c293efe360be7b30ee96579925d1b4634c94332e2ec73f7d8eca1 in /",
306+
},
307+
{
308+
CreatedBy: `HEALTHCHECK &{["CMD-SHELL" "curl --fail http://localhost:3000 || exit 1"] "10s" "3s" "0s" '\x00'}`,
309+
},
310+
{
311+
CreatedBy: `USER user`,
312+
EmptyLayer: true,
313+
},
314+
{
315+
CreatedBy: `/bin/sh -c #(nop) CMD [\"/bin/sh\"]`,
316+
EmptyLayer: true,
317+
},
318+
},
319+
},
320+
},
321+
want: &analyzer.ConfigAnalysisResult{
322+
Misconfiguration: &types.Misconfiguration{
323+
FileType: types.Dockerfile,
324+
FilePath: "Dockerfile",
325+
},
326+
},
327+
},
287328
}
288329
for _, tt := range tests {
289330
t.Run(tt.name, func(t *testing.T) {

pkg/misconf/scanner.go

+3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ type ScannerOption struct {
7474

7575
FilePatterns []string
7676
ConfigFileSchemas []*ConfigFileSchema
77+
78+
DisabledCheckIDs []string
7779
}
7880

7981
func (o *ScannerOption) Sort() {
@@ -212,6 +214,7 @@ func scannerOptions(t detection.FileType, opt ScannerOption) ([]options.ScannerO
212214
rego.WithEmbeddedPolicies(!opt.DisableEmbeddedPolicies),
213215
rego.WithEmbeddedLibraries(!opt.DisableEmbeddedLibraries),
214216
options.ScannerWithIncludeDeprecatedChecks(opt.IncludeDeprecatedChecks),
217+
rego.WithDisabledCheckIDs(opt.DisabledCheckIDs...),
215218
}
216219

217220
policyFS, policyPaths, err := CreatePolicyFS(opt.PolicyPaths)

0 commit comments

Comments
 (0)