CI/CD Integration
GitHub Actions
Scan every push and pull request in GitHub Actions with Safeguard, and fail the workflow on vulnerabilities
GitHub Actions
1. Add the secret
Create a secret key in Safeguard under Settings โ Developer with the scopes scans:trigger
and scans:read. In GitHub, add it under Settings โ Secrets and variables โ Actions โ New
repository secret with the name SAFEGUARD_API_KEY. An organisation secret works too.
2. Add the workflow
Save this as .github/workflows/safeguard.yml
(download):
name: Safeguard
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
scan:
runs-on: ubuntu-latest
steps:
- name: Safeguard scan
env:
SAFEGUARD_API_KEY: ${{ secrets.SAFEGUARD_API_KEY }}
SAFEGUARD_INSTALL_DIR: ${{ runner.temp }}/safeguard-bin
run: |
set -eu
curl -fsSL https://cli.safeguard.sh/install | bash
"$SAFEGUARD_INSTALL_DIR/safeguard" ci scan --wait --fail-on criticalNo checkout step is needed: Safeguard clones the repository. Push, and the run shows the scan's result and a link to it in Safeguard.
Choose the branches
on.push.brancheslists the branches whose pushes are scanned.on.pull_request.brancheslists the target branches of pull requests that are scanned. Delete thepull_requestblock to scan pushes only.
Wildcards work, for example [main, 'release/**']. On a pull request the head branch is
scanned and the version is named after its head commit.
Options
| Change | How |
|---|---|
| Report only | Drop --fail-on critical |
| Another threshold | --fail-on high (or medium, low) |
| Fail on a policy gate | Add --fail-on-gate all |
| Scan on the runner | Add - uses: actions/checkout@v4 before the step and --local to the command |
| A specific project | Add --project-id <id> |
| Pin the CLI version | Add SAFEGUARD_VERSION: "<version>" to env |
Troubleshooting
- Pull requests from forks fail. GitHub gives fork pull requests no secrets. Scan pushes
only, or use
pull_request_targetwith care: it runs with your secrets, so never run the fork's code in that job. - Other errors: see Troubleshooting.