check-docker-pin.sh 660 B

123456789101112131415161718
  1. #!/usr/bin/env bash
  2. # This script checks that all our Docker images are pinned to a specific SHA256 hash.
  3. #
  4. # References as to why...
  5. # - https://nickjanetakis.com/blog/docker-tip-18-please-pin-your-docker-image-versions
  6. # - https://snyk.io/blog/10-docker-image-security-best-practices/ (Specifically: USE FIXED TAGS FOR IMMUTABILITY)
  7. #
  8. # Explanation of regex ignore choices
  9. # - We ignore sha256 because it suggests that the image dep is pinned
  10. git ls-files -z | grep -z "Dockerfile*" | xargs -r -0 grep -s "FROM" | egrep -v 'sha256'
  11. if [ $? -eq 0 ]; then
  12. echo "[!] Unpinned docker files" >&2
  13. exit 1
  14. else
  15. echo "[+] No unpinned docker files"
  16. fi