Перейти к основному содержимому
Software Supply Chain Security: Dependencies, SBOM & SLSA
Урок 9 из 11

Software Supply Chain Security: Dependencies, SBOM & SLSA

Manage third-party dependency risks, generate and compare SPDX or CycloneDX SBOMs with Syft, and sign and verify container provenance with Cosign and SLSA.

Продвинутый 26 мин Облака и DevSecOps
Этого урока пока нет на выбранном языке — показана версия на другом языке. Перевод готовится.

Цели обучения

  • Explain dependency confusion, typosquatting, and transitive dependency risks in software builds
  • Generate and inspect CycloneDX or SPDX Software Bills of Materials (SBOMs) using Syft
  • Sign and verify container image digests and attestations using Sigstore Cosign
  • Evaluate build pipelines against SLSA Build Track levels 1 through 3

Рекомендуется заранее: Container & Docker Security: Namespaces, Rootless & ImagesCI/CD Pipeline Hardening & Secrets Management (OIDC/Vault)

#Why this matters

Even when your application code passes every static check and your CI/CD workflow uses OIDC and Vault, most of the bytes shipped inside a modern container image come from upstream open-source libraries and base OS packages. A single compromised transitive package or an altered image pushed to a registry can reach production unnoticed.

Software supply chain security addresses two fundamental questions before anything runs in Kubernetes or production: what components are inside this artifact? (answered by dependency pinning and SBOMs) and did our trusted pipeline actually build it without tampering? (answered by Cosign signatures and SLSA provenance).

#Dependency risks and lockfile hygiene

Application builds pull both direct dependencies (listed in package.json or pyproject.toml) and transitive dependencies (packages pulled in by those libraries). Attackers target this graph in three common ways:

Attack vector Mechanism Primary defence
Typosquatting Publishing a lookalike package name on PyPI or npm Review package names, inspect maintainers, restrict install sources
Dependency confusion Claiming an internal company package name on a public registry Use scoped namespaces, explicit private registry priority, and lockfiles
Compromised maintainer update Publishing a malicious patch release under a trusted package name Pin exact versions in lockfiles with integrity hashes (npm ci, pip --require-hashes)

Lockfiles (package-lock.json, poetry.lock, go.sum) ensure every build resolves the exact package version and cryptographic hash reviewed in code review. Without hash-verified lockfiles, a build on Tuesday can silently pull different code than the build tested on Monday.

#Generating and diffing SBOMs with Syft

A Software Bill of Materials (SBOM) is a structured inventory of every OS package, language library, and version inside an artifact. Two open formats dominate: SPDX (an ISO standard) and CycloneDX (widely used in security tooling). When a high-impact vulnerability is announced in a library, teams with stored SBOMs can query their inventory in seconds instead of rebuilding or unpacking hundreds of containers.

Syft inspects container images, filesystems, or archives and outputs CycloneDX or SPDX JSON:

Generating and comparing SBOMs for a lab container image
$ syft lab.local/portal:1.0.0 -o table | head -n 8
NAME               VERSION       TYPE
alpine-baselayout  3.4.3-r2      apk
busybox            1.36.1-r19    apk
ca-certificates    20240226-r0   apk
flask              3.0.2         python
jinja2             3.1.3         python
werkzeug           3.0.1         python

$ syft lab.local/portal:1.0.0 -o cyclonedx-json > sbom-v1.0.0.cdx.json
$ syft lab.local/portal:1.0.1 -o cyclonedx-json > sbom-v1.0.1.cdx.json

Diffing sbom-v1.0.0.cdx.json against sbom-v1.0.1.cdx.json (for example with jq on .components[] | "\(.name)@\(.version)" and diff -u) highlights unexpected package additions or suspicious version jumps before release. Storing the SBOM alongside the image lets downstream scanners check for newly disclosed CVEs continuously without touching source code.

#Artifact signing and provenance with Cosign

Container tags such as :1.0.0 or :latest are mutable labels that can be overwritten in a registry. Production deployments and verification checks must always reference the immutable SHA-256 image digest (lab.local/portal@sha256:...).

Sigstore Cosign signs container digests and attaches signed JSON attestations (such as an SBOM or SLSA provenance) directly in the OCI registry. In keyless signing, the CI runner uses its OIDC token to obtain a short-lived code-signing certificate from Sigstore's certificate authority (Fulcio), signs the digest, and records the signature timestamp in an append-only transparency log (Rekor).

Keyless artifact signing and cluster verification with CosignKeyless artifact signing and cluster verification with CosignCI_RunnerFulcio_CAOCI_RegistryRekor_LogDeployerPresent CI OIDC JWT and ephemeral public keyShort-lived certificate bound to repo and branchPush image digest and Cosign signatureRecord signed entry and timestampFetch image digest, signature, and Rekor proofVerify certificate issuer and repo identity before deploy

Teams running private infrastructure can also sign and verify with managed keypairs:

Signing and verifying an immutable image digest with Cosign
$ cosign sign --key cosign.key lab.local/portal@sha256:4b2a9f1e8c7d6b5a4b2a9f1e8c7d6b5a4b2a9f1e8c7d6b5a4b2a9f1e8c7d6b5a
$ cosign verify --key cosign.pub lab.local/portal@sha256:4b2a9f1e8c7d6b5a4b2a9f1e8c7d6b5a4b2a9f1e8c7d6b5a4b2a9f1e8c7d6b5a

Verification for lab.local/portal@sha256:4b2a9f1e8c7d6b5a4b2a9f1e8c7d6b5a4b2a9f1e8c7d6b5a4b2a9f1e8c7d6b5a --
The following checks were performed on each of these signatures:
  - The cosign claims were validated
  - The signatures were verified against the specified public key

You can attach an SBOM or provenance file as an OCI attestation using cosign attest --key cosign.key --predicate sbom-v1.0.1.cdx.json --type cyclonedx <image-digest> and verify both the image and its attestation in admission control.

#SLSA provenance levels

SLSA (Supply-chain Levels for Software Artifacts) provides a common vocabulary for build integrity. Its Build Track defines progressively stronger guarantees that an artifact came from the expected source and was not modified during compilation:

SLSA Build Level Core requirement Threats mitigated
Level 1 Build process produces machine-readable provenance Accidental mistakes, lack of build visibility
Level 2 Build runs on a hosted CI platform that signs provenance Post-build tampering and unverified local builds
Level 3 Hardened, isolated build platform prevents cross-job interference Build-time tampering by other workflows or tenants

Reaching SLSA Level 2 in GitHub Actions or similar hosted CI platforms is practical for most teams: run builds on ephemeral hosted runners, generate signed provenance attestations tied to the image digest, and reject unsigned or locally built images at deployment time.

#Defending and common mistakes

  • Verifying mutable tags instead of digests: Checking a signature on :1.0.0 and then pulling :1.0.0 later opens a time-of-check to time-of-use race if the tag is overwritten. Always resolve and deploy by @sha256:.
  • Generating SBOMs without storing or comparing them: An SBOM discarded at the end of a CI run helps nobody during an incident. Attach SBOMs as signed attestations or archive them per release digest.
  • Unpinned base images in Dockerfiles: Writing FROM python:3.12-slim pulls shifting OS packages on every build. Pin base images by digest (FROM python:3.12-slim@sha256:...) and update them deliberately.
  • Signing artifacts before security gates run: Never sign an image until tests, dependency checks, and IaC/container scans have all passed.

#Summary

Supply chain security protects both the ingredients inside software and the integrity of the build process that assembles them. Hash-verified lockfiles and pinned base images block unexpected upstream changes, while Syft produces SPDX or CycloneDX SBOMs for rapid inventory and release diffing. Pairing Sigstore Cosign signatures and attestations with SLSA-aligned hosted builds ensures production systems only deploy artifacts built from reviewed source code in trusted pipelines.

Проверка знаний

Войдите, чтобы проходить тест, завершать уроки и сохранять прогресс. Войти в систему

Практика: проверьте свои знания