diff --git a/.github/workflows/security.yaml b/.github/workflows/security.yaml new file mode 100644 index 00000000..e8be9ad2 --- /dev/null +++ b/.github/workflows/security.yaml @@ -0,0 +1,52 @@ +name: enforce-secret-scanning + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +env: + GITLEAKS_VERSION: "8.30.1" + GITLEAKS_SHA256: "551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb" + +jobs: + secret-scan: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install gitleaks (checksum-verified) + run: | + curl -sSL -o gitleaks.tar.gz "https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" + echo "${GITLEAKS_SHA256} gitleaks.tar.gz" | sha256sum --check + tar -xzf gitleaks.tar.gz gitleaks + sudo mv gitleaks /usr/local/bin/ + + - name: Scan repo history + run: gitleaks git . --verbose + + enforcement-canary: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install gitleaks (checksum-verified) + run: | + curl -sSL -o gitleaks.tar.gz "https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" + echo "${GITLEAKS_SHA256} gitleaks.tar.gz" | sha256sum --check + tar -xzf gitleaks.tar.gz gitleaks + sudo mv gitleaks /usr/local/bin/ + + - name: Planted secret MUST be caught + run: | + echo 'const key = "AKIAQQQQQQQQQQQQQQQQ"' > canary.ts + if gitleaks dir .; then + echo "::error::gitleaks passed a planted AWS key - scanning is broken" + exit 1 + fi + echo "Planted secret correctly rejected"