Security
DevSecOps & Supply Chain — scanning, SBOMs, signing, and least-privilege CI
Wire the core software-supply-chain controls into CI: dependency and secret scanning, SBOM generation, artifact signing with provenance, and short-lived OIDC credentials with scoped tokens — then gate the pipeline on them.
Quick reference — reach for these first
npm audit --audit-level=high # or: pip-auditFlag known-vulnerable dependencies (CVEs) before they ship.gitleaks detect --redact --source .Catch committed keys/tokens; pair with GitHub push protection.syft dir:. -o cyclonedx-json=sbom.cdx.jsonProduce a CycloneDX/SPDX inventory of every component shipped.cosign sign --yes IMAGE@sha256:DIGESTKeyless Sigstore signature so consumers can verify origin.permissions: { contents: read, id-token: write }Least-privilege GITHUB_TOKEN + OIDC instead of long-lived keys.Supply-chain controls mapped onto the build pipeline
Text equivalent: A left-to-right pipeline with five stages — Source, Build in CI, SBOM and scan, Sign and attest provenance, Deploy — each stage labeled with its control: secret scanning and push protection at Source; scoped GITHUB_TOKEN with OIDC federation at Build; SCA (npm audit, pip-audit, Trivy) plus SBOM (syft, CycloneDX, SPDX) at the scan stage; cosign keyless signing and SLSA provenance at the sign stage; and a cosign verify policy gate guarding Deploy.
Common tasks
Task · Command · What to check
| Task | Command | What to check |
|---|---|---|
| Pin SCA into CI and fail on high severity | npm audit --audit-level=high --omit=dev | Exit code 0 on clean tree; non-zero when a HIGH/CRITICAL advisory exists |
| Run the Python SCA equivalent | pip-audit -r requirements.txt --strict | Reports 'No known vulnerabilities found' or lists CVE + fixed-in version |
| Enable Dependabot / scheduled scanner | trivy fs --scanners vuln,secret --severity HIGH,CRITICAL . | Table lists package, severity, installed vs fixed version |
| Add secret scanning as a pre-merge gate | gitleaks detect --redact --no-banner --exit-code 1 | Exit 1 with a finding block when a secret matches; exit 0 when clean |
| [CHANGES REPO SETTINGS] Turn on GitHub push protection | gh api -X PATCH /repos/OWNER/REPO -f security_and_analysis='{"secret_scanning_push_protection":{"status":"enabled"}}' | A test push containing a known token pattern is rejected at the remote |
| Generate an SBOM for the build output | syft packages dir:./dist -o spdx-json=sbom.spdx.json | sbom.spdx.json exists and lists components with versions and licenses |
| Validate the SBOM against its schema | cyclonedx validate --input-file sbom.cdx.json | Prints 'BOM validated successfully' (no schema errors) |
| [CHANGES CI IDENTITY] Federate CI to the cloud via OIDC | aws sts assume-role-with-web-identity --role-arn ROLE_ARN --role-session-name ci --web-identity-token "$ACTIONS_ID_TOKEN" | Returns temporary AccessKeyId/SecretAccessKey/SessionToken; no static key in repo secrets |
| Scope GITHUB_TOKEN to least privilege | yq '.permissions' .github/workflows/release.yml | Shows only the scopes needed (e.g. contents: read, id-token: write), not write-all |
| [CHANGES PROD ARTIFACT] Sign the release artifact keylessly | cosign sign --yes REGISTRY/IMAGE@sha256:DIGEST | Signature + certificate uploaded to the registry and Rekor transparency log |
| Attach SLSA provenance / SBOM attestation | cosign attest --yes --predicate sbom.cdx.json --type cyclonedx REGISTRY/IMAGE@sha256:DIGEST | cosign verify-attestation returns the attestation payload |
| Add a verification gate before deploy | cosign verify --certificate-identity-regexp 'https://github.com/OWNER/.+' --certificate-oidc-issuer https://token.actions.githubusercontent.com REGISTRY/IMAGE@sha256:DIGEST | Exits 0 and prints the verified signature; deploy step is blocked on failure |
| Record a justified, time-boxed allowlist entry | printf '{"advisories":{"GHSA-XXXX":"not reachable; review 2026-12-01"}}' > .nsprc | Scanner passes while the suppression exists; CI comment records the reason + expiry |
A CI dependency scan flags a CVE — triage, fix, and re-verify
Dependency CVE in CI
npm audit --audit-level=high --json | jq '.vulnerabilities'
# lodash HIGH prototype pollution (GHSA-xxxx) installed 4.17.11 fixed in 4.17.21npm ls lodash
# app@1.0.0 -> some-lib@2.3.0 -> lodash@4.17.11 (transitive, used by templating path = reachable)npm install lodash@4.17.21 && npm dedupe
# added 1 package, changed 1 package; lockfile updated to 4.17.21printf '{"GHSA-xxxx":{"reason":"not reachable in prod path","expires":"2026-12-15"}}' > .audit-allow.json
# suppression recorded with reason + expiry (reviewed at next cycle, not forever)npm audit --audit-level=high
# found 0 vulnerabilitiesnpm ci && npm run build && npm test
# build succeeded; tests passed — safe to commit the lockfile changeTroubleshooting — symptom → first check → next check
| Symptom | First check | Establishes | Next check |
|---|---|---|---|
| Pipeline fails on a dependency CVE | Read the finding: package, severity, and fixed-in version, then check whether the vulnerable code path is actually reachable | Whether it is a true positive you must fix or a non-reachable finding you can justify-suppress | Bump/pin to the fixed version; if no fix exists and it is unreachable, add a time-boxed allowlist entry with a written justification and re-scan |
| A secret was committed and pushed | Confirm the match with gitleaks and identify the exact credential and where it is valid | That the secret is real and now compromised (git history is public even after deletion) | Rotate/revoke the credential at the provider FIRST, then purge from history; removing the commit alone does not un-leak it |
| Build fails on a newly added policy gate | Read the gate's output to see which control failed (scan, SBOM, signature, or token scope) | Whether the gate found a real violation or is misconfigured/too strict for existing debt | Fix the underlying violation; if pre-existing debt blocks everyone, set the gate to warn-only with a tracked deadline rather than disabling it |
| Signature or provenance verification fails at deploy | Run cosign verify with the expected --certificate-identity and --certificate-oidc-issuer and read the mismatch | Whether the artifact is unsigned/tampered or the verifier's expected identity/issuer is wrong | If identity is wrong, correct the regex/issuer; if genuinely unsigned or digest-mismatched, STOP the deploy — do not ship an unverifiable artifact |
| CI token has far broader scope than needed | Inspect the workflow permissions block and any static cloud keys stored in repo secrets | The blast radius if the runner or a dependency is compromised | Replace long-lived keys with OIDC federation and set job-level permissions to the minimum scopes; remove the static secrets |
| SBOM is empty or missing most components | Confirm syft is pointed at the built artifact (image/dir) rather than only source, and that lockfiles are present | Whether the scanner can see resolved dependencies or only manifests | Generate the SBOM from the final build output with lockfiles committed so transitive versions are pinned and captured |
References
- GitHub — Security hardening with OpenID Connectdocs.github.com
- Sigstore — cosign signing & verificationdocs.sigstore.dev
- SLSA — Provenance & build levelsslsa.dev
- CycloneDX — SBOM specificationcyclonedx.org
- npm Docs — npm auditdocs.npmjs.com
Examples assume a GitHub Actions + container-registry pipeline with Sigstore cosign (keyless OIDC) available; adapt the token/permissions syntax for GitLab CI or other runners.