Skip to content
This repository has been archived by the owner on Mar 30, 2021. It is now read-only.
/ dockersource Public archive

Check FROM directive of a Dockerfile for whitelisted or blacklisted image RegEx.

Notifications You must be signed in to change notification settings

oleg-fiksel/dockersource

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚠️ WARNING! This repo is moved to https://gitlab.com/olegfiksel/dockersource

Dockersource

Check FROM derective of a Dockerfile for whitelisted or blacklisted image RegEx.

Use-case

You want to make sure the sources for your Dockerfiles (FROM ...) are controlled by a whitelist or a backlist. This take cares of having such a Dockerfile in your project:

FROM wildhacker/openjdk:latest
COPY target/*.jar /work

Build

It's a Perl 5 script so you can use any Perl (>= v5.6.0) environment to run this script or use the official Docker image: https://hub.docker.com/r/olegfiksel/dockersource

Run

docker run olegfiksel/dockersource perl /opt/dockersource/dockersource.pl --help

dockersource.pl Version: 3.0.0
Usage: dockersource.pl (--whitelist 'regex'|--blacklist 'regex') [--summary] [--debug] [--help] /path/to/Dockerfile /path/to_another/Dockerfile

--whitelist         Specify a Perl RegEx to whitelist Docker images used in FROM clause
--blacklist         Specify a Perl RegEx to blacklist Docker images used in FROM clause
--summary           Print the whitelist and blacklist summary before the run
--debug             Enable debug output

Return codes:
      0 - No violations found
      0 - No parameters given
    >=1 - Number of violations found

Examples:
    dockersource.pl --whitelist '^my-private-registry.org/.*' /path/to/Dockerfile /path/to/another/Dockerfile
    dockersource.pl --whitelist '^openjdk' --whitelist 'openjdk' /path/to/Dockerfile
    dockersource.pl --whitelist '^openjdk:.*-alpine' /path/to/Dockerfile
    dockersource.pl --blacklist '^wildhacker/.*' /path/to/Dockerfile

GitLab-CI

Sample job definition (.gitlab-ci.yml:):

stages:
  - compliance

compliance:dockerfile:
  stage: compliance
  image: olegfiksel/dockersource
  script:
    - |
      find . -type f -name Dockerfile | xargs perl /opt/dockersource/dockersource.pl \
        --whitelist '^openjdk:\d+[\w\d-]*$' \
        --blacklist ':latest' \
        --blacklist '.'

About

Check FROM directive of a Dockerfile for whitelisted or blacklisted image RegEx.

Resources

Stars

Watchers

Forks

Packages

No packages published