kube-linter
KubeLinter is a static analysis tool that checks Kubernetes YAML files and Helm charts to ensure the applications represented in them adhere to best practices.
Top Related Projects
Find vulnerabilities, misconfigurations, secrets, SBOM in containers, Kubernetes, code repositories, clouds and more
Prevent cloud misconfigurations and find vulnerabilities during build-time in infrastructure as code, container images and open source packages with Checkov by Bridgecrew.
Security risk analysis for Kubernetes resources
Container Image Linter for Security, Helping build the Best-Practice Docker Image, Easy to start
A vulnerability scanner for container images and filesystems
Vulnerability Static Analysis for Containers
Quick Overview
KubeLinter is an open-source static analysis tool for Kubernetes YAML files and Helm charts. It checks for best practices, common mistakes, and potential security issues in Kubernetes configurations, helping developers and operators improve the quality and security of their deployments.
Pros
- Extensive set of built-in checks covering various aspects of Kubernetes configurations
- Customizable and extensible with the ability to add custom checks
- Integrates well with CI/CD pipelines for automated scanning
- Supports both YAML files and Helm charts
Cons
- May produce false positives in some cases, requiring manual review
- Limited documentation for creating custom checks
- Some advanced features may require a learning curve for new users
Getting Started
To install KubeLinter using Homebrew:
brew tap stackrox/kube-linter https://github.com/stackrox/kube-linter.git
brew install kube-linter
To run KubeLinter on a Kubernetes YAML file:
kube-linter lint /path/to/your/kubernetes-manifests.yaml
To run KubeLinter on a directory containing multiple YAML files:
kube-linter lint /path/to/your/kubernetes-manifests-directory
To run KubeLinter with a custom configuration file:
kube-linter lint --config kube-linter.yaml /path/to/your/kubernetes-manifests
Competitor Comparisons
Find vulnerabilities, misconfigurations, secrets, SBOM in containers, Kubernetes, code repositories, clouds and more
Pros of Trivy
- Broader scope: Scans containers, filesystems, git repositories, and more, not just Kubernetes manifests
- More comprehensive vulnerability database, including OS packages and language-specific dependencies
- Faster scanning speed, especially for large projects or repositories
Cons of Trivy
- Less focused on Kubernetes-specific issues and best practices
- May require more configuration for Kubernetes-specific use cases
- Can produce more false positives due to its broader scanning scope
Code Comparison
Trivy CLI command:
trivy k8s --report summary cluster
Kube-linter CLI command:
kube-linter lint /path/to/kubernetes/manifests
Key Differences
- Trivy is a more general-purpose security scanner, while Kube-linter is specifically designed for Kubernetes manifests
- Trivy provides a wider range of scanning capabilities, including container images and git repositories
- Kube-linter offers more Kubernetes-specific checks and best practices out of the box
- Trivy has a larger community and more frequent updates, potentially leading to faster vulnerability detection
Use Cases
- Choose Trivy for comprehensive security scanning across various components of your infrastructure
- Opt for Kube-linter when focusing specifically on Kubernetes manifest validation and best practices
Prevent cloud misconfigurations and find vulnerabilities during build-time in infrastructure as code, container images and open source packages with Checkov by Bridgecrew.
Pros of Checkov
- Broader scope: Checks multiple infrastructure-as-code formats (Terraform, CloudFormation, Kubernetes, etc.)
- Extensive policy library: Covers various cloud providers and security best practices
- Integration with CI/CD pipelines and cloud environments
Cons of Checkov
- Steeper learning curve due to its broader scope
- May require more configuration for Kubernetes-specific use cases
- Potentially slower execution for large-scale projects due to comprehensive checks
Code Comparison
Checkov:
from checkov.common.models.enums import CheckResult, CheckCategories
from checkov.kubernetes.checks.resource.base_spec_check import BaseK8Check
class ExampleCheck(BaseK8Check):
def __init__(self):
name = "Example Kubernetes check"
check_id = "CKV_K8S_EXAMPLE"
# ... (additional setup)
KubeLinter:
package checks
import (
"k8s.io/apimachinery/pkg/runtime"
"github.com/stackrox/kube-linter/pkg/check"
"github.com/stackrox/kube-linter/pkg/diagnostic"
)
func init() {
check.RegisterCheck("example-check", "Example check description", exampleCheck)
}
Both tools offer powerful static analysis capabilities for Kubernetes manifests, but Checkov provides a more comprehensive approach to infrastructure-as-code scanning across multiple platforms, while KubeLinter focuses specifically on Kubernetes configurations with potentially faster execution for Kubernetes-only projects.
Security risk analysis for Kubernetes resources
Pros of kubesec
- Provides a web-based interface for scanning Kubernetes YAML files
- Offers a REST API for integration with other tools and workflows
- Includes a detailed scoring system for security risks
Cons of kubesec
- Less comprehensive set of checks compared to kube-linter
- Not as actively maintained, with fewer recent updates
- Limited configuration options for customizing checks
Code Comparison
kubesec:
docker run -i kubesec/kubesec:512c5e0 scan /dev/stdin < deployment.yaml
kube-linter:
kube-linter lint deployment.yaml
Both tools can be used to scan Kubernetes manifests, but kube-linter offers a more straightforward command-line interface, while kubesec provides additional deployment options through Docker.
kube-linter generally offers more extensive and customizable checks, making it suitable for more complex Kubernetes environments. However, kubesec's web interface and API can be advantageous for teams looking for easy integration into existing workflows or those who prefer a visual representation of scan results.
Ultimately, the choice between these tools depends on specific project requirements, team preferences, and the desired level of customization and integration capabilities.
Container Image Linter for Security, Helping build the Best-Practice Docker Image, Easy to start
Pros of Dockle
- Focuses specifically on Docker image security and best practices
- Provides CIS benchmarks for Docker images
- Offers a simple CLI interface for easy integration into CI/CD pipelines
Cons of Dockle
- Limited to Docker image analysis, while Kube-linter covers Kubernetes manifests
- May not provide as comprehensive Kubernetes-specific checks
- Less actively maintained compared to Kube-linter (fewer recent updates)
Code Comparison
Dockle usage:
dockle image:tag
Kube-linter usage:
kube-linter lint /path/to/manifests
While both tools focus on container security, they serve different purposes. Dockle is primarily for Docker image analysis, whereas Kube-linter is designed for Kubernetes manifest linting. Kube-linter offers more extensive Kubernetes-specific checks and is more actively maintained. However, Dockle provides valuable Docker-specific security checks and CIS benchmarks, making it a useful tool for Docker image security. The choice between the two depends on whether you need to focus more on Docker image security or Kubernetes manifest validation.
A vulnerability scanner for container images and filesystems
Pros of Grype
- Focuses on vulnerability scanning for container images and filesystems
- Supports multiple operating systems and package formats
- Provides detailed vulnerability information, including severity and fix versions
Cons of Grype
- Limited to vulnerability scanning, doesn't cover Kubernetes-specific issues
- Requires separate integration for CI/CD pipelines
- May have higher resource usage for large-scale scanning
Code Comparison
Grype command:
grype <image_name>
Kube-linter command:
kube-linter lint <kubernetes_manifest>
Key Differences
- Grype focuses on vulnerability scanning for container images and filesystems, while Kube-linter specializes in Kubernetes manifest and helm chart linting.
- Kube-linter provides built-in checks for Kubernetes best practices and security issues, whereas Grype concentrates on identifying known vulnerabilities in packages and dependencies.
- Grype offers more comprehensive vulnerability information, including CVE details and fix versions, while Kube-linter provides Kubernetes-specific recommendations and policy checks.
Use Cases
- Use Grype for in-depth vulnerability scanning of container images and filesystems across various operating systems and package formats.
- Choose Kube-linter for static analysis of Kubernetes YAML files, helm charts, and ensuring adherence to best practices in Kubernetes configurations.
For a comprehensive security approach, consider using both tools in conjunction to cover both vulnerability scanning and Kubernetes-specific issues.
Vulnerability Static Analysis for Containers
Pros of Clair
- Focuses on container image vulnerability scanning, providing comprehensive security analysis
- Supports multiple operating systems and package managers
- Integrates well with container registries and CI/CD pipelines
Cons of Clair
- Limited to container image scanning, doesn't cover Kubernetes-specific issues
- Requires more setup and infrastructure compared to KubeLinter
- May have higher resource requirements for large-scale deployments
Code Comparison
KubeLinter example:
checks:
- name: privileged-containers
enabled: true
- name: run-as-non-root
enabled: true
Clair example:
clair:
database:
type: pgsql
options:
source: host=postgres port=5432 user=clair dbname=clair sslmode=disable
KubeLinter is more focused on Kubernetes manifest linting, while Clair's configuration is centered around vulnerability scanning setup. KubeLinter's configuration is simpler and directly related to Kubernetes security checks, whereas Clair requires more complex setup for its database and scanning infrastructure.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Static analysis for Kubernetes
What is KubeLinter?
KubeLinter analyzes Kubernetes YAML files and Helm charts, and checks them against a variety of best practices, with a focus on production readiness and security.
KubeLinter runs sensible default checks, designed to give you useful information about your Kubernetes YAML files and Helm charts. This is to help teams check early and often for security misconfigurations and DevOps best practices. Some common examples of these include running containers as a non-root user, enforcing least privilege, and storing sensitive information only in secrets.
KubeLinter is configurable, so you can enable and disable checks, as well as create your own custom checks, depending on the policies you want to follow within your organization.
When a lint check fails, KubeLinter reports recommendations for how to resolve any potential issues and returns a non-zero exit code.
Documentation
Visit https://docs.kubelinter.io for detailed documentation on installing, using and configuring KubeLinter.
Installing KubeLinter
Kube-linter binaries could be found here: https://github.com/stackrox/kube-linter/releases/latest
Using Go
To install using Go, run the following command:
go install golang.stackrox.io/kube-linter/cmd/kube-linter@latest
Otherwise, download the latest binary from Releases and add it to your PATH.
Using Homebrew for macOS or LinuxBrew for Linux
To install using Homebrew or LinuxBrew, run the following command:
brew install kube-linter
Using nix-shell
nix-shell -p kube-linter
Using docker
docker pull stackrox/kube-linter:latest
Development
Prerequisites
- Make sure that you have installed Go prior to building from source.
Building KubeLinter
Installing KubeLinter from source is as simple as following these steps:
-
First, clone the KubeLinter repository.
git clone git@github.com:stackrox/kube-linter.git
-
Then, compile the source code. This will create the kube-linter binary files for each platform and places them in the
.gobin
folder.make build
-
Finally, you are ready to start using KubeLinter. Verify your version to ensure you've successfully installed KubeLinter.
.gobin/kube-linter version
Testing KubeLinter
There are several layers of testing. Each layer is expected to pass.
-
go
unit tests:make test
-
end-to-end integration tests:
make e2e-test
-
and finally, end-to-end integration tests using
bats-core
:make e2e-bats
Verifying KubeLinter images
KubeLinter images are signed by cosign. We recommend verifying the image before using it.
Once you've installed cosign, you can use the KubeLinter public key to verify the KubeLinter image with:
cat kubelinter-cosign.pub
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEl0HCkCRzYv0qH5QiazoXeXe2qwFX
DmAszeH26g1s3OSsG/focPWkN88wEKQ5eiE95v+Z2snUQPl/mjPdvqpyjA==
-----END PUBLIC KEY-----
cosign verify --key kubelinter-cosign $IMAGE_NAME
KubeLinter also provides cosign keyless signatures.
You can verify the KubeLinter image with:
# NOTE: Keyless signatures are NOT PRODUCTION ready.
COSIGN_EXPERIMENTAL=1 cosign verify $IMAGE_NAME
Using KubeLinter
Local YAML Linting
Running KubeLinter to Lint your YAML files only requires two steps in its most basic form.
-
Locate the YAML file you'd like to test for security and production readiness best practices:
-
Run the following command:
kube-linter lint /path/to/your/yaml.yaml
Example
Consider the following sample pod specification file pod.yaml
. This file has two production readiness issues and one security issue:
Security Issue:
- The container in this pod is not running as a read only file system, which could allow it to write to the root filesystem.
Production readiness:
-
The container's memory limits are not set, which could allow it to consume excessive memory
apiVersion: v1 kind: Pod metadata: name: security-context-demo spec: securityContext: runAsUser: 1000 runAsGroup: 3000 fsGroup: 2000 volumes: - name: sec-ctx-vol emptyDir: {} containers: - name: sec-ctx-demo image: busybox resources: requests: memory: "64Mi" cpu: "250m" command: [ "sh", "-c", "sleep 1h" ] volumeMounts: - name: sec-ctx-vol mountPath: /data/demo securityContext: allowPrivilegeEscalation: false
-
Copy the YAML above to pod.yaml and lint this file by running the following command:
kube-linter lint pod.yaml
-
KubeLinter runs its default checks and reports recommendations. Below is the output from our previous command.
pod.yaml: (object: <no namespace>/security-context-demo /v1, Kind=Pod) The container "sec-ctx-demo" is using an invalid container image, "busybox". Please use images that are not blocked by the `BlockList` criteria : [".*:(latest)$" "^[^:]*$" "(.*/[^:]+)$"] (check: latest-tag, remediation: Use a container image with a specific tag other than latest.) pod.yaml: (object: <no namespace>/security-context-demo /v1, Kind=Pod) container "sec-ctx-demo" does not have a read-only root file system (check: no-read-only-root-fs, remediation: Set readOnlyRootFilesystem to true in the container securityContext.) pod.yaml: (object: <no namespace>/security-context-demo /v1, Kind=Pod) container "sec-ctx-demo" has memory limit 0 (check: unset-memory-requirements, remediation: Set memory limits for your container based on its requirements. Refer to https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#requests-and-limits for details.) Error: found 3 lint errors
To learn more about using and configuring KubeLinter, visit the documentation page.
Mentions/Tutorials
The following are tutorials on KubeLinter written by users. If you have one that you would like to add to this list, please send a PR!
- Ensuring YAML best practices using KubeLinter at civo.com by Saiyam Pathak.
- Analyze Kubernetes files for errors with KubeLinter at opensource.com by Jessica Cherry.
- How to add a new check in KubeLinter? by Priyanka Saggu.
- Extending kube-linter To Build A Custom Template by Gareth Healy.
Community
If you would like to engage with the KubeLinter community, including maintainers and other users, you can join the Slack workspace here.
To contribute, check out our contributing guide.
As a reminder, all participation in the KubeLinter community is governed by our code of conduct.
WARNING: Alpha release
KubeLinter is at an early stage of development. There may be breaking changes in the future to the command usage, flags, and configuration file formats. However, we encourage you to use KubeLinter to test your environment YAML files, see what breaks, and contribute.
LICENSE
KubeLinter is licensed under the Apache License 2.0.
StackRox
KubeLinter is made with â¤ï¸ by StackRox.
If you're interested in KubeLinter, or in any of the other cool things we do, please know that we're hiring! Check out our open positions. We'd love to hear from you!
Top Related Projects
Find vulnerabilities, misconfigurations, secrets, SBOM in containers, Kubernetes, code repositories, clouds and more
Prevent cloud misconfigurations and find vulnerabilities during build-time in infrastructure as code, container images and open source packages with Checkov by Bridgecrew.
Security risk analysis for Kubernetes resources
Container Image Linter for Security, Helping build the Best-Practice Docker Image, Easy to start
A vulnerability scanner for container images and filesystems
Vulnerability Static Analysis for Containers
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot