Skip to content

feat(cli): add --linux-network-host-mode for program start - #1733

Open
crazywriter1 wants to merge 7 commits into
theinterfold:mainfrom
crazywriter1:feat/linux-network-host-mode
Open

feat(cli): add --linux-network-host-mode for program start#1733
crazywriter1 wants to merge 7 commits into
theinterfold:mainfrom
crazywriter1:feat/linux-network-host-mode

Conversation

@crazywriter1

@crazywriter1 crazywriter1 commented Jul 19, 2026

Copy link
Copy Markdown

Summary

  • Add --linux-network-host-mode to interfold program start for Linux Docker host networking
  • Skip localhosthost.local rewrite when the flag is set (INTERFOLD_SKIP_LOCALHOST_REWRITE)
  • Document the flag in crates/support/README.md

Closes #548

Test plan

  • CARGO_BUILD_JOBS=1 cargo build -p e3-cli
  • ./target/debug/interfold program start --help | grep -A2 linux-network-host-mode
  • ctl/start / ctl/container dry-runs with stub docker

Summary by CodeRabbit

  • New Features

    • Added optional Linux host-networking mode when starting the program server.
    • Preserves callback URLs correctly when host networking is enabled.
    • Development mode warns that host networking has no effect.
    • The option is rejected on non-Linux systems, while standard networking remains unchanged.
  • Bug Fixes

    • Improved callback validation and blocked invalid or unsafe destinations.
    • Added reliable handling for loopback and host-networking callbacks.
  • Documentation

    • Added Linux-specific setup instructions, platform limitations, and callback behavior.

@vercel

vercel Bot commented Jul 19, 2026

Copy link
Copy Markdown

@crazywriter1 is attempting to deploy a commit to the Gnosis Guild Team on Vercel.

A member of the Team first needs to authorize it.

@crazywriter1
crazywriter1 force-pushed the feat/linux-network-host-mode branch 2 times, most recently from 5925bde to b6b1d95 Compare July 28, 2026 12:47

@Toby1009 Toby1009 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.

LGTM
Please update this branch with the latest main before merging.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The start command now supports --linux-network-host-mode. The flag propagates through Rust support APIs and shell scripts. Docker selects host networking on Linux, and callback validation preserves loopback URLs in this mode.

Changes

Linux network host mode

Layer / File(s) Summary
CLI and support API propagation
crates/cli/src/program.rs, crates/support-scripts/src/*.rs, crates/support-scripts/Cargo.toml
The start command accepts the flag and forwards it through the support API. Dev mode warns that the flag has no effect. RISC Zero passes it to the start script.
Container network configuration
crates/support-scripts/ctl/start, crates/support-scripts/ctl/container
The scripts parse the flag, reject non-Linux use, compare existing container modes, and select host or bridge networking settings.
Callback behavior and documentation
crates/support/app/src/main.rs, crates/support/README.md
The application validates callback URLs, disables webhook redirects, and conditionally preserves loopback URLs. The README documents Linux host networking and its platform limitations.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: ctrlc03, hmzakhalid

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant ProgramSupport
  participant StartScript
  participant Docker
  participant CallbackHandler
  CLI->>ProgramSupport: Start with linux_network_host_mode
  ProgramSupport->>StartScript: Forward --linux-network-host-mode
  StartScript->>Docker: Configure host or bridge networking
  Docker->>CallbackHandler: Send callback URL
  CallbackHandler->>CallbackHandler: Validate and preserve loopback URL
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the new --linux-network-host-mode flag for program start.
Linked Issues check ✅ Passed The changes implement the requested flag and Docker host networking behavior for enclave program start [#548].
Out of Scope Changes check ✅ Passed The changes support the host-networking objective, including container recreation and callback validation required by that mode.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/support-scripts/ctl/container`:
- Around line 55-80: Update the existing-container branch around the docker ps
check to verify that the container’s network mode and
INTERFOLD_SKIP_LOCALHOST_REWRITE setting match the requested
LINUX_NETWORK_HOST_MODE. When they differ, remove/recreate the container so
docker run applies the requested DOCKER_NET_ARGS and DOCKER_ENV_ARGS; otherwise
preserve the current docker exec behavior, or reject the command with a clear
removal instruction.

In `@crates/support/app/src/main.rs`:
- Around line 150-161: Validate callback_url before dispatching the background
task, including the skip-rewrite branch: allow only approved schemes and hosts,
and reject private or loopback destinations. Apply this validation in the
/run_compute request flow before the reqwest::Client::post spawn, while
preserving the existing localhost rewrite behavior when
INTERFOLD_SKIP_LOCALHOST_REWRITE is disabled.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7ba92779-3915-4e08-a24e-3d9dd632b24e

📥 Commits

Reviewing files that changed from the base of the PR and between ca2ff5c and 5c21497.

📒 Files selected for processing (10)
  • crates/cli/src/program.rs
  • crates/support-scripts/ctl/container
  • crates/support-scripts/ctl/start
  • crates/support-scripts/src/lib.rs
  • crates/support-scripts/src/program.rs
  • crates/support-scripts/src/program_dev.rs
  • crates/support-scripts/src/program_risc0.rs
  • crates/support-scripts/src/traits.rs
  • crates/support/README.md
  • crates/support/app/src/main.rs

Comment thread crates/support-scripts/ctl/container Outdated
Comment thread crates/support/app/src/main.rs Outdated
@crazywriter1

Copy link
Copy Markdown
Author

I've updated the branch with the latest main. Please let me know if you'd like me to address the remaining CodeRabbit suggestions as well. @Toby1009

@Toby1009

Toby1009 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

I've updated the branch with the latest main. Please let me know if you'd like me to address the remaining CodeRabbit suggestions as well. @Toby1009

I’d lean toward fixing these, but maybe we should also ask @ctrlc03 to take a look.

@ctrlc03 ctrlc03 changed the title Add --linux-network-host-mode for program start feat(cli): add --linux-network-host-mode for program start Aug 4, 2026
Comment thread crates/support-scripts/src/program_dev.rs Outdated
Comment thread crates/support-scripts/ctl/container Outdated
Lets Docker use --network=host so callbacks work without host.local rewrite or firewall tweaks for the bridge network.
Closes theinterfold#548
Use tracing::warn! for the dev-mode notice and reject --linux-network-host-mode on non-Linux hosts.
@crazywriter1
crazywriter1 force-pushed the feat/linux-network-host-mode branch from 0dc586b to 68e713c Compare August 5, 2026 08:49
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@crazywriter1

Copy link
Copy Markdown
Author

@ctrlc03 Thanks for the review sir. Addressed your two suggestions in the latest push (tracing::warn! + non-Linux guard).

CodeRabbit also suggested container mode mismatch handling and callback URL validation. Should I address those in this PR as well?

@crazywriter1
crazywriter1 requested a review from ctrlc03 August 5, 2026 08:57
@ctrlc03

ctrlc03 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

@ctrlc03 Thanks for the review sir. Addressed your two suggestions in the latest push (tracing::warn! + non-Linux guard).

CodeRabbit also suggested container mode mismatch handling and callback URL validation. Should I address those in this PR as well?

yes please can you address coderabbit comments too?

Recreate the support container when the requested network mode changes, and validate callback URLs before dispatching webhooks.
@crazywriter1

Copy link
Copy Markdown
Author

Addressed the remaining CodeRabbit feedback:

  • recreate the support container when network mode changes
  • validate callback URLs before webhook dispatch @ctrlc03

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/support/app/src/main.rs`:
- Around line 107-139: Update the webhook HTTP client construction around
reqwest::Client::new so redirect destinations cannot bypass
validated_callback_url’s host policy. Prefer disabling automatic redirects for
webhook delivery, or configure redirect handling to apply the same
loopback/private/reserved destination validation to every target while
preserving permitted callback behavior.
- Around line 91-105: Update host_is_private_or_reserved and the callback
validation/dispatch flow to resolve hostname targets before sending requests,
reject any resolved loopback, private, link-local, multicast, unspecified, or
reserved address, and prevent DNS rebinding by pinning the validated destination
address for dispatch; alternatively enforce that callback hosts match configured
origins. Preserve existing rejection behavior for invalid hosts and direct IP
targets.
- Around line 100-105: Update the IP validation expression around the visible
`ip` checks to replace unavailable `IpAddr::is_private()` and
`IpAddr::is_link_local()` calls with a parenthesized match over `IpAddr::V4` and
`IpAddr::V6`, invoking the corresponding address-family-specific methods while
preserving the existing multicast, unspecified, and special IPv4 checks.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 78295c27-20b8-49be-a62c-c29086403ef7

📥 Commits

Reviewing files that changed from the base of the PR and between 68e713c and b5c3835.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • crates/support-scripts/ctl/container
  • crates/support/app/src/main.rs

Comment thread crates/support/app/src/main.rs Outdated
Comment thread crates/support/app/src/main.rs Outdated
Comment thread crates/support/app/src/main.rs Outdated
Match e3-program-server by using reqwest redirect Policy::none() so callback validation cannot be bypassed via redirects.
@crazywriter1

Copy link
Copy Markdown
Author

Applied redirect Policy::none() to match e3-program-server. The DNS resolution/pinning suggestions go beyond what program server does today. Happy to discuss separately if you want stricter SSRF policy across both servers.

@ctrlc03

ctrlc03 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Applied redirect Policy::none() to match e3-program-server. The DNS resolution/pinning suggestions go beyond what program server does today. Happy to discuss separately if you want stricter SSRF policy across both servers.

please make sure you fix all coderabbit issues. thanks

Resolve and pin webhook destinations, reject unsafe addresses, disable redirects, and add callback validation tests to address CodeRabbit SSRF findings.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/support/app/src/main.rs`:
- Around line 421-431: Update host_mode_pins_localhost to use an IP-literal URL
instead of localhost, avoiding DNS resolver dependence while still exercising
loopback pinning. Replace the invalid callback.url.host().unwrap().is_loopback()
assertion by matching url::Host::Ipv4 and Host::Ipv6 and checking is_loopback()
on the contained address, then separately verify the expected host_header
behavior with a localhost input.
- Around line 154-162: Update the callback request flow around pin_callback_url
to preserve the original hostname in the URL instead of replacing it with the
resolved IP. Configure the reqwest ClientBuilder resolve mapping to pin the
hostname to the resolved address, and remove the host_header override while
retaining correct IPv4/IPv6 handling.
- Around line 114-131: Canonicalize IPv4-mapped IPv6 addresses before
destination classification: update ip_is_private_or_reserved and
ip_is_safe_public_destination to convert Ipv6Addr::to_ipv4_mapped() results into
IpAddr::V4 and reuse the existing IPv4 checks, while preserving normal IPv6
handling. Add regression tests covering mapped loopback and private addresses,
including ::ffff:127.0.0.1 and ::ffff:10.0.0.1.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5633d630-01c0-4641-900c-894e74cc9a88

📥 Commits

Reviewing files that changed from the base of the PR and between 88929be and a196f81.

📒 Files selected for processing (1)
  • crates/support/app/src/main.rs

Comment thread crates/support/app/src/main.rs Outdated
Comment thread crates/support/app/src/main.rs Outdated
Comment thread crates/support/app/src/main.rs
Pin resolved IPs, reject redirects, and block private/loopback
addresses in host-network mode to address CodeRabbit SSRF findings.
@crazywriter1

Copy link
Copy Markdown
Author

@ctrlc03 All CodeRabbit comments addressed in 0410a5d. Container recreation, callback validation, redirect blocking, DNS pinning, IPv4-mapped IPv6 handling, and test fixes. Ready for review.

@Toby1009

Toby1009 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Maybe I think the callback security changes have grown beyond what #548 needed, and
it may be better to split them out.

#548 asked for an optional Linux host-networking flag. The PR now adds 412 lines,
including 280 additions to e3-support-app, most of which implement callback
validation, DNS resolution, pinning, and related tests.

Three concerns:

  1. agent/CRATES_ARCHITECTURE.md:596 documents the equivalent e3-program-server
    endpoint as accepting caller-supplied HTTP(S) callback origins, and
    crates/program-server/src/lib.rs:182 implements exactly that. This PR
    introduces a substantially different policy in e3-support-app, without
    documenting why the two servers should have different callback trust
    boundaries.

  2. The new policy does not address the main callback risk introduced by host
    networking. Host mode makes host loopback-only services reachable. The
    host-mode branch accepts any loopback callback URL, including arbitrary ports
    and paths, so it does not distinguish the intended callback service from other
    host-local services. Meanwhile, the default bridge path now rejects RFC1918
    destinations (LAN, VPN, Compose service names), although this PR does not
    change that path's network reachability.

  3. The IP policy is difficult to maintain as a denylist. I re-ran CodeRabbit
    against the current head and it asks for five more CIDR ranges, so after four
    rounds it still classifies several non-global special-use ranges as safe.
    Also, crates/support is a separate workspace excluded from the root workspace
    (Cargo.toml:54), and its new callback tests are not currently run by CI.

I suggest keeping the flag, plumbing, non-Linux guard, container recreation, and
the contained Policy::none() change in this PR. DNS resolution, private-address
filtering, and pinning could move to a separate security issue that covers both
servers and starts by defining caller authentication and configu
origins.

Two bugs worth fixing either way:

  • the existing-container path always executes exit 0 after do failures inside the container are reported as success (the script has no set -e`)
  • the mode-switch path falls through from docker stop to docker run --name;
    --rm removal is async, so switching modes can hit a name con

Happy to be corrected if I have misunderstood the intended trust

@crazywriter1

Copy link
Copy Markdown
Author

@Toby1009 Thanks for the detailed review. The callback security work grew because @ctrlc03 asked me to address the remaining CodeRabbit comments; I wasn't aiming to expand #548 beyond the flag.

I agree it's gotten large and the policy inconsistency with e3-program-server is worth discussing separately. Happy to split the security changes out and keep this PR to flag + plumbing + container recreation + Policy::none(), and fix the two container script bugs either way. Leaving the call to you and @ctrlc03. Just say which direction and I'll update the branch.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add flag: enclave program start --linux-network-host-mode

3 participants