Skip to content

feat(privacy): seal endpoint, auto-enrolled credentials and reference values - #8384

Merged
ZaynJarvis merged 1 commit into
volcengine:mainfrom
t0saki:feat/privacy-seal-enroll
Nov 26, 2026
Merged

ZaynJarvis merged 1 commit into
volcengine:mainfrom
t0saki:feat/privacy-seal-enroll

Conversation

@t0saki

@t0saki t0saki commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

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

It adds a seal endpoint: a client sends text that is about to go to a model, and gets it back with the user's secrets replaced by {{ov_privacy:…}} references. New tokens can be stored and replaced in the same call. Nothing calls the endpoint until a client turns sealing on, so existing deployments are not affected, apart from the behaviour changes listed below.

Based directly on main, one commit. It touches no plugin or gateway file and does not depend on #8408. The privacy_seal row of the server feature table is added by #8445, the first client that reads it.

This PR used to hold the server, gateway and plugin parts together (about 13,000 lines). It is now the server part only, and the code was trimmed before the split. The clients are in their own PRs, stacked on this one:

It also replaces the two earlier drafts, #7340 and #7341.

What changes

  • POST /api/v1/privacy-configs/seal takes a list of texts and returns, per text, the spans whose value matched a registered secret, with the reference that replaces each. It matches the current and earlier versions of credential targets, so a rotated token is still replaced. It works whatever the user's privacy mode is. Any failure is an error response, never unsealed text.
  • Auto-enrollment. Texts marked enroll also have new tokens stored and replaced, using the same detector, custom_rules and never_mask as today. Each value gets its own target in a new built-in category auto. A span reports temporary while its target is still in auto. One call stores at most 1024 new values, and a match longer than a stored value may be (64 KiB) is left as it is. Only this endpoint writes to auto.
  • A reference as a value. upsert, patch and MCP privacy_upsert accept a whole reference as a value and copy that field's value. A source in auto is removed after the write. This is how a model saves a temporary entry under a proper name without seeing the value. When a reference was given, the response shows references instead of values.
  • Descriptions. A target can carry a description: MCP privacy_upsert(description=…), returned by the tree. MCP privacy_tree leaves auto out unless asked.
  • Credential revision is persisted per user under settings/, so workers share it; the matcher cache is keyed on it.
  • Docs: the seal endpoint and the reference-as-value rules in the Privacy API reference (en and zh).

Behaviour changes for existing callers

  • A value that contains {{ov_privacy: inside a longer string is now rejected with INVALID_ARGUMENT; before, it was stored literally.
  • A top-level value that is a whole reference used to be stored literally; it is now replaced by the referenced field's value.
  • upsert and patch with category=auto are rejected.
  • The sanitizer's credential revision moved from an in-process counter to a file. Every credential write bumps it under a lock.

Size

39 files, +1769/−100 in this PR's own commit: about 670 lines of source, 880 of tests and 200 of docs. The rest is the version manifests.

How it was tested

On this branch, on main at b6ab3ef:

Suite Result
Server privacy tests in tests/server and tests/unit, including every test file this PR touches 288 passed
ruff check and format on the changed files clean
Docs: check:docs, check:api, site build, built-anchor check pass

The ruff and docs rows are from an earlier base; the files they cover have not changed since.

The endpoint was also exercised end to end by its two clients with a real model; see #8444 and #8445.

Known limits

  • Only whole values are matched. A prefix or a re-encoded form is not recognised.
  • auto entries that nobody saves under a name accumulate; there is no cleanup yet.
  • The matcher skips anything shaped like a reference, so plain text wrapped in a forged reference is not replaced.
  • The revision file and the enroll lock live under the user's settings/ directory, which, like settings/user_config.json, is not a protected root.

Notes for reviewers

Open questions for the Privacy module are listed in section 10 of the RFC supplement: the auto category and its naming, where the revision is persisted, sealing earlier versions while the storage path does not, and cleanup of auto.

https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx

Comment thread openviking_gateway/sealing.py Fixed
Comment thread openviking_gateway/sealing.py Fixed
Comment thread openviking_gateway/sealing.py Fixed
Comment thread tests/gateway/test_seal_secrets.py Fixed
@t0saki
t0saki force-pushed the feat/privacy-seal-enroll branch 2 times, most recently from 9da7214 to 848d4bc Compare November 25, 2026 09:37
@t0saki t0saki changed the title feat(privacy): seal secrets out of model requests, with auto-enrollment (server, gateway, Claude Code, Pi) feat(privacy): seal endpoint, auto-enrolled credentials and reference values Nov 25, 2026
t0saki pushed a commit to t0saki/OpenViking that referenced this pull request Nov 25, 2026
A secret a user pastes into a conversation goes to the model provider with
that message and with every later request. This adds a context-profile
switch, `seal_secrets` (off by default), that makes the gateway send a
user's registered secrets, and new tokens the user types, to the provider
only as {{ov_privacy:...}} references, while client tools still get the
real value. It uses the server's seal endpoint (POST
/api/v1/privacy-configs/seal, server 0.5.7 or newer).

Depends on volcengine#8384 (the seal endpoint, the `auto`
category and the `privacy_seal` feature row), which is based on volcengine#8408 (the
server feature table that `privacy_seal` and `supports` come from).

Not in this PR: sealing in the Claude Code and pi plugins (`sealSecrets`,
`enrollToolSecrets`) is a sibling PR, also on volcengine#8384, that does not depend on
this one. The "gateway or plugin" comparison moved to that PR, and the
cross-links between the gateway and plugin pages follow once both merge.

How it works:
- Before a request leaves, the gateway sends the content of every JSON
  model request (user, assistant and system text, tool results, attached
  blocks, history) to the seal endpoint with the user's own key and
  writes the references back. Structure is not touched (model, tool
  names, IDs, schemas, signed reasoning); JSON inside strings is
  rewritten in place. A final sweep covers what the gateway adds itself:
  recall, compaction summaries and its hidden OpenViking tool rounds.
  Results are cached in process memory by user, revision and text, never
  in shared storage.
- New 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 privacy_upsert, plus a short explanation of
  references. A conversation that started before the switch was turned on
  gets the explanation once, with its next turn. `enroll_tool_secrets` (off by default) also stores new
  tokens from tool output and attached blocks, without a note.
- References the model writes into client tool-call arguments are turned
  back into values in what the client receives. Assistant text, the
  gateway's own records, OpenViking's own tools and `ov privacy` commands
  keep the reference. With sealing on, tool-call arguments are no longer
  streamed piece by piece; replies the kernel did not prepare go through
  an unseal-only relay.
- Conversation identity ignores which reference a secret maps to, so
  saving, renaming or rotating a credential does not split a session. This
  applies whether or not sealing is on, and NORMALIZATION_VERSION stays as
  it is: a stored conversation whose history already holds a literal
  {{ov_privacy:...}} reference (from privacy configs or `ov privacy run`)
  hashes differently after the upgrade and starts a new gateway session
  once, losing its recorded injection. This is a one-time effect.

Turning sealing on never adds a failure: when the server is too old, its
version cannot be read, a seal call fails or the request cannot be sealed,
the request goes out unsealed and the request record carries
`seal_unsupported`, `seal_failed` or `unseal_failed`. The option
`seal_secrets_strict` rejects such requests instead, with 503
`secret_seal_failed` (the call failed or the server cannot seal), 400
`secret_seal_invalid_request` (the request cannot be sealed) or, on the
reply side, 502 `secret_unseal_failed`. Support is decided from the server
feature table row `privacy_seal` through a new
`VikingClient.server_version`. Seal and resolve calls count toward the
per-account OpenViking circuit breaker like any other call. The
`X-OpenViking-Context` header cannot set any of the three switches.

Also: the Studio profile editor gets the three switches, request records
count `secrets_sealed`, `secrets_enrolled`, `secrets_unsealed`,
`seal_calls`, `seal_cache_hits` and `seal_ms`, and the docs get a new page,
"Secret sealing in the gateway" (en and zh), with entries in context
profiles, configuration, security and troubleshooting. The Privacy API
reference now links to that page, and the gateway API reference lists the
three new model-route reasons.

Claude-Session: https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx
@t0saki
t0saki force-pushed the feat/privacy-seal-enroll branch 2 times, most recently from 24e98b0 to 607e104 Compare November 26, 2026 04:48
t0saki pushed a commit to t0saki/OpenViking that referenced this pull request Nov 26, 2026
A secret a user pastes into a conversation goes to the model provider with
that message and with every later request. This adds a context-profile
switch, `seal_secrets` (off by default), that makes the gateway send a
user's registered secrets, and new tokens the user types, to the provider
only as {{ov_privacy:...}} references, while client tools still get the
real value. It uses the server's seal endpoint (POST
/api/v1/privacy-configs/seal, server 0.5.7 or newer).

Depends on volcengine#8384 (the seal endpoint, the `auto`
category and the `privacy_seal` feature row), which is based on volcengine#8408 (the
server feature table that `privacy_seal` and `supports` come from).

Not in this PR: sealing in the Claude Code and pi plugins (`sealSecrets`,
`enrollToolSecrets`) is a sibling PR, also on volcengine#8384, that does not depend on
this one. The "gateway or plugin" comparison moved to that PR, and the
cross-links between the gateway and plugin pages follow once both merge.

How it works:
- Before a request leaves, the gateway sends the content of every JSON
  model request (user, assistant and system text, tool results, attached
  blocks, history) to the seal endpoint with the user's own key and
  writes the references back. Structure is not touched (model, tool
  names, IDs, schemas, signed reasoning); JSON inside strings is
  rewritten in place. A final sweep covers what the gateway adds itself:
  recall, compaction summaries and its hidden OpenViking tool rounds.
  Results are cached in process memory by user, revision and text, never
  in shared storage.
- New 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 privacy_upsert, plus a short explanation of
  references. A conversation that started before the switch was turned on
  gets the explanation once, with its next turn. `enroll_tool_secrets` (off by default) also stores new
  tokens from tool output and attached blocks, without a note.
- References the model writes into client tool-call arguments are turned
  back into values in what the client receives. Assistant text, the
  gateway's own records, OpenViking's own tools and `ov privacy` commands
  keep the reference. With sealing on, tool-call arguments are no longer
  streamed piece by piece; replies the kernel did not prepare go through
  an unseal-only relay.
- Conversation identity ignores which reference a secret maps to, so
  saving, renaming or rotating a credential does not split a session. This
  applies whether or not sealing is on, and NORMALIZATION_VERSION stays as
  it is: a stored conversation whose history already holds a literal
  {{ov_privacy:...}} reference (from privacy configs or `ov privacy run`)
  hashes differently after the upgrade and starts a new gateway session
  once, losing its recorded injection. This is a one-time effect.

Once sealing is on, nothing goes out unsealed. When the server is too old,
its version cannot be read, a seal call fails or the request cannot be
sealed, the request is refused: 503 `secret_seal_failed` (the call failed
or the server cannot seal) or 400 `secret_seal_invalid_request` (the
request cannot be sealed). A reply whose tool calls cannot be unsealed
fails with 502 `secret_unseal_failed`. Each message names the case and
what to do. Support is decided from the server feature table row
`privacy_seal` through a new `VikingClient.server_version`; the version is
read again within 30 s, so sealing resumes without a gateway restart. Seal
and resolve calls count toward the per-account OpenViking circuit breaker
like any other call. The `X-OpenViking-Context` header cannot set either
switch.

Also: the Studio profile editor gets the two switches, request records
count `secrets_sealed`, `secrets_enrolled`, `secrets_unsealed`,
`seal_calls`, `seal_cache_hits` and `seal_ms`, and the docs get a new page,
"Secret sealing in the gateway" (en and zh), with entries in context
profiles, configuration, security and troubleshooting. The Privacy API
reference now links to that page, and the gateway API reference lists the
three new model-route errors.

Claude-Session: https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx
@t0saki
t0saki marked this pull request as ready for review November 26, 2026 07:05
t0saki pushed a commit to t0saki/OpenViking that referenced this pull request Nov 26, 2026
A secret a user pastes into a conversation goes to the model provider with
that message and with every later request. This adds a context-profile
switch, `seal_secrets` (off by default), that makes the gateway send a
user's registered secrets, and new tokens the user types, to the provider
only as {{ov_privacy:...}} references, while client tools still get the
real value. It uses the server's seal endpoint (POST
/api/v1/privacy-configs/seal, server 0.5.7 or newer).

Depends on volcengine#8384 (the seal endpoint, the `auto`
category and the `privacy_seal` feature row), which is based on volcengine#8408 (the
server feature table that `privacy_seal` and `supports` come from).

Not in this PR: sealing in the Claude Code and pi plugins (`sealSecrets`,
`enrollToolSecrets`) is a sibling PR, also on volcengine#8384, that does not depend on
this one. The "gateway or plugin" comparison moved to that PR, and the
cross-links between the gateway and plugin pages follow once both merge.

How it works:
- Before a request leaves, the gateway sends the content of every JSON
  model request (user, assistant and system text, tool results, attached
  blocks, history) to the seal endpoint with the user's own key and
  writes the references back. Structure is not touched (model, tool
  names, IDs, schemas, signed reasoning); JSON inside strings is
  rewritten in place. A final sweep covers what the gateway adds itself:
  recall, compaction summaries and its hidden OpenViking tool rounds.
  Results are cached in process memory by user, revision and text, never
  in shared storage.
- New 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 privacy_upsert, plus a short explanation of
  references. A conversation that started before the switch was turned on
  gets the explanation once, with its next turn. `enroll_tool_secrets` (off by default) also stores new
  tokens from tool output and attached blocks, without a note.
- References the model writes into client tool-call arguments are turned
  back into values in what the client receives. Assistant text, the
  gateway's own records, OpenViking's own tools and `ov privacy` commands
  keep the reference. With sealing on, tool-call arguments are no longer
  streamed piece by piece; replies the kernel did not prepare go through
  an unseal-only relay.
- Conversation identity ignores which reference a secret maps to, so
  saving, renaming or rotating a credential does not split a session. This
  applies whether or not sealing is on, and NORMALIZATION_VERSION stays as
  it is: a stored conversation whose history already holds a literal
  {{ov_privacy:...}} reference (from privacy configs or `ov privacy run`)
  hashes differently after the upgrade and starts a new gateway session
  once, losing its recorded injection. This is a one-time effect.

Once sealing is on, nothing goes out unsealed. When the server is too old,
its version cannot be read, a seal call fails or the request cannot be
sealed, the request is refused: 503 `secret_seal_failed` (the call failed
or the server cannot seal) or 400 `secret_seal_invalid_request` (the
request cannot be sealed). A reply whose tool calls cannot be unsealed
fails with 502 `secret_unseal_failed`. Each message names the case and
what to do. Support is decided from the server feature table row
`privacy_seal` through a new `VikingClient.server_version`; the version is
read again within 30 s, so sealing resumes without a gateway restart. Seal
and resolve calls count toward the per-account OpenViking circuit breaker
like any other call. The `X-OpenViking-Context` header cannot set either
switch.

Also: the Studio profile editor gets the two switches, request records
count `secrets_sealed`, `secrets_enrolled`, `secrets_unsealed`,
`seal_calls`, `seal_cache_hits` and `seal_ms`, and the docs get a new page,
"Secret sealing in the gateway" (en and zh), with entries in context
profiles, configuration, security and troubleshooting. The Privacy API
reference now links to that page, and the gateway API reference lists the
three new model-route errors.

Claude-Session: https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx
@t0saki
t0saki force-pushed the feat/privacy-seal-enroll branch from 607e104 to f5255ca Compare November 26, 2026 07:16
t0saki pushed a commit to t0saki/OpenViking that referenced this pull request Nov 26, 2026
A secret a user pastes into a conversation goes to the model provider with
that message and with every later request. This adds a context-profile
switch, `seal_secrets` (off by default), that makes the gateway send a
user's registered secrets, and new tokens the user types, to the provider
only as {{ov_privacy:...}} references, while client tools still get the
real value. It uses the server's seal endpoint (POST
/api/v1/privacy-configs/seal, server 0.5.7 or newer).

Depends on volcengine#8384 (the seal endpoint and the `auto`
category), on volcengine#8408 (the server feature table `supports` comes from) and
on volcengine#8445, which adds the table's `privacy_seal` row. This branch sits on
volcengine#8445.

Not in this PR: sealing in the Claude Code and pi plugins (`sealSecrets`,
`enrollToolSecrets`) is volcengine#8445. The gateway code uses nothing from it but
that row. The "gateway or plugin" comparison moved to that PR, and the
cross-links between the gateway and plugin pages follow once both merge.

How it works:
- Before a request leaves, the gateway sends the content of every JSON
  model request (user, assistant and system text, tool results, attached
  blocks, history) to the seal endpoint with the user's own key and
  writes the references back. Structure is not touched (model, tool
  names, IDs, schemas, signed reasoning); JSON inside strings is
  rewritten in place. A final sweep covers what the gateway adds itself:
  recall, compaction summaries and its hidden OpenViking tool rounds.
  Results are cached in process memory by user, revision and text, never
  in shared storage.
- New 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 privacy_upsert, plus a short explanation of
  references. A conversation that started before the switch was turned on
  gets the explanation once, with its next turn. `enroll_tool_secrets` (off by default) also stores new
  tokens from tool output and attached blocks, without a note.
- References the model writes into client tool-call arguments are turned
  back into values in what the client receives. Assistant text, the
  gateway's own records, OpenViking's own tools and `ov privacy` commands
  keep the reference. With sealing on, tool-call arguments are no longer
  streamed piece by piece; replies the kernel did not prepare go through
  an unseal-only relay.
- Conversation identity ignores which reference a secret maps to, so
  saving, renaming or rotating a credential does not split a session. This
  applies whether or not sealing is on, and NORMALIZATION_VERSION stays as
  it is: a stored conversation whose history already holds a literal
  {{ov_privacy:...}} reference (from privacy configs or `ov privacy run`)
  hashes differently after the upgrade and starts a new gateway session
  once, losing its recorded injection. This is a one-time effect.

Once sealing is on, nothing goes out unsealed. When the server is too old,
its version cannot be read, a seal call fails or the request cannot be
sealed, the request is refused: 503 `secret_seal_failed` (the call failed
or the server cannot seal) or 400 `secret_seal_invalid_request` (the
request cannot be sealed). A reply whose tool calls cannot be unsealed
fails with 502 `secret_unseal_failed`. Each message names the case and
what to do. Support is decided from the server feature table row
`privacy_seal` through a new `VikingClient.server_version`; the version is
read again within 30 s, so sealing resumes without a gateway restart. Seal
and resolve calls count toward the per-account OpenViking circuit breaker
like any other call. The `X-OpenViking-Context` header cannot set either
switch.

Also: the Studio profile editor gets the two switches, request records
count `secrets_sealed`, `secrets_enrolled`, `secrets_unsealed`,
`seal_calls`, `seal_cache_hits` and `seal_ms`, and the docs get a new page,
"Secret sealing in the gateway" (en and zh), with entries in context
profiles, configuration, security and troubleshooting. The Privacy API
reference now links to that page, and the gateway API reference lists the
three new model-route errors.

Claude-Session: https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx
@t0saki
t0saki force-pushed the feat/privacy-seal-enroll branch from f5255ca to cc98a73 Compare November 26, 2026 07:30
… values

A secret pasted into an agent conversation is sent to the model provider
with that message and again with every later request. This change gives
OpenViking the server half of "sealing": clients send model-bound text to
the server, get it back with the user's secrets replaced by
{{ov_privacy:...}} references, and turn references back into values only
when a tool runs. This PR is the server side only; the gateway and the
Claude Code and pi plugin halves are in their own pull requests and are
not in this PR.

It touches no plugin or gateway file and sits directly on main. The
`privacy_seal` row of the server feature table (volcengine#8408) comes with the
plugin PR, the first client that reads it.

What it adds:
- POST /api/v1/privacy-configs/seal takes a list of texts and returns,
  per text, the spans whose value matched a registered secret, with the
  reference that replaces it. Matching covers the current and earlier
  versions of `credential` targets and the `auto` category, so a rotated
  token is still replaced. It works whatever the user's privacy mode is,
  fails with an error rather than returning unsealed text, and returns a
  revision that callers can cache results on.
- Texts marked `enroll` also have new tokens found by the existing
  detector stored, each in its own target of a new `auto` category under
  a generated name, and replaced. A span reports `temporary` while its
  target is still in `auto` and `created` when this call stored it. One
  call stores at most 1024 new values. A match longer than a stored
  value may be (64 KiB) is left as it is. Only this endpoint writes to
  `auto`; upsert and patch reject `category=auto`.
- A value given to upsert, patch or the MCP `privacy_upsert` tool may be
  a whole reference: the server copies the referenced field's value, and
  removes the source when it was an `auto` entry. This is how a model
  gives a temporary entry a proper name without ever seeing the value.
  When a reference was given, the response shows references, not values.
- A target can carry a description; `privacy_upsert` takes it and the
  privacy tree returns it. MCP `privacy_tree` leaves `auto` out unless it
  is asked for.
- The endpoint's own state (the credential revision and the enroll lock)
  lives under the user's settings/ directory, not in the privacy
  category namespace.

Behaviour changes for existing callers of upsert, patch and the storage
sanitizer:
- A value that contains {{ov_privacy: inside a longer string is now
  rejected with INVALID_ARGUMENT in every category; before, it was stored
  literally.
- A top-level value that is a whole reference used to be stored literally;
  it is now replaced by the referenced field's value.
- Upsert and patch with category=auto are rejected.
- The sanitizer's credential revision moved from an in-process counter to
  a file under settings/. Every storage-path sanitize reads it, the first
  sanitize for a user writes it under a lock, and every credential write
  takes an exact lock and bumps it. This fixes the cross-worker cache
  staleness that the TTL used to paper over.
- Credential warnings are computed on the stored values after the write.

Docs: the seal endpoint and the reference-as-value rules in the Privacy
API reference (en and zh).

Claude-Session: https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx
@t0saki
t0saki force-pushed the feat/privacy-seal-enroll branch from cc98a73 to e5d88e4 Compare November 26, 2026 08:07
t0saki pushed a commit to t0saki/OpenViking that referenced this pull request Nov 26, 2026
A secret a user pastes into a conversation goes to the model provider with
that message and with every later request. This adds a context-profile
switch, `seal_secrets` (off by default), that makes the gateway send a
user's registered secrets, and new tokens the user types, to the provider
only as {{ov_privacy:...}} references, while client tools still get the
real value. It uses the server's seal endpoint (POST
/api/v1/privacy-configs/seal, server 0.5.7 or newer).

Depends on volcengine#8384 (the seal endpoint and the `auto`
category), on volcengine#8408 (the server feature table `supports` comes from) and
on volcengine#8445, which adds the table's `privacy_seal` row. This branch sits on
volcengine#8445.

Not in this PR: sealing in the Claude Code and pi plugins (`sealSecrets`,
`enrollToolSecrets`) is volcengine#8445. The gateway code uses nothing from it but
that row. The "gateway or plugin" comparison moved to that PR, and the
cross-links between the gateway and plugin pages follow once both merge.

How it works:
- Before a request leaves, the gateway sends the content of every JSON
  model request (user, assistant and system text, tool results, attached
  blocks, history) to the seal endpoint with the user's own key and
  writes the references back. Structure is not touched (model, tool
  names, IDs, schemas, signed reasoning); JSON inside strings is
  rewritten in place. A final sweep covers what the gateway adds itself:
  recall, compaction summaries and its hidden OpenViking tool rounds.
  Results are cached in process memory by user, revision and text, never
  in shared storage.
- New 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 privacy_upsert, plus a short explanation of
  references. A conversation that started before the switch was turned on
  gets the explanation once, with its next turn. `enroll_tool_secrets` (off by default) also stores new
  tokens from tool output and attached blocks, without a note.
- References the model writes into client tool-call arguments are turned
  back into values in what the client receives. Assistant text, the
  gateway's own records, OpenViking's own tools and `ov privacy` commands
  keep the reference. With sealing on, tool-call arguments are no longer
  streamed piece by piece; replies the kernel did not prepare go through
  an unseal-only relay.
- Conversation identity ignores which reference a secret maps to, so
  saving, renaming or rotating a credential does not split a session. This
  applies whether or not sealing is on, and NORMALIZATION_VERSION stays as
  it is: a stored conversation whose history already holds a literal
  {{ov_privacy:...}} reference (from privacy configs or `ov privacy run`)
  hashes differently after the upgrade and starts a new gateway session
  once, losing its recorded injection. This is a one-time effect.

Once sealing is on, nothing goes out unsealed. When the server is too old,
its version cannot be read, a seal call fails or the request cannot be
sealed, the request is refused: 503 `secret_seal_failed` (the call failed
or the server cannot seal) or 400 `secret_seal_invalid_request` (the
request cannot be sealed). A reply whose tool calls cannot be unsealed
fails with 502 `secret_unseal_failed`. Each message names the case and
what to do. Support is decided from the server feature table row
`privacy_seal` through a new `VikingClient.server_version`; the version is
read again within 30 s, so sealing resumes without a gateway restart. Seal
and resolve calls count toward the per-account OpenViking circuit breaker
like any other call. The `X-OpenViking-Context` header cannot set either
switch.

Also: the Studio profile editor gets the two switches, request records
count `secrets_sealed`, `secrets_enrolled`, `secrets_unsealed`,
`seal_calls`, `seal_cache_hits` and `seal_ms`, and the docs get a new page,
"Secret sealing in the gateway" (en and zh), with entries in context
profiles, configuration, security and troubleshooting. The Privacy API
reference now links to that page, and the gateway API reference lists the
three new model-route errors.

Claude-Session: https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx

@ZaynJarvis ZaynJarvis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ZaynJarvis
ZaynJarvis merged commit 83afb6d into volcengine:main Nov 26, 2026
17 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in OpenViking project Nov 26, 2026
t0saki added a commit that referenced this pull request Nov 26, 2026
…ls (#8444)

* feat(gateway,plugins): one table for the server features clients depend on

The gateway and the plugins each need to know whether the OpenViking server
they talk to already has a capability, and today each answers that on its
own: the gateway hard-codes "0.5.0" for working memory opt-in, and a plugin
that needed the same answer would carry its own number and its own version
parser. Two copies of a fact drift, and two parsers disagree about the same
string.

examples/memory-plugin-shared/lib/server-features.json now lists each such
capability with the first server version that has it. The JS reader
(lib/server-features.mjs) answers for the plugins; the sync script copies
the table byte for byte into the gateway package, where client.py reads it.
Rules for a row, and the steps to add one, are in the shared README: the
version is the next unreleased release when the server change merges, only
the release part counts (0.5.7.dev44 is 0.5.7), an unreadable version counts
as not supporting, and callers ask the table instead of inferring support
from a 404.

The gateway's working memory check now reads its version from the table and
is otherwise unchanged: it still goes through health(), so a /health that
fails, a root key, or a version below the gateway minimum or unreadable stops
create_session and commit as before. One answer does move: under the
release-part rule, pre-releases and dev builds of 0.5.0 (0.5.0rc1,
0.5.0.devN) now count as 0.5.0 and get the 0.5.0 bodies.

Both readers take (feature, version) and accept PEP 440 and nothing else, so
they give the same answer for the same string; tests/fixtures holds one list
of version cases that both test suites run, and both the gateway workflow and
the plugin job now trigger on it. The sync now carries a JSON file a module
reads beside itself along with that module, and the PR check fails when the
gateway's committed copy differs from the source.

No plugin imports the reader yet, so no plugin ships a copy in this change;
the "every shared module is reachable" test exempts server-features.mjs. Its
first consumer is the privacy seal change, whose plugins import it for
featureStatus and healthVersion; that change removes the exemption. Every
distributed plugin still gets a patch bump, because the version check counts
any change under memory-plugin-shared/lib as a change to all of them.

Claude-Session: https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx

* feat(privacy): seal endpoint, auto-enrolled credentials and reference values

A secret pasted into an agent conversation is sent to the model provider
with that message and again with every later request. This change gives
OpenViking the server half of "sealing": clients send model-bound text to
the server, get it back with the user's secrets replaced by
{{ov_privacy:...}} references, and turn references back into values only
when a tool runs. This PR is the server side only; the gateway and the
Claude Code and pi plugin halves are in their own pull requests and are
not in this PR.

It touches no plugin or gateway file and sits directly on main. The
`privacy_seal` row of the server feature table (#8408) comes with the
plugin PR, the first client that reads it.

What it adds:
- POST /api/v1/privacy-configs/seal takes a list of texts and returns,
  per text, the spans whose value matched a registered secret, with the
  reference that replaces it. Matching covers the current and earlier
  versions of `credential` targets and the `auto` category, so a rotated
  token is still replaced. It works whatever the user's privacy mode is,
  fails with an error rather than returning unsealed text, and returns a
  revision that callers can cache results on.
- Texts marked `enroll` also have new tokens found by the existing
  detector stored, each in its own target of a new `auto` category under
  a generated name, and replaced. A span reports `temporary` while its
  target is still in `auto` and `created` when this call stored it. One
  call stores at most 1024 new values. A match longer than a stored
  value may be (64 KiB) is left as it is. Only this endpoint writes to
  `auto`; upsert and patch reject `category=auto`.
- A value given to upsert, patch or the MCP `privacy_upsert` tool may be
  a whole reference: the server copies the referenced field's value, and
  removes the source when it was an `auto` entry. This is how a model
  gives a temporary entry a proper name without ever seeing the value.
  When a reference was given, the response shows references, not values.
- A target can carry a description; `privacy_upsert` takes it and the
  privacy tree returns it. MCP `privacy_tree` leaves `auto` out unless it
  is asked for.
- The endpoint's own state (the credential revision and the enroll lock)
  lives under the user's settings/ directory, not in the privacy
  category namespace.

Behaviour changes for existing callers of upsert, patch and the storage
sanitizer:
- A value that contains {{ov_privacy: inside a longer string is now
  rejected with INVALID_ARGUMENT in every category; before, it was stored
  literally.
- A top-level value that is a whole reference used to be stored literally;
  it is now replaced by the referenced field's value.
- Upsert and patch with category=auto are rejected.
- The sanitizer's credential revision moved from an in-process counter to
  a file under settings/. Every storage-path sanitize reads it, the first
  sanitize for a user writes it under a lock, and every credential write
  takes an exact lock and bumps it. This fixes the cross-worker cache
  staleness that the TTL used to paper over.
- Credential warnings are computed on the stored values after the write.

Docs: the seal endpoint and the reference-as-value rules in the Privacy
API reference (en and zh).

Claude-Session: https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx

* feat(plugins): seal secrets in Claude Code and pi

A secret a user pastes into an agent conversation goes to the model
provider with that message and with every later request. This adds
plugin-side sealing to the Claude Code plugin and the pi extension: with
`sealSecrets` on, what the user types and every tool result reach the
model with the user's secrets replaced by {{ov_privacy:...}} references,
and a reference the model writes into a tool call is turned back into the
real value before the tool runs. It runs on the user's machine and uses
the server's seal endpoint (POST /api/v1/privacy-configs/seal, server
0.5.7 or newer, from the privacy PR this one is based on); it needs no
gateway and does not depend on the gateway PR.

- One shared core, memory-plugin-shared/lib/seal-core.mjs, talks to the
  seal and resolve endpoints, builds sealed text from the returned spans
  and decides support from the server feature table row `privacy_seal`.
  Claude Code and pi now import the table's reader, so the sync test no
  longer exempts server-features.mjs.
- The server feature table (#8408) gets the row "privacy_seal": "0.5.7",
  the first release with the endpoint; its synced gateway copy, the type
  union and the shared version fixture move with it.
- Claude Code: hooks-module mods on prompt submit, tool calls and
  attachments seal the prompt, tool results and the files, reminders and
  hook context Claude Code attaches; the first sealed prompt of a session
  (and the first after a compaction) carries the text that explains
  references to the model. The setting is read once per session by a
  small helper process; where that cannot run (surfaces without the
  process API, such as the Desktop Code tab or the VS Code panel),
  sealing stays off silently unless OPENVIKING_SEAL_SECRETS=1 asks for it,
  and then prompts are stopped with the reason.
- pi: handlers on input, tool_result and tool_call seal before pi stores
  or sends anything, so the session file holds references too.
- New tokens in what the user types are stored by the server in the
  `auto` category, and the model is asked to save them under a proper
  name. `enrollToolSecrets` (off by default) also stores new tokens found
  in tool output.
- Once sealing is on, nothing goes on unsealed: when the server is too
  old, its version cannot be read or a call fails, the input is stopped,
  the tool result withheld or the tool call blocked, with a message that
  names the case and what to do. After a stop the server is asked again,
  so sealing resumes once it can seal.
- The openviking-memory skill gains a "Saved credentials" section on
  references and the `ov privacy` CLI, synced to every host.
- The URI guard no longer fires on viking:// inside a privacy reference.

Both settings are off by default and can be set in ovcli.conf or
the environment. Docs: the plugin READMEs and the Claude Code and pi
integration pages (en and zh).

Not in this PR:
- Only Claude Code and pi seal. codex, opencode, agent-hook, dsh and
  magpie get only the skill text, the config knobs (no effect there) and
  a version bump.
- The gateway side of sealing is a separate PR on top of this one,
  because it reads the `privacy_seal` row added here. Nothing here names
  a gateway option or links to gateway pages.
  The comparison of sealing in the plugin and in the gateway (table and
  figure) and the cross-links between the two docs come in a follow-up
  once both have merged. One shared test compares the session text with
  the gateway's and skips while the gateway source is absent.
- mods/seal/seal.test.ts runs only under `claude plugin test`, which CI
  does not run; it passed locally (26/26 with sources.test.ts, Claude
  Code 2.1.331). `tsc -p mods/seal` was not run, since it needs the types
  `claude --plugin-dir` generates.
- This branch sits on #8408 and the server PR. #8408 already bumps
  every plugin once; the second patch bump here is expected, because the
  shared library changes again.

Claude-Session: https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx

* feat(gateway): seal secrets out of model requests and unseal tool calls

A secret a user pastes into a conversation goes to the model provider with
that message and with every later request. This adds a context-profile
switch, `seal_secrets` (off by default), that makes the gateway send a
user's registered secrets, and new tokens the user types, to the provider
only as {{ov_privacy:...}} references, while client tools still get the
real value. It uses the server's seal endpoint (POST
/api/v1/privacy-configs/seal, server 0.5.7 or newer).

Depends on #8384 (the seal endpoint and the `auto`
category), on #8408 (the server feature table `supports` comes from) and
on #8445, which adds the table's `privacy_seal` row. This branch sits on
#8445.

Not in this PR: sealing in the Claude Code and pi plugins (`sealSecrets`,
`enrollToolSecrets`) is #8445. The gateway code uses nothing from it but
that row. The "gateway or plugin" comparison moved to that PR, and the
cross-links between the gateway and plugin pages follow once both merge.

How it works:
- Before a request leaves, the gateway sends the content of every JSON
  model request (user, assistant and system text, tool results, attached
  blocks, history) to the seal endpoint with the user's own key and
  writes the references back. Structure is not touched (model, tool
  names, IDs, schemas, signed reasoning); JSON inside strings is
  rewritten in place. A final sweep covers what the gateway adds itself:
  recall, compaction summaries and its hidden OpenViking tool rounds.
  Results are cached in process memory by user, revision and text, never
  in shared storage.
- New 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 privacy_upsert, plus a short explanation of
  references. A conversation that started before the switch was turned on
  gets the explanation once, with its next turn. `enroll_tool_secrets` (off by default) also stores new
  tokens from tool output and attached blocks, without a note.
- References the model writes into client tool-call arguments are turned
  back into values in what the client receives. Assistant text, the
  gateway's own records, OpenViking's own tools and `ov privacy` commands
  keep the reference. With sealing on, tool-call arguments are no longer
  streamed piece by piece; replies the kernel did not prepare go through
  an unseal-only relay.
- Conversation identity ignores which reference a secret maps to, so
  saving, renaming or rotating a credential does not split a session. This
  applies whether or not sealing is on, and NORMALIZATION_VERSION stays as
  it is: a stored conversation whose history already holds a literal
  {{ov_privacy:...}} reference (from privacy configs or `ov privacy run`)
  hashes differently after the upgrade and starts a new gateway session
  once, losing its recorded injection. This is a one-time effect.

Once sealing is on, nothing goes out unsealed. When the server is too old,
its version cannot be read, a seal call fails or the request cannot be
sealed, the request is refused: 503 `secret_seal_failed` (the call failed
or the server cannot seal) or 400 `secret_seal_invalid_request` (the
request cannot be sealed). A reply whose tool calls cannot be unsealed
fails with 502 `secret_unseal_failed`. Each message names the case and
what to do. Support is decided from the server feature table row
`privacy_seal` through a new `VikingClient.server_version`; the version is
read again within 30 s, so sealing resumes without a gateway restart. Seal
and resolve calls count toward the per-account OpenViking circuit breaker
like any other call. The `X-OpenViking-Context` header cannot set either
switch.

Also: the Studio profile editor gets the two switches, request records
count `secrets_sealed`, `secrets_enrolled`, `secrets_unsealed`,
`seal_calls`, `seal_cache_hits` and `seal_ms`, and the docs get a new page,
"Secret sealing in the gateway" (en and zh), with entries in context
profiles, configuration, security and troubleshooting. The Privacy API
reference now links to that page, and the gateway API reference lists the
three new model-route errors.

Claude-Session: https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx

---------

Co-authored-by: zhengxiao.wu <x@x>
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