Extensions can reach any network host regardless of accepted egress #241

Closed
opened 2026-10-27 13:35:31 +00:00 by sam · 1 comment
Owner

Problem

An extension's package declares egressHosts and the operator accepts them at install, but the running extension has unrestricted network access. Declared environment is enforced; declared egress is not.

Done when

[ ] A running extension can reach only the egress hosts the operator accepted for it.
[ ] A connection to any other host fails, whatever the extension's code does.
[ ] Enforcement does not depend on the package update flow.

Design

Design: extension egress confinement via network namespaces

Decision

Kernel network isolation for every extension process, without Docker. Proxy
environment variables alone cannot satisfy "fails whatever the code does" (a
plugin can dial raw TCP past HTTPS_PROXY); Landlock filters by port, not host,
and seccomp cannot see hostnames, so kernel netns is the cheapest option that
meets the done-when criteria. This is a deliberate mechanism addition (re-exec
wrapper + in-netns relay), re-litigating the choice should start from those
rejected alternatives.

The existing egress stack is reused, not extended into new protocols:
egress.Proxy sessions with plain CONNECT host filtering (allow list from the
accepted authority) is sufficient for extensions, because they already receive
their real credentials through their environment. Unlike Kits, no MITM CA and
no SSL_CERT_FILE injection; extensions never trust an archie CA.

Mechanism

  1. Every extension launched by extension.Host.Start runs in a fresh user +
    network namespace (cmd.SysProcAttr.Cloneflags = CLONE_NEWUSER|CLONE_NEWNET
    with uid/gid mappings). No exception for extensions that declare no egress:
    an extension with no accepted egress hosts simply gets no relay, so its
    netns contains only loopback and it cannot reach anything.
  2. A re-exec wrapper subcommand of the existing binary (__extension-egress)
    is the plugin's parent inside the netns. It brings loopback up using
    CAP_NET_ADMIN in its own user namespace, starts an in-netns relay on
    127.0.0.1:3128, and drops capabilities before exec'ing the plugin, so the
    plugin never holds CAP_NET_ADMIN or any other capability.
  3. The relay forwards over a Unix socket fd passed at exec (AF_UNIX crosses
    netns; filesystem-scoped) to the host side, which is the egress.Proxy
    session registered with NetworkRules{Allow: AcceptedAuthority.EgressHosts}
    — reuse sessions and policy matching unchanged.
  4. HTTP(S)_PROXY/ALL_PROXY point at 127.0.0.1:3128. Non-HTTP protocols are
    CONNECT-only to accepted host:port. No DNS inside the netns: proxy clients
    hand hostnames to the proxy.
  5. AcceptedAuthority nil means no egress at all (no relay), matching the
    acceptance-record fail-closed semantics.

Platform gate

Fail-closed means fail-closed: refuse to start ANY extension where network
isolation is not available (non-Linux, unprivileged user namespaces disabled),
not only extensions that declare egress. No unconfined fallback.

Wiring

  • Spec gains an Egress field (session token / unix-socket path) in
    internal/infrastructure/extension.
  • Both launch sites pass it from AcceptedAuthority:
    internal/infrastructure/secretengine/runner.go and
    internal/app/archied/forge_extensions.go.
  • Sessions are registered at Start and Revoked at Stop/sync-removal next to
    host.Stop.

Work slices

  1. egress: session registration from a plain host allow list; proxy env
    variant not bound to the Kit relay alias.
  2. extension (linux build tag): Spec.Egress, wrapper Cmd with clone flags +
    ExtraFiles, relay loop, capability drop.
  3. Re-exec wrapper subcommand (internal, __-prefixed, of the existing
    binary; no new binary).
  4. Launch-site wiring + session revoke.
  5. Test: a testdata plugin dialing one allowed and one blocked host, run
    through Host.Start in a netns; blocked must fail, allowed must pass. A
    missing kernel feature FAILS the test run, never skips — a quietly skipped
    security test protects nothing, and the same kernel prerequisite makes the
    product refuse to start extensions.

Risks

  • Unprivileged user namespaces availability (kernel.unprivileged_userns_clone,
    container seccomp). Unavailability is detected and refused, never weakened.
  • go-plugin handshake is stdio-based, unaffected by the netns.

Close reason

Fixed in b512c5fb.


Imported from beads archie-core-em7s.10 · GitHub #1241 · type bug · priority P0 · created 2026-10-05 · closed 2026-10-05

## Problem An extension's package declares egressHosts and the operator accepts them at install, but the running extension has unrestricted network access. Declared environment is enforced; declared egress is not. ## Done when [ ] A running extension can reach only the egress hosts the operator accepted for it. [ ] A connection to any other host fails, whatever the extension's code does. [ ] Enforcement does not depend on the package update flow. ### Design # Design: extension egress confinement via network namespaces ## Decision Kernel network isolation for every extension process, without Docker. Proxy environment variables alone cannot satisfy "fails whatever the code does" (a plugin can dial raw TCP past HTTPS_PROXY); Landlock filters by port, not host, and seccomp cannot see hostnames, so kernel netns is the cheapest option that meets the done-when criteria. This is a deliberate mechanism addition (re-exec wrapper + in-netns relay), re-litigating the choice should start from those rejected alternatives. The existing egress stack is reused, not extended into new protocols: `egress.Proxy` sessions with plain CONNECT host filtering (allow list from the accepted authority) is sufficient for extensions, because they already receive their real credentials through their environment. Unlike Kits, no MITM CA and no SSL_CERT_FILE injection; extensions never trust an archie CA. ## Mechanism 1. Every extension launched by `extension.Host.Start` runs in a fresh user + network namespace (`cmd.SysProcAttr.Cloneflags = CLONE_NEWUSER|CLONE_NEWNET` with uid/gid mappings). No exception for extensions that declare no egress: an extension with no accepted egress hosts simply gets no relay, so its netns contains only loopback and it cannot reach anything. 2. A re-exec wrapper subcommand of the existing binary (`__extension-egress`) is the plugin's parent inside the netns. It brings loopback up using CAP_NET_ADMIN in its own user namespace, starts an in-netns relay on 127.0.0.1:3128, and drops capabilities before exec'ing the plugin, so the plugin never holds CAP_NET_ADMIN or any other capability. 3. The relay forwards over a Unix socket fd passed at exec (AF_UNIX crosses netns; filesystem-scoped) to the host side, which is the egress.Proxy session registered with NetworkRules{Allow: AcceptedAuthority.EgressHosts} — reuse sessions and policy matching unchanged. 4. HTTP(S)_PROXY/ALL_PROXY point at 127.0.0.1:3128. Non-HTTP protocols are CONNECT-only to accepted host:port. No DNS inside the netns: proxy clients hand hostnames to the proxy. 5. AcceptedAuthority nil means no egress at all (no relay), matching the acceptance-record fail-closed semantics. ## Platform gate Fail-closed means fail-closed: refuse to start ANY extension where network isolation is not available (non-Linux, unprivileged user namespaces disabled), not only extensions that declare egress. No unconfined fallback. ## Wiring - `Spec` gains an Egress field (session token / unix-socket path) in `internal/infrastructure/extension`. - Both launch sites pass it from `AcceptedAuthority`: `internal/infrastructure/secretengine/runner.go` and `internal/app/archied/forge_extensions.go`. - Sessions are registered at Start and Revoked at Stop/sync-removal next to `host.Stop`. ## Work slices 1. `egress`: session registration from a plain host allow list; proxy env variant not bound to the Kit relay alias. 2. `extension` (linux build tag): Spec.Egress, wrapper Cmd with clone flags + ExtraFiles, relay loop, capability drop. 3. Re-exec wrapper subcommand (internal, `__`-prefixed, of the existing binary; no new binary). 4. Launch-site wiring + session revoke. 5. Test: a testdata plugin dialing one allowed and one blocked host, run through Host.Start in a netns; blocked must fail, allowed must pass. A missing kernel feature FAILS the test run, never skips — a quietly skipped security test protects nothing, and the same kernel prerequisite makes the product refuse to start extensions. ## Risks - Unprivileged user namespaces availability (kernel.unprivileged_userns_clone, container seccomp). Unavailability is detected and refused, never weakened. - go-plugin handshake is stdio-based, unaffected by the netns. ### Close reason Fixed in b512c5fb. --- _Imported from beads `archie-core-em7s.10` · GitHub #1241 · type bug · priority P0 · created 2026-10-05 · closed 2026-10-05_
sam added the criticalbug labels 2026-10-27 13:35:31 +00:00
sam self-assigned this 2026-10-27 13:35:31 +00:00
sam closed this issue 2026-10-27 13:35:32 +00:00
Author
Owner

sam wrote (originally 2026-10-05):

Landed. Every extension runs in its own user and network namespace (loopback only) under a launcher re-exec'd from the host binary; its only way out is a local proxy relayed to an allow-list filter on the host that splices CONNECT without touching TLS. Accepted hosts named exactly may be on a private network; loopback is always refused. No Linux namespaces means the extension does not start. The host now verifies the binary's checksum itself and the launcher execs that verified descriptor. TestHostLaunch covers accepted host reachable, other host refused, raw dial bypassing the proxy failing, loopback refused.

_sam wrote (originally 2026-10-05):_ Landed. Every extension runs in its own user and network namespace (loopback only) under a launcher re-exec'd from the host binary; its only way out is a local proxy relayed to an allow-list filter on the host that splices CONNECT without touching TLS. Accepted hosts named exactly may be on a private network; loopback is always refused. No Linux namespaces means the extension does not start. The host now verifies the binary's checksum itself and the launcher execs that verified descriptor. TestHostLaunch covers accepted host reachable, other host refused, raw dial bypassing the proxy failing, loopback refused.
sam added a new dependency 2026-11-14 14:45:20 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Blocks
#1305 Store
sam/archie
Reference: sam/archie#241