Credential Brokering Patterns for AI Agents Part 4: Eliminating Plaintext The fourth and final installment of the "Credential Brokering Patterns for AI Agents" series proposes moving the final credential unwrap from the controller to the gateway so the controller only ever holds ciphertext, closing the gap where a control-plane component sees plaintext upstream tokens. The post argues the gateway already terminates the agent's MCP/API/LLM connection and puts the upstream token on the wire, so it is no more exposed than TLS-intercepting egress proxies such as Zscaler, Netskope and Squid with bumping, and it points to trusted execution environments (TEEs) as a next step so the gateway never sees the credential at all. The series author, whose earlier posts drew viral LinkedIn discussion arguing the risk was merely moved to the gateway, responds that the gateway was always going to see those tokens. Credential Brokering Patterns for AI Agents Part 4: Eliminating Plaintext The gateway in a credential brokering setup sees the same bearer tokens any intercepting egress proxy already sees. The controller didn't need to see them too, so let the gateway do the final unwrap, and then look at what it would take to close the one gap brokering adds at the gateway. This is the last part in the Credential Brokering Patterns for AI Agents series https://blog.christianposta.com/credential-brokering-patterns-for-ai-agent-egress/ . The series reviewed patterns for securing the credentials used by AI agents with the premise that: you can’t trust what an AI agent will do with credentials you give to it. They WILL eventually leak. Littering API keys/OAuth tokens/client secrets all over your AI agents creates a governance nightmare, with no way to expire/revoke/audit/control. If we adopted a credential brokering pattern, we can alleviate this pain but introduce a new potential issue. What happens to the token vault if the process that reads it is compromised? Links to the previous posts: - Part 2: Securing the Vault with AWS KMS https://blog.christianposta.com/credential-brokering-patterns-for-ai-agent-egress-part2/ - Part 2.5: Picking up where KMS grants stop Scaling https://blog.christianposta.com/credential-brokering-mode-3-at-scale/ - Part 3: Protecting the token vault with OpenBAO and Vault https://blog.christianposta.com/credential-brokering-patterns-for-ai-agent-egress-part3/ The responses for each of these posts have been absolutely incredible, with a number of them going viral https://www.linkedin.com/posts/ceposta you-should-not-give-ai-agents-any-share-7518426181592113152-rEot/ Both part 2.5 https://blog.christianposta.com/credential-brokering-mode-3-at-scale/ and part 3 https://blog.christianposta.com/credential-brokering-patterns-for-ai-agent-egress-part3/ reactions got some version of “you didn’t remove the risk you just moved it to the gateway” on LinkedIn https://lnkd.in/p/ggyMGWn5 . In the part 3 thread https://www.linkedin.com/feed/update/urn:li:activity:7523131357552762882/ someone pointed out that a compromised gateway can just log credentials after each authorized use, it only takes longer. That’s all true, and it’s the dwell/trickle blast radius I mentioned at the end of part 3. But the gateway was always going to see those tokens. So we didn’t actually “move the risk to the gateway”. It was already there. The gateway terminates the agent’s MCP/API/LLM connection and puts the upstream token on the wire the agent never holds one, which was the whole point of part 1 https://blog.christianposta.com/credential-brokering-patterns-for-ai-agent-egress/ , so it sees plaintext on every live request. So does every TLS-intercepting egress proxy you already run Zscaler, Netskope, Squid with bumping, etc , for every script, CI job, and SaaS integration, not just agents. So what did brokering add? It put every user’s upstream tokens in one logical store. And then we discussed how to prevent the component with access to the store from total melt down if compromised. But we ended up with some “control plane” component still seeing plaintext credentials at some point in time. And this motivates part 4: Why should we have another component get exposed to plaintext beside the gateway when doing the injection? In this post I want to move the final unwrap to the gateway, so the controller only ever holds ciphertext and the gateway is exactly as exposed as it already was. Then I’ll look at where this could go next to make the gateway unwrap safer including attaching the credential inside a trusted execution environment TEE so the gateway never sees it. Let’s get into it Why does the controller see plaintext at all? In the 2.5 post, the controller sends the subject token, a freshness proof, and the row’s wrapped DEK to the broker, gets the plaintext DEK back, opens the inner AES-GCM layer, and hands the upstream token to the gateway. It does all of that because it’s the STS, and the RFC 8693 https://www.rfc-editor.org/rfc/rfc8693 token exchange contract is subject token in, upstream token out. That’s a perfectly reasonable API, but it means the controller passes the plaintext token back to the gateway. The controller needs to find the right row, but does it really need to open it? What if we want ONLY the gateway to see the plaintext? If we change the API, the gateway gets the ciphertext from the controller, the plaintext DEK from the broker, and only it can decrypt. The gateway was going to hold the plaintext token a few milliseconds later anyway, so the only thing that changes on the gateway is where the AES-GCM decrypt happens. The controller becomes just a store and a state machine elicitation state, row metadata, expiry with no decrypt path and no plaintext credential. The controller loses encrypt permission too, which it can only do if we adopt the “refresher” component from 2.5. That refresher component became the OAuth client that completes the code exchange and wraps the rows it writes, so with the read path moved to the gateway there’s nothing left for the controller to call KMS or Transit for. The flow The broker only accepts the gateway’s SVID, so a compromised controller can’t ask for an unwrap at all, no matter how many subject tokens it has harvested. In parts 2 and 3 the gateway-signed freshness proof did that job. The broker still verifies the subject token against the IdP JWKS on every unwrap, which limits the gateway to users who are actually active. The controller only releases ciphertext to the gateway for the row’s owner, so nobody else can bulk-pull the store. The grant-shaped versions work the same way with a different party calling Decrypt . On KMS, the broker mints a grant https://docs.aws.amazon.com/kms/latest/developerguide/grants.html with the gateway’s role as grantee instead of the controller’s. In Mode 3b on OpenBao, the broker mints the batch token with token bound cidrs set to the gateway’s pod CIDR, and the gateway calls transit/decrypt itself. Part 3’s vault-login design is the smallest change of all, since the gateway already logs in as the user and holds the OpenBao token, so it would call Transit directly instead of handing the token to the controller. That takes the controller out, and the gateway ends up where it is in the other designs, since a live request already opened all of that user’s rows. What does the gateway get to decrypt? Only the access token. In the store from part 2, each row’s payload is the whole token response access token, refresh token, id token under one DEK, which is fine when the controller opens it and only hands the access token on. If the gateway opened that same row it would get the refresh token too, so the refresh token has to live under its own DEK in the refresher’s store from 2.5 that the gateway never gets. When an access token expires, the refresher writes a new wrapped access-token row and the gateway unwraps it like any other, so neither the gateway nor the controller ever sees a refresh token. What does a compromised gateway get? “So now the most exposed component on the network does all of the decrypting. How is that better?” The gateway already held the plaintext for every in-use token, in every mode, because it’s the thing putting the token on the wire. What this change does is stop a second component from holding it too. An attacker who sits on the gateway harvests in-use tokens at the rate of use whether or not the gateway does the AES-GCM open, and that was true in part 2. An attacker who sits on the controller, which in 2.5 harvested exactly the same tokens, now gets ciphertext. For tokens in flight, a compromised brokering gateway sees exactly what a compromised intercepting proxy would. The one thing it can do that a proxy can’t is ask for credentials. With alice’s live subject token it can call the broker for her Slack and Jira rows even if her agents only touched GitHub that day, because the gateway is the one naming the resource a confused deputy . That works for as long as her subject token is valid typically about an hour after her last request , and it’s capped at the rows of users who are active during the compromise. Nothing works offline, dormant users are out of reach, and every pull shows up in the broker’s decision log. Part 3’s comparison table says the same for both OpenBao designs, so moving the unwrap doesn’t change it. The trickle doesn’t stop when you evict the attacker, either. The gateway collects at the rate of use while the attacker sits on it, but whatever it logged stays usable until the upstream expires it, so the lifetime of the upstream access tokens is part of the gateway’s blast radius, and that varies a lot by provider some issue tokens that don’t expire unless you turn expiration on . Here’s what each single compromise gets you after the change. - Controller: ciphertext only, never plaintext, never a DEK. It can serve a stale row for the same user and resource, or refuse to serve anything DoS . The two attacks from 2.5 sitting on the hot path, and seeing plaintext at creation are both gone. - Gateway: plaintext for in-use tokens, same as any intercepting proxy, plus the active users’ other rows described above. Same as every earlier design. - Broker: standing decrypt and the wrapped DEKs it sees on live requests, but never a payload, so on its own it reads nothing. Paired with the controller or any other path to the DB it reads the whole store, which makes it the high-value target. Same as 2.5, and broker-to-DB isolation is still what stops it from using that decrypt on the store, so lock that path down and keep the broker and the controller in separate trust domains separate identities, separate network paths to the DB and to KMS/OpenBao so one compromise doesn’t hand over both. - Refresher: unchanged from 2.5, roughly Mode 2 posture for refresh tokens, which is why it gets the tightest network policy in the system. The one thing a ciphertext-only controller can still do is let an attacker steal ciphertext now and hope to get the KEK later root on the OpenBao node, a key policy mistake during a migration, etc . On OpenBao the answer is to rewrap https://openbao.org/api-docs/secret/transit/ on a schedule and then raise min decryption version on the Transit key, so ciphertext stolen before the rewrap goes stale. Rewrap on its own doesn’t help, since the old key version still decrypts whatever the attacker took. Where could this go? Everything above leaves the gateway with the same two problems every earlier design had. The plaintext token is in the gateway, since it’s the thing putting the token on the wire, so whatever a compromised gateway logs/captures keeps working after you evict it. And the gateway decides which credential to fetch, so with a live subject token it can ask for an active user’s other rows. An agent-signed proof takes that choice away from the gateway, and a TEE takes the plaintext off the gateway host. The gateway picks the credential I don’t think per-upstream subject tokens e.g. RFC 8707 https://www.rfc-editor.org/rfc/rfc8707 resource indicators are the way to fix this one, since the subject token should be scoped to the gateway, which is what the agent is actually calling. What would close it is a proof signed by the agent and bound to what it’s trying to reach, which the gateway can carry to the broker but can’t make. The IETF WIMSE working group has two drafts that do this, a Workload Proof Token and an HTTP Message Signatures profile. The agent holds a Workload Identity Token WIT from SPIRE https://spiffe.io/docs/latest/spire-about/ or equivalent, with its public key in cnf . With the Workload Proof Token https://datatracker.ietf.org/doc/draft-ietf-wimse-wpt/ WPT , it signs a short-lived JWT with that key on every request, with the request’s target URI as the aud . 1 2 3 4 5 6 7 { "aud": "https://agw.internal/mcp/github", "exp": 1793260830, "jti": "7f3a9c1e-2b8d-4c51-9e0a-6d4f1b2a8c33", "wth": "