STACK
Ch 18 · Security & Compliance
Chapter 18 · Defence in depth

Security & Compliance — the controls every system needs

18.1 · The stance — assume breach

The right mental model
Design so the blast radius of a stolen credential, a compromised dependency, or a leaked key is small. Defence in depth + least privilege + observable everything.

18.2 · Threat modeling — STRIDE

LetterThreatMitigation
SSpoofing identityStrong auth, mTLS, signed requests.
TTamperingHMAC, signatures, integrity checks.
RRepudiationAudit logs (append-only, signed).
IInformation disclosureEncryption, least-privilege, masking.
DDenial of serviceRate limits, autoscale, WAF.
EElevation of privilegeAuthz checks at every layer; principle of least authority.

18.3 · OWASP Top-10 (2021, refreshed 2025)

#RiskDefence
A01Broken Access ControlDeny by default; tested authz; RLS.
A02Cryptographic FailuresTLS 1.3, AES-GCM, KMS keys.
A03Injection (SQL, NoSQL, command, LDAP)Parameterised queries; never interpolate.
A04Insecure DesignThreat model; security reqs in stories.
A05Security MisconfigurationCIS Benchmarks; IaC; admission control.
A06Vulnerable / Outdated ComponentsSBOM + Renovate + CI scan gate.
A07AuthN FailuresOAuth/OIDC, passkeys, MFA, rate-limit login.
A08Software & Data Integrity FailuresSigstore / Cosign verify.
A09Logging & Monitoring FailuresTamper-evident logs; SIEM; alerting.
A10SSRFEgress allow-list; block metadata service; egress proxy.

18.4 · SAST · DAST · IAST · SCA

TypeWhatTools
SASTStatic analysis of source.Semgrep, CodeQL, SonarQube, Snyk Code.
DASTDynamic test against running app.ZAP, Burp, Nuclei.
IASTInstrumented runtime analysis.Contrast, Seeker.
SCASoftware Composition Analysis — known CVEs in deps.Snyk, Dependabot, OSV-Scanner, Trivy.
Container scanningImage CVEs at build/registry.Trivy, Grype, Clair.
IaC scanningMisconfig in Terraform / K8s.Checkov, tfsec, Kics, Kubescape.

18.5 · Crypto & key management

  • In transit: TLS 1.3, HSTS, OCSP stapling. Post-quantum (Kyber+X25519) shipping in 2026.
  • At rest: envelope encryption with KMS (AWS / GCP / Azure) or HashiCorp Vault Transit.
  • Field-level: pgcrypto, app-side AES-GCM, tokenisation services.
  • HSMs: CloudHSM, YubiHSM for FIPS 140-2/3 needs.
  • Never invent crypto. Use libsodium, WebCrypto, cloud KMS.

18.6 · Network — mTLS, Zero Trust

  • mTLS between services (service mesh handles it).
  • Zero Trust — verify every request; never trust the network. BeyondCorp, Cloudflare Access, Tailscale, Twingate.
  • Egress control — squid proxy, NetworkPolicy, allow-list outbound.
  • WAF — Cloudflare, AWS WAF, Fastly Next-Gen.
  • DDoS — cloud-native; layer-7 rules; rate limit.

18.7 · Supply chain

  • SBOM (Syft / CycloneDX / SPDX) on every build.
  • SLSA levels for build provenance.
  • Sigstore / Cosign signatures; verify in admission control (Kyverno, Gatekeeper).
  • Org-level allow-list of npm/PyPI/Maven sources.
  • Reproducible builds where feasible.

18.8 · Secrets

  • Vault, AWS Secrets Manager, GCP Secret Manager, Doppler, SOPS, age.
  • Rotation policy in code; rotate quarterly minimum.
  • Pre-commit scanning (gitleaks, trufflehog) + push-protection on repo.
  • Alert on retrieval anomalies; audit every fetch.
  • OIDC federation from CI → cloud (no long-lived keys in pipelines).

18.9 · Runtime & container security

ToolNotes
FalcoRuntime detection via eBPF / kernel.
TetragonCilium-based runtime security.
Kyverno / OPA GatekeeperK8s admission control (policy-as-code).
seccomp / AppArmor / SELinuxConstrain syscalls per container.
gVisor / Kata Containers / FirecrackerStronger isolation than vanilla containers.

18.10 · Cloud security posture (CSPM / CIEM / CNAPP)

  • CSPM: cloud config drift detection (Prisma, Wiz, Orca, Defender for Cloud).
  • CIEM: entitlements / IAM analysis.
  • CNAPP: combined (Wiz, Prisma, Orca, Aqua).
  • IAM hygiene: no *:*; deny-list specific high-risk actions; SCPs / Org Policies.

18.11 · Privacy

  1. Collect less data.
  2. Pseudonymise / tokenise where possible.
  3. Field-level encryption for PII.
  4. Retention policy enforced by jobs.
  5. Right-to-be-forgotten runbook + tested delete API.
  6. Data residency: pick region per tenant; pin storage and processing.

18.12 · Standards & frameworks

FrameworkNotes
SOC 2 Type IIUS Trust Services audit; B2B table-stakes.
ISO/IEC 27001Information Security Management System; global default.
ISO/IEC 27017 / 27018Cloud / PII extensions.
ISO/IEC 42001AI Management System.
NIST CSF 2.0Cybersecurity Framework — Govern · Identify · Protect · Detect · Respond · Recover.
NIST 800-53 / 800-171US federal controls; CMMC for defense supply chain.
HIPAA / PCI-DSSHealthcare / card data.
GDPR / UK GDPR / CCPA / CPRAEU / UK / California privacy.
EU AI Act / NIST AI RMFAI-specific (see AI Codex Ch 16).
EU CRA (Cyber Resilience Act)Vulnerability disclosure + SBOM required for products in EU.
OWASP ASVSApp Security Verification Standard — testable requirements.
CIS BenchmarksOS / K8s / cloud hardening baselines.
FedRAMP / IL5US federal cloud authorisations.

18.13 · Red-team / pen-test cadence

  • Internal pen-test annually; external every 1–2 years for B2B.
  • Bug bounty (HackerOne, Bugcrowd, Intigriti) for continuous attention.
  • Tabletop exercises quarterly — practice the incident playbook.
  • Purple team — defenders + attackers in the same room.

18.14 · Self-check

Q1 · Most important defence against SSRF (A10)?
TLS everywhere
Egress allow-list + block metadata service
CSP headers
HTTPS-only cookies