โšก
Zero to Platform Architect2026
Phase 3 & 3B: DevSecOps & Fleet Patching

Lesson 1: Container Security, Vulnerability Scanning, Cryptographic Signing & Exception Handling

๐Ÿง  The Concept (Explain Like Iโ€™m 5)

Imagine ordering medicine online from an unknown vendor:

  • Untrusted Container: A dusty plastic bottle with no label, no seal, and no expiration date. You have no idea if it contains life-saving medicine or poison, who manufactured it, or whether someone tampered with it in transit.
  • Trivy (The Laboratory Toxicology Screen): A certified forensic chemist who tests the liquid for thousands of known toxins and impurities (CVE Vulnerability Scanning). If any toxic chemicals are detected, the bottle is marked unsafe.
  • Syft (The Exact Chemical Recipe): A detailed nutritional factsheet listing every single molecular ingredient, preservative, and packaging material bundled inside (Software Bill of Materials / SBOM).
  • Cosign (The Tamper-Proof Hologram): A tamper-evident cryptographic seal stamped onto the cap by the verified manufacturer. If anyone opens the cap or swaps the liquid, the hologram shatters.
  • Kyverno (The Strict Hospital Gatekeeper): An automated policy officer guarding the hospital pharmacy doors. If a bottle arrives without a valid holographic seal, the officer immediately destroys it before it ever reaches a patient (Kubernetes Admission Control).

๐Ÿข The Enterprise Context (Why Platform Architects Care)

  1. Supply Chain Attacks (e.g., SolarWinds, Codecov, XZ Utils): Attackers no longer focus solely on exploiting running production servers. They compromise developer laptops, open-source dependencies, or CI/CD build pipelines to inject backdoors directly into trusted software before deployment.
  2. Regulatory Mandates & Executive Order 14028: High-trust enterprises (finance, healthcare, defense) are legally required to produce an immutable, cryptographically verifiable Software Bill of Materials (SBOM) for every software artifact running in production.
  3. Keyless Signing via Sigstore: Historically, teams managed private GPG or RSA signing keys on disk. If a private key leaked, the entire company was compromised; if it expired, production deployments halted. Modern DevSecOps uses Keyless Signing: cryptographic identities are minted on-the-fly for 10 minutes using OIDC tokens, anchored to public transparency logs.

๐Ÿ—บ๏ธ Visual Architecture: Cryptographic Supply Chain Pipeline

flowchart TD
    Git["๐Ÿ‘จโ€๐Ÿ’ป Developer Push to Git"] --> Runner["GitHub Actions Runner"]

    subgraph BuildScanPhase ["1. Build & Forensic Scanning"]
        Runner --> Build["Docker Build Container Image"]
        Build --> Trivy{"<b>Trivy Scan</b><br/>(Vulnerabilities & Misconfigs)"}
        Trivy -->|"CVE Severity >= HIGH"| TrivyFail["โŒ Block CI Pipeline & Post Slack Alert"]
        Trivy -->|"Passes Clean"| Syft["<b>Syft</b>: Generate SBOM (CycloneDX JSON)"]
    end

    subgraph SigningPhase ["2. Sigstore Keyless Signing & Attestation"]
        Syft --> PushImage["Push Unsigned Image to AWS ECR"]
        PushImage --> Fulcio["<b>Sigstore Fulcio CA</b><br/>(Issues ephemeral 10m certificate via GitHub OIDC token)"]
        Fulcio --> CosignSign["<b>Cosign Sign</b><br/>Signs image digest SHA256"]
        CosignSign --> Rekor[("<b>Sigstore Rekor Log</b><br/>Tamper-proof Merkle Tree transparency audit ledger")]
        CosignSign --> CosignAttest["<b>Cosign Attest</b><br/>Cryptographically attaches SBOM to ECR"]
    end

    subgraph AdmissionPhase ["3. Kubernetes Gatekeeper Enforcement"]
        CosignAttest --> EKS["โ˜ธ๏ธ Production EKS Cluster (ArgoCD Deploy)"]
        EKS --> Kyverno{"<b>Kyverno Admission Controller</b><br/>Verifies signature & OIDC issuer before Pod admission"}
        
        Kyverno -->|"Invalid / Missing Signature"| RejectPod["โŒ Deny Admission (Image Blocked)"]
        Kyverno -->|"Valid Cryptographic Proof"| AdmitPod["โœ… Pod Admitted & Scheduled"]
    end

๐Ÿ”ฌ Under the Hood: Sigstore Keyless Architecture & Merkle Trees

Traditional container signing required storing a long-lived private key (e.g. cosign.key) inside GitHub Secrets or HashiCorp Vault. Keyless Sigstore eliminates long-lived private keys entirely:

sequenceDiagram
    autonumber
    participant CI as ๐Ÿค– GitHub Actions Workflow
    participant OIDC as ๐ŸŒ GitHub OIDC Provider
    participant Fulcio as ๐Ÿ›๏ธ Fulcio (Ephemeral Root CA)
    participant Rekor as ๐Ÿ“œ Rekor (Transparency Ledger)
    participant ECR as ๐Ÿชฃ Amazon ECR Registry

    CI->>OIDC: Request OpenID Connect JWT (Audience: sigstore)
    OIDC-->>CI: Returns Signed JWT (Claims: repo, branch, workflow)
    CI->>CI: Generates ephemeral in-memory ECDSA keypair (Expires in 10 mins)
    CI->>Fulcio: Send Public Key + GitHub OIDC JWT
    Note over Fulcio: Verifies JWT signature.<br/>Issues short-lived X.509 certificate binding public key to Git identity.
    Fulcio-->>CI: Returns Signed X.509 Certificate
    CI->>CI: Signs image SHA256 digest using ephemeral private key
    CI->>Rekor: Publish signature, certificate, and image digest
    Note over Rekor: Appends entry to append-only cryptographic Merkle Tree.<br/>Generates Signed Entry Timestamp (SET).
    Rekor-->>CI: Returns SET Proof
    CI->>ECR: Uploads signature layer (.sig) and attestation (.att)
  1. Fulcio: A free, public Certificate Authority that issues short-lived (10-minute) X.509 certificates. It verifies that the entity holding the private key matches the OIDC claims from GitHub Actions or Google Cloud.
  2. Rekor: An append-only cryptographic transparency ledger built on a Merkle Tree. Once an entry is committed to Rekor, it is mathematically impossible to alter, forge, or backdate a signature without invalidating the cryptographic tree root.
  3. OCI Storage (.sig & .att artifacts): Cosign does not modify the original image bytes. It pushes a companion OCI artifact to the registry tagged as sha256-<digest>.sig.

๐Ÿ’ป Production Implementation: Security Workflows & Kyverno Policies

1. Hardened GitHub Actions Supply Chain Workflow (.github/workflows/secure-build.yml)

name: Production Secure Build, Scan & Cryptographic Sign

on:
  push:
    branches: [main]

permissions:
  contents: read
  packages: write
  id-token: write # CRITICAL: Grants permission to mint GitHub OIDC JWT for Sigstore & AWS

jobs:
  build-and-sign:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v4

      - name: Setup Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Authenticate to AWS ECR
        uses: aws-actions/amazon-ecr-login@v2
        env:
          AWS_REGION: us-east-1

      - name: Build and Push OCI Image
        id: build-image
        uses: docker/build-push-action@v5
        with:
          context: .
          push: true
          tags: 123456789012.dkr.ecr.us-east-1.amazonaws.com/payment-service:${{ github.sha }}

      # ------------------------------------------------------------------------
      # Step 1: Forensic Vulnerability Scan with Trivy
      # ------------------------------------------------------------------------
      - name: Run Trivy Security Vulnerability Scan
        uses: aquasecurity/trivy-action@master
        with:
          image-ref: 123456789012.dkr.ecr.us-east-1.amazonaws.com/payment-service:${{ github.sha }}
          format: 'table'
          exit-code: '1' # Fails the pipeline if CRITICAL vulnerabilities exist
          ignore-unfixed: true
          severity: 'CRITICAL,HIGH'

      # ------------------------------------------------------------------------
      # Step 2: Generate Software Bill of Materials (SBOM) using Syft
      # ------------------------------------------------------------------------
      - name: Generate CycloneDX SBOM
        uses: anchore/sbom-action@v0
        with:
          image: 123456789012.dkr.ecr.us-east-1.amazonaws.com/payment-service:${{ github.sha }}
          format: cyclonedx-json
          output-file: sbom.cyclonedx.json

      # ------------------------------------------------------------------------
      # Step 3: Install Cosign & Execute Keyless Signing
      # ------------------------------------------------------------------------
      - name: Install Cosign CLI
        uses: sigstore/cosign-installer@v3.5.0

      - name: Sign Container Image (Keyless Sigstore)
        run: |
          cosign sign --yes \
            123456789012.dkr.ecr.us-east-1.amazonaws.com/payment-service:${{ github.sha }}

      - name: Cryptographically Attest SBOM to ECR
        run: |
          cosign attest --yes \
            --predicate sbom.cyclonedx.json \
            --type cyclonedx \
            123456789012.dkr.ecr.us-east-1.amazonaws.com/payment-service:${{ github.sha }}

2. Kyverno ClusterPolicy: Enforcing Cryptographic Signatures in EKS

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: enforce-signed-images
  annotations:
    policies.kyverno.io/title: Verify Container Signatures
    policies.kyverno.io/severity: critical
spec:
  validationFailureAction: Enforce
  webhookTimeoutSeconds: 15
  failurePolicy: Fail # Reject Pod if admission webhook encounters an error
  rules:
    - name: verify-sigstore-github-issuer
      match:
        any:
        - resources:
            kinds:
              - Pod
            namespaces:
              - workloads-prod
              - workloads-staging
      verifyImages:
      - imageReferences:
        - "123456789012.dkr.ecr.us-east-1.amazonaws.com/*"
        attestors:
        - entries:
          - keyless:
              issuer: "https://token.actions.githubusercontent.com"
              subject: "https://github.com/corp-enterprise/payment-service/.github/workflows/secure-build.yml@refs/heads/main"
              rekor:
                url: "https://rekor.sigstore.dev"

โš ๏ธ Real-World Failure Modes, Exceptions & Break-Glass Playbooks

Exception 1: Critical CVE False Positive During a Sev-1 Outage (Break-Glass Waiver)

  • The Problem: Production payment processing is down. An urgent hotfix is pushed to Git. However, Trivy blocks the pipeline because a legacy transitive dependency has a newly published CRITICAL CVE (e.g., an unexploitable vulnerability in a CLI documentation parser). The engineering team cannot deploy the Sev-1 hotfix!
  • The Architectural Exception Pattern (Signed CVE Waivers): Never disable security gates globally. Implement an auditable, cryptographically signed exception file (.trivyignore) with a mandatory expiration date and Jira security ticket justification:
# .trivyignore
# EXCEPTION APPROVED BY: Head of Security (SEC-9402)
# RATIONALE: Unexploitable in headless container environment. Patch scheduled in Sprint 44.
# EXPIRES: 2026-10-19 (Auto-revokes in 7 days)
CVE-2026-28192

In your CI pipeline, enforce that .trivyignore entries cannot exceed a 7-day lifetime using an automated pre-scan validator script.

Exception 2: Corporate Air-Gap & Sigstore Rekor/Fulcio Unreachability

  • The Problem: In highly regulated banking, healthcare, or military environments, worker nodes and CI runners operate inside VPCs with zero public internet access. Public Sigstore services (rekor.sigstore.dev, fulcio.sigstore.dev) are blocked by corporate egress proxies.
  • The Enterprise Solution (AWS KMS Asymmetric Signing): Configure Cosign to use an AWS KMS Asymmetric Key Pair (RSA-4096 or ECDSA P-256) hosted inside your private AWS account:
# 1. Sign image using AWS KMS private key over VPC endpoint (Zero internet access required!)
cosign sign --yes \
  --key awskms://arn:aws:kms:us-east-1:123456789012:key/b6d1911e-450a-4a52-b810-platform-key \
  123456789012.dkr.ecr.us-east-1.amazonaws.com/payment-service:v2.1.0

# 2. Verify signature using KMS public key directly in Kyverno
# Inside Kyverno ClusterPolicy:
# attestors:
# - entries:
#   - keys:
#       kms: "awskms://arn:aws:kms:us-east-1:123456789012:key/b6d1911e-450a-4a52-b810-platform-key"

Exception 3: Admission Webhook Timeout Paralysis

  • The Problem: During an unexpected node scaling event (e.g. 50 pods spinning up simultaneously), Kyvernoโ€™s admission webhook attempts to verify Cosign signatures by querying Amazon ECR. ECR throttles the API requests (Rate exceeded), causing webhook calls to exceed webhookTimeoutSeconds: 15.
  • The Catastrophe: If failurePolicy: Fail is set globally, every single Pod across the cluster fails to launch, including DNS pods (coredns), metrics exporters, and ingress controllers, plunging the entire cluster into a death spiral.
  • Architectural Safeguards:
    1. Strict Namespace Scoping: Never apply admission verification policies to kube-system, kube-public, or the namespace hosting Kyverno itself!
    2. Local Signature Caching: Enable Kyvernoโ€™s local image signature cache (imageVerificationCache) in memory to eliminate redundant ECR registry lookups for already-validated image digests.
    3. Break-Glass Emergency Admission Bypass: Configure an emergency annotation allowed only via a break-glass IAM role:
      metadata:
        annotations:
          breakglass.platform.corp/bypass-signature: "INCIDENT-8921-APPROVED"

๐Ÿ“ Staff Architect & SRE Interview Scenarios

โ“ ๐ŸŸข Low Difficulty: Image Tag Immutability vs SHA256 Digests

Question: Why do security architects strictly forbid deploying container images using human-readable tags like :latest or :v1.2.0, requiring explicit immutable SHA256 digests (@sha256:...) instead?

Answer: Container tags are mutable pointers; anyone with write access to the registry can overwrite payment:v1.2.0 with a malicious image without altering the tag string. If Node A pulls v1.2.0 at 10:00 AM, and Node B pulls v1.2.0 at 10:30 AM after a malicious overwrite, the two nodes will run completely different code under the exact same version label. SHA256 digests represent the cryptographic hash of the image manifest itself: if a single byte changes, the digest changes, guaranteeing 100% immutability.

โ“ ๐ŸŸก Medium Difficulty: What is in-toto Attestation vs Raw Signature?

Question: What is the technical difference between running cosign sign versus cosign attest?

Answer: cosign sign creates a simple cryptographic signature verifying authenticity (proving that an authorized identity produced this exact image digest). cosign attest binds structured, machine-readable metadata (in-toto predicates) to the image digest, such as an SBOM (CycloneDX/SPDX), vulnerability scan results, or SLSA provenance build metadata. This allows admission controllers not just to check who built the container, but to enforce conditional rules such as: โ€œOnly admit this image if its attached vulnerability report has 0 critical CVEs and was compiled on an ephemeral GitHub runner.โ€

โ“ ๐Ÿ”ด Hard Difficulty: The Failure Mode of Kyverno with `failurePolicy: Fail`

Question: Explain the operational failure mode when Kyverno or OPA Gatekeeper uses failurePolicy: Fail during a control plane network partition, and how platform engineers architect resilience against it.

Answer: If failurePolicy: Fail is configured on a ValidatingWebhookConfiguration, the Kubernetes API Server will reject all incoming Pod creation requests if the webhook pod is unreachable or times out. If the node hosting Kyverno crashes, the API Server cannot reach Kyverno to validate new pods. If Kyverno cannot be rescheduled because the API Server rejects the newly scheduled Kyverno pod itself, the cluster enters an unrecoverable deadlock.

The Fix:

  1. Deploy Kyverno with at least 3 replicas, spread across different failure domains using topologySpreadConstraints.
  2. Configure namespaceSelector to strictly exclude kube-system and platform management namespaces from webhook interception.
  3. Configure high-priority PriorityClass (system-cluster-critical) on Kyverno pods to guarantee they are never evicted by worker node resource exhaustion.
โ“ ๐ŸŸฃ Complex Difficulty: Rekor Transparency Log Split-Brain Attack

Question: In keyless signing, how does Rekor protect against an attacker who compromises an ephemeral OIDC identity token and attempts to backdate a signature to make an unauthorized container appear legitimate?

Answer: Rekor utilizes an append-only Merkle Tree (RFC 6962). When an entry is submitted, Rekor returns a Signed Entry Timestamp (SET) and incorporates the entry into the leaf nodes of the tree. The root hash of the tree is updated monotonically. Because every signature must be timestamped and sealed within an immutable hash chain, an attacker cannot insert an entry into the past without altering the cryptographic root hash of all subsequent entries. Kyverno verifies the SET against Rekorโ€™s public key, mathematically proving the signature was executed during the exact 10-minute window when the OIDC certificate was valid.