kubesec: Security risk analysis for Kubernetes resources

kubesec

Security risk analysis for Kubernetes resources

 

Download

Kubesec is available as a:

Or install the latest commit from Github with go get -u github.com/controlplaneio/kubesec/cmd/kubesec

Command-line usage:

$ kubesec scan k8s-deployment.yaml

Usage example:

[pastacode lang=”markup” message=”” highlight=”” provider=”manual” manual=”%24%20cat%20%3C%3CEOF%20%3E%20kubesec-test.yaml%0AapiVersion%3A%20v1%0Akind%3A%20Pod%0Ametadata%3A%0A%20%20name%3A%20kubesec-demo%0Aspec%3A%0A%20%20containers%3A%0A%20%20-%20name%3A%20kubesec-demo%0A%20%20%20%20image%3A%20gcr.io%2Fgoogle-samples%2Fnode-hello%3A1.0%0A%20%20%20%20securityContext%3A%0A%20%20%20%20%20%20readOnlyRootFilesystem%3A%20true%0AEOF%0A%24%20kubesec%20scan%20kubesec-test.yaml”/]

Docker usage:

Run the same command in Docker:

$ docker run -i kubesec/kubesec:512c5e0 scan /dev/stdin < kubesec-test.yaml

Kubesec HTTP Server

Kubesec includes a bundled HTTP server

CLI usage example:

Start the HTTP server in the background

[pastacode lang=”markup” message=”” highlight=”” provider=”manual” manual=”%24%20kubesec%20http%208080%20%26%0A%5B1%5D%2012345%0A%7B%22severity%22%3A%22info%22%2C%22timestamp%22%3A%222019-05-12T11%3A58%3A34.662%2B0100%22%2C%22caller%22%3A%22server%2Fserver.go%3A69%22%2C%22message%22%3A%22Starting%20HTTP%20server%20on%20port%208080%22%7D”/]

Use curl to POST a file to the server

Finally, stop the Kubesec server by killing the background process

$ kill %

Docker usage example:

Start the HTTP server using Docker

$ docker run -d -p 8080:8080 kubesec/kubesec:d432be9 http 8080

Use curl to POST a file to the server

$ curl -sSX POST –data-binary @test/asset/score-0-cap-sys-admin.yml http://localhost:8080/scan …

Don’t forget to stop the server.

Kubesec-as-a-Service

Kubesec is also available via HTTPS at v2.kubesec.io/scan

Command-line usage:

$ curl -sSX POST –data-binary @k8s-deployment.yaml https://v2.kubesec.io/scan

Usage example:

Define a BASH function

POST a Kubernetes resource to v2.kubesec.io/scan

$ kubesec ./deployment.yml

Return non-zero status code is the score is not greater than 10

$ kubesec ./score-9-deployment.yml | jq –exit-status .score > 10 >/dev/null # status code 1

Example output

Kubesec returns a JSON array and can scan multiple YAML documents in a single input file.

[pastacode lang=”markup” message=”” highlight=”” provider=”manual” manual=”%5B%0A%20%20%7B%0A%20%20%20%20%22object%22%3A%20%22Pod%2Fsecurity-context-demo.default%22%2C%0A%20%20%20%20%22valid%22%3A%20true%2C%0A%20%20%20%20%22message%22%3A%20%22Failed%20with%20a%20score%20of%20-30%20points%22%2C%0A%20%20%20%20%22score%22%3A%20-30%2C%0A%20%20%20%20%22scoring%22%3A%20%7B%0A%20%20%20%20%20%20%22critical%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%22selector%22%3A%20%22containers%5B%5D%20.securityContext%20.capabilities%20.add%20%3D%3D%20SYS_ADMIN%22%2C%0A%20%20%20%20%20%20%20%20%20%20%22reason%22%3A%20%22CAP_SYS_ADMIN%20is%20the%20most%20privileged%20capability%20and%20should%20always%20be%20avoided%22%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%22advise%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%22selector%22%3A%20%22containers%5B%5D%20.securityContext%20.runAsNonRoot%20%3D%3D%20true%22%2C%0A%20%20%20%20%20%20%20%20%20%20%22reason%22%3A%20%22Force%20the%20running%20image%20to%20run%20as%20a%20non-root%20user%20to%20ensure%20least%20privilege%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%2F%2F%20…%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%5D%0A%20%20%20%20%7D%0A%20%20%7D%0A%5D”/]

Tutorial

Copyright 2017 control-plane.io

Source: https://github.com/controlplaneio/

Support Our Threat Intelligence

If you find our technology report and cybersecurity news helpful, consider supporting our work.

Crypto QR Code
USDT (TRC20):
TN8BdV8cp4T1Cd28gK9qTAnZknzzuwyUtm
USDT (ERC20):
0x3725e1a7d3bc5765499fa6aaafe307fabcd75bce