Skip to content

feat(policy): isolate overlapping credential-bound accounts - #5995

Draft
stevenlee-oai wants to merge 6 commits into
ai-openshell:mainfrom
stevenlee-oai:feat/5988-credential-account-policy/stevenlee-oai
Draft

stevenlee-oai wants to merge 6 commits into
ai-openshell:mainfrom
stevenlee-oai:feat/5988-credential-account-policy/stevenlee-oai

Conversation

@stevenlee-oai

@stevenlee-oai stevenlee-oai commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Let two accounts share an inspected MCP or REST endpoint while keeping their credentials and request permissions separate. Each credential has a unique placeholder. The caller selects one placeholder; the Supervisor authorizes that account's request and then injects its token. This uses deployed policy, with no request-time authorization relay.

Closes #5988.

Changes

  • Add opt-in enforce-credential-bound routes. Account A can allow search while B allows search and send at the same URL. Ordinary enforce retains its behavior.
  • Reject duplicate credential names across attached Providers, including expired Providers. Build policy ownership with each actual credential binding, and reject conflicting policies for one credential or overlapping ordinary routes that could bypass account selection.
  • Require exactly one admitted placeholder before forwarding a protected HTTP request. Missing, unknown, mixed, and withdrawn selections are rejected. Existing explicit denies remain global; use positive allowlists for different account permissions.
  • Carry the capability through Supervisor configuration admission and Gateway-internal credential refresh checks. Document MCP initialization, discovery, and the optional event stream.

Verification

Ran the official TypeScript MCP SDK 1.29.0 inside a disposable Docker Sandbox through locally built Gateway, Supervisor, and Sandbox binaries, against a controlled MCP server. Both accounts completed initialize, notifications/initialized, the optional SSE GET, tools/list, and permitted tool calls.

Request Result observed at the controlled server
A: search Allowed, A's bearer
A: send HTTP 403, zero upstream calls
B: search, send Allowed, B's bearer
Missing or unknown placeholder HTTP 403, zero upstream requests
Withdraw A, retry its cached placeholder HTTP 403, zero upstream requests
B: send after A is withdrawn Allowed, B's bearer

openshell-conformance run --include-ignored account_bound_mcp_sdk_client_isolates_accounts

openshell-conformance: 1 passed, 0 failed in 18.8s

Runtime binaries reported ee7791b59; the final commit 1235bee records the exact test-only withdrawal correction used in that passing run. The Gateway regression two_static_provider_bindings_activate_with_distinct_policy_owners also passed, including the expired-Provider collision. The stable build and focused Gateway test used temporary qualification workspaces because the local registry lacked an unused experimental Cedar dependency; every selected dependency matched the repository lockfile.

Hosted Branch Checks and Helm Lint still await upstream maintainer approval for fork workflows. The green hosted E2E status means test:e2e was not applied; it is not a hosted test result.

  • Focused Gateway regression and real MCP SDK Sandbox conformance passed
  • Unit and E2E coverage updated
  • Signed-off Conventional Commits
  • User-facing policy and Provider documentation updated

Signed-off-by: stevenlee-oai <213687449+stevenlee-oai@users.noreply.github.com>
Signed-off-by: stevenlee-oai <213687449+stevenlee-oai@users.noreply.github.com>
Signed-off-by: stevenlee-oai <213687449+stevenlee-oai@users.noreply.github.com>
Signed-off-by: stevenlee-oai <213687449+stevenlee-oai@users.noreply.github.com>
Signed-off-by: stevenlee-oai <213687449+stevenlee-oai@users.noreply.github.com>
Signed-off-by: stevenlee-oai <213687449+stevenlee-oai@users.noreply.github.com>
@mrunalp

mrunalp commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Review: account-scoped credential authorization (#5988)

Reviewed at 1235beeefc1f4b7692806fdb320e7912bfa31fde by reading the code. Nothing below was reproduced with a build or test run, so each blocking item comes with the test we'd like to see.

Verdict: request changes. The PR solves the right problem in the right place. Supervisor-local enforcement, Gateway-stamped owners, no hot-path RPCs, and a wire value that older runtimes reject are all choices we want to keep. Three correctness issues need fixing before merge, and three design changes should land with it.

Blocking

1. Incremental policy updates can fold one account's rules into another's. endpoints_overlap matches on host, path and port only (merge.rs#L2064-L2075), and nothing in merge.rs reads credential_binding. When account B's rule is added under a new name with the same binary scope as account A's, the overlap fallback picks A's rule (#L1338-L1356) and merge_endpoint appends B's allow rules to A's endpoint while keeping A's binding (#L1639-L1642). The inheritance guard does not catch it, because the operation names the port and the binaries match. A then holds B's permissions and B has no endpoint. The PR's own Example 7 in skills/generate-sandbox-policy/examples.md has this shape: two rules with the same binary, host, port and path.

This predates the PR, but it only matters once two providers can share a URL, which is what this PR enables.

  • Fix: treat credential_binding.provider as part of endpoint identity in endpoints_overlap, find_matching_endpoint_mut and endpoint_attributes_cover, and reject an update whose target binding is ambiguous.
  • Test: applying A then B incrementally yields the same policy as loading both at once.

2. One account with two credential headers is rejected. validate_credential_selection requires used.len() == 1 (secrets.rs#L417-L432), and used holds environment keys (#L482-L492). A single provider that needs two headers, such as a key and an org ID, gets credential_selection_required.

  • Fix: count distinct providers, not keys.
  • Test: one bound provider with two placeholders in one request is forwarded; two providers in one request are rejected.

3. Reserving expired keys breaks existing sandboxes on upgrade. On main, a key name belonged to a provider only while its credential was unexpired. reserved_keys_with_refresh_states now reserves it permanently (provider.rs#L2647-L2675), and the check runs every time a sandbox's environment is resolved (#L1322), not only at attach. A sandbox with two providers sharing a key name, one expired, was valid before and returns FailedPrecondition after. Rotating a credential by attaching a new provider under the same key name produces exactly that state.

The reservation is right for account-bound providers, where the key name selects the account and must not change hands. Please keep it, but be strict when writing and tolerant when reading:

  • Keep the strict rule on sandbox create, sandbox update and provider update, so no new collision can be created.
  • On the resolve path, go back to the expiry-aware rule for ordinary providers. Account-bound providers stay strict there; request_policy_owners is already a parameter of that function.
  • Emit a warning when the tolerant path is used, so leftover collisions get cleaned up.
  • Tests: a sandbox in that state on main still resolves its environment after upgrade; creating or updating into that state is rejected; a bound provider's expired key cannot be taken by another provider.

Should change before merge

4. Check the account before request middleware. Today policy admits on the union of both accounts, middleware runs, and only then does credential preparation ask which endpoint owners admit the request (relay.rs#L229-L273). When A calls a tool only B may use, middleware processes a request A was never allowed to make, and the caller gets credential_selection_required where a tool nobody may use gets policy_denied.

The per-account decision already exists; it runs too late. Please run it before middleware as well:

  • Mechanism. On a bound endpoint, read which placeholder the request carries, map it to its provider, and run the existing allowed_token_grant_owners admission for the request. Deny if the selected provider's owners are not admitted. This needs no change to the Rego or the policy input. Passing the selected account into policy is the better long-term shape and can come with Cedar.
  • One shared function. Three relay paths evaluate policy and then run middleware (#L2001, #L2861, #L3830). The check should live in one place they all call, and the placeholder scan should be the same one header rewriting uses, so selection and injection cannot disagree.
  • No placeholder. A request to a bound endpoint that carries no account placeholder is rejected before middleware. Please document that unauthenticated calls to a bound URL are blocked.
  • After middleware. Keep the existing owner check, since middleware can rewrite the request. Also remember the provider selected before middleware and deny if the rewritten request selects a different one. Nothing compares the two today.
  • Batches. The owner admission already intersects across the calls in a JSON-RPC batch, so a batch passes only if the selected account may make every call. Keep that.

Error contract:

Case Response Severity
Zero or several accounts selected 403 credential_selection_required Medium
One account, request not allowed for it 403 policy_denied, identical to any other policy denial Medium
Middleware changed the selected account 403 policy_denied, with credential_selection_changed in the event only Medium

The second row must not reveal that another account could make the call. We'd like this in the PR because the error contract is hard to change once callers depend on it.

  • Tests: A calling a B-only tool gets policy_denied and middleware is not invoked; no placeholder and two placeholders each get credential_selection_required before middleware; middleware that swaps A's placeholder for B's is denied; a batch with one call outside the selected account's rules is denied.

5. Log the selection denial at Medium. This is the first row of the table in item 4. The event is High with no finding (relay.rs#L792-L807). AGENTS.md reserves High for security findings and puts policy denials at Medium.

6. Author the setting on credential_binding, not as an enforcement mode. Policy authors currently write enforcement: enforce-credential-bound, and the PR's skill examples already teach that form. Enforcement says what happens on a violation (enforce or audit). This setting says how a credential is tied to its endpoint, and the validator treats it that way: it requires credential_binding.provider, and a provider cannot mix bound and ordinary endpoints (lib.rs#L1982-L2025). The runtime parser also splits it straight back into Enforce plus a require_credential_selection flag.

  • Proposed authored form, shown on account_a from the PR's Example 7, with enforcement: enforce required and audit rejected on bound endpoints:

    # today
    enforcement: enforce-credential-bound
    credential_binding: {provider: account-a}
    

    proposed

    enforcement: enforce
    credential_binding: {provider: account-a, mode: account-bound}

  • Lower that to the existing NETWORK_ENFORCEMENT_MODE_ENFORCE_CREDENTIAL_BOUND wire value, so nothing changes on the wire or for version skew.

  • We'd like this before merge because the authored form becomes public API once it ships, and it is a parser and docs change only. It also leaves a clean mapping to Cedar, where the selected account belongs in request context.

Fine as is, or follow-up

  • Keep NETWORK_ENFORCEMENT_MODE_ENFORCE_CREDENTIAL_BOUND as the wire value. Older runtimes reject an unknown enum value, where they would silently ignore a new field on the NetworkCredentialBinding message. Item 6 changes only the authored YAML, and that fails closed too: the YAML NetworkCredentialBinding already has deny_unknown_fields on main, so an older parser rejects mode instead of dropping it.
  • Keep explicit denies global. The Rego says this is deliberate. Please document that a deny_rules entry on one account's endpoint blocks every account on that URL. Per-account denies can be a later feature.
  • firewall_rule attribution. The name is the alphabetically first matching policy (sandbox-policy.rego#L85), so events can name the wrong account. Item 4 makes the selected account available to fix this; a follow-up is fine.
  • The Mutex in CredentialSelection is per-request and goes away with item 4. No separate action.
  • Version skew. Please add a test for an older Supervisor that sees a single remaining account after the other is withdrawn.

Worth stating in the docs

Both accounts' placeholders live in the same sandbox, so the agent can pick either. This feature prevents one account's token being sent on a request only the other may make. It does not confine an agent to one account.

This branch has not been deployed

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

Labels

state:accepted A maintainer decided OpenShell should pursue this issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(policy): support independently authorized accounts on one endpoint

2 participants