Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

✨ Adds ability to not filter CRDS, see ISSUE #373 #374

Merged
merged 2 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ coverage.txt
*.swp
/vendor
/.vscode
.go-version
6 changes: 4 additions & 2 deletions cmd/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type rootFlags struct {
namespace string
minSeverity string
exitCode int
includegenerated bool
}

// RootCmd defines the shell command usage for kubeaudit.
Expand Down Expand Up @@ -50,6 +51,7 @@ func init() {
RootCmd.PersistentFlags().StringVarP(&rootConfig.minSeverity, "minseverity", "m", "info", "Set the lowest severity level to report (one of \"error\", \"warning\", \"info\")")
RootCmd.PersistentFlags().StringVarP(&rootConfig.format, "format", "p", "pretty", "The output format to use (one of \"pretty\", \"logrus\", \"json\")")
RootCmd.PersistentFlags().StringVarP(&rootConfig.namespace, "namespace", "n", apiv1.NamespaceAll, "Only audit resources in the specified namespace. Not currently supported in manifest mode.")
RootCmd.PersistentFlags().BoolVarP(&rootConfig.includegenerated, "includegenerated", "g", false, "Include generated resources in scan (eg. pods generated by deployments).")
RootCmd.PersistentFlags().StringVarP(&rootConfig.manifest, "manifest", "f", "", "Path to the yaml configuration to audit. Only used in manifest mode.")
RootCmd.PersistentFlags().IntVarP(&rootConfig.exitCode, "exitcode", "e", 2, "Exit code to use if there are results with severity of \"error\". Conventionally, 0 is used for success and all non-zero codes for an error.")
}
Expand Down Expand Up @@ -101,14 +103,14 @@ func getReport(auditors ...kubeaudit.Auditable) *kubeaudit.Report {
}

if k8sinternal.IsRunningInCluster(k8sinternal.DefaultClient) && rootConfig.kubeConfig == "" {
report, err := auditor.AuditCluster(k8sinternal.ClientOptions{Namespace: rootConfig.namespace})
report, err := auditor.AuditCluster(k8sinternal.ClientOptions{Namespace: rootConfig.namespace, IncludeGenerated: rootConfig.includegenerated})
if err != nil {
log.WithError(err).Fatal("Error auditing cluster")
}
return report
}

report, err := auditor.AuditLocal(rootConfig.kubeConfig, kubeaudit.AuditOptions{Namespace: rootConfig.namespace})
report, err := auditor.AuditLocal(rootConfig.kubeConfig, kubeaudit.AuditOptions{Namespace: rootConfig.namespace, IncludeGenerated: rootConfig.includegenerated})
if err != nil {
log.WithError(err).Fatal("Error auditing cluster in local mode")
}
Expand Down
6 changes: 4 additions & 2 deletions internal/k8sinternal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func IsRunningInCluster(client Client) bool {
type ClientOptions struct {
// Namespace filters resources by namespace. Defaults to all namespaces.
Namespace string
IncludeGenerated bool
}

// GetAllResources gets all supported resources from the cluster
Expand All @@ -103,8 +104,9 @@ func GetAllResources(clientset kubernetes.Interface, options ClientOptions) []k8
resources = append(resources, GetNamespaces(clientset, options)...)
resources = append(resources, GetServices(clientset, options)...)
resources = append(resources, GetJobs(clientset, options)...)

resources = excludeGenerated(resources)
if options.IncludeGenerated == false {
resources = excludeGenerated(resources)
}

return resources
}
Expand Down