Giter VIP home page Giter VIP logo

stackrox / kube-linter Goto Github PK

View Code? Open in Web Editor NEW
2.8K 36.0 221.0 1.78 MB

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.

Home Page: https://docs.kubelinter.io/

License: Apache License 2.0

Makefile 0.63% Go 89.63% Shell 9.73% Dockerfile 0.01%
static-analysis yaml-files helm-charts kubernetes hactoberfest

kube-linter's Introduction

Static analysis for Kubernetes

Go Report Card

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

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

Building from source

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:

  1. First, clone the KubeLinter repository.

    git clone [email protected]:stackrox/kube-linter.git
  2. 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
  3. 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.

  1. go unit tests:

    make test
  2. end-to-end integration tests:

    make e2e-test
  3. 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.

  1. Locate the YAML file you'd like to test for security and production readiness best practices:

  2. 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:

  1. 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:

  1. 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
  2. Copy the YAML above to pod.yaml and lint this file by running the following command:

    kube-linter lint pod.yaml
  3. 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!

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!

kube-linter's People

Contributors

arghya88 avatar charlesoconor avatar chenrui333 avatar crunchtime-ali avatar dependabot[bot] avatar dhaus67 avatar fahlmant avatar garethahealy avatar gj262 avatar heckler1 avatar janisz avatar jtcarnes avatar kreamkorokke avatar lluan444 avatar mancubus77 avatar mstoetzer avatar msugakov avatar mtodor avatar nirav24 avatar owenrumney avatar pedrosilva9 avatar priyankasaggu11929 avatar sbose78 avatar shireenf-ibm avatar simonbaeumer avatar slysunkin avatar supersandro2000 avatar trumant avatar viswajithiii avatar wushujames avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kube-linter's Issues

linter shows incorrect error about no matched label in deployments in helm.

Describe the bug
Kubelinter miss interprets helm charts service matched labels in deployments.

To Reproduce
Steps to reproduce the behavior:

  1. Install kube-linter on linux (ubuntu server 18.04) using brew install kube-linter
  2. Download the example chart zipped.
  3. Unzip it
  4. Walk in the example directory and run /home/ubuntu/.linuxbrew/bin/kube-linter lint .

Expected behavior
No errors to appear regarding a dangling service

Screenshots
helm template . of the example showing service label exists inside deployment

# Source: example/templates/service.yml
apiVersion: v1
kind: Service
metadata:
  name: example
  namespace: default
  labels:
    app: example
    helm.sh/chart: example-1.0.0
    app.kubernetes.io/instance: RELEASE-NAME
    app.kubernetes.io/version: "1.0.0"
    app.kubernetes.io/managed-by: Helm
spec:
  ports:
  - port: 8080
    name: http-example
  selector:
    app: example
---
# Source: example/templates/deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: RELEASE-NAME-example
  namespace: default
  labels:
    APP_NAME: example
    app: example
    helm.sh/chart: example-1.0.0
    app.kubernetes.io/instance: RELEASE-NAME
    app.kubernetes.io/version: "1.0.0"
    app.kubernetes.io/managed-by: Helm
spec:
  replicas: 1
  selector:
    matchLabels:
      app: example
  template:
    metadata:
      labels:
        APP_NAME: example
        app: example
    spec:
      containers:
      - name: example
        imagePullPolicy: Always
        image: alpine:3.11
        securityContext:
          runAsUser: 1000
          runAsNonRoot: true
          readOnlyRootFilesystem: true
        ports:
        - containerPort: 8080
        livenessProbe:
          exec:
            command:
              - python3
              - /app/scripts/healthcheck.py
          initialDelaySeconds: 30
          periodSeconds: 30
          timeoutSeconds: 5
        readinessProbe:
          exec:
            command:
              - python3
              - /app/scripts/healthcheck.py
          initialDelaySeconds: 25
          periodSeconds: 25
          timeoutSeconds: 5
        resources:
          limits:
            cpu: 500m
            memory: 500Mi
          requests:
            cpu: 500m
            memory: 500Mi

Error:

/home/ubuntu/.linuxbrew/bin/kube-linter lint .
example/templates/service.yml: (object: default/example /v1, Kind=Service) no pods found matching service labels (map[app:example]) (check: dangling-service, remediation: Make sure your service's selector correctly matches the labels on one of your deployments.)

Error: found 1 lint errors

Please let me know if i am missing anything.

helm_chart_example.zip

Allow users to specify non-default values for Helm charts

Currently, Helm charts are rendered using the values.yaml file next to Chart.yaml. We need to support a way for users to test with other values. More generally, we want people to be able to specify a bunch of different combinations of values that kube-linter checks their configurations against.

There are two ways we can do this, which are not mutually exclusive:

  1. Support Helm's -f and --set flags. However, this only makes sense if you lint one chart, so will require a separate lint-helm command or similar, which strictly takes the path to a Helm chart. In this case, the user will be responsible for calling kube-linter lint-helm multiple times, for each set of -f and --set arguments they want to lint against.
  2. One way to do this might be to allow a .kubelinterrc directory in every Helm chart directory, where users specify this. We need to be careful about how we design this, because we want to ensure that:
    1. users can specify multiple renders of Helm charts -- ie, they should be able to specify a few different sets of values, have the chart be rendered with each set of values, and have each set of rendered YAML files linted independently.
    2. users can specify multiple values in each render. That is, just like helm install supports multiple -f arguments, users should be able to specify multiple values.yaml files, and the order in which they are applied, for each render. Importantly, if one of these is the values.yaml file in the Chart's root directory, it should be possible for the user to specify that without having to duplicate its contents.

Finally, we should ensure that if values are specified like this, we render the chart in strict code, and actually fail if required values are not specified.

'make build' on clean Mac with GoLang fails with " /bin/bash: packr: command not found"

Catalina 10.15.7
Golang: go version go1.15.3 darwin/amd64

~/w/r/kube-linter ❯❯❯brew install go
==> Downloading https://homebrew.bintray.com/bottles/go-1.15.3.catalina.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/6bd0119a31c1ae26831105490a67b97bed5d0fd2c6ad140cdf4c84aa7a315af2?response-content-disposition=attachment%3Bfilename%3D%22go-1.15.3.catalina.bottle.tar.gz%22&Policy=eyJTdGF0
######################################################################## 100.0%
==> Pouring go-1.15.3.catalina.bottle.tar.gz
🍺 /usr/local/Cellar/go/1.15.3: 9,780 files, 494.3MB
~/w/r/kube-linter ❯❯❯ make build

  • deps
    go: downloading github.com/golangci/golangci-lint v1.30.0
    go: downloading github.com/ghodss/yaml v1.0.0
    go: downloading k8s.io/api v0.19.2
    go: downloading github.com/pkg/errors v0.9.1
    go: downloading k8s.io/apimachinery v0.19.2
    go: downloading honnef.co/go/tools v0.0.1-2020.1.5
    go: downloading k8s.io/cli-runtime v0.19.2
    go: downloading github.com/stretchr/testify v1.6.1
    go: downloading k8s.io/gengo v0.0.0-20200728071708-7794989d0000
    go: downloading github.com/gobuffalo/packr v1.30.1
    go: downloading k8s.io/client-go v0.19.2
    go: downloading github.com/Masterminds/sprig/v3 v3.1.0
    go: downloading github.com/davecgh/go-spew v1.1.1
    go: downloading golang.org/x/text v0.3.3
    go: downloading github.com/googleapis/gnostic v0.4.1
    go: downloading gopkg.in/inf.v0 v0.9.1
    go: downloading github.com/modern-go/reflect2 v1.0.1
    go: downloading gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
    go: downloading github.com/gobuffalo/envy v1.7.1
    go: downloading sigs.k8s.io/kustomize v2.0.3+incompatible
    go: downloading github.com/json-iterator/go v1.1.10
    go: downloading github.com/mitchellh/copystructure v1.0.0
    go: downloading k8s.io/klog v1.0.0
    go: downloading github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
    go: downloading k8s.io/klog/v2 v2.2.0
    go: downloading github.com/golang/protobuf v1.4.2
    go: downloading github.com/Masterminds/semver v1.5.0
    go: downloading k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6
    go: downloading gopkg.in/yaml.v2 v2.3.0
    go: downloading github.com/Masterminds/semver/v3 v3.1.0
    go: downloading gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f
    go: downloading google.golang.org/protobuf v1.24.0
    go: downloading sigs.k8s.io/structured-merge-diff/v4 v4.0.1
    go: downloading github.com/mitchellh/mapstructure v1.1.2
    go: downloading github.com/go-logr/logr v0.2.0
    go: downloading github.com/huandu/xstrings v1.3.1
    go: downloading github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
    go: downloading github.com/spf13/cobra v1.0.0
    go: downloading golang.org/x/time v0.0.0-20191024005414-555d28b269f0
    go: downloading github.com/gobuffalo/packd v0.3.0
    go: downloading github.com/fatih/color v1.9.0
    go: downloading github.com/google/go-cmp v0.5.0
    go: downloading github.com/inconshreveable/mousetrap v1.0.0
    go: downloading helm.sh/helm/v3 v3.3.4
    go: downloading github.com/joho/godotenv v1.3.0
    go: downloading golang.org/x/tools v0.0.0-20200724022722-7017fd6b1305
    go: downloading github.com/mitchellh/reflectwalk v1.0.0
    go: downloading sigs.k8s.io/yaml v1.2.0
    go: downloading golang.org/x/net v0.0.0-20200707034311-ab3426394381
    go: downloading k8s.io/utils v0.0.0-20200729134348-d5654de09c73
    go: downloading github.com/gogo/protobuf v1.3.1
    go: downloading github.com/spf13/viper v1.7.0
    go: downloading golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6
    go: downloading github.com/spf13/pflag v1.0.5
    go: downloading golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
    go: downloading github.com/pmezard/go-difflib v1.0.0
    go: downloading gopkg.in/ini.v1 v1.51.0
    go: downloading github.com/google/uuid v1.1.1
    go: downloading github.com/rogpeppe/go-internal v1.6.0
    go: downloading github.com/spf13/afero v1.2.2
    go: downloading github.com/spf13/cast v1.3.1
    go: downloading github.com/google/gofuzz v1.1.0
    go: downloading github.com/golangci/revgrep v0.0.0-20180526074752-d9c87f5ffaf0
    go: downloading github.com/pelletier/go-toml v1.2.0
    go: downloading github.com/hashicorp/hcl v1.0.0
    go: downloading github.com/imdario/mergo v0.3.8
    go: downloading github.com/fsnotify/fsnotify v1.4.9
    go: downloading github.com/go-critic/go-critic v0.5.0
    go: downloading github.com/magiconair/properties v1.8.1
    go: downloading github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b
    go: downloading k8s.io/apiextensions-apiserver v0.18.8
    go: downloading github.com/spf13/jwalterweatherman v1.0.0
    go: downloading github.com/stretchr/objx v0.2.0
    go: downloading github.com/sirupsen/logrus v1.6.0
    go: downloading github.com/BurntSushi/toml v0.3.1
    go: downloading github.com/gobwas/glob v0.2.3
    go: downloading github.com/mitchellh/go-homedir v1.1.0
    go: downloading github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2
    go: downloading github.com/ssgreg/nlreturn/v2 v2.0.1
    go: downloading github.com/Masterminds/goutils v1.1.0
    go: downloading github.com/Djarvur/go-err113 v0.0.0-20200511133814-5174e21577d5
    go: downloading github.com/securego/gosec/v2 v2.4.0
    go: downloading github.com/golangci/errcheck v0.0.0-20181223084120-ef45e06d44b6
    go: downloading github.com/uudashr/gocognit v1.0.1
    go: downloading github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e
    go: downloading github.com/golangci/gofmt v0.0.0-20190930125516-244bba706f1a
    go: downloading mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed
    go: downloading github.com/maratori/testpackage v1.0.1
    go: downloading github.com/ryancurrah/gomodguard v1.1.0
    go: downloading github.com/quasilyte/regex/syntax v0.0.0-20200407221936-30656e2c4a95
    go: downloading github.com/go-toolsmith/astequal v1.0.0
    go: downloading golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4
    go: downloading github.com/go-toolsmith/astfmt v1.0.0
    go: downloading github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2
    go: downloading mvdan.cc/gofumpt v0.0.0-20200709182408-4fd085cb6d5f
    go: downloading github.com/sonatard/noctx v0.0.1
    go: downloading golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
    go: downloading github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4
    go: downloading github.com/golangci/prealloc v0.0.0-20180630174525-215b22d4de21
    go: downloading github.com/sourcegraph/go-diff v0.5.3
    go: downloading github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e
    go: downloading github.com/jingyugao/rowserrcheck v0.0.0-20191204022205-72ab7603b68a
    go: downloading github.com/konsorten/go-windows-terminal-sequences v1.0.3
    go: downloading github.com/mattn/go-isatty v0.0.12
    go: downloading github.com/golangci/misspell v0.0.0-20180809174111-950f5d19e770
    go: downloading github.com/matoous/godox v0.0.0-20190911065817-5d6d842e92eb
    go: downloading github.com/gostaticanalysis/analysisutil v0.0.3
    go: downloading golang.org/x/mod v0.3.0
    go: downloading github.com/go-toolsmith/strparse v1.0.0
    go: downloading mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b
    go: downloading github.com/subosito/gotenv v1.2.0
    go: downloading github.com/go-toolsmith/astcopy v1.0.0
    go: downloading github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca
    go: downloading github.com/go-openapi/spec v0.19.3
    go: downloading github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a
    go: downloading github.com/gofrs/flock v0.7.1
    go: downloading github.com/ultraware/funlen v0.0.2
    go: downloading github.com/nishanths/exhaustive v0.0.0-20200708172631-8866003e3856
    go: downloading github.com/ultraware/whitespace v0.0.4
    go: downloading github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d
    go: downloading github.com/quasilyte/go-ruleguard v0.1.2-0.20200318202121-b00d7a75d3d8
    go: downloading github.com/go-toolsmith/typep v1.0.2
    go: downloading google.golang.org/appengine v1.6.5
    go: downloading github.com/OpenPeeDeeP/depguard v1.0.1
    go: downloading github.com/mattn/go-colorable v0.1.7
    go: downloading github.com/denis-tingajkin/go-header v0.3.1
    go: downloading github.com/smartystreets/goconvey v1.6.4
    go: downloading github.com/go-toolsmith/pkgload v1.0.0
    go: downloading github.com/emicklei/go-restful v2.9.5+incompatible
    go: downloading github.com/kr/text v0.2.0
    go: downloading github.com/golangci/go-misc v0.0.0-20180628070357-927a3d87b613
    go: downloading github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0
    go: downloading github.com/jirfag/go-printf-func-name v0.0.0-20191110105641-45db9963cdd3
    go: downloading github.com/go-openapi/jsonpointer v0.19.3
    go: downloading github.com/bombsimon/wsl/v3 v3.1.0
    go: downloading github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c
    go: downloading github.com/onsi/ginkgo v1.13.0
    go: downloading github.com/golangci/goconst v0.0.0-20180610141641-041c5f2b40f3
    go: downloading github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041
    go: downloading github.com/phayes/checkstyle v0.0.0-20170904204023-bfd46e6a821d
    go: downloading github.com/golangci/gocyclo v0.0.0-20180528144436-0a533e8fa43d
    go: downloading github.com/go-toolsmith/astcast v1.0.0
    go: downloading github.com/daixiang0/gci v0.0.0-20200727065011-66f1df783cb2
    go: downloading github.com/ryanrolds/sqlclosecheck v0.3.0
    go: downloading github.com/nakabonne/nestif v0.3.0
    go: downloading github.com/onsi/gomega v1.10.1
    go: downloading github.com/go-openapi/swag v0.19.5
    go: downloading github.com/golangci/ineffassign v0.0.0-20190609212857-42439a7714cc
    go: downloading github.com/xeipuuv/gojsonschema v1.2.0
    go: downloading github.com/go-openapi/jsonreference v0.19.3
    go: downloading github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e
    go: downloading mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f
    go: downloading github.com/tommy-muehle/go-mnd v1.3.1-0.20200224220436-e6f9a994e8fa
    go: downloading github.com/evanphx/json-patch v4.9.0+incompatible
    go: downloading github.com/cyphar/filepath-securejoin v0.2.2
    go: downloading github.com/PuerkitoBio/purell v1.1.1
    go: downloading github.com/mailru/easyjson v0.7.0
    go: downloading sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4
    go: downloading github.com/jtolds/gls v4.20.0+incompatible
    go: downloading github.com/kisielk/gotool v1.0.0
    go: downloading github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415
    go: downloading github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d
    go: downloading github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578
    go: downloading github.com/kyoh86/exportloopref v0.1.7
    go: downloading github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f
    go: downloading github.com/peterbourgon/diskv v2.0.1+incompatible
    go: downloading github.com/tetafro/godot v0.4.8
    go: downloading github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7
    go: downloading github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de
    go: downloading github.com/google/btree v1.0.0
    go: downloading github.com/go-toolsmith/astp v1.0.0
    go: downloading github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1
    go: downloading github.com/nxadm/tail v1.4.4
    go: downloading gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7
    all modules verified
  • /Users/todd/workspace/replicated/kube-linter/.gobin/packr
    packr
    /bin/bash: packr: command not found
    make: *** [packr] Error 127

Improved errors for invalid yaml files

Today, kube-linter shows the output Warning: no valid objects found. when there is an invalid yaml file.

The error messages could be made more clear. Rather than asking users to use verbose logging kube-linter lint -v pod.yaml we should display errors that showcase what the issue is. I think it would be ideal to have custom error conditions to show users why something is not valid.

Option 1: The file scanned at ./pod.yaml is not a valid yaml file. Please check to ensure the file is in proper yaml format.
Option 2: The file scanned is not a valid kubernetes object please run kube-linter lint -v pod.yaml for more details.

Alternatively, we could also point them to run kube-linter lint -v pod.yaml for more details directly in the error.

Add flag in lint command to ignore list of specific check type

we use terraform to create k8s specific resources like k8s service account, etc.

when I try to perform link in helm chart, it shows below error

serviceAccount "service-account-name" not found (check: non-existent-service-account, remediation: Make sure to create the service account, or to refer to an existing service account.)

In normal scenario, this is valid error. but, since this service account is created by terraform and is in not helm chart, this error becomes irrelevant for me.

It'd be good to have --ingore check-type flag in lint command to ingore specific type of check ( in this case - non-existent-service-account)

Lint Helm Charts using repo or tar.gz file as a parameter

To improve usability it would be great to directly scan helm charts using a reference to a helm repository or by directly specifying a tar.gz file that could be obtained using a helm pull on the repo. This would greatly reduce the complexity of helm chart scanning for users as it stands today.

Workflows:

  1. I want to scan my helm chart that I have created.
  • I package my helm chart and create a tar.gz file
  • I then can run kube-linter on it before I try a helm install or upload to a repo
  1. I want to scan a helm chart that is in a repo
  • I can either pull the helm chart and get the tar.gz file
  • I can specify the repo and the chart version so that I can pull down the chart from a repo directly.

@viswajithiii what do you think here?

Support config files with well-known file names

Right now, the config file is passed using the --config flag to kube-linter lint. In practice, however, users may want to have different configs (with different custom checks and different lists of enabled checks) for different apps, which may be in different directories or different Helm charts. Similar to .eslintrc files, we could support config files with a well-known filename, say .kube-linterrc, and have kube-linter lint automatically read them and merge them into the existing config as it walks directories.

Spelling of "following" in README.md

Could you please fix the spelling of the phrase "following" in README.md?

It is currently "follwoing" in the snippet:
To lint this file with KubeLinter, run the follwoing command:

Allow objects to come from stdin

Allow a YAML stream to come from stdin. Many tools use - to indicate stdin, e.g.:

cat objects.yaml | kube-linter lint -

Obviously you wouldn't do that specific thing but, combined with #43, it would make the tool much easier to use in an automated pipeline.

Enhancement: Add CIS Benchmark Check Control:5.2.3

Another update for consideration:

The CIS benchmark for Kubernetes asks to minimize admission of containers with that share the hostIPC namespace.

Consider adding a linting check for pods that share the host IPC namespace in the pod specification for hostIPC: True to align with that benchmark.

Usability Enhancement - Add preferences file for simplified configuration

When passing configurations frequently it can be repetitive for a user to put the --config flag on every command.

A possible suggestion to improve this experience is to have a default hidden file (or just generally a file that is always referenced by default) that passes all configurations that is always respected by kube-linter unless a config file is explicitly passed. This way a user could set their default profile for exactly what they want to check for once and not have to pass the --config parameters each time they want to lint something. This would allow users to set default custom configurations and to turn on and off checks.

As an industry example, in Redis there is a hidden file .redisclirc that allows users to add some preferences to the command line interface. This can be found here: https://github.com/redis/redis/blob/5d0c6b08686d51d552bae7dbb640625cfc1d73db/src/redis-cli.c#L76

Add support for automatic rewrites

Add support for automatic rewrites of files based on errors identified, a la eslint --fix or gofmt -w.

Since most KubeLinter checks change semantics, we will probably not want to overwrite files in-place, but err on the side of writing a new .proposed file for each file that contains errors.

It is unclear how to handle this for Helm charts.

"env-var-secret" triggered even though secretKeyRef utilized

Seeing an env-var-secret error even though secretKeyRef is utilized, however, I am still seeing kube-linter throwing an error.

Deployment yaml:

 44         env:
 45         - name: AWS_ACCESS_KEY_ID
 46           valueFrom:
 47             secretKeyRef:
 48               key: aws-access-key-id
 49               name: aws-test
 50         - name: AWS_ACCESS_KEY_SECRET
 51           valueFrom:
 52             secretKeyRef:
 53               key: aws-secret-access-key
 54               name: aws-test

Output:

dev/test-secrets/deploy.yaml: (object: default/test-secrets apps/v1, Kind=Deployment) environment variable AWS_ACCESS_KEY_SECRET in container "test-secrets" found (check: env-var-secret, remediation: Don't use raw secrets in an environment variable. Instead, either mount the secret as a file or use a secretKeyRef. See https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets for more details.)

Support CRDs

We should support linting custom resources. Some suggestions we've got from users are: Prometheus Operator (specifically, PrometheusRule manifests), Cert Manager, ArgoCD, and Istio.

Docker image for kube-linter

Hi,

It would be nice if there would be a official docker image for kube-linter. Which would help in usage in CI/CD process .

Kevin

Support OpenShift objects

Support checks on OpenShift objects. Suggestions we got were to look at imagestreams, deploymentconfigs, buildconfigs and routes.

Add Support for Multiple Files

This is not that easy.

Imagine the following:

  • services.yaml contains the definition of services
  • deployment.yaml contains the defintion of a deployment
  • services.yaml references this deployment using labels
  • kube-linter takes care of that

Idea:
Checking, if files are in the same directory and if a selector / label could be found in this directory. But this is also not the best way of doing it...

any ideas?

Enhancement Request: Improved usability for linting output

Here are some readability/UX enhancement requests for Kube-Linter.

Here are some initial suggestions for your consideration that I think would improve the user experience. There are several so feel free to cherry-pick as you see merit.

Suggestions:

  1. If there is no namespace then don't output it as but rather show nothing.
  2. Remove /v1 as a means of unique identification. Personally, I'm not sure what the use case for having this would be.
  3. Rather than showing the check that failed in the output why not remove it or add some additional context to it.
  4. "sec-ctx-demo" does not have a read-only root file system is what's important so why not make this the title so it shows what's important first.
  5. I think it would be awesome to showcase the line of code where the issue is occurring to make it simpler to fix.
  6. Alternatively, consider using the file path rather than the object.

Current output

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 your container's securityContext.)

Suggested output

Warning: Container "sec-ctx-demo" does not have a read-only root file system.
 
Check: Check 'no-read-only-root-fs' failed at line 24 in the pod found in /path/to/file.yaml   
Fix: Add the line readOnlyRootFilesystem: true to your container securitycontext after line 24.

Flag errors when YAML files can't be parsed

Currently, KubeLinter is permissive if a YAML file fails to parse. This is to handle the case where we are walking a directory and encounter files that aren't Kubernetes manifests. We can change this to be smarter: we can detect if a file contains Kubernetes manifests using some heuristics, and fail hard when we detect those.

VS Code Extension

Add support for VS Code to lint kube config yaml files automatically / on demand

Support comments for ignore directives

Currently, ignore directives can only be accomplished by annotations. Consider supporting comments to do this. Comments could be of the form # kube-linter ignore-check <check-names> or similar.

Whether we add this mostly depends on whether people want it. Annotations are preferable in many ways -- they are more visible, don't get lost on roundtrips to the API server -- so we will still continue to recommend that even if we implement this.

Checksum for release versions

As an integrity check, we should add a SHA256 hash reference for each release. This could be as simple as a document with each shasum per release.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.