Skip to content

Use os.Root when extracting files - #9601

Merged
taylorsilva merged 1 commit into
masterfrom
9597-tar
Jun 15, 2026
Merged

taylorsilva merged 1 commit into
masterfrom
9597-tar

Conversation

@taylorsilva

@taylorsilva taylorsilva commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

Changes proposed by this PR

closes #9597

Basically reverting #9486, but adding one safe-guard against path escapes from symlinks when creating a relative symlink. os.Root is doing the heavy-lifting for us here. It'll protect us from extraction attacks that try to write outside the destination directory. It'll still allow us to create the symlink, but it'll fail if someone tries to do an extraction attack using the symlink.

I left a comment in the code path where we create symlinks explaining this a bit more.

I manually setup a pipeline using the test repo from Pix4D: https://github.com/Pix4D/concourse-tar-streaming-issue

resources:
  - name: repo
    type: git
    source:
      uri: https://github.com/Pix4D/concourse-tar-streaming-issue.git

jobs:
  - name: job
    plan:
      - get: repo
      - task: windows
        config:
          platform: windows
          inputs:
            - name: repo
          run:
            path: powershell
            args:
              - -Command
              - |
                ls .

and streamed it from a linux to windows worker. I verified I could reproduce the issue from master first:

{"timestamp":"2026-06-15T16:14:50.724027700Z","level":"info","source":"worker","message":"worker.baggageclaim.api.volume-server.stream-in.bad-stream-payload","data":{"error":"entry './safe-intra-repo-windows/workers/images-vars.tf' links outside of target directory: ../shared/images-vars.tf","session":"2.2.1.11","volume":"bb0f01bf-1b35-4206-a0bc-9a40840081be"}}
image

Redeploying the windows worker with this PR, it worked:
image

@taylorsilva
taylorsilva requested a review from a team June 15, 2026 16:21
@taylorsilva taylorsilva added this to the v8.2.4 milestone Jun 15, 2026
@taylorsilva taylorsilva mentioned this pull request Jun 15, 2026
4 tasks done
Basically reverting #9486, but adding one safe-guard against path
escapes from symlinks when creating a relative symlink. `os.Root` is
doing the heavy-lifting for us here. It'll protect us from extraction
attacks that try to write outside the destination directory.

Signed-off-by: Taylor Silva <[email protected]>
@taylorsilva
taylorsilva merged commit 1cec401 into master Jun 15, 2026
11 checks passed
@taylorsilva
taylorsilva deleted the 9597-tar branch June 15, 2026 20:10
@aliculPix4D

aliculPix4D commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

@taylorsilva first impressions: it doesn't seem to fully resolve the issue for us.

This is all the logs I have so far:

from ATC:

atc.tracker.notify.run.task-step.find-or-create-cow-volume-for-container.failed-to-create-volume-in-baggageclaim: "error":"failed to create volume"
atc.tracker.notify.run.task-step.failed-to-create-volume-mounts-for-container: "error":"failed to create volume"
atc.tracker.notify.run.run.errored","data":{"build":"1","build_id":15318,"error":"find or create container on worker wrk-vs2019-win-0-0ae43318ab7cb4760: failed to create volume

From worker:

{"level":"error","source":"worker","message":"worker.baggageclaim.api.volume-server.create-volume-async.create-volume.failed-to-materialize-strategy","data":{"error":"exit status 9\n","handle":"4921c41c-495a-4aa9-ba1a-cdae80b0d8ac","privileged":false,"session":"2.2.1.1401.1","strategy":{"type":"cow","volume":"6731f982-9fb8-4051-a136-178d816bbdd8"}}}
{"level":"error","source":"worker","message":"worker.baggageclaim.api.volume-server.create-volume-async.failed-to-create","data":{"error":"exit status 9\n","handle":"4921c41c-495a-4aa9-ba1a-cdae80b0d8ac","privileged":false,"session":"2.2.1.1401","strategy":{"type":"cow","volume":"6731f982-9fb8-4051-a136-178d816bbdd8"}}}

the exit status 9\n doesn't give us any real clue to what the problem is.

What I noticed is the following:

  • It seems to work fine on Windows Server 2025 AMI
  • It consistently fails on Windows Server 2019 AMI

I will get back to you as soon as I have more information and confirmation that this is still related to the symlink issue.

UPDATE: this is definitely still related to symlinks. Doing a simple test, just by removing the symlinks from the repo, and everything passes.
UPDATE2: some extra notes:

  • The exit code 9 is 1 (some files copied successfully) + 8 (failed to copy some files or directory)
  • streaming works when symlinks are files, but not directories (both on 2019 and 2025)
  • file symlinks are broken and unreadable (both on 2019 and 2025)
  • there must be something related also to permissions:
      - task: check-privileges-<windows-os-version>
        tags: [win2025 or win20219]
        config:
          platform: windows
          run:
            path: cmd.exe
            args: ["/c", "whoami /priv"]

shows:

SeCreateSymbolicLinkPrivilege Create symbolic links Disabled

UPDATE 3: Thanks to @odormond who noticed that contrary to: os.Symlink, unfortunately, root.Symlink() doesn't really work properly on Windows (and backward and forward slashes). I will prepare small examples that show the exact problem.

@taylorsilva

Copy link
Copy Markdown
Member Author

The "exit status 9" indicates to me that we're in another part of the code where we are exec'ing some binary. The immediate spot that comes to mind is when we call robocopy when creating COW volumes, which appears to be what is happening here. My guess is that robocopy is having issues with copying the symlink? Maybe this goes back to the creation of the symlink that you mentioned in your "UPDATE 3"?

Are you still able to reproduce the issue with your example repo: https://github.com/Pix4D/concourse-tar-streaming-issue ?

@aliculPix4D

aliculPix4D commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Are you still able to reproduce the issue with your example repo: https://github.com/Pix4D/concourse-tar-streaming-issue ?

So your example in the PR description would reproduce the issue, if instead of ls you just tried to cat the file, like I do here:
https://github.com/Pix4D/concourse-tar-streaming-issue/blob/fcd72d3832d94bbbd860b23e1cd803a88dde2c64/ci/pipeline.yml#L58

Sure, in this case, it will successfully stream, but the created symlink will be unusable (due to forward slashes on Windows).
We think that the root cause of the issue is root.Symlink which doesn't work properly on Windows if the symlink uses forward slash (everything works fine with backward slash).

This just manifested itself differently when you also have a directory symlink in the repository. In that case, it will fail during the streaming, as the error in my original post shows... but the root cause remains the same: root.Symlink (we think; otherwise there are really 2 issues)

Please allow me some time to prepare the examples.

@taylorsilva

Copy link
Copy Markdown
Member Author

Feel free to open a new issue when you have a final report.

@aliculPix4D

Copy link
Copy Markdown
Contributor

Feel free to open a new issue when you have a final report.

Finally done in: #9609

It took a lot more time than expected :)

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.

PR #9486 breaks volumes containing symlinks on Windows

2 participants