Software Supply Chain Security, Kubernetes Security Hardening and Compliance as Code

DevOps Certification 24 min min read Updated: Nov 17, 2026 Advanced
Software Supply Chain Security, Kubernetes Security Hardening and Compliance as Code
Advanced Topic 2 of 2

Supply Chain Attacks

Attackers increasingly target how software is built and delivered, not only the running app: poisoned open-source packages, stolen CI credentials, tampered images, malicious GitHub Actions. The goal is to prove what is in your software and how it was built.

RiskDefense
Malicious or vulnerable dependencyLock files, pinned versions, SCA, Dependabot/Renovate, private registry proxies, review new dependencies
Compromised CI pipelineLeast-privilege tokens, OIDC, ephemeral runners, pinned actions, protected branches, required reviews
Tampered imageSign images, verify signatures at admission, deploy by digest
Unknown contentsGenerate and store SBOMs
Typosquatting and dependency confusionScoped registries, allow lists, internal package names reserved

SBOM and Provenance

bash # Create an SBOM (SPDX or CycloneDX) syft ghcr.io/myorg/shop-api:1.4.2 -o cyclonedx-json > sbom.cdx.json # Scan the SBOM for vulnerabilities later (even after release) grype sbom:./sbom.cdx.json # Attach it to the image as an attestation cosign attest --predicate sbom.cdx.json --type cyclonedx ghcr.io/myorg/shop-api@sha256:DIGEST

SLSA (Supply-chain Levels for Software Artifacts) is a framework with levels describing build integrity. Higher levels require builds on a hosted, isolated build service that creates signed provenance (who built what from which source). GitHub provides actions/attest-build-provenance and a SLSA generator for this.

Sign and Verify Images

yaml # In GitHub Actions: keyless signing with the workflow identity permissions: id-token: write packages: write contents: read steps: - uses: sigstore/cosign-installer@v3 - run: cosign sign --yes ghcr.io/${{ github.repository }}@${{ steps.build.outputs.digest }}
bash cosign verify ghcr.io/myorg/shop-api@sha256:DIGEST \ --certificate-identity-regexp '^https://github.com/myorg/shop-api/.*' \ --certificate-oidc-issuer https://token.actions.githubusercontent.com

Enforce at Admission: Kyverno

Admission controllers check or change objects before Kubernetes stores them. Kyverno uses plain YAML policies. OPA Gatekeeper uses Rego.

yaml apiVersion: kyverno.io/v1 kind: ClusterPolicy metadata: name: verify-image-signature spec: validationFailureAction: Enforce webhookTimeoutSeconds: 30 rules: - name: verify-cosign match: any: - resources: { kinds: [Pod] } verifyImages: - imageReferences: ["ghcr.io/myorg/*"] attestors: - entries: - keyless: issuer: https://token.actions.githubusercontent.com subject: "https://github.com/myorg/*" --- apiVersion: kyverno.io/v1 kind: ClusterPolicy metadata: name: disallow-latest-and-root spec: validationFailureAction: Enforce rules: - name: no-latest-tag match: { any: [{ resources: { kinds: [Pod] } }] } validate: message: "Images must use a pinned tag, not :latest" pattern: spec: containers: - image: "!*:latest" - name: run-as-non-root match: { any: [{ resources: { kinds: [Pod] } }] } validate: message: "Containers must not run as root" pattern: spec: securityContext: runAsNonRoot: true
Roll out safely: Start policies in Audit mode, review violations, fix workloads, then switch to Enforce.

Pod Security

Pod Security Standards have three profiles: privileged (no limits), baseline (blocks known escalations) and restricted (hardened best practice). Kubernetes enforces them per namespace through the built-in Pod Security Admission.

bash kubectl label namespace prod \ pod-security.kubernetes.io/enforce=restricted \ pod-security.kubernetes.io/warn=restricted \ pod-security.kubernetes.io/audit=restricted
yaml # A pod spec that meets the restricted profile apiVersion: v1 kind: Pod metadata: { name: hardened } spec: automountServiceAccountToken: false securityContext: runAsNonRoot: true runAsUser: 10001 seccompProfile: { type: RuntimeDefault } containers: - name: app image: ghcr.io/myorg/shop-api@sha256:DIGEST securityContext: allowPrivilegeEscalation: false readOnlyRootFilesystem: true capabilities: { drop: ["ALL"] } resources: requests: { cpu: 100m, memory: 128Mi } limits: { memory: 256Mi } volumeMounts: [{ name: tmp, mountPath: /tmp }] volumes: - name: tmp emptyDir: {}

Cluster Hardening Checklist

  • API server: private endpoint or restricted CIDRs, audit logging on, anonymous auth off
  • RBAC: least privilege, no wildcard roles, review cluster-admin bindings, short-lived human access via SSO
  • Secrets: encryption at rest, external secret manager, no secrets in env when avoidable
  • Network: default-deny NetworkPolicies, then allow needed flows. Consider a service mesh (mTLS)
  • Nodes: minimal OS, auto patching, no SSH, restrict instance metadata access (IMDSv2, hop limit)
  • Images: trusted registries only, scan, sign, non-root
  • etcd: encrypted, restricted, backed up
  • Keep Kubernetes updated within the supported versions
yaml # Default deny all ingress in a namespace apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: { name: default-deny, namespace: prod } spec: podSelector: {} policyTypes: [Ingress, Egress]

Benchmarks and Scanners

bash # CIS Kubernetes Benchmark checks for nodes kube-bench run --targets node,master # Scan live cluster and manifests for misconfigurations and risky RBAC trivy k8s --report summary cluster kubescape scan framework nsa

Runtime Detection with Falco

yaml # Falco rule: shell started inside a container - rule: Terminal shell in container desc: A shell was spawned in a container with an attached terminal condition: > evt.type = execve and container.id != host and proc.name in (bash, sh, zsh) and proc.tty != 0 output: "Shell in container (user=%user.name container=%container.name image=%container.image.repository cmd=%proc.cmdline)" priority: WARNING

Falco watches system calls using eBPF and alerts on suspicious behavior: shells in containers, reading /etc/shadow, unexpected network connections, privilege escalation. Send alerts to your SIEM or chat.

Compliance as Code

  • Express rules as policies (Kyverno, OPA, Azure Policy, AWS Config rules, Terraform Sentinel/OPA)
  • Evaluate them continuously and in pipelines, not once a year
  • Collect evidence automatically: scan reports, change history from Git, access logs
  • Map controls to frameworks such as CIS, SOC 2, ISO 27001, PCI DSS and HIPAA, with the help of your compliance team
  • Use cloud posture tools: AWS Security Hub, Microsoft Defender for Cloud, Google Security Command Center, open-source Prowler and ScoutSuite

CKS and Security Certification Notes

  • The Certified Kubernetes Security Specialist (CKS) is a hands-on exam that requires an active CKA
  • Topics: cluster setup and hardening, system hardening, minimizing microservice vulnerabilities, supply chain security, monitoring, logging and runtime security
  • Practice with Pod Security, NetworkPolicy, RBAC, AppArmor and seccomp profiles, Falco, Trivy, audit policy and ImagePolicyWebhook
  • Check the Linux Foundation site for the current curriculum and Kubernetes version

Practice Tasks

  1. Generate an SBOM for an image and scan it later with Grype
  2. Sign an image in CI with cosign and verify it in a Kyverno policy on a kind cluster
  3. Label a namespace with the restricted Pod Security level and fix a Deployment to pass
  4. Apply default-deny NetworkPolicies and add explicit allows
  5. Run kube-bench and fix three findings

Conclusion

Supply chain security proves what you ship with SBOMs, provenance and signatures, admission policies enforce it in the cluster, and hardening plus runtime detection limit damage. Roll out policies in audit mode first.

Quick Summary: SBOM + provenance + cosign; Kyverno/Gatekeeper admission; Pod Security restricted; default-deny network; Falco; kube-bench; compliance as code.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators