Sometimes a real password, or a cloud key, gets committed by accident. Bots scan public repositories for keys within minutes. GitHub's secret scanning watches for this, and you can add your own check to CI as well.
This step searches the repository for text shaped like an Amazon cloud key. AKIA, then sixteen capital letters or digits. If grep finds one, the step prints it and fails. Real tools, like GitHub's push protection, or gitleaks, know hundreds of key shapes.
.github/workflows/secrets.ymlyaml
name: Secret checkon: [push, pull_request]jobs: secrets: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Look for cloud keys run: | if grep -rnE "AKIA[0-9A-Z]{16}" --exclude-dir=.git .; then echo "Found something that looks like a key"; exit 1 fi echo "No keys found"
First, the check passes. No keys. Then someone pastes a key into a config file, by accident. The check finds it, shows the file and line, and fails. If a real key is ever pushed, removing it isn't enough. Revoke it immediately, because it may already have been copied.
Terminal
run-steps .github/workflows/secrets.yml | grep -E "✓|No keys" ✓ Look for cloud keys No keys foundecho 'aws_key = AKIAABCDEFGHIJKLMNOP' > config.pyrun-steps .github/workflows/secrets.yml | grep -vE "^Workflow|↷"Job: secrets ✗ Look for cloud keys ./config.py:1:aws_key = AKIAABCDEFGHIJKLMNOP Found something that looks like a key Error: Process completed with exit code 1. Job failed