Skip to content

feat(docker): linux privilege elevation for Docker and Podman providers#737

Draft
skevetter wants to merge 3 commits into
mainfrom
feat/docker-podman-privilege-elevation
Draft

feat(docker): linux privilege elevation for Docker and Podman providers#737
skevetter wants to merge 3 commits into
mainfrom
feat/docker-podman-privilege-elevation

Conversation

@skevetter

@skevetter skevetter commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Closes #732

Summary

Rootful Docker/Podman daemons expose a socket accessible only to root and the docker group, so the local provider fails with a permission error for users outside that group. Joining the group grants persistent root-equivalent access, and running the whole process as root is undesirable.

This adds an explicit, opt-in privilege-elevation mechanism:

  • New provider option DOCKER_ELEVATION (docker provider) and PODMAN_ELEVATION (podman provider): one of none (default), pkexec, sudo, doas.
  • When set, every docker/podman invocation is wrapped with the chosen helper via the single DockerHelper.buildCmd choke point.
  • Authentication happens once, up front at driver construction, warming the OS credential cache so an operation's many commands share a single prompt — rather than each command triggering its own dialog.
  • The one-time auth runs on its own generous timeout, keeping the interactive prompt out of the short (5s) per-command probe timeouts that would otherwise kill it mid-authentication.
  • Client-only runtime detection (--version) stays unelevated.

This resolves both problems reported in #732 when using a pkexec wrapper: multiple simultaneous auth dialogs, and the operation failing before password entry completed.

Notes

  • Elevation is for rootful daemons. For rootless Podman (the common case) leave it none — elevating would target a separate rootful instance.
  • pkexec targets local desktop sessions with a running polkit agent; use sudo/doas on headless/SSH hosts.

Summary by CodeRabbit

  • New Features
    • Added optional privilege elevation for Docker and Podman commands.
    • Supports pkexec, sudo, and doas, with interactive authentication.
    • Added provider configuration options for enabling and selecting elevation helpers.
    • Elevation is disabled by default and accepts none to run commands normally.
  • Bug Fixes
    • Invalid elevation settings now produce a clear configuration error.

…providers

Rootful Docker/Podman daemons expose a socket accessible only to root and
the docker group, so the local provider fails with a permission error for
users outside that group. Adding an explicit, opt-in privilege-elevation
mechanism lets those users run the provider without joining the group or
running the whole process as root.

Add a DOCKER_ELEVATION / PODMAN_ELEVATION option (none, pkexec, sudo, doas)
that wraps every docker/podman invocation with the chosen helper. To avoid
a prompt per command and to keep the interactive prompt out of the short
per-command probe timeouts, authentication is performed once up front at
driver construction, warming the OS credential cache for the rest of the
operation. Client-only runtime detection stays unelevated.
@netlify

netlify Bot commented Jul 24, 2026

Copy link
Copy Markdown

Deploy Preview for images-devsy-sh canceled.

Name Link
🔨 Latest commit b0a6d4c
🔍 Latest deploy log https://app.netlify.com/projects/images-devsy-sh/deploys/6a63b4c44ff0f3000982a2ef

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@skevetter, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 46 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 47cad18d-d8cb-47e6-899a-9b824692dede

📥 Commits

Reviewing files that changed from the base of the PR and between c0fa726 and b0a6d4c.

📒 Files selected for processing (3)
  • pkg/docker/elevate.go
  • pkg/docker/elevate_test.go
  • pkg/docker/helper.go
📝 Walkthrough

Walkthrough

Adds optional pkexec, sudo, or doas elevation for Docker and Podman commands, including provider configuration, one-time authentication, command wrapping, driver wiring, and unit tests.

Changes

Docker privilege elevation

Layer / File(s) Summary
Elevation configuration flow
pkg/provider/provider.go, pkg/options/resolve.go, providers/docker/provider.yaml, providers/podman/provider.yaml
Adds the elevation configuration field, provider options, defaults, and agent configuration wiring.
Elevation helper runtime
pkg/docker/elevate.go, pkg/docker/helper.go
Selects supported helpers, authenticates once with a timeout, wraps Docker commands, and preserves direct execution when elevation is unset.
Driver wiring and validation
pkg/driver/docker/docker.go, pkg/docker/elevate_test.go
Parses elevation settings during driver creation, performs initial authentication, and tests selection, wrapping, no-op behavior, and command construction.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ProviderConfig
  participant NewDockerDriver
  participant DockerHelper
  participant Elevator
  participant DockerCLI
  ProviderConfig->>NewDockerDriver: provide elevation setting
  NewDockerDriver->>Elevator: create configured helper
  NewDockerDriver->>DockerHelper: EnsureElevated()
  DockerHelper->>Elevator: authenticate once
  Elevator->>DockerCLI: run helper --version
  DockerHelper->>Elevator: wrap Docker command
  DockerHelper->>DockerCLI: execute elevated command
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Podman elevation support and PODMAN_ELEVATION were added, but the linked issue only requested Docker provider elevation. Move Podman support to a separate PR or add a linked issue that explicitly covers it.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The Docker elevation flow matches #732 by adding optional helpers, one-time auth, and secure socket access.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: optional privilege elevation for Docker and Podman providers.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@netlify

netlify Bot commented Jul 24, 2026

Copy link
Copy Markdown

Deploy Preview for devsydev canceled.

Name Link
🔨 Latest commit b0a6d4c
🔍 Latest deploy log https://app.netlify.com/projects/devsydev/deploys/6a63b4c401953800087ece8a

Extract pkexec/sudo/doas string constants (goconst), wrap long lines
(golines), and mark the trusted-config exec calls //nolint:gosec (G204).
@skevetter
skevetter marked this pull request as ready for review July 24, 2026 16:41

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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 `@pkg/docker/helper.go`:
- Around line 529-537: The buildCmd flow must preserve DockerHelper.Environment
across Elevator.wrap instead of allowing sudo/doas to discard provider
configuration such as DOCKER_HOST. Update the elevation handling around
EnsureElevated and Elevator.wrap to explicitly forward or allowlist the required
Docker configuration variables, or reject incompatible
elevation-plus-environment configurations before executing the command.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d4dca378-0bc6-46a6-9317-7906d1697aba

📥 Commits

Reviewing files that changed from the base of the PR and between b3896a6 and c0fa726.

📒 Files selected for processing (8)
  • pkg/docker/elevate.go
  • pkg/docker/elevate_test.go
  • pkg/docker/helper.go
  • pkg/driver/docker/docker.go
  • pkg/options/resolve.go
  • pkg/provider/provider.go
  • providers/docker/provider.yaml
  • providers/podman/provider.yaml

Comment thread pkg/docker/helper.go
@skevetter skevetter changed the title feat(docker): optional privilege elevation for Docker and Podman providers feat(docker): linux privilege elevation for Docker and Podman providers Jul 24, 2026
sudo/pkexec/doas reset the child environment, so provider-configured
variables such as DOCKER_HOST (set via the docker/podman env block) were
silently dropped when elevation was active. Forward them explicitly through
env(1) so the elevated docker command receives the intended configuration.
@skevetter
skevetter marked this pull request as draft July 24, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add optional privilege elevation for the Docker provider (pkexec/sudo/doas)

1 participant