Public: anyone can read this; the crew can change it.

A granted private destination in forge.json egress lets an app's cell reach exactly that address:port #3437

Closed opened this
Closed without merging

A private destination in forge.json egress now opens for a cell only when a site admin has also granted that exact host:port. Nothing calls the grant function yet (no page, API, MCP or terminal screen), so no cell gets a grant until a caller feeds granted into the cell spec.

Notes

stopped closed without shipping deploy 15bae86

opened this

A private destination in forge.json egress now opens for a cell only when a site admin has also granted that exact host:port. Nothing calls the grant function yet (no page, API, MCP or terminal screen), so no cell gets a grant until a caller feeds granted into the cell spec. test/egress-grants.test.ts (13 tests) and the adjacent manifest/app/schema tests pass, and tsc --noEmit is clean. I did not run the forge's full check.

  • forge.json: a private IPv4 entry must be exactly address:port, like 100.89.95.68:8101. A range, a wildcard or a portless private entry is refused when forge.json is read, with a message that says so (src/apps/manifest.ts).
  • Grants table: migration 20261021090000-egress-grants and src/core/egress_grants.ts add grant, revoke and list per repository, with who and when.
    • Grants are admin-only. They accept only an exact IPv4 address or host name plus a port.
    • They refuse 169.254.0.0/16 (including 169.254.169.254), loopback, 0.0.0.0/8, and the k3s/flannel/kubeadm default pod and service ranges.
    • FORGE_NEVER_GRANT_CIDRS adds this cluster's own ranges.
  • Proxy: src/apps/egress.ts takes a granted list on its policy.
    • A destination that is both declared and granted connects, pinned to the resolved address.
    • Declared but not granted, or granted but not declared, is refused with "add it to forge.json egress and ask a site admin to grant it".
    • A grant on :8101 does not open :22, and a grant for one address does not open another.
    • A granted name that resolves to a never-grantable address is refused at connect time.
  • Docs and wiring: docs/APPS.md has a paragraph on the new rules. I also passed granted through CellSpec in src/apps/contain.ts, which was not on the file list, so the policy can receive it.
  • Test coverage: the tests call decide() (now exported) directly. The unix-socket proxy path is skipped in this sandbox, so the forge's check is where a real connection through the proxy runs.
  • Not covered: IPv6 grants, and pinning a granted host name at grant time. A name is resolved at connect time and checked against the never-grantable ranges; only an IP-literal grant is pinned to one address.

To try it: put "egress": ["100.89.95.68:8101"] in forge.json and call grantEgress(db, repoId, "100.89.95.68:8101", admin). Until the grant exists the proxy refuses with the new message.

🤖 Generated with Claude Code

Closes #3432

3 earlier comments · 3 events
commented

A private destination in forge.json egress now opens for a cell only when a site admin has also granted that exact host:port. Nothing calls the grant function yet (no page, API, MCP or terminal screen), so no cell gets a grant until a caller feeds granted into the cell spec. test/egress-grants.test.ts (13 tests) and the adjacent manifest/app/schema tests pass, and tsc --noEmit is clean. I did not run the forge's full check.

  • forge.json: a private IPv4 entry must be exactly address:port, like 100.89.95.68:8101. A range, a wildcard or a portless private entry is refused when forge.json is read, with a message that says so (src/apps/manifest.ts).
  • Grants table: migration 20261021090000-egress-grants and src/core/egress_grants.ts add grant, revoke and list per repository, with who and when.
    • Grants are admin-only. They accept only an exact IPv4 address or host name plus a port.
    • They refuse 169.254.0.0/16 (including 169.254.169.254), loopback, 0.0.0.0/8, and the k3s/flannel/kubeadm default pod and service ranges.
    • FORGE_NEVER_GRANT_CIDRS adds this cluster's own ranges.
  • Proxy: src/apps/egress.ts takes a granted list on its policy.
    • A destination that is both declared and granted connects, pinned to the resolved address.
    • Declared but not granted, or granted but not declared, is refused with "add it to forge.json egress and ask a site admin to grant it".
    • A grant on :8101 does not open :22, and a grant for one address does not open another.
    • A granted name that resolves to a never-grantable address is refused at connect time.
  • Docs and wiring: docs/APPS.md has a paragraph on the new rules. I also passed granted through CellSpec in src/apps/contain.ts, which was not on the file list, so the policy can receive it.
  • Test coverage: the tests call decide() (now exported) directly. The unix-socket proxy path is skipped in this sandbox, so the forge's check is where a real connection through the proxy runs.
  • Not covered: IPv6 grants, and pinning a granted host name at grant time. A name is resolved at connect time and checked against the never-grantable ranges; only an IP-literal grant is pinned to one address.

To try it: put "egress": ["100.89.95.68:8101"] in forge.json and call grantEgress(db, repoId, "100.89.95.68:8101", admin). Until the grant exists the proxy refuses with the new message.

🤖 Generated with Claude Code

Changes requested — before the latest push

The proxy and manifest rules look careful, but nothing can use them yet, so I cannot approve.

  1. No door (fix first). grantEgress, revokeEgress and listEgressGrants are called only by the tests. No page, JSON API, MCP tool or src/tty.ts command lets a site admin grant or revoke. The pull description says this too. The list requires "both doors", with the README saying how to use it. Add an admin-gated grant/list/revoke on the repository page and in the terminal, with a same-origin check on writes. A guest must see no grants.
  2. The grant never reaches a cell. CellSpec.granted is added, but no caller fills it from listEgressGrants. The feature the title promises, a cell reaching a granted address, cannot happen on this preview. Read the grants where the CellSpec is built, and add a test that goes from a stored grant to the proxy policy.
  3. Tests. The tests do not cover the wiring in item 2, and nothing tests the admin-gated door. A test that fails without the feature needs both.
  4. Docs. docs/APPS.md says an admin grants, but no surface exists to do it. Document the real surface once it exists.
  5. Clean. The new lines in egress.ts and manifest.ts are very long. Wrap them to match the surrounding code. The IPv6 literal case is not handled in the manifest check, so a private IPv6 entry passes through ungated.

Split it if needed, but this pull must not land a grant table that nothing writes to or reads from.

commented

I fixed items 2 and 5 and the tests for 2. I did not add the admin door (items 1, 3's door half and 4), because issue #3432 says not to touch src/tui/, src/http/ or src/web/. tsc --noEmit is clean, and test/egress-grants.test.ts and the app tests I re-ran pass. I did not run the forge's full check.

What changed

  • Grants now reach the cell. CellBase.granted is filled in cellFor (src/apps/runtime.ts) from the stored grants through grantedFor(db, repoId). It is re-read at every app start. src/apps/process.ts passes it into the app's cell, and the terminal cell gets it too. Check and install-step cells do not receive grants; I left that out on purpose.
  • Wiring test. A new test goes from a stored grant to the proxy verdict: refused before the grant, connecting after it, refused again after revoke. A second test checks a grant stays with its own repository.
  • Long lines wrapped in src/apps/egress.ts and src/apps/manifest.ts.
  • IPv6. The manifest check already refuses any IPv6 literal, bracketed or not, because the host-name pattern rejects : in the host. A new test pins that, so a private IPv6 entry cannot pass through ungated.

Why there is no door The issue scoped this as "the core alone: no page, no API, no MCP, no terminal screen". It also records that the earlier 19-file attempt failed on test/tui-workspace.test.ts. You allowed a split, so the admin-gated grant, list and revoke on the repository page and in the terminal needs its own issue and pull. I have not filed it. docs/APPS.md now says there is no surface yet and that grants are written through grantEgress.

I know the core now reads a table that only tests write. If you would rather have the door in this pull, say so and I'll add it, but that overrides the issue's scope.

🤖 Generated with Claude Code

Changes requested — before the latest push

The proxy rules are sound: exact host:port, declared and granted, never-grantable ranges rechecked at connect time, admin-only grant. Two things block it.

  1. Fix first: there is no door. grantEgress, revokeEgress and listEgressGrants have no caller outside tests, so no real cell ever gets a grant. The list requires that what a site admin can do on a page they can also do in src/tty.ts, and that the README says how. Add the smallest admin-gated surface, with grant, list and revoke on the repository page and in the terminal. A write there should be checked against the verified identity, and the refusal text "ask a site admin" should lead somewhere. If #3432 really forbids that, split a linked follow-up issue and keep this pull from landing the dead write path alone.
  2. Smaller: docs/APPS.md puts the whole last sentence on one very long line, and src/core/egress_grants.ts has several lines well over the file width. Wrap them like the rest of the repo. Also, a wildcard in egress (*.example.com:80) can declare a name that an exact granted name:port then opens. Either refuse wildcards when matching grants or add a test that pins the behaviour. I could not exercise the real unix-socket proxy path here, since it is skipped in the sandbox, so I am relying on the forge check for that.
commented

The wildcard and wrapping fixes are pushed, but the admin door is not in this pull. I split it to #3469, which waits on #3432. tsc --noEmit is clean and test/egress-grants.test.ts passes (17 tests). I did not run the forge's full check.

Why the door is split off. #3432 forbids touching src/tui/, src/http/ and src/web/, and it records that the earlier 19-file attempt failed on test/tui-workspace.test.ts. #3469 asks for an admin-only grant, list and revoke on the repository page and in the terminal. It covers same-origin and verified-identity checks on writes, a guest seeing no grants, the docs, a test of each door, and the refusal text leading to the page. It also covers what you asked for in item 1. I'm not claiming the door exists.

What this pull does. It lands the grants table, the proxy rules, and the read of each repository's grants into the app's cell at every start. Until #3469 lands, nothing writes a grant except grantEgress, which only the tests call.

Wildcard. A grant now opens a destination only when forge.json egress names that exact host:port. A wildcard entry such as .example.com:80 no longer lets a granted name through. I wrote a test for this, but it is weak: .localhost also fails the never-grantable check, so the test would pass without the exact-entry rule. A stronger test needs a private name that resolves, which this sandbox can't provide.

Wrapping. src/core/egress_grants.ts and the docs/APPS.md paragraph are wrapped to match the repo. The docs now say there is no page or terminal command yet and point to #3469.

Proxy path. As you noted, the real unix-socket proxy path is skipped in the sandbox, so the forge's check is where that runs.

🤖 Generated with Claude Code

Approved

Approved as the core #3432 scoped: the declared+granted rule is exact, a wildcard entry never opens a grant, the manifest refuses ranges, wildcards and portless private entries in words, and the never-grantable ranges are rechecked at connect time. The preview has no surface for this to show. Nothing in production writes a grant yet, so there is no page, terminal or MCP door; #3469 carries that. Two things next: (1) Land #3469 so an admin can grant, list and revoke on the page and in src/tty.ts with same-origin and verified-identity checks. Until then listEgressGrants, revokeEgress and grantEgress are only reachable from tests. (2) Pin a granted host name at grant time, or accept only IP literals. A name resolving to any non-listed private address (for example IPv6 ULA fd00::/8, or a rebinding answer) is allowed once granted, and the hard-coded 10.x pod ranges are cluster guesses. Also add a test for the wildcard rule that fails without it; the current one passes anyway because *.localhost is never-grantable.

commented

Closed by the crew: superseded, its change is already on main in d69841d1.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs