Chapter 9: Security
Security is a property of the whole system, so it has to be reviewed against the whole system’s diagram. By this chapter the system is complete: a public gateway, a serving engine, stores for keys, usage, and models, an operator control plane, and an agent that reaches external tools. Each piece was built with its own tests, but no test of a single component tells you where an attacker can act on the whole. This chapter turns the architecture into a list of threats, ties each threat to a control and a test, and makes the shipped artifacts accountable through supply-chain records.
Concepts from other sections (12)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- Control plane: the API server, etcd, scheduler, and controller manager, which store desired state and decide what should run where; worker nodes carry out those decisions. Read more: Chapter 10: Kubernetes Workloads and Deployment in Systems Engineering
- Data-flow diagram (DFD): a diagram of external entities, processes, data stores, the flows between them, and trust boundaries. Read more: 9.1 Threat modeling with STRIDE
- Container view: the C4 level-2 diagram in which each box is a separately deployable process or managed store, and each arrow is a protocol or file boundary. Read more: 11.1 C4 diagrams in D2
- STRIDE: six prompting questions (spoofing, tampering, repudiation, information disclosure, denial of service, elevation of privilege) asked of each boundary and asset. Read more: 9.1 Threat modeling with STRIDE
- Trust boundary: a line in the diagram where the privilege of data changes; nothing crossing it is trusted until checked. Read more: 9.1 Threat modeling with STRIDE
- SBOM: a software bill of materials, an inventory of the packages in one built artifact and the dependency edges between them. Read more: 9.2 SBOM and supply chain
- HMAC: a keyed hash construction, , resistant to length extension. Read more: 10.1 API Keys, Scopes, Model Allowlists, and Tenants
- Residual risk: what a control does not stop, written down with an owner who accepts and watches it. Read more: 9.1 Threat modeling with STRIDE
- SPDX: a standard SBOM format; version 2.3 is used here. Read more: 9.2 SBOM and supply chain
- Dependency policy: the human-maintained list of what may be used (
allowed-deps.toml), against which each SBOM is reviewed. Read more: 9.2 SBOM and supply chain - API key: a credential
tl_<id>_<secret>whose public id locates a record and whose secret proves possession. Read more: 10.1 API Keys, Scopes, Model Allowlists, and Tenants - Authorization matrix: a table of principals against actions in which every cell is an explicit allow (with its condition) or deny. Read more: 9.3 Secrets and authorization review
The chapter is organized around the four questions every threat model asks: what are we building, what can go wrong, what are we going to do about it, and did we do a good job? The first section answers the first two by drawing a data-flow diagram from the system’s C4 container view and applying STRIDE (spoofing, tampering, repudiation, information disclosure, denial of service, elevation of privilege) to every trust boundary, including the path where retrieved text reaches a tool call. The second and third sections take rows of that model and answer the last two questions in depth. One treats the supply chain as part of the system: an SBOM per artifact, plus provenance for builds, records what was shipped so the next CVE can be traced to the artifacts it affects. The other reviews where secrets live (TL_API_KEY, the HMAC pepper) and how scopes and tenants are checked in the gateway.
Every section produces a document rather than code, and each has a model answer in the solutions tree; the threat model is docs/THREAT_MODEL.md.
Learning objectives
- Build a data-flow diagram with trust boundaries from a C4 container view and threat-model it with STRIDE.
- Write threat rows that name a control, evidence, residual risk, and an owner, and say when the model must be revisited.
- Read and validate an SPDX SBOM and compare it against a dependency policy during a CVE response.
- Review an authorization design as a matrix of principals, actions, and resources, and inventory every secret with its logging and rotation rules.
- Define the findings that block a release and the evidence a release must attach.
Before you begin
Section titled “Before you begin”The threat model is drawn from the container view in Diagramming with the C4 Model in Software Engineering, so read that chapter first if you have not. The chapter also assumes you know the system it reviews end to end, in particular the gateway’s API keys, scopes, and tenants from Authorization and Access Control in Software Engineering. A good warm-up is to read the OWASP Threat Modeling Cheat Sheet, then sketch your own data-flow diagram of the system before reading the first section, and compare it with the model’s afterwards.
In this chapter
Section titled “In this chapter”- Threat modeling with STRIDE: draw the data-flow diagram, find its four trust boundaries, and build a STRIDE table in which every threat has a control, evidence, residual risk, and owner.
- SBOM and supply chain: read SPDX 2.3 inventories for the engine and gateway, see why they must be generated from the image digest, and compare them against the dependency policy.
- Secrets and authorization review: build the authorization matrix and secret inventory, check them against the gateway’s
auth.go, and set the release-blocking findings.
Related chapters
Section titled “Related chapters”Two chapters of AI Engineering pick up where this one stops. Usage Policy covers abuse cases and their enforcement, and Professional Responsibility covers disclosure when a threat becomes a vulnerability.
Key terms
Section titled “Key terms”- Threat model: a structured answer to four questions about a system: what are we building, what can go wrong, what are we going to do about it, and did we do a good job? It turns an architecture into a list of threats, each tied to a control and a test.
Further reading
Section titled “Further reading”- Adam Shostack, Threat Modeling: Designing for Security (Wiley).
- OWASP, Threat Modeling Cheat Sheet.
- SLSA, for build provenance.
- The CycloneDX and SPDX SBOM specifications.
- OWASP ASVS.
- OWASP, Top 10 for LLM Applications.