Blog

Secrets a plugin never holds

How Kumi will let a plugin use your API key without ever giving the key to the plugin.

A plugin that talks to a model provider needs your API key. In Kumi it will never get it. The request it builds will carry a header like this:

authorization: Bearer hdl_bbrDGr0LElqQXsFW3FtAy3WzQCXcd22JCJggNM5S

That hdl_ value is not your key. It is a stand-in that the kernel hands out. When the request is sent, the kernel takes the stand-in out and puts the real key in its place, and the real key only goes to the hosts it was approved for. The plugin builds the request, but it never sees what is in that header on the wire.

Kumi is an AI agent client, and nearly everything in it is a plugin. The kernel is the fixed part underneath that isn't one. Earlier posts covered what a plugin may do and how a tool call travels through the kernel. This one is about what a plugin may hold. For secrets, the design's answer is: nothing that works outside Kumi.

A stand-in, not the key

By design, Kumi keeps secrets in a vault, and the vault is the only place a secret value is stored. The kernel will select the secret and give the plugin a handle, not its value.

What the plugin gets back is a handle. Here is how the vault's source describes one (excerpt, reindented):

/// A token that stands for a secret.
///
/// A handle has no relation to the name of the secret. It is 30 random
/// bytes. The first six bytes are the handle id, which appears in audit
/// events. The other 24 bytes are known only to the holder, so the audit log
/// never contains a usable handle.

A handle is random, so it says nothing about the secret behind it. Asking again for the same secret as the same caller gives the same handle. Handles live in memory only, so after a restart every plugin asks again. When a key is rotated or revoked, every handle for it stops working at once, and a new secret with the same name does not bring an old handle back.

There is a small detail we like. A plugin that asks for a name that doesn't exist gets the same error as one that asks for a secret it isn't allowed to have. A plugin can't use the vault to find out which secrets you keep.

Two lists on every secret

Each secret carries a scope with two lists. The first says who may get a handle. The second says where the real value may be sent. Both lists are required, so a secret with nowhere to go can't be stored.

Who is a name, such as a plugin's id, and it is compared exactly. Where is a host name, compared label by label, meaning the parts between the dots. That matters, because comparing host names as plain text is a classic way to send a key to the wrong place:

Destination in the scope Host of the request Gets the key
example.com example.com yes
example.com evil.example.com no
example.com example.com.evil.net no
*.example.com api.example.com yes
*.example.com evilexample.com no
*.example.com example.com no

Case and one trailing dot are ignored. A host with a port, a path, a user name or non-ASCII characters is refused, and so is a wildcard as wide as *.com.

The swap happens at the door

This is the part that makes the stand-in worth having. The plugin never resolves the handle. Only the kernel will, and only when a request leaves.

Before that, the kernel will build a second copy of the request from the same chat, separately from the running plugin. It will compare the two before any network use. The method, the host, the port, the path, the body and the header contents all have to match, including the handle. Header order does not matter. For this request, a query string is refused outright.

Then come the checks on the key itself. The handle in the header has to be exactly the one the kernel issued for this key, and the request's host has to be the destination the key is bound to. The vault checks that host against the secret's scope before it gives the value out, and again just before the request is sent.

Only then is the outgoing request built, and the kernel builds it, not the plugin (excerpt, reindented):

let body = &self.expected.body;
if body
  .windows(secret.len())
  .any(|window| window == secret.expose())
  || body
    .windows(slot.handle.len())
    .any(|window| window == slot.handle.as_bytes())
{
  return Err(RequestRefused);
}
let mut bytes = Zeroizing::new(Vec::with_capacity(secret.len() + slot.prefix.len()));
bytes.extend_from_slice(slot.prefix.as_bytes());
bytes.extend_from_slice(secret.expose());

Read the first half first. If the body of the request contains the key or the handle, the request is refused. A plugin can't get the kernel to paste the key into a message and send it along. The second half writes the real header into a buffer that is wiped when it is dropped. Right after this, the header value is marked as sensitive, so it stays out of the HTTP library's debug output.

And on the way back

A provider's answer is untrusted text, and a server can echo a request back. So the kernel will read the answer before the plugin does. It looks for the key and for the handle in the stream, and if either one shows up, the answer is refused. Only frames the kernel has checked are passed on to the plugin.

A redirect gets no second chance either. For this request the kernel accepts a plain 200 as the final answer, so a server that says "go ask that other host" is refused, not followed. A redirect is a request to a host nobody approved.

Where the key rests

On disk, the vault is one file. Each value is encrypted with XChaCha20-Poly1305, with a new random nonce every time. Each record is bound to its name and its full scope, so a value copied to another name doesn't decrypt, and neither does a record whose scope was edited by hand. The key that unlocks the file comes from your passphrase through Argon2id. A file that asks for weaker settings than the minimum is refused before any key is derived.

In memory, a value has its own type. It can't be cloned or displayed, and code that tries doesn't compile. Its debug output is [redacted], and its bytes are overwritten when it is dropped. The vault's audit events name the secret. They never hold the value or a usable handle.

What it doesn't protect against

We'd rather say this plainly. The vault's design notes keep a list of limits, and these are the ones worth repeating:

  • Someone with root on your machine can read the kernel's memory.
  • While the vault is open, its key is in memory, and swap or a core dump can hold it. Wiping on drop narrows that window. It doesn't close it.
  • The kernel checks the host name. It can't tell what the receiving server does with your key.
  • Someone who can write the vault file can put back an older copy, and a revoked key, or the old value of a replaced one, comes back with it.

The kernel itself is trusted here. The design keeps the plugin at arm's length, not the code that resolves the handle.

A key you never hand over

The plugin holds a random token. The real key is added at the door, and only for hosts on the secret's list. This is how Kumi will handle your secrets, and we're building it now. If you see a way for a plugin to get the key out of this, write to us and tell us how.


If you'd like to hear when you can try Kumi, there's a waitlist.

← All posts