Skip to content

Commit

Permalink
feat: skip-intrusive flag support for skipping node-collector
Browse files Browse the repository at this point in the history
Signed-off-by: chenk <[email protected]>
  • Loading branch information
chen-keinan committed Mar 17, 2024
1 parent 98546fc commit 6b8397e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
5 changes: 2 additions & 3 deletions docs/docs/references/configuration/cli/trivy_kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ trivy kubernetes [flags] { cluster | all | specific resources like kubectl. eg:
--no-progress suppress progress bar
--node-collector-imageref string indicate the image reference for the node-collector scan job (default "ghcr.io/aquasecurity/node-collector:0.0.9")
--node-collector-namespace string specify the namespace in which the node-collector job should be deployed (default "trivy-temp")
--non-intrusive When the flag is activated, the node-collector job will not be executed, thus skipping misconfiguration findings on the node.
--skip-intrusive When the flag is activated, the node-collector job will not be executed, thus skipping misconfiguration findings on the node.
--offline-scan do not issue API requests to identify dependencies
-o, --output string output file name
--output-plugin-arg string [EXPERIMENTAL] output plugin arguments
Expand Down Expand Up @@ -118,5 +118,4 @@ trivy kubernetes [flags] { cluster | all | specific resources like kubectl. eg:

### SEE ALSO

* [trivy](trivy.md) - Unified security scanner

* [trivy](trivy.md) - Unified security scanner
14 changes: 7 additions & 7 deletions pkg/flag/kubernetes_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ var (
Shorthand: "A",
Usage: "fetch resources from all cluster namespaces",
}
NonIntrusive = Flag[bool]{
Name: "non-intrusive",
SkipIntrusive = Flag[bool]{
Name: "skip-intrusive",
ConfigName: "kubernetes.non.intrusive",
Usage: "When the flag is activated, the node-collector job will not be executed, thus skipping misconfiguration findings on the node.",
}
Expand Down Expand Up @@ -106,7 +106,7 @@ type K8sFlagGroup struct {
Components *Flag[[]string]
K8sVersion *Flag[string]
Tolerations *Flag[[]string]
NonIntrusive *Flag[bool]
SkipIntrusive *Flag[bool]
NodeCollectorImageRef *Flag[string]
AllNamespaces *Flag[bool]
NodeCollectorNamespace *Flag[string]
Expand All @@ -127,7 +127,7 @@ type K8sOptions struct {
AllNamespaces bool
NodeCollectorNamespace string
ExcludeOwned bool
NonIntrusive bool
SkipIntrusive bool
ExcludeNodes map[string]string
QPS float32
Burst int
Expand All @@ -141,7 +141,7 @@ func NewK8sFlagGroup() *K8sFlagGroup {
Components: ComponentsFlag.Clone(),
K8sVersion: K8sVersionFlag.Clone(),
Tolerations: TolerationsFlag.Clone(),
NonIntrusive: NonIntrusive.Clone(),
SkipIntrusive: SkipIntrusive.Clone(),
AllNamespaces: AllNamespaces.Clone(),
NodeCollectorNamespace: NodeCollectorNamespace.Clone(),
ExcludeOwned: ExcludeOwned.Clone(),
Expand All @@ -163,7 +163,7 @@ func (f *K8sFlagGroup) Flags() []Flagger {
f.KubeConfig,
f.Components,
f.K8sVersion,
f.NonIntrusive,
f.SkipIntrusive,
f.Tolerations,
f.AllNamespaces,
f.NodeCollectorNamespace,
Expand Down Expand Up @@ -202,7 +202,7 @@ func (f *K8sFlagGroup) ToOptions() (K8sOptions, error) {
Components: f.Components.Value(),
K8sVersion: f.K8sVersion.Value(),
Tolerations: tolerations,
NonIntrusive: f.NonIntrusive.Value(),
SkipIntrusive: f.SkipIntrusive.Value(),
AllNamespaces: f.AllNamespaces.Value(),
NodeCollectorNamespace: f.NodeCollectorNamespace.Value(),
ExcludeOwned: f.ExcludeOwned.Value(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/k8s/commands/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func clusterRun(ctx context.Context, opts flag.Options, cluster k8s.Cluster) err
return xerrors.Errorf("get k8s artifacts with node info error: %w", err)
}
case types.FormatJSON, types.FormatTable:
if opts.Scanners.AnyEnabled(types.MisconfigScanner) && !opts.NonIntrusive {
if opts.Scanners.AnyEnabled(types.MisconfigScanner) && !opts.SkipIntrusive {
artifacts, err = trivyk8s.New(cluster, log.Logger, trivyk8s.WithExcludeOwned(opts.ExcludeOwned)).ListArtifactAndNodeInfo(ctx,
trivyk8s.WithScanJobNamespace(opts.NodeCollectorNamespace),
trivyk8s.WithIgnoreLabels(opts.ExcludeNodes),
Expand Down

0 comments on commit 6b8397e

Please sign in to comment.