Add RFC6761 section 6.3 support (*.localhost -> 127.0.0.1 / ::1)

未关闭
#5,972 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
18/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
docker, kubernetes, linux, networking, rust
领域
networking

调研方向

Start with PolicyDnsService::answer_query in crates/openshell-supervisor-network/src/policy_dns/mod.rs, where no loopback-name case exists before stage_observation runs, and with observation_eligible in the same file. The issue lists open design questions (AAAA behavior when policy_dns_ipv6_egress is disabled, whether the exact name localhost is included, and the shared classification location), so resolve those with maintainers first. Done means .localhost names return 127.0.0.1 or ::1 without allocating addresses or producing denials, with tests covering the excluded look-alike names.

由索引模型根据 Issue 内容生成。

描述

state:triage-needed
User Story

I use OpenShell to run sandboxed agent workloads on a remote machine.
Inside a sandbox I queried myapplication.localhost to reach a service listening in that same sandbox, and the name resolved to
198.18.0.4 instead of loopback, so I could not reach the service by name.

Services like Portless rely on this loopback resolver described in RFC6761 Section 6.3.
(Portless uses dynamically generated *.localhost domains)

Problem Statement

localhost resolves inside a sandbox only because the container runtime's /etc/hosts contains 127.0.0.1 localhost.

A name under .localhost is not in /etc/hosts, so the libc resolver sends it to the mediated policy DNS listener at 127.0.0.53. Policy DNS treats it as an unapproved external hostname: it stages a contract-free observation mapping from the synthetic 198.18.0.0/15 pool and returns that placeholder.

The placeholder is not loopback, so the client cannot reach an in-sandbox service; the following TCP attempt is denied and surfaced as a policy proposal for a destination no policy can usefully allow.

RFC6761 Section 6.3 reserves localhost. and every name under .localhost. and expects resolution APIs to return a loopback address without querying a resolver. Browsers implement this, which is why the same name works on the host.

Impact / Why This Matters
  • Host/sandbox parity gap: the host browser and systemd-resolved resolve app.localhost to 127.0.0.1; the sandbox does not. Name-based local development inside a sandbox breaks.
  • Current workarounds are insufficient:
    • Connecting to 127.0.0.1:<port> directly loses the hostname, so name-based virtual hosts, cookies, and multi-service setups on loopback cannot be expressed.
    • Editing /etc/hosts is unavailable for Docker, Podman, and Kubernetes sandboxes because the runtime bind-mounts a generated file. Only the VM driver preserves a non-empty image-authored file.
  • Every .localhost query consumes a synthetic observation identity and produces a denial plus a proposal for a loopback destination. That is noise in telemetry and the policy advisor, and it can never be
    satisfied by an endpoint rule.
  • Fail-closed quarantine turns these names into REFUSED, so even name resolution stops working once policy validation fails.
Proposed Design

Inside every sandbox, localhost and every name ending in a .localhost label resolve to 127.0.0.1, and to ::1 for AAAA queries when the runtime answers AAAA.

  • Applies to the whole subtree, case-insensitively, with or without a trailing dot.
  • Requires no policy rule, allocates no synthetic address, and sends no upstream query.
  • Does not depend on /etc/hosts; the relay answer is a fallback for images whose hosts file lacks loopback names.
  • These names stay outside policy: loopback traffic completes inside the sandbox and is not proxied, so the behavior adds no reach.
  • Names that merely contain localhost (mylocalhost, localhost.example.com, app.localhost.example.com) keep today's behavior.

No new command, flag, or configuration. Just make the existing workflow work:

openshell sandbox connect <sandbox>
getent hosts myapplication.localhost   # 127.0.0.1
curl -v http://myapplication.localhost:8080/ # should connect to 127.0.0.1
Acceptance Criteria
  • In a sandbox, getent hosts app.localhost returns 127.0.0.1 and curl http://app.localhost:/ reaches a service listening on sandbox loopback.
  • LOCALHOST, app.localhost., and nested names such as a.b.localhost behave the same.
  • AAAA queries return ::1 when the runtime answers AAAA, and stay suppressed when AAAA answers are disabled, so dual-stack clients fall back to A.
  • These queries allocate no synthetic address, send no trusted-resolver query, and produce no denial or policy proposal.
  • mylocalhost, localhost.example.com, and app.localhost.example.com are unaffected.
  • localhost resolves even when the image's /etc/hosts lacks it.
  • The behavior holds while the policy engine is fail-closed.
  • Documented in the network rules docs.
Alternatives Considered
  1. Add the name as a policy endpoint. Policy DNS still resolves eligible names through the trusted upstream resolver, and allowed_ips only filters the returned addresses. A .localhost name is not
    resolvable upstream, so the query fails.
  2. Add the name to /etc/hosts. Docker, Podman, and Kubernetes replace that file with a runtime-generated one. The VM lane preserves a non-empty image-authored file, which makes the workaround
    driver-specific and unavailable for ordinary local sandboxes.
  3. Use host.openshell.internal / host.docker.internal. Those aliases point at the host, not at a service inside the sandbox.
  4. Use gateway service routing (*.openshell.localhost). That exposes a sandbox service to a host browser. It is the opposite direction and requires the gateway.
  5. Add a configuration switch. The only DNS-related driver configuration is policy_dns_ipv6_egress. A switch for names that RFC 6761 already reserves adds surface without changing what users can express.
  6. Refuse instead of answering loopback. This removes the synthetic placeholder but keeps the parity gap and the denied/proposed telemetry.
Agent Investigation

Observed resolver chain:

  • Compute drivers write /etc/resolv.conf with nameserver 127.0.0.53 (Docker crates/openshell-driver-docker/src/lib.rs:6541, Podman crates/openshell-driver-podman/src/driver.rs:40, Kubernetes
    crates/openshell-driver-kubernetes/src/driver.rs:7487, VM crates/openshell-driver-vm/scripts/openshell-vm-sandbox-init.sh:673).
  • The seccomp broker's DNS relay (crates/openshell-sandbox/src/network_broker.rs:535, accept_dns at :393) forwards the raw query to the supervisor as a mediated DNS query.
  • PolicyDnsService::answer_query (crates/openshell-supervisor-network/src/policy_dns/mod.rs:184) has no loopback-name case. With no matching policy endpoint it calls stage_observation (mod.rs:334) after
    observation_eligible (mod.rs:443) excludes only the exact name localhost.
  • allocate_address (policy_dns/store.rs:626) hands out pool addresses sequentially from the ranges built in policy_dns/runtime.rs:57: 198.18.0.0/15 with 198.18.0.1 reserved for the sandbox-local API, so
    198.18.0.2 is the first external identity. 198.18.0.4 is consistent with the third allocation in an epoch-0 pool (inference; not reproduced against a live sandbox in this environment).
  • Loopback TCP connects complete inside the sandbox through connect_local_tcp (network_broker.rs:1081), never reaching the proxy or policy. Users can already connect to 127.0.0.1 by literal, so answering
    *.localhost with loopback grants no new reach.
  • Proposal generation classifies only the exact hostname localhost as internal/loopback (crates/openshell-supervisor/src/mechanistic_mapper.rs, crates/openshell-sandbox/src/mechanistic_mapper.rs), which is
    why .localhost names appear as ordinary proposals today.

Prototype status: a prototype exists only in an uncommitted local working tree from a prior session; it is not accepted work, has no PR, and its tests were not executed here (no network, no cargo cache,
and the sandbox blocks the linker). The spike record does not depend on it.

Open questions:

  1. For AAAA queries when policy_dns_ipv6_egress answers are disabled, should loopback names still return ::1 (strict RFC 6761), or keep the current suppression so clients fall back to A?
  2. Should the relay answer the exact name localhost as well, or only names under .localhost, since /etc/hosts normally handles localhost first?
  3. Gateway service hostnames under the configured openshell.localhost base domain would also become loopback inside a sandbox. Confirm that this side effect is acceptable.
  4. Where should the shared classification live so proposal generation, policy DNS, and any future resolver path agree?
Checklist
  • I've reviewed existing issues and the published docs
  • This is a design proposal, not a "please build this" request
主要语言
Rust
星标
21.5k
派生
2.1k
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

NVIDIA/OpenShell 的其他 Issue

查看 NVIDIA/OpenShell 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。