Skip to content

compat: confine dockerfile to build context#28072

Open
1seal wants to merge 4 commits intocontainers:mainfrom
1seal:codex/podman-build-dockerfile-confinement
Open

compat: confine dockerfile to build context#28072
1seal wants to merge 4 commits intocontainers:mainfrom
1seal:codex/podman-build-dockerfile-confinement

Conversation

@1seal
Copy link
Copy Markdown

@1seal 1seal commented Feb 11, 2026

this fixes the compat build handler's dockerfile query parameter resolution to ensure the resolved path cannot escape the extracted build context directory.

  • rejects ../ traversal escapes
  • rejects absolute paths outside ContextDirectory (still allows absolute paths within the context for libpod/local build semantics)
  • adds a linux-only unit test for confinement checks

this is being filed as a bug/hardening change (not a security issue) per maintainer guidance on the podman system service threat model.

The compat build handler accepts a dockerfile query parameter and
turns it into a filesystem path. Ensure the resolved path cannot escape
the extracted build context directory, rejecting traversal and absolute
paths outside the context.

Add a linux-only unit test covering confinement checks.

Signed-off-by: 1seal <security@1seal.org>
@github-actions github-actions bot added the kind/api-change Change to remote API; merits scrutiny label Feb 11, 2026
Copy link
Copy Markdown
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

I have not made a careful look on what is going but this is breaking many tests depending on the current behavior, seems like there are many tests checking that we can use dockerfiles outside of the context dir so I am not sure we can or should switch that as it could break many users.

@1seal
Copy link
Copy Markdown
Author

1seal commented Feb 11, 2026

thanks for the review.

i agree this is an API change and will break any callers/tests that relied on the compat handler reading a dockerfile outside the provided build context.

the motivation for the change is twofold:

  • correctness/compat: the compat build docs describe dockerfile as a “path within the build context”, but the current handler allows ../ escapes and absolute paths to become host filesystem paths.
  • hardening: confining dockerfile to the extracted context removes a surprising host-path read behavior from the API surface.

to reduce user impact, i think the right direction is:

  • keep local build semantics unchanged (where podman build -f /abs/path may be valid for local workflows).
  • for the docker-compat POST /build handler, treat dockerfile as context-relative only and reject values that resolve outside ContextDirectory.

if we have tests asserting “dockerfile outside context works”, i suggest updating them to build a context that includes the intended dockerfile (client-side), then pass a context-relative path.

this pr already allows absolute paths that still resolve within ContextDirectory, and rejects traversal/absolute paths that escape.

@giuseppe
Copy link
Copy Markdown
Member

I don't see why we need this limitation, there is nothing harmful in a Dockerfile outside of the build context

@1seal
Copy link
Copy Markdown
Author

1seal commented Feb 12, 2026

thanks.

i’m not trying to introduce a new security boundary here (agree with the system service threat model).

the main reasons for confining dockerfile in the compat POST /build handler are correctness/compat and reducing surprising host-fs reads:

  • the compat API docs describe dockerfile as a path within the build context, but today ../ and some absolute paths can be interpreted as host filesystem paths outside the extracted context.
  • docker remote build semantics assume the daemon only reads inputs from the provided context (the client is responsible for adding a dockerfile that lives elsewhere into the context tar).
  • allowing the server to reach outside the context makes remote builds less reproducible and harder for API clients to reason about.

local podman build -f /abs/path workflows remain valid; this change is limited to the docker-compat service handler. #28072 also still permits absolute paths that resolve within ContextDirectory.

@1seal
Copy link
Copy Markdown
Author

1seal commented Feb 12, 2026

pushed an update to address the ci failures caused by the stricter dockerfile confinement.

changes in this commit:

  • server: apply the dockerfile confinement checks only for the docker-compat POST /build handler (non-libpod). keep libpod local build semantics (absolute dockerfile paths can be outside the context), which fixes the apiv2 expectation for a 404 on a missing dockerfile path.
  • client (bindings): for remote POST /build, ensure any dockerfile outside the context (including -f - stdin) is copied into the context directory and the dockerfile query param is set to a context-relative path. this keeps remote builds working for -f -, -f /abs/path, and -f ../Dockerfile-style cases without requiring the service to read host paths.
  • windows/remote-tag unit tests: add a minimal remote stub file for pkg/api/handlers/compat so test runners that enable the remote build tag don’t fail with “build constraints exclude all Go files”.

hopefully this unblocks the remote/system build tests that were previously relying on absolute host dockerfile paths.

Signed-off-by: 1seal <security@1seal.org>
@1seal 1seal force-pushed the codex/podman-build-dockerfile-confinement branch from 3ee8bdb to 701b6aa Compare February 12, 2026 10:13
@1seal
Copy link
Copy Markdown
Author

1seal commented Feb 12, 2026

pushed a dco-signed amend for the latest commit (no functional changes).

Signed-off-by: 1seal <security@1seal.org>
@1seal
Copy link
Copy Markdown
Author

1seal commented Feb 12, 2026

follow-up: tightened server-side scoping so confinement applies to /build and /libpod/build, while /libpod/local/build keeps host-path dockerfile semantics.

@packit-as-a-service
Copy link
Copy Markdown

tmt tests failed for commit 3ee8bdb. @lsm5, @psss, @thrix please check.

@1seal
Copy link
Copy Markdown
Author

1seal commented Feb 12, 2026

thanks.

fyi that packit/tmt failure was for an earlier commit (3ee8bdb). current pr head is ee0734a95 and packit testing-farm jobs for it are already running.

once those finish, happy to take another look if anything is still failing.

@packit-as-a-service
Copy link
Copy Markdown

tmt tests failed for commit ee0734a. @lsm5, @psss, @thrix please check.

Signed-off-by: 1seal <security@1seal.org>
@1seal
Copy link
Copy Markdown
Author

1seal commented Feb 13, 2026

minor follow-up: fixed the linux unit test to use a path-only request target (previously used an absolute URL, which caused IsLibpodRequest() to misclassify libpod endpoints in the test). current head includes 44e24ef14.

@packit-as-a-service
Copy link
Copy Markdown

tmt tests failed for commit 44e24ef. @lsm5, @psss, @thrix please check.

@jankaluza
Copy link
Copy Markdown
Member

I checked the code and it looks OK, but I cannot judge if the feature makes a sense in general. That's up to others :-).

@thrix
Copy link
Copy Markdown

thrix commented Feb 26, 2026

/packit retest-failed

@github-actions
Copy link
Copy Markdown

A friendly reminder that this PR had no activity for 30 days.

@1seal
Copy link
Copy Markdown
Author

1seal commented Mar 29, 2026

stale bot pinged this, so a brief follow-up.

current head narrows the server-side confinement to the remote build handlers (/build and /libpod/build) while keeping /libpod/local/build host-path semantics intact, and the bindings side copies out-of-context dockerfiles into the context for remote builds. the goal is to avoid surprising host-fs reads on the remote API surface without changing local build workflows.

if maintainers prefer a different shape here, i can split this further, adjust tests again, or close it. otherwise, is there a preferred next step or decision on whether this hardening/compat change should move forward?

@github-actions github-actions bot removed the stale-pr label Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/api-change Change to remote API; merits scrutiny

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants