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
Metadata
Release files for dockerfile-sec 1.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| dockerfile-sec-1.0.6.tar.gz | 7.7 kB | Without provenance | Details |
Release files / dockerfile-sec-1.0.6.tar.gz
| Download URL | dockerfile-sec-1.0.6.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
469df0a8c2ea2ac534177fab8e5caaf8c0061e0ffc9dfc13b5d35425996d22cb
|
|
BLAKE2b-256 checksum How to use checksums |
a8178a9a21e5cdd9e7cadca7a42aafe16da16251386387f83001c3e4d1bd847d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Security for dockerfile-sec 1.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.