feat(up): add --auto-forward dynamic user-space port forwarding#188
Open
pofallon wants to merge 2 commits into
Open
feat(up): add --auto-forward dynamic user-space port forwarding#188pofallon wants to merge 2 commits into
pofallon wants to merge 2 commits into
Conversation
Adds a `deacon up --auto-forward` flag (deacon consumer extension, modeled on
VS Code Dev Containers) that starts a detached, host-side forwarder for the
container. The forwarder polls the container's TCP LISTEN sockets
(/proc/net/tcp{,6} via `docker exec`, ~1s) and relays each detected or declared
port to a 127.0.0.1:<host-port> listener over `docker exec -i`, reaching even
127.0.0.1-bound servers that static `-p` cannot.
- New core module `crates/core/src/port_forward/` (detect, registry, relay,
daemon): pure /proc/net/tcp parser; host-global forwarded_ports.json registry
with fs2 advisory lock + atomic writes and collision-free allocation
(same-number preference, privileged->>=1024 remap, stale-pid pruning);
per-connection relay with socat/nc/dev-tcp fallback (fail-fast); supervisor
loop with eager declared + lazy auto-detected forwarding, withdrawal,
onAutoForward honoring, compose service:port dialing, PORT_EVENT emission,
pid marker, SIGTERM/self-exit cleanup. Detach/signaling via safe nix wrappers
(setsid/dup2/kill); production stays unsafe-free; Unix-only in v1.
- CLI: `--auto-forward` on `up`, hidden `__forward-daemon` re-exec entrypoint,
spawn/adopt-or-reuse + static `-p` suppression in the up container & compose
paths, reap hooks in `down` and `up --remove-existing-container`.
- Tests: hermetic unit tests (parser, registry, attributes, marker) + Docker
integration suite (loopback reach, dynamic detect/withdraw, multi-container
collision-free, down/replace reaping, ignore/silent/notify, compose
service:port). integration_auto_forward is docker-exclusive (binds real host
ports).
- Docs/examples: up SPEC.md section, SECURITY.md surface, README section, and
the self-verifying examples/up/auto-forward/ canary.
Best-effort: forwarding failures warn loudly but never fail `up`. Loopback-only,
TCP-only, Unix-only in v1; remaining scope tracked as deferrals (T054-T060).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jun 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
deacon up --auto-forward— a deacon consumer extension (modeled on VS Code Dev Containers) that starts a detached, host-side forwarder for the container, polls its TCP LISTEN sockets (/proc/net/tcp{,6}viadocker exec, ~1s), and relays each detected or declared port to a127.0.0.1:<host-port>listener overdocker exec -i. Becausedocker execshares the container netns, this reaches127.0.0.1-bound servers that static-ppublishing cannot.upreturns to the shell immediately.Implements feature spec
specs/015-auto-forward-ports/(US1–US5); all active tasks T001–T053 done, T054–T060 tracked as intentional deferrals.Highlights
crates/core/src/port_forward/(detect,registry,relay,daemon):/proc/net/tcp{,6}LISTEN parser (little-endian v4/v6 decode + dedup).forwarded_ports.jsonregistry:fs2advisory lock + atomic temp-file/rename writes; collision-free allocation (same-number preference, privileged→≥1024 remap), stale-pid pruning, release.socat/nc/bash-/dev/tcpfallback and fail-fast when none.portsAttributes.onAutoForwardhonoring (ignore/silent/notify), compose"service:port"dialing,PORT_EVENT:emission, pid marker,SIGTERM/self-exit cleanup. Detach/signaling via safenixwrappers (setsid/dup2/kill) — production staysunsafe-free.--auto-forwardflag, hidden__forward-daemonre-exec entrypoint, spawn/adopt-or-reuse + static-psuppression in theupcontainer & compose paths, reap hooks indownandup --remove-existing-container.up/SPEC.md§2.1,SECURITY.mdsurface,README.mdsection, and the self-verifyingexamples/up/auto-forward/canary (registered in the aggregator).Behavior contract
127.0.0.1, never0.0.0.0/LAN), TCP-only, Unix-only in v1 (non-Unix warns,upunaffected).forwardPorts/appPort/--forward-port) forward eagerly and are suppressed from static-p; undeclared ports forward lazily and are withdrawn when they stop.up(exit 0).upresult JSON on stdout is unchanged.Tests
integration_auto_forward, docker-exclusive — it binds real host ports): loopback reach, dynamic detect/withdraw viaexec, multi-container collision-free + release,down/replace reaping,ignore/silent/notify, compose"service:port".cargo fmt --all -- --check,cargo clippy --all-targets --all-features -- -D warnings,make test-nextest(2784 passed, 0 failed).Notes
integration_auto_forwardis classifieddocker-exclusivein.config/nextest.toml(per spec task T033) because it binds real host ports and must not race other port-publishing docker tests.exec --workspace-foldercan't resolveup's container due to aconfigHashmismatch between the two paths — filed as exec/run-user-commands can't resolve up's container: configHash mismatch between up and exec #187 (the US2 test works around it viaexec --container-id).🤖 Generated with Claude Code