[release-1.26] Properly validate cache IDs and sources
Backport the changes from https://github.com/containers/buildah/pull/5778 to release-1.26
The --mount type=cache argument to the RUN instruction in Dockerfiles was using filepath.Join on user input, allowing crafted paths to be used to gain access to paths on the host, when the command should normally be limited only to Buildah;s own cache and context directories. Switch to filepath.SecureJoin to resolve the issue.
Fixes CVE-2024-9675
What type of PR is this?
/kind bug
What this PR does / why we need it:
How to verify it
Includes the new test from the original change, build-check-cve-2024-9675
Which issue(s) this PR fixes:
https://issues.redhat.com/browse/RHEL-62366 https://issues.redhat.com/browse/RHEL-62371
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Fixed CVE-2024-9675 which allowed arbitrary paths from the host to be mounted into a build container using the `--mount type=cache` argument to the `RUN` instruction in Dockerfiles.
Changes LGTM.
The older variants of Buildah version themselves slightly differently. I'm not sure what's out of whack on this one, I'd try running ./tests/version.bats from the command line to see if that detects anything.
Forgot to add a new changelog entry to the spec file. Updated.
@dashea I re-ran two tests that had flakes - "quay: 503 gateway timeout". Quay is notoriously flaky on these older branches. In podman CI too.
Just to summarize the changes since Tom's approval: @cevich disabled selinux on the new test since selinux was preventing access to /var/tmp with or without the code change, and I added a pre-fetch on busybox in run check --from with arg due to a failure in that test to find the image.
/approve /lgtm
[APPROVALNOTIFIER] This PR is APPROVED
This pull-request has been approved by: dashea, nalind
The full list of commands accepted by this bot can be found here.
The pull request process is described here
- ~~OWNERS~~ [nalind]
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment