Git Product home page Git Product logo

dockerfile-security's Introduction

Dockerfile-sec

Dockerfile-sec is a simple but powerful rules-based checker for Dockerfiles.

Install

> pip install dockerfile-sec 

Quick start

Analyze a Dockerfile

> dockerfile-sec examples/Dockerfile-example
+----------+-------------------------------------------+----------+
| Rule Id  | Description                               | Severity |
+----------+-------------------------------------------+----------+
| core-002 | Missing USER sentence in dockerfile       | Medium   |
| core-003 | Posible text plain password in dockerfile | High     |
| core-005 | Recursive copy found                      | Medium   |
| core-006 | Use of COPY instead of ADD                | Low      |
| core-007 | Use image tag instead of SHA256 hash      | Medium   |
| cred-001 | Generic credential                        | Medium   |
+----------+-------------------------------------------+----------+  

Using docker

> cat Dockerfile | docker run --rm -t cr0hn/dockerfile-sec  
IMPORTANT: By using docker you can pass a rules file or a docker file as paramenter. You need to use a pipe or mount a volume

Usage

With remote rules

> dockerfile-sec -r http://127.0.0.1:9999/rules/credentials.yaml Dockerfile 

With built-in rules

All rules

All rules are enabled by default:

> dockerfile-sec Dockerfile

Core rules only

https://github.com/cr0hn/dockerfile-security/blob/master/dockerfile_sec/rules/core.yaml

> dockerfile-sec -R core Dockerfile

Credentials rules only

https://github.com/cr0hn/dockerfile-security/blob/master/dockerfile_sec/rules/credentials.yaml

> dockerfile-sec -R credentials Dockerfile

Disabling built-in rules

> dockerfile-sec -R none Dockerfile

With user defined rules

> dockerfile-sec -r my-rules.yaml Dockerfile

Export results as json

> dockerfile-sec -o results.json Dockerfile 

Quiet mode

Not writing anything in the console:

> dockerfile-sec -q -o results.json Dockerfile 

Filtering false positives

By ignore file

Dockerfile-sec allows to ignore rules by using a file that contains the rules you want to ignore.

> dockerfile-sec -F ignore-rules.text Dockerfile 

Ignore file format contains the IDs of rules you want to ignore. one ID per line. Example:

> ls ignore-rules.text
core-001
core-007

By using the cli

You also can use cli to ignore specific IDs:

> dockerfile-sec -i core-001,core007 Dockerfile 

Using as a pipeline

You also can use dockerfile-sec as UNIX pipeline.

Loading Dockerfile from stdin:

> cat Dockerfile | dockerfile-sec -i core-001,core007 

Exposing results via pipe:

> cat Dockerfile | dockerfile-sec -i core-001,core007 | jq 

Output formats

JSON Output format

[
  {
    "description": "Missing USER sentence in dockerfile",
    "id": "core-002",
    "reference": "https://snyk.io/blog/10-docker-image-security-best-practices/",
    "severity": "Medium"
  }
]

References

dockerfile-security's People

Contributors

cr0hn avatar hacks4snacks avatar mariuszmichalowski 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

Watchers

 avatar  avatar  avatar  avatar

dockerfile-security's Issues

Issue with core-006

Hi cr0hn,

According to your core.yaml file, you cite "https://snyk.io/blog/10-docker-image-security-best-practices/" for core-006. I am assuming you are referring to the heading "7. Use COPY is stead of ADD".

There seems to be a misunderstanding with this finding, as your solution flags the usage of COPY as a vulnerability. From what I understand one should use the COPY function rather that the ADD function. Thus, core-006 title and regex case are both incorrect.

Your solution should be searching for the use of ADD rather than COPY.

Issue with the rule - core-002

The regex needs to be worked on.... even though there is a USER defined in the Dockerfile, it is failing. Changing the regex to "^(USER[\s]+[\w\d_]+)$" might fix this....

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.