← All cheatsheets

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.

Docs-checkeddevsecopssupply-chainsbomsigstoresca

Quick reference — reach for these first

SCA scannpm audit --audit-level=high # or: pip-auditFlag known-vulnerable dependencies (CVEs) before they ship.
Secret scangitleaks detect --redact --source .Catch committed keys/tokens; pair with GitHub push protection.
SBOMsyft dir:. -o cyclonedx-json=sbom.cdx.jsonProduce a CycloneDX/SPDX inventory of every component shipped.
Sign artifactcosign sign --yes IMAGE@sha256:DIGESTKeyless Sigstore signature so consumers can verify origin.
Scope CI tokenpermissions: { contents: read, id-token: write }Least-privilege GITHUB_TOKEN + OIDC instead of long-lived keys.

Supply-chain controls mapped onto the build pipeline

Supply-chain controls across the build pipelineFive pipeline stages left to right, each annotated with the DevSecOps control that guards it, ending at a signature-verification policy gate before deploy.SourceBuild (CI)SBOM + scanSign + provenanceDeploysecret scangitleaks + pushprotectionleast privilegescoped token +OIDC federationSCA + inventorynpm audit / pip-auditsyft CycloneDX/SPDXauthenticitycosign keyless+ SLSA provenancepolicy gatecosign verifyblocks on failEach control fails the pipeline closed: a finding, a missing SBOM, or an unverifiable signature stops promotion.

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

TaskCommandWhat to check
Pin SCA into CI and fail on high severitynpm audit --audit-level=high --omit=devExit code 0 on clean tree; non-zero when a HIGH/CRITICAL advisory exists
Run the Python SCA equivalentpip-audit -r requirements.txt --strictReports 'No known vulnerabilities found' or lists CVE + fixed-in version
Enable Dependabot / scheduled scannertrivy fs --scanners vuln,secret --severity HIGH,CRITICAL .Table lists package, severity, installed vs fixed version
Add secret scanning as a pre-merge gategitleaks detect --redact --no-banner --exit-code 1Exit 1 with a finding block when a secret matches; exit 0 when clean
[CHANGES REPO SETTINGS] Turn on GitHub push protectiongh 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 outputsyft packages dir:./dist -o spdx-json=sbom.spdx.jsonsbom.spdx.json exists and lists components with versions and licenses
Validate the SBOM against its schemacyclonedx validate --input-file sbom.cdx.jsonPrints 'BOM validated successfully' (no schema errors)
[CHANGES CI IDENTITY] Federate CI to the cloud via OIDCaws 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 privilegeyq '.permissions' .github/workflows/release.ymlShows only the scopes needed (e.g. contents: read, id-token: write), not write-all
[CHANGES PROD ARTIFACT] Sign the release artifact keylesslycosign sign --yes REGISTRY/IMAGE@sha256:DIGESTSignature + certificate uploaded to the registry and Rekor transparency log
Attach SLSA provenance / SBOM attestationcosign attest --yes --predicate sbom.cdx.json --type cyclonedx REGISTRY/IMAGE@sha256:DIGESTcosign verify-attestation returns the attestation payload
Add a verification gate before deploycosign verify --certificate-identity-regexp 'https://github.com/OWNER/.+' --certificate-oidc-issuer https://token.actions.githubusercontent.com REGISTRY/IMAGE@sha256:DIGESTExits 0 and prints the verified signature; deploy step is blocked on failure
Record a justified, time-boxed allowlist entryprintf '{"advisories":{"GHSA-XXXX":"not reachable; review 2026-12-01"}}' > .nsprcScanner 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

1
Read the finding emitted by the scanner — capture package, severity, and fixed-in version
npm audit --audit-level=high --json | jq '.vulnerabilities'
# lodash  HIGH  prototype pollution (GHSA-xxxx)  installed 4.17.11  fixed in 4.17.21
2
Decide reachability: is the vulnerable API actually called, or only pulled in transitively?
npm ls lodash
# app@1.0.0 -> some-lib@2.3.0 -> lodash@4.17.11  (transitive, used by templating path = reachable)
3
Prefer the smallest safe change — bump/pin to the fixed version
npm install lodash@4.17.21 && npm dedupe
# added 1 package, changed 1 package; lockfile updated to 4.17.21
4
If no fix exists AND the code path is unreachable, record a justified, time-boxed allowlist instead of a blind ignore
printf '{"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)
5
Re-scan to confirm the gate is green
npm audit --audit-level=high
# found 0 vulnerabilities
6
Verify the app still builds and tests pass after the bump
npm ci && npm run build && npm test
# build succeeded; tests passed — safe to commit the lockfile change

Troubleshooting — symptom → first check → next check

SymptomFirst checkEstablishesNext check
Pipeline fails on a dependency CVERead the finding: package, severity, and fixed-in version, then check whether the vulnerable code path is actually reachableWhether it is a true positive you must fix or a non-reachable finding you can justify-suppressBump/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 pushedConfirm the match with gitleaks and identify the exact credential and where it is validThat 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 gateRead 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 debtFix 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 deployRun cosign verify with the expected --certificate-identity and --certificate-oidc-issuer and read the mismatchWhether the artifact is unsigned/tampered or the verifier's expected identity/issuer is wrongIf 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 neededInspect the workflow permissions block and any static cloud keys stored in repo secretsThe blast radius if the runner or a dependency is compromisedReplace 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 componentsConfirm syft is pointed at the built artifact (image/dir) rather than only source, and that lockfiles are presentWhether the scanner can see resolved dependencies or only manifestsGenerate the SBOM from the final build output with lockfiles committed so transitive versions are pinned and captured

References

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.