Skip to content

feat(gateway): seal secrets out of model requests and unseal tool calls - #8444

Merged
t0saki merged 5 commits into
volcengine:mainfrom
t0saki:feat/gateway-seal-secrets
Nov 26, 2026
Merged

t0saki merged 5 commits into
volcengine:mainfrom
t0saki:feat/gateway-seal-secrets

Conversation

@t0saki

@t0saki t0saki commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Gateway part of the RFC in #7335 ("Agent 密钥可用不可见") and its supplement on auto-enrollment (comment).

A new context-profile switch, seal_secrets, makes the gateway send a user's registered secrets, and new tokens the user types, to the model provider only as {{ov_privacy:…}} references. Client tools still receive the real value. It is off by default, and nothing changes for an existing deployment until it is turned on. Once it is on, a request that cannot be sealed is refused rather than sent unsealed.

Stacked on #8408 (server feature table), #8384 (server seal endpoint) and #8445 (plugins). Until those merge, their commits show up here as the first three; review only the last commit, feat(gateway): seal secrets out of model requests and unseal tool calls. The gateway code uses one thing from #8445: the privacy_seal row it adds to the feature table.

This PR was split out of #8384, which used to hold the server, gateway and plugin parts together. The plugin part is #8445.

What changes

  • Sealing requests. Before a request leaves, the content of every JSON model request (user, assistant and system text, tool results, history) goes through the server's seal endpoint and the references are written back. Structure (model, tool names, ids, schemas, signed reasoning) is not touched. A last sweep covers what the gateway adds itself: recall, the compaction summary and hidden tool rounds.
  • New tokens. Tokens in the latest user message are stored by the server in the auto category. The model gets a note asking it to save the entry under a proper name with a description. enroll_tool_secrets (off by default) also stores tokens found in tool output.
  • Unsealing tool calls. References the model writes into client tool-call arguments are replaced with the value in what the client receives. Assistant text, the gateway's own records, OpenViking's own tools and ov privacy commands keep the reference.
  • Session identity no longer depends on which reference a secret maps to, so saving, renaming or rotating a credential does not split a session.
  • When sealing cannot be done, the request is refused. Server too old, version unreadable, or a failed seal call: 503 secret_seal_failed. A request that cannot be sealed (compressed or unparseable body, a text too large, tool calls that could not be unsealed): 400 secret_seal_invalid_request. A reply whose tool calls cannot be unsealed: 502 secret_unseal_failed. Each message names the case and what to do. There is no option that lets such traffic through; turning seal_secrets off is the way out.
  • Server support is read from the feature table row privacy_seal (0.5.7). Against an older server the gateway refuses without calling the seal endpoint, and the message gives both versions. The version is read again within 30 s, so sealing resumes without a gateway restart.
  • Studio profile editor (two switches), request-record counters (secrets_sealed, secrets_enrolled, secrets_unsealed, seal_calls, seal_cache_hits, seal_ms), and a docs page, docs/{en,zh}/gateway/14-seal-secrets.md, with one figure.

Size

36 files, +4014/−44 in this PR's own commit: about 1520 lines of source (openviking_gateway/sealing.py is most of it), 1770 of tests and 720 of docs including the figure.

How it was tested

On this branch, rebased on main at b6ab3ef. tests/gateway was rerun there; the other rows are from the previous base, and the files they cover have not changed since:

Suite Result
tests/gateway 1447 passed, 86 skipped
web-studio vitest run src/features/admin/gateway src/i18n 567 passed
ruff check and format on the changed files clean
Docs: check:docs, check:api pass
Docs: site build, built-anchor check pass two rebases ago, not rerun since

End to end with a real model (deepseek-v4-1-flash) through a local server and gateway, with a recording proxy in front of the model endpoint, so the check is what was actually sent to the provider. These runs were made on the combined tree (server, gateway and plugins together) before the split and before the last rebase. At that time the code also had a mode that let unsealable requests through and an option, seal_secrets_strict, that refused them; the refusing path is now the only one, and the runs below that concern failures used it:

  • A new token typed by the user: the provider saw only references; the model saved the entry as credential/github with a description and used it through ov privacy run; the tool got the real value.
  • enroll_tool_secrets on, read a file with a token and write it back: nothing reached the provider, and the written file holds the real value.
  • Server stopped: 503 secret_seal_failed and nothing sent upstream. Sealing resumed without a gateway restart once the server was back.
  • A compressed request body: 400 secret_seal_invalid_request, nothing sent upstream.

Earlier runs on the same design (Chat, Anthropic and Responses protocols, rotation, a 60-token burst, Claude Code, pi and Codex CLI as clients, latency measurements) are described in the RFC supplement.

Known limits

  • With seal_secrets on, model requests of that profile fail while OpenViking is unreachable or older than 0.5.7. That is the intended trade: the switch is opt-in, and it promises that nothing goes out unsealed.
  • A client that compresses its request bodies gets 400 with seal_secrets on.
  • Only whole values are matched. A prefix, a re-encoded form or character-by-character output is not recognised.
  • Unregistered tokens in tool output are not sealed unless enroll_tool_secrets is on.
  • OpenViking's own tools are recognised by name. If the client registers the OpenViking MCP server under a name without openviking, references in calls to its tools reach the tool as values.
  • Encoded file content in a request (a data: URI, or long base64 under data / file_data) is not scanned.
  • A stored conversation whose history already holds a literal {{ov_privacy:…}} reference starts a new gateway session once after the upgrade, because conversation identity now ignores the reference.

Notes for reviewers

  • A session that turns seal_secrets on after it started no longer offers the gateway tool privacy_resolve: the tool is dropped from the list whenever the session is sealed, whatever was chosen when the session began.
  • proxy.py was merged with the per-upstream billing evidence from feat(gateway): record per-upstream billing evidence #8337: a body is sealed before begin_call, and when a reply fails at unsealing, the upstream call is closed with the upstream's status and usage and the error secret_unseal_failed.
  • The comparison "gateway or plugin" and the links between the gateway page and the plugin pages are left out of both PRs, so that each one's docs build alone. A small follow-up adds them once both have merged.

https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants