diff --git a/.github/workflows/secret-scan.yml b/.github/workflows/secret-scan.yml new file mode 100644 index 0000000..3735a28 --- /dev/null +++ b/.github/workflows/secret-scan.yml @@ -0,0 +1,40 @@ +name: Secret Scanning + +on: + pull_request: + push: + branches: [main, master] + +permissions: + contents: read + +jobs: + secret-scan: + name: Gitleaks Secret Scan + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install Gitleaks + run: | + VERSION=$(curl -sI https://github.com/gitleaks/gitleaks/releases/latest | grep -i '^location:' | sed 's/.*tag\/v//' | tr -d '\r') + curl -sSfL "https://github.com/gitleaks/gitleaks/releases/download/v${VERSION}/gitleaks_${VERSION}_linux_x64.tar.gz" | tar xz + chmod +x gitleaks + + - name: Scan for secrets + run: | + if [ "${{ github.event_name }}" = "pull_request" ]; then + ./gitleaks detect --source . --log-opts "${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}" --verbose + else + BEFORE="${{ github.event.before }}" + if [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then + # Branch creation push -- no prior SHA. Scan full tree. + ./gitleaks detect --source . --verbose + else + ./gitleaks detect --source . --log-opts "${BEFORE}..${{ github.sha }}" --verbose + fi + fi