Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Published Rules - dockerfile.audit.dockerfile-source-not-pinned #1861

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions dockerfile/audit/dockerfile-source-not-pinned.yaml
@@ -0,0 +1,26 @@
rules:
- id: dockerfile-source-not-pinned
patterns:
- pattern-either:
- patterns:
- pattern: FROM $IMAGE:$VERSION@$HASH
- metavariable-regex:
metavariable: $HASH
regex: (?!sha256:)
- patterns:
- pattern: FROM $IMAGE
- pattern: FROM $IMAGE:$VERSION
- pattern-not-inside: FROM $IMAGE:$VERSION@$HASH
message: To ensure reproducible builds, pin Dockerfile `FROM` commands to a specific
hash. You can find the hash by running `docker pull $IMAGE` and then specify it
with `$IMAGE:$VERSION@sha256:<hash goes here>`
fix: FROM $IMAGE:$VERSION@sha256:$HASH
languages:
- dockerfile
severity: ERROR
metadata:
references:
- https://stackoverflow.com/a/33511811/4965
category: best-practice
technology:
- docker
20 changes: 20 additions & 0 deletions dockerfile/audit/dockerfile-source-not-pinnedDockerfile
@@ -0,0 +1,20 @@
# ruleid: dockerfile-source-not-pinned
FROM ocaml/opam2:debian-stable

# ok: dockerfile-source-not-pinned
# The docker base image below in the FROM currently uses OCaml 4.12.0

# ruleid: dockerfile-source-not-pinned
FROM returntocorp/ocaml:alpine-2021-07-15 as build-semgrep-core

# ruleid: dockerfile-source-not-pinned
FROM python:3.10.1-alpine3.15

# ruleid: dockerfile-source-not-pinned
FROM python:3.10.1-alpine3.15@v1

# ruleid: dockerfile-source-not-pinned
FROM python:3.10.1-alpine3.15@sha256

# ok: dockerfile-source-not-pinned
FROM python:3.10.1-alpine3.15@sha256:4be65b406f7402b5c4fd5df7173d2fd7ea3fdaa74d9c43b6ebd896197a45c448