check-docker-pin.sh 861 B

1234567891011121314151617181920
  1. #!/usr/bin/env bash
  2. # This script is checks to 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. # Explaination of regex ignore choices
  9. # - We ignore sha256 because it suggests that the image dep is pinned
  10. # - We ignore scratch because it's literally the docker base image
  11. # - We ignore solana AS (builder|ci_tests) because it's a relative reference to another FROM call
  12. #
  13. git ls-files | grep "Dockerfile*" | xargs grep -s "FROM" | egrep -v 'sha256|scratch|solana AS (builder|ci_tests)'
  14. if [ $? -eq 0 ]; then
  15. echo "[!] Unpinned docker files" >&2
  16. exit 1
  17. else
  18. echo "[+] No unpinned docker files"
  19. fi