Skip to content

bug(network): IPv4-mapped loopback connects (::ffff:127.0.0.1) are policy-evaluated and denied, while native 127.0.0.1 and ::1 bypass policy #5546

Open

Description

@cfzlp

User Story

As a developer running coding agents in OpenShell sandboxes on a Bazel monorepo, I need in-sandbox loopback connections to work the same whether a client dials 127.0.0.1 or ::ffff:127.0.0.1, so dual-stack tools like Bazel can reach their own local servers.

Problem Statement

Inside a sandbox, a TCP connect to a loopback service succeeds when it's dialed as 127.0.0.1 (AF_INET) or ::1 (AF_INET6), but fails with EACCES when an AF_INET6 socket dials the same IPv4 listener as ::ffff:127.0.0.1. The supervisor logs this as a policy denial for 127.0.0.1:<port>, so the connection goes through policy evaluation even though its destination is loopback.

On #3735, a maintainer described the intended behaviour as: "The broker handles any loopback destination natively and only non-loopback TCP goes through the policy path." IPv4-mapped loopback doesn't follow that.

This isn't new in 0.1.8. On 0.1.7 the same connect was also denied, reported as ::ffff:127.0.0.1. Since #5101, the denial reports the normalized 127.0.0.1. #5101 covers [::ffff:127.0.0.1] for the Google metadata endpoint and the policy-local address, but not for other loopback ports.

Related but different:

Impact / Why This Matters

Dual-stack runtimes commonly dial IPv4 loopback addresses in mapped form, e.g. the Bazel client connecting to a server whose JVM runs with -Djava.net.preferIPv4Stack=true. In-sandbox services those clients depend on are unreachable, and the failure is reported as a policy denial. Adding policy rules doesn't help, because loopback isn't something a policy can allow.

On 0.1.8, the workaround is to drop preferIPv4Stack so the server listens on [::1], but that only works where the runtime lets you choose.

Acceptance Criteria

Reproduction Steps

  1. Create a sandbox from an image with busybox nc (no policy changes needed):
    openshell sandbox create --name v4m --from python:3.13-alpine
    
  2. Start an IPv4-only listener on 127.0.0.1 and connect to it as 127.0.0.1, then again as ::ffff:127.0.0.1 (busybox nc -l exits after one connection, so each connect gets a fresh listener):
    openshell sandbox exec -n v4m -- sh -c '
    nc -l -s 127.0.0.1 -p 9000 >/dev/null & sleep 1
    nc -vz -w 3 127.0.0.1 9000
    nc -l -s 127.0.0.1 -p 9000 >/dev/null & sleep 1
    nc -vz -w 3 ::ffff:127.0.0.1 9000'
    

Output:

127.0.0.1 (127.0.0.1:9000) open
nc: ::ffff:127.0.0.1 ([::ffff:127.0.0.1]:9000): Permission denied

The listener is IPv4-only (it's in /proc/net/tcp, not /proc/net/tcp6). A ::1 listener and a ::1 client connect fine.

Outside OpenShell, the same commands in a plain python:3.13-alpine container (podman run --rm python:3.13-alpine sh -c '…') connect both times:

127.0.0.1 (127.0.0.1:9000) open
::ffff:127.0.0.1 ([::ffff:127.0.0.1]:9000) open

Environment

  • OpenShell: 0.1.8 (CLI and gateway)
  • macOS (Apple Silicon), VM compute driver, gateway via Homebrew: reproduced with the steps above.
  • Ubuntu 24.04 (kernel 6.8, Docker 29.1.3), Docker compute driver: same Bazel failure (client can't connect to its IPv4 loopback server). The reproduction steps above weren't run there.
  • Also failed on 0.1.7 (VM driver).

Logs

[sandbox] [OCSF ] [ocsf] NET:OPEN [MED] DENIED /bin/busybox(0) -> 127.0.0.1:9000 [reason:transparent_tcp_policy_denied]

# Same failure from the Bazel client, in a sandbox that has network policies:
[sandbox] [WARN ] [openshell_supervisor_network::proxy] Denied staged transparent connection destination=127.0.0.1:44281 reason=endpoint 127.0.0.1:44281 is not allowed by any policy
[sandbox] [OCSF ] [ocsf] NET:OPEN [MED] DENIED /sandbox/.cache/bazelisk/downloads/sha256/<digest>/bin/bazel(0) -> 127.0.0.1:44281 [reason:transparent_tcp_policy_denied]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    state:triage-neededOpened without agent diagnostics and needs triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions