Module 6 · Security, governance and the capstone · Chapter 21 · Free
Security for AI infrastructure: keys, tenants and platform guardrails
- Keys live in a secrets store, never in images, repos or prompts. One short lived key per workload keeps a leak small.
- Tenant isolation is enforced by the platform, in separate indexes or hard filters, and tested. A prompt line is not isolation.
- Pods reach only allowlisted endpoints, and the gateway enforces tool lists, rate limits and checks in one place.
The picture: the platform is a building with locked doors per floor, not one master key and a sign asking visitors to behave.
- Where keys belong, and how per workload keys shrink a leak.
- How to isolate tenants in retrieval, and test it.
- Egress allowlists, gateway guardrails and audit logs.
- A break-it lab: four platform flaws to find and fix.
Copperline is a made up B2B SaaS company. On a Tuesday, Priya Nair, its staff platform engineer, got two alerts in one hour. All figures here are illustrative.
- A scanner found the model provider key inside a published container image. Anyone who pulled the image owned the key.
- Ana, the support lead, reported the copilot quoting one customer's ticket inside another customer's answer.
- All three workloads shared that one key, so rotating it meant touching everything at once.
Nothing clever had been hacked. The platform had never drawn its boundaries.
- Scope: the platform layer, and what the app layer already covers.
- Keys and secrets: store, lifetime, rotation, one per workload.
- Tenant isolation in retrieval, enforced and tested.
- Egress control: pods call only what the allowlist permits.
- Gateway guardrails and audit, in one place each.
- The picture, a blast radius example, and the break-it lab.
Next: where this chapter starts, and where it deliberately stops.
Step 1: The platform layer, not the prompt layer
AI security has two layers. The model layer covers prompt injection and app guardrails. The AI engineering course covers that in Chapter 19, Guardrails and security; this chapter does not repeat it.
This chapter is the platform layer: keys, networks, indexes and gateways. Priya's rule is simple.
- Assume the model can be talked into anything. A prompt is a request, not a control.
- Enforce at the platform. A component outside the model checks each rule: store, index, network, gateway.
- Prove it with tests and logs. An untested boundary is a hope.
Think of a bank vault versus a polite note on the door. Where the picture breaks down:
- A vault guards one room. Platform controls guard every request.
- Prompts still guide the model. They just cannot be the lock.
Next: the keys, where they live and how long they live.
Step 2: Keys and secrets, one per workload
Your platform holds powerful credentials: provider keys, vector database keys, tool credentials. Treat each like a production database password.
- Store, do not bake. Keys live in a secrets store, injected at runtime. Never in an image layer, a git repo, a manifest, or a prompt.
- Short lived beats permanent. Where supported, workloads fetch tokens that expire in hours, so a stolen token dies on its own.
- Rotate on a schedule and on suspicion. Rotation is a routine task, rehearsed before it is an emergency.
- One key per workload. Copilot, pipeline and agents each get their own key, scoped to their needs.
Why? Blast radius. If the agents' key leaks, Priya revokes that one. The copilot keeps answering. With a shared key, every leak is a full platform incident.
Next: keeping one customer's documents out of another customer's answers.
Step 3: Tenant isolation, enforced and tested
The rule is absolute: one customer's documents must never surface in another's retrieval, answer or citation.
- Separate indexes: one index or namespace per tenant. Retrieval physically cannot reach another tenant's vectors. Strongest and simplest.
- Shared index, enforced filter: every chunk carries a tenant field, and the platform adds the filter from the caller's identity, never from user or model supplied text.
- Never a prompt instruction. It fails the moment a document or user talks the model out of obeying.
- Quotas are security too. Per tenant limits stop one tenant, or one stolen token, draining the platform.
Then test like an attacker. Priya's canary check seeds a unique marker per tenant, queries as tenant A, and fails the deploy if tenant B's marker appears. Chapter 13 covers index mechanics; this chapter owns the boundary.
Think of filing cabinets with separate locks versus one cabinet and a promise. Where the picture breaks down:
- A shared index mixes by default unless the filter is enforced.
- Retrieval filters must be applied on every query, not once.
Next: what your pods are allowed to call out to.
Step 4: Egress control, an allowlist for pods
By default, a pod can often call any internet address. That is a hole: a steered agent or compromised dependency can send your data to an attacker's endpoint, or pull instructions from one.
- Default deny. Serving and agent pods start with no outbound access.
- Allowlist the real needs: the provider endpoint, the vector database, the approved tool APIs from Chapter 15, nothing else.
- Enforce in the network layer, so the rule holds even if app code is fooled.
- Log denials. A blocked call signals a bug, a bad dependency, or an attack rehearsing.
Think of an office phone that dials only listed numbers. Where the picture breaks down:
- The list holds endpoints and ports, not people.
- A pod cannot ask for an exception, which is the point.
Predict first:
Almost every platform has one forgotten call: a metrics export, a licence check. Default deny surfaces it in the denial log within the hour. Roll it out with the log open, not during an incident.
Next: one enforcement point for tools, limits and checks.
Step 5: Gateway guardrails and the audit trail
Chapter 15, Agent runtimes in production, put a tool gateway between agents and tools. It is also your security checkpoint, since every call passes through it.
- Tool allowlists per workload: the coding agent may call the repo tool; the copilot may not. The gateway rejects anything off list.
- Rate limits and quotas: per workload and per tenant caps, enforced before the call runs.
- Content checks at the boundary, as one shared platform service.
- One place to change: a new rule lands once, not in three codebases.
Enforcement without records is half a control. Chapter 17, Observability for AI services, sets the pattern: who called what, with which key, for which tenant. After the leak, that log answered the key question: what did the leaked key do? Chapter 23 builds the full audit trail on it.
Next: the picture, one request crossing every boundary.
Step 6: The picture, a request crossing the boundaries
Press Next to walk a copilot request past each control.
- A tenant A user asks the copilot a question. Their identity, not their text, sets the tenant.
- The gateway applies the tool allowlist, the tenant quota and content checks before anything runs.
- The serving pod gets its own short lived key from the secrets store at runtime. No key sits in the image.
- Retrieval reads only the tenant A index, so tenant B documents cannot surface.
- The pod may call only allowlisted APIs. Any other outbound call is denied and logged.
Next: the worked example, what one leak costs under two key designs.
Step 7: Worked example, the blast radius of one leaked key
The provider key leaks at 09:00. All figures are illustrative. Compare the two designs Priya costed after the incident.
1. Shared key, step one. Revoke it. All 3 workloads stop calling the provider at once.
2. Shared key, recovery. Issue a new key, update and verify 3 deployments. At an illustrative 25 minutes each: 3 x 25 = 75 minutes degraded.
3. Shared key, the audit gap. Logs show one key, so the team cannot tell which workload's traffic was the attacker's. Review work triples.
4. One key per workload. The agents' key leaks. Revoke only it: 1 x 25 = 25 minutes, agents only. Copilot and pipeline never stop, and the log names the workload.
5. The lesson. Same leak. Per workload keys cut recovery from 75 to 25 illustrative minutes and kept 2 of 3 workloads up.
Next: the break-it lab, where you fix the setup that caused the cold open.
Step 8: Break-it lab, debug Copperline's platform setup
Why this exercise: the cold open was not bad luck. Four flaws caused it, each visible below if you read like an auditor.
Lab: This is the setup that caused the chapter's cold open, widened to the whole platform. This lab runs in your browser and needs JavaScript enabled.
Next: a field note and the mix-ups.
In production practice, automated scanners commonly find leaked keys in public repos or images, so teams treat any exposure as a live compromise: rotate first, investigate second. Cross tenant leaks are worse for trust than a short outage. Test isolation in CI, not after a report.
Mix-ups to avoid
- "The prompt says tenants are separate, so they are." Prompts guide. Filters separate.
- "The key is safe, the repo is private." Images get copied and repos get shared. Use the secrets store regardless.
- "Egress is a network team's hobby." For agents, egress is the exfiltration boundary. Own it.
- "One key is simpler." Until the first leak turns it into three incidents at once.
- "Guardrails belong in each app." Shared rules belong in the gateway, enforced once.
Chapter quiz
Five questions, 70% to pass.
Review this chapter in 5 minutes
Watch the whole chapter recapped: Keys in a secrets store, tenant isolation tested, egress allowlists, and gateway guardrails.
- Platform layer only: prompt injection and app guardrails live in the AI engineering course, Chapter 19.
- Keys in a secrets store, short lived, rotated. Never in images, repos or prompts.
- One key per workload: recovery fell from 75 to 25 illustrative minutes, 2 of 3 workloads stayed up.
- Tenant isolation in separate indexes or identity based filters, proven by a canary test. Quotas count as security too.
- Egress default deny. Gateway enforces tool lists and limits. Audit logs record who called what, with which key.
Decision rule: if a rule matters, enforce it in the platform, outside the model, and prove it with a test or a log.
Review
Glossary
- Secrets store
- Service holding credentials, handed to workloads at runtime. Example: the copilot fetching its key at startup.
- Blast radius
- How much breaks when one thing leaks. Example: one shared key, three workloads down.
- Rotation
- Replacing a credential on schedule or after exposure. Example: a fresh key issued, the old one revoked.
- Tenant isolation
- One customer's data never reaches another. Example: tenant A retrieval cannot return tenant B documents.
- Canary test
- A planted marker that detects leaks. Example: a unique document per tenant.
- Egress
- Outbound traffic from a workload. Example: a pod calling the provider endpoint.
- Allowlist
- Permitted targets; all else denied. Example: only the provider and two tool APIs.
- Tool gateway
- Checkpoint between agents and tools. Example: it rejects an off list tool call.
- Per tenant quota
- A cap on one tenant's calls or spend. Example: one tenant cannot drain the platform.
- Audit log
- Record of who called what, with which key. Example: tracing a leaked key's calls.
Next: "Air-gapped and regulated deployments: offline models and updates".