Skip to content

Find the host data path without a self-inspection - #340

Merged
athNdev merged 1 commit into
mainfrom
fix/host-network-mounts
Nov 4, 2026
Merged

athNdev merged 1 commit into
mainfrom
fix/host-network-mounts

Conversation

@athNdev

@athNdev athNdev commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Found while updating the local dev instance: it runs with network_mode: host, and the new self-detection reported Server data directory /app/data is used as-is by the Docker host (no translation).

Why

A host-networked container shares the host's UTS namespace, so os.Hostname() returns the machine name (DESKTOP-81EKL5T), not the container ID. ContainerInspect therefore returns 404, which the client correctly reports as "not a container", and the resolver fell back to the identity mapping.

That is the worst kind of fallback: the panel would ask the daemon to bind /app/data/servers/x on the host, where no such directory exists. Docker would create an empty root-owned directory and mount it into the server container instead of the world.

Fix

Resolve now has a second source before it gives up: the kernel mount table. For a bind mount the kernel records the source path in the root field, so /app/data inside the container maps to /opt/carbon-panel/data on the host with no daemon call at all.

Order of authority:

  1. The daemon's view of our own container (unchanged, still authoritative for named volumes).
  2. The kernel mount table's bind source (new).
  3. The deprecated CARBONPANEL_HOST_DATA_PATH.
  4. Identity — only when nothing is mounted and the table could not be read.

A container whose mounts are visible but do not cover the data directory is still refused with ErrNotMounted, whether the answer came from the daemon or the kernel.

This also covers a Docker socket proxy that forbids GET /containers/**: the mapping is still correct without container read access.

Verification

  • New tests: resolve-from-mount-table when the daemon sees no container, daemon-beats-table precedence, still-refuses-when-unmounted, root-mounted path ignored, deepest mount wins.
  • go build ./..., go vet ./..., go test ./internal/hostmount ./internal/docker ./cmd/..., knowledge-lint 10/10.
  • To be confirmed on the dev instance after merge: the log should read maps to /opt/carbon-panel/data on the Docker host (container mount table).

A host-networked container shares the host's UTS namespace, so its
hostname is the machine name and the daemon has no container to inspect.
Self-detection then concluded 'not a container' and used the data directory
as-is, which would have asked the daemon to bind /app/data on the host: an
empty root-owned directory instead of the world.

Resolve now falls back to the kernel mount table, where the source path of a
bind mount is recorded, before giving up. The daemon's view still wins when it
has one, and a container whose mounts do not cover the data directory is still
refused.
@athNdev
athNdev merged commit b3a7118 into main Nov 4, 2026
11 checks passed
@athNdev
athNdev deleted the fix/host-network-mounts branch November 4, 2026 03:52
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.

1 participant