Skip to content

(fix) Feat/4945 policy change closes everything - #5361

Open
mr-miles wants to merge 16 commits into
ai-openshell:mainfrom
mr-miles:feat/4945-policy-change-closes-everything
Open

mr-miles wants to merge 16 commits into
ai-openshell:mainfrom
mr-miles:feat/4945-policy-change-closes-everything

Conversation

@mr-miles

@mr-miles mr-miles commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Every network policy reload, provider attach/detach, and middleware registry change causes outbound network connections to be closed by the supervisor, and errors reported back to the sandbox.

This was deliberate (#2373, "invalidate relays on policy changes") and is documented, but much coarser than it needs to be. Also the behaviour is very confusing for workloads that ask for approvals while they are running, causing agents to focus on "solving" and diagnosing connectivity issues rather than their assigned work.

This PR adds the ability to re-validate open connections against a newly received policy, and close them only if the new policy would not allow them. The same behaviour applies for credential changes.

Related issue

Changes

Policy reloads

  • When the policy generation moves, a relay re-checks its connection instead of closing. It closes only if the answer changed.
  • A ConnectionPolicyContract is compared, to re-evaluate the connection against the new policy.
  • Every relay type: raw TCP, TLS passthrough, transparent TCP, CONNECT HTTP (passthrough and inspected), upgrades and forward HTTP is wired through one entry point, revalidating_generation_guard.
  • A reload that lands between authorization and relay setup is re-evaluated the same way: setup continues at the current generation if the connection's contract is unchanged, and refuses only if it changed, on a quarantine, or if the decision's generation has left the history.
  • An inspected (L7) relay clones its evaluator from the generation the pin reached, and a CONNECT route hydrated after an unrelated reload is accepted.
  • A kept-alive passthrough connection selects its middleware chain before reading each request. If an unrelated reload re-pins it while the request is read, the chain is selected again under the current policy instead of the connection closing.

Policy DNS

  • A synthetic address now stands for one name and address family for the life of the store, not for a policy generation. A client that keeps a DNS answer can keep connecting with it after reloads that don't affect it.
  • The mapping pins the trusted resolver addresses that passed at least one eligible endpoint's destination rules. Each connection is authorized by the current policy, and the deciding endpoint's rules filter the pinned addresses. A reload can never add an address to a kept answer, and one binary's looser endpoint can't widen another's.
  • Reordering a policy, adding a port, or narrowing allowed_ips no longer refuses kept answers. A name also keeps its address on a fresh lookup instead of taking a new one from the never-reused pool on every reload (proto conversion stamps a hash of the whole policy into every endpoint).
  • A kept answer used on a port the policy doesn't allow is now a policy denial, which the policy advisor sees as a proposal, not a mapping refusal.
  • The refresh-on-connect from fix(network): refresh expired policy DNS mappings on connect #5650 is kept and judged by the current policy like any other answer. The policy generation check and the per-record eligible_ports gate are removed, since mappings are no longer tied to a generation or to the ports authored when they were published. A hostname the current policy no longer allows refreshes to an observation at another address, and the connection is denied.
  • A connection looks its mapping up twice: to name the destination, and to pin addresses after authorization. The second lookup now refreshes too (PolicyDnsService::lookup_for_pin), so a TTL-0 mapping that expires during authorization is refreshed rather than refused. The bare store and its non-refreshing lookup are test-only, so no connection path can bypass the refresh.

Provider credentials

  • Each proxied connection records which credentials it injected, and at which version. Recording happens at SecretResolver and inject_or_report.
  • The credential state keeps one version per credential, and the version changes only when the credential's content does.
  • A connection closes only when a credential it sent is rotated, reconfigured, removed, or was already superseded when sent. Other providers' changes and identical reinstalls leave it open.
  • Not covered (the remaining part of bug(supervisor): routine provider token refresh bumps the policy generation and closes in-flight tunnels and streams #4945): a connection that injected the credential being rotated still closes. Keeping it open would need the connection to move to the new value.

Credential revocation (pre-existing bug)

  • Revoking static credentials now publishes a generation, so connections that sent a revoked credential close. Two paths revoke: failed or unready refreshes and wrong-revision snapshots go through revoke_provider_environment, and invalid bindings go through reject_provider_bindings.
  • It publishes only if something was actually revoked, so a refresh that keeps failing doesn't wake connections on every poll.

Endpoint status (MCP)

  • A re-pinned tunnel reports status under the policy hash of the generation it's pinned to, so status keeps flowing after unrelated reloads.

Direct transparent TCP (Linux)

  • Pinning is split out of the connection handler (pin_transparent_tcp) so it can be tested without a netfilter-redirected socket.
  • It now applies the decision's destination rules, using the trusted host gateway as policy DNS does, to the pinned addresses. Previously it dialed the matched endpoint's pins directly.

Safety boundaries

  • Only the network crate can create revalidating guards. Every guard another crate gets from the engine is a plain, cheap comparison.

Release notes

Re-validate open connections against a newly received policy, and close them only if the new policy would not allow them. Cached policy DNS answers keep working across policy changes, and an expired answer is refreshed when a connection uses it.

Testing

Structured as red/green pairs:

  • Connection revalidation: characterisation tests, fix, new-component tests, test tidy-up
  • Relay setup across a reload: failing tests, fix
  • Policy DNS: refactor with characterisation tests for the direct transparent path, failing tests, fix, guard tests, RFC update
  • Policy DNS refresh at pin time: a TTL-0 mapping that expires between the connect lookup and the pin is refreshed; an observation is refused at pin time

Rebased onto main, including #5650's refresh-on-connect; its tests are adapted to mappings that are not tied to a generation.

Manual check: open a long-lived connection (for example a WebSocket or curl to a slow endpoint) through the sandbox proxy, approve an endpoint for a different host, and confirm that the connection survives, the log shows "Policy change does not affect established connection; re-pinned", and the connection closes when its own host's rules change.

Running in my own setup, have had no occurrences of dropped connections using the updated code. Previously I had an approx 60% success rate on triggering it with approvals while the agents were at work.

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)
  • Architecture docs updated (if applicable)

@copy-pr-bot

copy-pr-bot Bot commented Nov 7, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

All contributors have signed the DCO ✍️ ✅
Posted by the DCO Assistant Lite bot.

@mr-miles

mr-miles commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor Author

I have read the DCO document and I hereby sign the DCO.

@mr-miles mr-miles changed the title Feat/4945 policy change closes everything (fix) Feat/4945 policy change closes everything Nov 7, 2026
@mr-miles

mr-miles commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

recheck

@mr-miles
mr-miles force-pushed the feat/4945-policy-change-closes-everything branch 2 times, most recently from f6cf210 to 180527a Compare November 9, 2026 10:20
mr-miles pushed a commit to mr-miles/OpenShell that referenced this pull request Nov 11, 2026
… affect them (v0.1.7 backport)

Backport of feat/4945-policy-change-closes-everything (PR ai-openshell#5361) onto
v0.1.7, squashed, for running against a v0.1.7 gateway and the
openshell-firecracker driver. Not for merging.

Differences from the branch: v0.1.7 has no credential placements, so the
resolver tracking in ProviderCredentialState wraps the v0.1.7 resolvers
directly, and one relay test uses rewrite_header_value in place of
rewrite_header_value_for_name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mr-miles
mr-miles force-pushed the feat/4945-policy-change-closes-everything branch 2 times, most recently from 88d6b76 to 4ac8e89 Compare November 15, 2026 23:05
@mr-miles
mr-miles force-pushed the feat/4945-policy-change-closes-everything branch 2 times, most recently from 6390b5b to a996acd Compare November 20, 2026 11:27
@johntmyers
johntmyers force-pushed the feat/4945-policy-change-closes-everything branch from a996acd to 3b4dee2 Compare November 20, 2026 22:27
@johntmyers

Copy link
Copy Markdown
Contributor

/ok to test 3b4dee2

@johntmyers johntmyers added the test:e2e Requires end-to-end coverage label Nov 20, 2026
@johntmyers

Copy link
Copy Markdown
Contributor

gator-agent

Blocked

GitHub reports merge conflicts with main, so code review is deferred until the branch is rebased or the conflicts are resolved.

@johntmyers, I checked the current-head runs after your test request. /ok to test no longer starts CI. I applied test:e2e because this change affects policy enforcement, network relays, and provider credentials. The existing E2E run skipped its suites; a replacement E2E run is not yet visible, so runtime coverage is still outstanding.

Action required: @mr-miles, resolve the merge conflicts and inspect the failed Linux Rust lint jobs. A maintainer must accept linked issues #4945, #5363, #5365, #5366, and #5367 with state:accepted, then rerun PR Issue Acceptance. If E2E remains absent after the conflicts are resolved, a maintainer must arrange its execution; approve any run that explicitly awaits native Actions approval.

DCO passed. Branch Checks is still running, with Rust lint failures on x86_64-linux and aarch64-linux. The annotations report exit code 101, but detailed logs were inaccessible from this sandbox, so the lint cause is not established. No workflow approvals, reruns, or dispatches were performed.

Gator metadata
  • Head SHA: 3b4dee2c8d368548ea9fb7fbc7968a5f3248bfa3
  • Base SHA: d197671b54af7c7b2165f974ff57834e0ae22884
  • Merge base SHA: d197671b54af7c7b2165f974ff57834e0ae22884
  • Patch ID: 8dbbf2f3d15836847d5b324060b68d575a2326a0
  • Gator payload: 15
  • Review mode: initial; reviewer deferred for process blockers
  • Review history: no prior Gator dispositions or threads
  • Next state: gator:blocked
  • Blocked reason: merge_conflicts
  • Additional process gate: linked issue acceptance failed
  • E2E: test:e2e applied; no current-head execution confirmed

@johntmyers johntmyers added the gator:blocked Gator is blocked by process or repository gates label Nov 20, 2026
@johntmyers
johntmyers force-pushed the feat/4945-policy-change-closes-everything branch from 3b4dee2 to 0c01687 Compare November 20, 2026 22:48
@johntmyers

Copy link
Copy Markdown
Contributor

gator-agent

Blocked

@mr-miles, your updated branch is now mergeable with main; the earlier merge-conflict blocker is resolved. DCO also passes. Code review remains deferred while the repository's process gates are outstanding.

Current-head CI runs now exist, including Branch E2E Checks, but require native GitHub Actions approval. Branch Checks, Helm Lint, and Trivy Changes also report action_required. The existing test:e2e label is appropriate for the policy, relay, and credential changes, so no duplicate test trigger is needed.

PR Issue Acceptance failed because linked issues #4945, #5363, #5365, #5366, and #5367 still have state:triage-needed rather than state:accepted.

Action required: a maintainer must review and approve the pending current-head workflow runs in GitHub, decide acceptance of the five linked issues, and rerun PR Issue Acceptance after accepting them. Workflow approval and reruns are outside this invocation's authorization.

Gator metadata
  • Head SHA: 0c01687a71a5d7d355cfe65f4cd1063cad0ee9e7
  • Base SHA: de7c2a5f3d6e5eb00f9bb56a5cf8a10becedbd69
  • Merge base SHA: de7c2a5f3d6e5eb00f9bb56a5cf8a10becedbd69
  • Patch ID: b5b28205fdbaf296550f396b3754d8be8024877d
  • Gator payload: 15
  • Review mode: initial; reviewer deferred for process blockers
  • Review history: prior-head process disposition preserved; no current-head disposition or submitted PR reviews found before this comment
  • Checks: DCO passed; PR Issue Acceptance failed; required CI awaits native approval
  • E2E: existing test:e2e; current-head run awaits approval
  • Next state: gator:blocked
  • Blocked reason: test_dispatch_required
  • Additional process gate: linked issue acceptance failed

@johntmyers

johntmyers commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

gator-agent

Blocked

The new head passes DCO and PR Issue Acceptance, resolving the earlier issue-acceptance blocker. Current-head Branch Checks, Helm Lint, Trivy Changes, and Branch E2E Checks await native GitHub Actions approval. Code review remains deferred under the process-blocker gate.

Action required: a maintainer must inspect and approve the pending current-head workflows in GitHub. The existing test:e2e label covers the policy, relay, and credential changes; another test trigger is unnecessary.

The previous head had failed Rust lint jobs; those results do not establish the outcome for this new commit. No workflow approval, rerun, or dispatch was performed.

Gator metadata
  • Head SHA: 2e90ffc0337a94455cd4d110e2e3c48c99a3ef7e
  • Base SHA: de7c2a5f3d6e5eb00f9bb56a5cf8a10becedbd69
  • Merge base SHA: de7c2a5f3d6e5eb00f9bb56a5cf8a10becedbd69
  • Patch ID: 9c8831fda394e154bb00ea888d4236e404b30443
  • Gator payload: 15
  • Review mode: initial; reviewer deferred for process blockers
  • Review history: preserved; no current-head disposition or submitted review found before this comment
  • Checks: DCO and PR Issue Acceptance passed; required workflows action_required
  • E2E: test:e2e present; current-head run awaits native approval
  • Next state: gator:blocked
  • Blocked reason: test_dispatch_required

@johntmyers johntmyers left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

gator-agent

PR Review Status

The first code review is complete. One blocking Warning remains: an authenticated connection can survive rotation of a credential it used.

@johntmyers, I checked the current-head runs following your test request: required checks and the selected E2E suite have passed. The earlier merge, issue-acceptance, DCO, and workflow-approval blockers are resolved, so the earlier process-only reports did not suppress this review.

Action required: @mr-miles, address the credential-continuity finding below and add the two regression cases.

Blocking findings:

  • GATOR-2e90ffc0-01: Preserve credential invalidation across publication and coalesced rotations.

Carried findings: None.

Gator metadata
  • Validation: Implements accepted issues #5363, #5365, #5366, and #5367; partially addresses accepted issue #4945 within the stated connection-revalidation scope.
  • Docs: Published policy management and network rules pages updated; no navigation change needed.
  • Checks: Current-head required DCO, Branch Checks, Helm Lint, and E2E passed; PR Issue Acceptance and Trivy Changes also passed. Non-required statuses do not gate progression.
  • E2E: Existing test:e2e; current-head Branch E2E Checks run 44834339546 completed successfully. No additional trigger needed; no Windows-specific change identified.
  • Head SHA: 2e90ffc0337a94455cd4d110e2e3c48c99a3ef7e
  • Base SHA: de7c2a5f3d6e5eb00f9bb56a5cf8a10becedbd69
  • Merge base SHA: de7c2a5f3d6e5eb00f9bb56a5cf8a10becedbd69
  • Patch ID: 9c8831fda394e154bb00ea888d4236e404b30443
  • Gator payload: 16
  • Review mode: initial
  • Previous reviewed SHA: none
  • Review budget exhausted: no
  • Maintainer decision required: no
  • Next state: gator:in-review

@johntmyers johntmyers added gator:in-review Gator is reviewing or awaiting PR review feedback and removed gator:blocked Gator is blocked by process or repository gates labels Nov 21, 2026

@johntmyers johntmyers left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

gator-agent

PR Review Status

The follow-up code review found no new blocking issues. GATOR-2e90ffc0-01 is fixed: credential continuity is checked after configuration publication, and credential versions retain intervening rotations and revocations. The added regression cases cover the publication race and A→B→A transitions, including prepared installs and grant configuration changes. I checked the code and test coverage; no local tests were run.

@mr-miles, your latest commit addresses both parts of the credential finding. I also verified @johntmyers's resolution of the original thread and preserved it.

Required Branch Checks and E2E are running on this head. The existing test:e2e label is appropriate, and no additional trigger is needed. The failed advisory compatibility review is not a required gate. Gator will inspect required CI results next cycle.

Blocking findings: None.

Carried findings: None; GATOR-2e90ffc0-01 is resolved.

Gator metadata
  • Validation: Preserved project-validity review for accepted connection-revalidation issues; follow-up stays within that scope.
  • Docs: Existing published policy management and network rules updates remain applicable; no new UX contract introduced by this fix.
  • Checks: DCO, Helm Lint, PR Issue Acceptance, and Trivy Changes passed. Required Branch Checks remains pending.
  • E2E: Existing test:e2e; current-head Branch E2E Checks run 44844509966 is in progress.
  • Head SHA: 53380750ae427217ed37a94beff907b50a9ec948
  • Base SHA: de7c2a5f3d6e5eb00f9bb56a5cf8a10becedbd69
  • Merge base SHA: de7c2a5f3d6e5eb00f9bb56a5cf8a10becedbd69
  • Patch ID: 23f5cfb48dd30dae3974f39c2a8dc58e2d532c8a
  • Gator payload: 16
  • Review mode: follow_up
  • Previous reviewed SHA: 2e90ffc0337a94455cd4d110e2e3c48c99a3ef7e
  • Review budget exhausted: no
  • Maintainer decision required: no
  • Next state: gator:watch-pipeline

@johntmyers johntmyers added gator:watch-pipeline Gator is monitoring PR CI/CD status and removed gator:in-review Gator is reviewing or awaiting PR review feedback labels Nov 21, 2026
mr-miles and others added 16 commits November 20, 2026 16:57
…lose

Every policy reload advances one sandbox-wide generation, and every pinned
relay closes when it moves, so approving an endpoint for one host drops
every open proxied connection in the sandbox.

Add tests, against the existing relay and engine entry points, for how
established connections should respond to reloads. Each test's doc comment
says whether it describes behaviour the following change alters
("Changed", failing on this commit) or behaviour it must keep
("Unchanged", passing before and after).

Changed: connections stay open when a reload does not affect them:
- raw TCP, HTTP passthrough and inspected (L7) relays, when an endpoint is
  approved for another host, an endpoint is inserted before theirs, or a
  gateway-delivered policy is restamped with a new policy hash;
- relays without middleware, when middleware is added for another host or
  the middleware registry is replaced; a kept-alive passthrough connection
  that runs middleware, on its next request after an unrelated reload;
- relays that sleep through several unrelated reloads, or are checked
  between any number of them;
- HTTP relays, across provider credential changes they did not take part
  in: credentials never injected on the connection, other providers'
  rotations and attachments (including through install_prepared), identical
  reinstalls, suppression of a credential from child processes, and a
  credential first injected after its provider was attached or served
  through an aged-out placeholder, and a credential sent through its
  canonical or stable-handle placeholder, or through the previous
  revision's placeholder while unchanged, when another credential rotates;
- a kept-alive MCP tunnel keeps reporting endpoint status after an
  unrelated reload, against the new policy once its inventory is published.

Unchanged: connections still close when a reload does affect them:
revoked endpoints, narrowed L7 rules (YAML and gateway-delivered),
middleware added for their host, changed or made fail-closed, a replaced
registry for connections that run middleware, reloads that revoked or
changed them even if a later reload restored them, a long run of reloads
they slept through, rotated or detached credentials they injected
(including rotations that coalesced, and a rotation behind an unchanged
stable-handle placeholder), a superseded value sent through an older
retained revision, untracked credential handles, a reload between
authorization and relay setup, and plain generation guards.
Endpoint-status results of a kept-alive MCP tunnel are never attributed to
an inventory of a policy it is not running under: not before the reloaded
policy's inventory is published, not to an inventory published ahead of the
runtime, and not after a rules change, which closes the tunnel.
One test records that every reload restamps policy_hash on unchanged
endpoints.
Changed, in the supervisor: revoking provider credentials (an unavailable
environment, bindings that fail validation, or a snapshot for another
revision) publishes a policy generation, so open connections re-check the
credentials they sent. Today revocation publishes nothing, and a
connection authenticated once with a revoked credential, such as an
upgraded WebSocket, stays open.
Unchanged: a revocation that finds nothing left to revoke, as when a
failed refresh repeats on every poll, publishes no generation.

Existing relay tests use Arc<OpaEngine>, which the change requires.

Signed-off-by: mr-miles <miles.waller@gmail.com>
… affect them

Every policy reload, middleware registry change and provider credential
change advanced one sandbox-wide generation, and every pinned relay closed
when it moved. Approving an endpoint for one host dropped every open
proxied connection in the sandbox.

When the generation moves, a pinned guard now re-checks the connection it
protects and closes only if the answer changed.

Policy: a ConnectionPolicyContract captures what decides how a connection
is relayed: the L4 action and matched policy, the ordered matched
endpoints (policy name and endpoint object, ignoring the endpoint index and
the per-reload policy_hash stamp), the exact-host flag, and the host's
middleware chain plus the registry epoch when that chain is non-empty.
Endpoint configs, which relays also read, are not compared separately:
Rego derives them from the same endpoints, in the same order. The engine records its last 16 published generations, and a
waking connection is re-checked against every generation since its pin,
because the generation watch coalesces reloads. If every contract equals
the one that authorized it, the guard re-pins; any difference, evaluation
error, fail-closed generation, or pin that has left the history makes the
guard permanently stale and the relay closes as before. Per-request Rego
rules read only the matched endpoints, so a tunnel's cloned evaluator stays
valid after a re-pin.

Credentials: the provider credential state owns one version per credential
(static environment key or token-grant provider:credential identity),
recomputed lazily by comparing content whenever its snapshot changes. Each
proxied connection gets a tracked handle and records the version of every
credential it injects, at the two points credential material leaves the
supervisor: SecretResolver handing out a secret, and inject_or_report
adding a grant. HTTP-family relays close only when a credential they
injected changes or is removed, or when they sent a value that was
already superseded. A use counts as current when the value it handed out
is its key's current value, whichever placeholder form named it: provider
revisions are sandbox-wide, so an older revision's placeholder usually
still names the current value.
Untracked handles and unattributable uses close on the next check. Raw TCP
and TLS passthrough relays never inject credentials and carry no pin.

Endpoint status: a tunnel's endpoint config carries the hash of the policy
it was selected from, so an MCP tunnel that re-pinned would have stopped
reporting endpoint status. The revalidator now records the stamped policy
hash of the generation its guard is pinned to, from authorization through
every re-pin, and observations (and token-grant reports) use it. The
inventory check is unchanged, so results are still dropped while the
inventory describes a different policy.

Revocation: the supervisor revokes static provider credentials when a
provider refresh fails, its bindings fail validation, or it delivers the
wrong revision, but it published no generation, so connections that had
sent a revoked credential were never checked. Both revocation paths now
call OpaEngine::publish_credential_change, which publishes a generation of
the unchanged policy (keeping any quarantine), when the revocation changed
any credential, judged by comparing
ProviderCredentialState::installed_credential_versions before and after.
A failed refresh that repeats on every poll therefore wakes connections
once, not every time. Connections that sent the revoked credential close;
the rest re-pin.

A reload between authorization and relay setup still refuses the relay.
OpaEngine::revalidating_generation_guard is the single entry point for
pinning a revalidating guard, and it and with_revalidator are crate-private,
so every guard another crate obtains from the engine is plain: checking it
is a cheap comparison that never evaluates policy or takes the engine lock. The HTTP passthrough middleware path lets the
guard re-pin before comparing raw generation numbers. The policy docs now
describe which changes close a connection.

Signed-off-by: mr-miles <miles.waller@gmail.com>
Unit tests for the code the previous commit introduces, which need its new
APIs. Behaviour visible through the relays is covered by the earlier
characterisation tests.

- contracts: unrelated endpoints are ignored; endpoint, L7 rule, binary and
  overlapping-policy changes close the connection and keep it closed after
  the policy is restored; quarantine always closes; policy_hash restamping
  is not a change; denials capture no revalidator; guard clones share one
  pin; the wait ignores unrelated reloads;
- middleware: any field of the selected chain changing closes the
  connection, an identical chain does not, and only reloads that replace
  the registry close connections that run middleware;
- capture: baselines come from the recorded authorizing generation, and a
  generation that left the history cannot be captured;
- credential versions: recording of key and version per secret sent,
  including SigV4-style lookups; unused credentials; versions shared across
  connections and stable across identical reinstalls; a removed and
  restored key gets a new version; an older revision records stale only
  if its value has since changed; child-env-only installs and revocation
  retire credentials; grant versions follow their configuration;
  untracked handles and unattributable uses;
- installed credential versions: unchanged by identical reinstalls and by
  a revocation with nothing left to revoke; changed by a new value, an
  added or removed credential, and a grant configuration change;
- credential change publication: a new generation of the unchanged policy
  makes plain guards stale and lets a connection without credentials
  re-pin; a quarantine stays in force;
- pinned policy hash: the authorizing generation's from the start, then
  that of the generation the guard re-pinned to (not a newer one it has not
  checked); none for plain guards or policies without a stamp;
- endpoint configs are exactly the matched endpoints that carry extended
  configuration, in the same order, which is why the contract does not
  compare them;
- token grants record their identity; passthrough middleware runs on the
  next request after an unrelated reload.

Signed-off-by: mr-miles <miles.waller@gmail.com>
Test-only. The first commit's tests were written against the APIs that
existed before the change so that they could run, and fail, on their own.
Now that the change has landed:

- authorize test decisions through EgressDecision::policy_input, the input
  revalidation re-evaluates;
- check that injecting a credential is recorded on the connection, and
  that a connection that never injected one records nothing;
- drop the test module's own ProviderCredentialState import, which the
  module now inherits;
- drop the "Changed"/"Unchanged" labels and the descriptions of the old
  behaviour from the doc comments.

Signed-off-by: mr-miles <miles.waller@gmail.com>
Relay setup pins the policy generation of the L4 decision and refuses the
connection if any reload landed after it, even one that leaves the
connection's contract unchanged. CONNECT answers 403 "policy changed",
raw, passthrough and inspected relays do not start, and the direct
transparent path refuses the connection. The window is short, but every
policy approval lands in it for any connection being set up, and a
retry is the only remedy.

These tests state that a reload between the decision and relay setup is
re-evaluated: the pin follows it when the connection's contract is
unchanged, so the relay starts at the current generation, and an L7 route
hydrated after such a reload is the decision's own route.

The existing test that any reload between authorization and the pin
refuses the relay is replaced by these.

Guard tests that pass today: a reload that changes the connection's
rules, and a quarantine, still refuse relay setup.

Signed-off-by: mr-miles <miles.waller@gmail.com>
Relay setup pinned the generation of the L4 decision strictly, so any
reload between the decision and the pin refused the connection, even one
that left its contract unchanged: CONNECT answered 403 "policy changed",
relays did not start, and the direct transparent path refused the
connection. Every policy approval lands in that window for connections
being set up at the time.

revalidating_generation_guard now re-evaluates the connection against
every generation since the decision, as the guard of an established
connection does, and starts at the current generation if the contract
held. A changed contract, a quarantine, or a decision that cannot be
re-evaluated (a denial, or a generation no longer in the history) still
refuses the connection. An L7 evaluator is cloned from the generation
the pin reached, following any reload between pinning and cloning, and an
L7 route hydrated after the decision is accepted when the guard shows the
contract held up to the route's generation. Relay setup pins before it
validates the route, so that check sees the followed guard.

Signed-off-by: mr-miles <miles.waller@gmail.com>
Move the part of handle_transparent_tcp_connection that pins an allowed
connection, from holding the decision's policy generation to building the
connector from the policy DNS mapping, into pin_transparent_tcp. The
connection handler keeps capture, identity, the policy decision and every
audit emission, so behaviour is unchanged.

The direct path had no tests: the handler needs a netfilter-redirected
socket for the original destination and a procfs process identity. The
pinning step now runs with a supplied decision, and characterisation
tests pin down what it does today: it dials only the mapping's addresses
for the authorized endpoint, re-evaluates a reload after the decision,
and refuses a reload that changes the connection, an observation and an expired
mapping.

Signed-off-by: mr-miles <miles.waller@gmail.com>
…ot its layout

A policy DNS mapping is bound to the policy generation it was published
in, so every reload refuses every kept answer, even when the current
policy still allows the connection. Claude Code (node) keeps the answer
for api.anthropic.com and is refused with transparent_tcp_mapping_denied
when an operator approves another host. Proto conversion also stamps the
hash of the whole policy into every endpoint, so any reload gives every
name a new synthetic address from the never-reused pool.

These tests state that an answer stands for its name: the current policy
decides each connection, a denied port is a proposed policy denial, and
the deciding endpoint's destination rules select from the pinned
addresses. A kept answer survives an unrelated reload, inserting an
endpoint before it in the same policy, a port added to it, narrower
allowed_ips that still contain the resolved address, and an unrelated
reload for the trusted host gateway alias, on the staged and the direct
transparent paths. A name keeps its address on a fresh lookup through
the same changes. A reload never adds an address to a kept answer, and a
kept answer whose addresses the reloaded endpoint forbids is refused by
the destination rules, not because a reload happened.

Guard tests that pass today: a kept observation is still refused once its
name is approved, a control-plane port added to an exact host stays
refused, and the direct path refuses addresses a reloaded endpoint
forbids.

Signed-off-by: mr-miles <miles.waller@gmail.com>
… one that issued them

A policy DNS mapping recorded a contract per endpoint and port, keyed by
endpoint position, and was bound to the policy generation it was
published in, and its allocation identity hashed the endpoint objects,
including the per-reload policy_hash stamp. Any reload refused every
kept answer and gave every name a new synthetic address, even when the
current policy still allowed the connection.

A synthetic address now stands for one name and address family. Its
record pins the trusted resolver addresses that passed the destination
rules of at least one endpoint eligible for the name, and it is not tied
to a policy generation. Each connection is authorized by the current
policy as before, and the pinned addresses are filtered through that
decision's own destination rules, so an address pinned for another
endpoint of the name, another binary's or a looser one, is not reachable
through a stricter one. A reload can never add a real address to a kept
answer; the TTL still bounds how long it is used, and the name is never
resolved again at connect time.

The direct Linux transparent path now hydrates the decision's
destination plan, with the trusted host gateway policy DNS uses, and
filters the pinned addresses through it; it previously dialed the
addresses pinned for the matched endpoint without the decision's rules.
The port of a connection is decided by the policy alone, so a port added
to an endpoint is usable with a kept answer, and a port the policy does
not allow is a policy denial that the policy advisor sees as a proposal,
like any other denied connection, rather than a mapping refusal.

The allocation identity hash, the per-port endpoint contracts and the
endpoint join between mappings and decisions are removed. The mapping lookup
error the direct path reports for a reload during authorization is
renamed PolicyChanged: the store never returns it.

Signed-off-by: mr-miles <miles.waller@gmail.com>
…icy denies

A kept answer is refused by the policy decision once its host leaves the
policy or the policy is quarantined. One name allowed for two binaries
with different destination rules pins both resolved addresses, and each
connection reaches only the addresses its own endpoint permits, driven
through a real policy DNS answer. The record pins the union of what the
eligible endpoints permit, in resolver order.

Signed-off-by: mr-miles <miles.waller@gmail.com>
The egress adapter design said a mapping holds an endpoint identifier and
allowed ports and that a reload invalidates mappings whose endpoint
contract changed. A mapping now holds the addresses some eligible
endpoint permitted, each connection is decided by the current policy,
and the deciding endpoint's rules filter the pinned addresses.

Signed-off-by: mr-miles <miles.waller@gmail.com>
…ization

A transparent connection to a synthetic address looks its mapping up twice:
once to name the destination, refreshing it if it has expired, and again to
pin the addresses after the connection is authorized. The second lookup
read the store directly and never refreshed, so a mapping that was live at
the first lookup but expired while the connection was authorized was
refused with transparent_tcp_mapping_denied, on a host the policy allows.
With a trusted resolver that answers TTL 0, every mapping lives one second,
and authorization includes resolving the connecting binary's identity.

The direct, staged and dispatch paths now pin through
PolicyDnsService::lookup_for_pin, which refreshes an expired mapping the
way the first lookup does and refuses observations. The bare store
accessor and its non-refreshing lookup are test-only, so no connection
path can bypass the refresh.

Refs ai-openshell#4674

Signed-off-by: mr-miles <miles.waller@gmail.com>
The policy DNS paragraph said a placeholder stays the same only while its
endpoint policy is unchanged, and that policy changes invalidate cached
mappings. A placeholder now stands for its hostname for the life of the
sandbox and each connection is judged by the current policy; an expired
mapping is refreshed on connect, and a hostname the policy no longer allows
is denied.

Signed-off-by: mr-miles <miles.waller@gmail.com>
Signed-off-by: John Myers <9696606+johntmyers@users.noreply.github.com>
Signed-off-by: John Myers <9696606+johntmyers@users.noreply.github.com>
Signed-off-by: John Myers <9696606+johntmyers@users.noreply.github.com>
@johntmyers
johntmyers force-pushed the feat/4945-policy-change-closes-everything branch from 5338075 to 66ab128 Compare November 21, 2026 00:58

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

gator:watch-pipeline Gator is monitoring PR CI/CD status test:e2e Requires end-to-end coverage

Projects

None yet

2 participants