Skip to content

fix(oauth): detect Podman containers via /run/.containerenv - #4008

Open
leninworld wants to merge 1 commit into
github:mainfrom
leninworld:fix/4007-podman-container-detection
Open

leninworld wants to merge 1 commit into
github:mainfrom
leninworld:fix/4007-podman-container-detection

Conversation

@leninworld

Copy link
Copy Markdown

This PR fixes issue #4007.

Summary

Under Podman the OAuth callback was bound to the container's own loopback, so the published callback port never reached it and browser login always failed. Container detection now also recognises Podman's /run/.containerenv marker.

Why

isRunningInDocker() only checked /.dockerenv and docker/containerd in /proc/1/cgroup. Podman creates neither: it writes /run/.containerenv, and with cgroup v2 + crun /proc/1/cgroup is just 0::/. The server then treated the run as native, listenCallback() bound 127.0.0.1 inside the container, and every connection to the published port was reset (as the issue traces).

Fixes #4007

What changed

  • internal/oauth/env.go: isRunningInDocker() keeps its non-Linux early return and now delegates to containerMarkersPresent(root), which checks the existing markers plus /run/.containerenv. Production passes /; the root parameter only makes the check testable. The doc comment now names Podman and both decisions the result drives (skipping random-port PKCE, binding the callback to all interfaces).
  • internal/oauth/env_test.go (new): table test over t.TempDir() roots: no markers, .dockerenv, run/.containerenv, Docker cgroup, containerd cgroup, and a bare cgroup v2 0::/ (still not a container). With the .containerenv check removed, the Podman case fails (expected: true, actual: false).

MCP impact

  • No tool or API changes
    Only container detection for the local OAuth login changes.
  • Tool schema or behavior changed
  • New tool added

Prompts tested (tool changes only)

  • Not applicable (no tool changes).

Security / limits

  • No security or limits impact
  • Auth / permissions considered
    Podman runs now get the same handling Docker runs already get: a random callback port goes to device flow, and a fixed port binds all container interfaces with the existing warning to publish it to loopback only. Like /.dockerenv today, the marker does not tell host-network containers (--network=host, Toolbox, Distrobox) apart from isolated ones; that is unchanged in kind and left out of this PR.
  • Data exposure, filtering, or token/size limits considered

Tool renaming

  • I am renaming tools as part of this PR (e.g. a part of a consolidation effort)
    • I have added the new tool aliases in deprecated_tool_aliases.go
  • I am not renaming tools as part of this PR

Lint & tests

  • Linted locally with ./script/lint
    Ran gofmt -s and golangci-lint v2.14.0 (the pinned version) on ./...: 0 issues.
  • Tested locally with ./script/test
    go test -race ./... passes.

Docs

  • Not needed
  • Updated (README / docs / examples)

Skills

  • Updated relevant skills or confirmed no bundled skill applies
    No tools or toolset instructions change, so no bundled skill applies.

Podman creates /run/.containerenv instead of /.dockerenv, and with
cgroup v2 /proc/1/cgroup is just "0::/", so the server treated a
Podman run as native and bound the OAuth callback to the container's
loopback, where the published callback port cannot reach it.

Fixes github#4007
@leninworld
leninworld requested a review from a team as a code owner December 2, 2026 12:06
Copilot AI adaptive review requested due to automatic review settings December 2, 2026 12:06

Copilot AI 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.

🟢 Approval recommended

No active review issues are reported for the change adding Podman detection to local OAuth handling.

No open issues 🎉

What changed in this PR

Fixes #4007 by detecting Podman containers so local OAuth uses the existing container-specific callback handling.

Changes:

  • Recognizes /run/.containerenv alongside existing Docker and containerd markers.
  • Extracts marker detection into a testable helper and clarifies its documentation.
  • Adds table-driven tests for container markers and non-container cases.
File Description
internal/​oauth/​env.go Adds Podman detection while preserving the Linux-only guard.
internal/​oauth/​env_test.go Tests marker detection using isolated temporary directories.

Review effort: Balanced (adaptive)

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

Labels

None yet

Projects

None yet

3 participants