Skip to content

Latest commit

 

History

History
226 lines (136 loc) · 8.69 KB

RULES.md

File metadata and controls

226 lines (136 loc) · 8.69 KB

Rules

D0:avoid-add-external

Avoid using ADD with external files or archives. Use COPY instead.

The ADD command supports pulling files over HTTP(s), and auto-extracts some archives. Docker's own best practices strongly encourage using COPY of a local file.

Priority: Critical
Analyzes: ADD

D2:single-cmd

Only a single CMD instruction is supported

More than one CMD may indicate a programming error. Docker will run the last CMD instruction only, but this could be a security concern.

Priority: Critical
Analyzes: CMD

D3:avoid-copy-all

Avoid copying entire source directory into image

Explicitly copying sources helps avoid accidentally persisting secrets or other files that should not be shared.

Priority: High
Analyzes: COPY

D5:no-debian-frontend

Convert DEBIAN_FRONTEND to an ARG.

Avoid DEBIAN_FRONTEND, which affects derived images and docker run. Change this to an ARG. This rule matches against the pattern \bDEBIAN_FRONTEND\b

Priority: Critical
Analyzes: ENV

D5:secret-aws-access-key

Secrets shouldn't be hard-coded. You should remove and rotate any secrets.

This rule matches against the pattern \bAK[A-Z0-9]{18}\b

Priority: Critical
Analyzes: ENV

D5:secret-aws-secret-access-key

Secrets shouldn't be hard-coded. You should remove and rotate any secrets.

This rule matches against the pattern \b[A-Za-z0-9/+=]{40}\b

Priority: Critical
Analyzes: ENV

D6:questionable-expose

Avoid documenting EXPOSE with sensitive ports

The EXPOSE command is metadata and does not actually open ports. Documenting the intention to expose sensitive ports poses a security concern.

Priority: Low
Analyzes: EXPOSE

D7:tagged-latest

Avoid using images tagged as Latest in production builds

Docker best practices suggest avoiding latest images in production builds

Priority: High
Analyzes: FROM

D7:tagged-latest-builder

Avoid using images tagged as Latest in builder stages

Using latest images in builders is not recommended (builds are not repeatable).

Priority: Low
Analyzes: FROM

D9:formatting-labels

Label keys should be formatted correctly.

Label keys should begin and end with a lower-case letter and should only contain lower-case alphanumeric characters, the period character (.), and the hyphen character (-). Consecutive periods or hyphens are not allowed.

Priority: High
Analyzes: LABEL

D9:oci-labels

Consider using common annotations defined by Open Containers Initiative

Open Containers Initiative defines a common set of annotations which expose as labels on containers

Priority: Medium
Analyzes: LABEL

D9:reserved-labels

You can't define labels which are reserved by docker.

Docker reserves the following namespaces in labels: com.docker.*, io.docker.*, and org.dockerproject.*.

Priority: Critical
Analyzes: LABEL

DA:maintainer-deprecated

MAINTAINER is deprecated

MAINTAINER instruction is deprecated; Use LABEL instead, which can be queried via docker inspect. This rule matches against the pattern [[:graph:]]+

Priority: Low
Analyzes: MAINTAINER

DC:apt-get-update-install

You must perform apt-get update and install in same RUN layer

Having apt-get update and install in separate RUN layers will break caching. Having install without update is not recommended. Include both commands in the same layer.

Priority: Critical
Analyzes: RUN

DC:avoid-sudo

Avoid running root elevation tasks like sudo/su

Non-root users should avoid having sudo access in containers, as it has unpredictable TTY and signal-forwarding behavior that can cause problems. Consider using gosu instead.

Priority: Medium
Analyzes: RUN

DC:consider-multistage

Consider using multi-stage builds for complex operations like building code.

A multi-stage build can reduce the final image size by building necessary components or downloading large archives in a separate build context. This can help keep your final image lean.

Priority: Low
Analyzes: RUNFROM

DC:curl-without-fail

Avoid using curl without the silent failing option -f/--fail

Invoking curl without -f/--fail may result in incorrect, missing or stale data, which is a security concern. Ignore this rule only if you're handling server errors or verifying file contents separately.

Priority: Critical
Analyzes: RUN

DC:gpg-without-batch

GPG call without --batch (or --no-tty) may error.

Running GPG without --batch (or --no-tty) may cause GPG to fail opening /dev/tty, resulting in docker build failures.

Priority: Medium
Analyzes: RUN

DC:layered-ownership-change

Change ownership in the same layer as file operation (RUN or COPY)

In AUFS, ownership defined in an earlier layer can not be overridden by a broader mask in a later layer. This rule matches against the pattern [^ch(own|mod)\b]

Priority: Medium
Analyzes: RUN

DC:minimize-layers

Try to minimize the number of layers which increase image size

RUN, ADD, and COPY create new layers which may increase the size of the final image. Consider condensing these to fewer than 7 combined layers or use multi-stage builds where possible.

Priority: Low
Analyzes: RUNADDCOPY

DC:sort-installer-args

Sort installed packages for package managers: apt-get, apk, npm, etc.

Sorting installed packages alphabetically prevents duplicates and simplifies maintainability.

Priority: Low
Analyzes: RUN

DF:named-user

Reference a user by name rather than UID.

Reference a user by name to avoid maintenance or runtime issues with generated IDs.

Priority: High
Analyzes: USERCOPY