kubeaudit helps you audit your Kubernetes clusters against common security controls
kubeaudit helps you audit your Kubernetes clusters against common security controls
It is now a requirement for clusters to run Kubernetes >=1.19.
override labels with unregistered
kubernetes.ioannotations will be deprecated. It'll soon be a requirement to usekubeaudit.ioinstead. Refer to this discussion for additional context.
Kubeaudit is planned for deprecation by October 2024.
We are actively seeking maintainers who are interested in taking over the stewardship of this project. If you are passionate about continuing its development and maintenance, please reach out to us.
For users looking for alternatives, we recommend transitioning to Kubebench, which offers similar functionality and is actively maintained.
Thank you to the community for your contributions and support.
kubeaudit is a command line tool and a Go package to audit Kubernetes clusters for various
different security concerns, such as:
tldr. kubeaudit makes sure you deploy secure containers!
To use kubeaudit as a Go package, see the package docs.
The rest of this README will focus on how to use kubeaudit as a command line tool.
brew install kubeauditKubeaudit has official releases that are blessed and stable: Official releases
Main may have newer features than the stable releases. If you need a newer feature not yet included in a release, make sure you're using the latest Go and run the following:
go get -v github.com/Shopify/kubeauditStart using kubeaudit with the Quick Start or view all the supported commands.
Prerequisite: kubectl v1.12.0 or later
With kubectl v1.12.0 introducing easy pluggability of external functions, kubeaudit can be invoked as kubectl audit by
make plugin and having $GOPATH/bin available in your path.or
kubectl-audit and having it available in your path.We no longer release images to Docker Hub (since Docker Hub sunset Free Team organizations). For the time being, old images are still available but may stop being available at any time. We will start publishing images to the Github Container registry soon.
To run kubeaudit as a job in your cluster see Running kubeaudit in a cluster.
kubeaudit has three modes:
If a Kubernetes manifest file is provided using the -f/--manifest flag, kubeaudit will audit the manifest file.
Example command:
kubeaudit all -f "/path/to/manifest.yml"Example output:
…If no errors with a given minimum severity are found, the following is returned:
All checks completed. 0 high-risk vulnerabilities foundManifest mode also supports autofixing all security issues using the autofix command:
kubeaudit autofix -f "/path/to/manifest.yml"To write the fixed manifest to a new file instead of modifying the source file, use the -o/--output flag.
kubeaudit autofix -f "/path/to/manifest.yml" -o "/path/to/fixed"To fix a manifest based on custom rules specified on a kubeaudit config file, use the -k/--kconfig flag.
kubeaudit autofix -k "/path/to/kubeaudit-config.yml" -f "/path/to/manifest.yml" -o "/path/to/fixed"Kubeaudit can detect if it is running within a container in a cluster. If so, it will try to audit all Kubernetes resources in that cluster:
kubeaudit allKubeaudit will try to connect to a cluster using the local kubeconfig file ($HOME/.kube/config). A different kubeconfig location can be specified using the --kubeconfig flag. To specify a context of the kubeconfig, use the -c/--context flag.
kubeaudit all --kubeconfig "/path/to/config" --context my_clusterFor more information on kubernetes config files, see https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/
Kubeaudit produces results with three levels of severity:
Error: A security issue or invalid kubernetes configurationWarning: A best practice recommendationInfo: Informational, no action required. This includes results that are overriddenThe minimum severity level can be set using the --minSeverity/-m flag.
By default kubeaudit will output results in a human-readable way. If the output is intended to be further processed, it can be set to output JSON using the --format json flag. To output results as logs (the previous default) use --format logrus. Some output formats include colors to make results easier to read in a terminal. To disable colors (for example, if you are sending output to a text file), you can use the --no-color flag.
You can generate a kubeaudit report in SARIF using the --format sarif flag. To write the SARIF results to a file, you can redirect the output with >. For example:
kubeaudit all -f path-to-my-file.yaml --format="sarif" > example.sarifIf there are results of severity level error, kubeaudit will exit with exit code 2. This can be changed using the --exitcode/-e flag.
For all the ways kubeaudit can be customized, see Global Flags.
| Command | Description | Documentation |
|---|---|---|
all |
Runs all available auditors, or those specified using a kubeaudit config. | docs |
autofix |
Automatically fixes security issues. | docs |
version |
Prints the current kubeaudit version. |
Auditors can also be run individually.
| Command | Description | Documentation |
|---|---|---|
apparmor |
Finds containers running without AppArmor. | docs |
asat |
Finds pods using an automatically mounted default service account | docs |
capabilities |
Finds containers that do not drop the recommended capabilities or add new ones. | docs |
deprecatedapis |
Finds any resource defined with a deprecated API version. | docs |
hostns |
Finds containers that have HostPID, HostIPC or HostNetwork enabled. | docs |
image |
Finds containers which do not use the desired version of an image (via the tag) or use an image without a tag. | docs |
limits |
Finds containers which exceed the specified CPU and memory limits or do not specify any. | docs |
mounts |
Finds containers that have sensitive host paths mounted. | docs |
netpols |
Finds namespaces that do not have a default-deny network policy. | docs |
nonroot |
Finds containers running as root. | docs |
privesc |
Finds containers that allow privilege escalation. | docs |
privileged |
Finds containers running as privileged. | docs |
rootfs |
Finds containers which do not have a read-only filesystem. | docs |
seccomp |
Finds containers running without Seccomp. | docs |
| Short | Long | Description |
|---|---|---|
| --format | The output format to use (one of "sarif", "pretty", "logrus", "json") (default is "pretty") | |
| --kubeconfig | Path to local Kubernetes config file. Only used in local mode (default is $HOME/.kube/config) |
|
| -c | --context | The name of the kubeconfig context to use |
| -f | --manifest | Path to the yaml configuration to audit. Only used in manifest mode. You may use - to read from stdin. |
| -n | --namespace | Only audit resources in the specified namespace. Not currently supported in manifest mode. |
| -g | --includegenerated | Include generated resources in scan (such as Pods generated by deployments). If you would like kubeaudit to produce results for generated resources (for example if you have custom resources or want to catch orphaned resources where the owner resource no longer exists) you can use this flag. |
| -m | --minseverity | Set the lowest severity level to report (one of "error", "warning", "info") (default is "info") |
| -e | --exitcode | 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. (default is 2) |
| --no-color | Don't use colors in the output (default is false) |
The kubeaudit config can be used for two things:
Any configuration that can be specified using flags for the individual auditors can be represented using the config.
The config has the following format:
…For more details about each auditor, including a description of the audi
No open issues yet, or sync has not completed.