Skip to content

Commit e739ab8

Browse files
authored
feat: support --skip-images scanning flag (aquasecurity#6334)
Signed-off-by: chenk <[email protected]>
1 parent c6d5d85 commit e739ab8

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

docs/docs/references/configuration/cli/trivy_kubernetes.md

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ trivy kubernetes [flags] [CONTEXT]
9696
--skip-db-update skip updating vulnerability database
9797
--skip-dirs strings specify the directories or glob patterns to skip
9898
--skip-files strings specify the files or glob patterns to skip
99+
--skip-images skip the downloading and scanning of images (vulnerabilities and secrets) in the cluster resources
99100
--skip-java-db-update skip updating Java index database
100101
--skip-policy-update skip fetching rego policy updates
101102
-t, --template string output template

pkg/flag/kubernetes_flags.go

+10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ var (
4747
ConfigName: "kubernetes.exclude.owned",
4848
Usage: "exclude resources that have an owner reference",
4949
}
50+
SkipImages = Flag[bool]{
51+
Name: "skip-images",
52+
ConfigName: "kubernetes.skipImages",
53+
Usage: "skip the downloading and scanning of images (vulnerabilities and secrets) in the cluster resources",
54+
}
5055
ExcludeNodes = Flag[[]string]{
5156
Name: "exclude-nodes",
5257
ConfigName: "kubernetes.exclude.nodes",
@@ -95,6 +100,7 @@ type K8sFlagGroup struct {
95100
NodeCollectorImageRef *Flag[string]
96101
NodeCollectorNamespace *Flag[string]
97102
ExcludeOwned *Flag[bool]
103+
SkipImages *Flag[bool]
98104
ExcludeNodes *Flag[[]string]
99105
ExcludeKinds *Flag[[]string]
100106
IncludeKinds *Flag[[]string]
@@ -118,6 +124,7 @@ type K8sOptions struct {
118124
ExcludeNamespaces []string
119125
IncludeNamespaces []string
120126
QPS float32
127+
SkipImages bool
121128
Burst int
122129
}
123130

@@ -136,6 +143,7 @@ func NewK8sFlagGroup() *K8sFlagGroup {
136143
IncludeNamespaces: IncludeNamespaces.Clone(),
137144
NodeCollectorImageRef: NodeCollectorImageRef.Clone(),
138145
QPS: QPS.Clone(),
146+
SkipImages: SkipImages.Clone(),
139147
Burst: Burst.Clone(),
140148
}
141149
}
@@ -159,6 +167,7 @@ func (f *K8sFlagGroup) Flags() []Flagger {
159167
f.ExcludeNamespaces,
160168
f.IncludeNamespaces,
161169
f.QPS,
170+
f.SkipImages,
162171
f.Burst,
163172
}
164173
}
@@ -199,6 +208,7 @@ func (f *K8sFlagGroup) ToOptions() (K8sOptions, error) {
199208
ExcludeNodes: exludeNodeLabels,
200209
NodeCollectorImageRef: f.NodeCollectorImageRef.Value(),
201210
QPS: float32(f.QPS.Value()),
211+
SkipImages: f.SkipImages.Value(),
202212
ExcludeKinds: f.ExcludeKinds.Value(),
203213
IncludeKinds: f.IncludeKinds.Value(),
204214
ExcludeNamespaces: f.ExcludeNamespaces.Value(),

pkg/k8s/scanner/scanner.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (s *Scanner) Scan(ctx context.Context, artifactsData []*artifacts.Artifact)
8989

9090
onItem := func(ctx context.Context, artifact *artifacts.Artifact) (scanResult, error) {
9191
scanResults := scanResult{}
92-
if s.opts.Scanners.AnyEnabled(types.VulnerabilityScanner, types.SecretScanner) {
92+
if s.opts.Scanners.AnyEnabled(types.VulnerabilityScanner, types.SecretScanner) && !s.opts.SkipImages {
9393
opts := s.opts
9494
opts.Credentials = make([]ftypes.Credential, len(s.opts.Credentials))
9595
copy(opts.Credentials, s.opts.Credentials)

0 commit comments

Comments
 (0)