Skip to content

fix(release): prevent tar/zip slip path traversal in artifact extraction - #333

Merged
cert-manager-prow[bot] merged 1 commit into
cert-manager:masterfrom
FelixPhipps:release-tar-slip
Jul 9, 2026
Merged

cert-manager-prow[bot] merged 1 commit into
cert-manager:masterfrom
FelixPhipps:release-tar-slip

Conversation

@FelixPhipps

Copy link
Copy Markdown
Member

Description

Problem

The cmrel gcb publish command downloads pre-built artifact bundles from a GCS staging area and unpacks them inside the privileged Cloud Build worker. The extractors tar.UntarGz() and zip.Unzip() write each archive entry to filepath.Join(dst, header.Name) with the entry name taken at face value — and a bundle can come from an untrusted source (anyone with write access to the staging bucket). The current code writes them with no safeguards:

  • Path traversal: entry names are joined onto the destination with no ..-stripping or absolute-path rejection, so an entry named ../../go/bin/cosign escapes the temp unpack dir and lands on the shared /go volume.
  • Arbitrary overwrite: files are opened without O_EXCL, overwriting binaries the worker is about to execute (e.g. cosign), yielding root RCE with GITHUB_TOKEN, quay creds and the KMS signing key in scope.
  • Symlink/hardlink & mode abuse: link entries are unhandled and header.Mode is used verbatim, so setuid/setgid bits and attacker-controlled link targets pass straight through.

Solution

Guard both extractors with filepath.IsLocal() to reject absolute paths and parent-directory traversal, open regular files with O_EXCL so an entry can no longer overwrite an existing file, and mask the mode to permission bits to drop setuid/setgid/sticky. Symlink and hardlink tar entries are rejected outright. Legitimate release archives behave unchanged.

Test plan

  • TestUntarGz — traversal, absolute-path, symlink and hardlink entries are all rejected, and a well-formed archive extracts unchanged.
  • TestUnzip — traversal and absolute-path entries are rejected; a well-formed archive extracts unchanged.
  • Both new tests (tarball_test,zip_test) assert nothing escapes the destination directory.
  • Existing pkg/release tests pass unchanged.
  • go build ./..., go vet ./..., and gofmt clean.

The tar.UntarGz() and zip.Unzip() extractors joined attacker-controlled
archive entry names onto the destination directory without any
confinement, so an entry named e.g. "../../go/bin/cosign" could escape
the temporary unpack directory and overwrite arbitrary files on the
shared Cloud Build volume, leading to code execution with the release
credentials in scope (CWE-22 / CWE-59 / CWE-94).

Guard both extractors with filepath.IsLocal() to reject absolute paths
and parent-directory traversal, open regular files with O_EXCL so an
entry can no longer silently overwrite an existing file, and mask the
mode to permission bits to drop setuid/setgid/sticky. Symlink and
hardlink tar entries are now rejected outright since their link targets
are attacker-controlled.

Add tests covering well-formed extraction and rejection of traversal,
absolute-path and symlink/hardlink entries.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Felix Phipps <[email protected]>
@cert-manager-prow cert-manager-prow Bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 8, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

Hi @FelixPhipps. Thanks for your PR.

I'm waiting for a cert-manager member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@cert-manager-prow cert-manager-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 8, 2026
@SgtCoDFish

Copy link
Copy Markdown
Member

/ok-to-test

and a bundle can come from an untrusted source (anyone with write access to the staging bucket)

It's important to say that the bundles don't come from an untrusted source. The only SAs with access to the staging bucket are trusted maintainers, CNCF admins and CI processes designed specifically for the purpose of releasing cert-manager.

That doesn't mean this PR has no value - defence in depth is good! - but we'd consider it a code red high severity situation if anyone untrusted could ever access that bucket.

@cert-manager-prow cert-manager-prow Bot added ok-to-test and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 9, 2026

@SgtCoDFish SgtCoDFish left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm
/approve

Hardening / defence in depth. We don't need to go super deep on this - thanks! 🚀

@cert-manager-prow cert-manager-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Jul 9, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: SgtCoDFish

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@cert-manager-prow cert-manager-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 9, 2026
@cert-manager-prow
cert-manager-prow Bot merged commit e34f633 into cert-manager:master Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. lgtm Indicates that a PR is ready to be merged. ok-to-test size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants