Skip to content

Image extraction shifts uid 1001 → 1002 on btrfs workers, breaking non-root user tasks #9662

Closed

Description

@neddp

Summary

When a task uses image: <registry-image-resource> (i.e. a get step result as the task image via image: key), files in the image that are owned by uid 1001 end up with uid 1002 on the worker's btrfs subvolume after extraction. Files owned by uid 1000 are unaffected. This causes Permission denied at runtime for any task that runs as that user and tries to write to its home directory.

How to reproduce

  1. Build an image using oci-build-task (i.e. via concourse/oci-build-task) with a Dockerfile like:
FROM ubuntu
RUN useradd non-root-user --shell /bin/bash --create-home

The Ubuntu base image (ubuntu:noble / ubuntu:resolute) includes a pre-created ubuntu user at uid 1000, so useradd non-root-user assigns uid 1001.

  1. Push the image via a registry-image put step.

  2. Use the image in a task:

- task: my-task
  image: my-registry-image-resource
  config:
    run:
      path: bash
      args: [-c, "mkdir -p $HOME/.config/gcloud/"]
    user: non-root-user
  1. Task fails: mkdir: Permission denied

Diagnostic data

Inside the failing container (captured via fly hijack):

whoami=non-root-user  id=uid=1001(non-root-user)
stat /home/non-root-user:  Uid: ( 1002/ UNKNOWN)   Gid: ( 1001/non-root-user)
writable check: NOT writable

The process runs as uid 1001 but the home directory is owned by uid 1002 on disk. The uid_map in the container is identity (1 1 N), so this is NOT a runtime namespace issue — the file literally has inode uid 1002 on the worker's btrfs.

Image tar layer inspection confirms the layer header has the correct uid 1001:

$ tar -tzvf home-layer.tar
drwxr-x---  0 1001   1001        0  home/non-root-user/

So the +1 shift is introduced during extraction, not during image build.

Key observations

  • uid 1000 is unaffected: /home/ubuntu (uid 1000 in the same layer) is correctly uid 1000 on disk.
  • Only uid 1001 shifts to 1002: the shift is specific to this uid range.
  • Image content is identical between a working docker-image-resource-built image and a non-working oci-build-task-built image. Both have uid 1001 in the tar header.
  • image_resource: (inline fetch) works correctly: a fly execute task with image_resource: pointing at the same image digest sees uid 1001 correctly. Only image: <resource> (volume-based path) exhibits the bug.
  • The bug is on the btrfs worker: the inode on the btrfs subvolume has uid 1002, not 1001. The problem is in the extraction path, not at runtime.
Pinned by taylorsilva

Activity

  1. taylorsilva commented on Jun 12, 2026

    @taylorsilva
    Member

    Thanks for the report. I'll take a look at this since since it might affect how #9593 is implemented.

  2. moved this from Icebox to Backlog in Concourse Roadmapon Jun 12, 2026
  3. taylorsilva commented on Jun 15, 2026

    @taylorsilva
    Member

    I locally built and pushed the image with docker build. Used this test pipeline:

    resources:
      - name: img
        type: registry-image
        source:
          repository: docker.io/taylorsilva/issue404
          tag: latest
    
    jobs:
      - name: job
        plan:
          - get: img
          - task: ubuntu
            image: img
            config:
              platform: linux
              run:
                user: non-root-user
                path: bash
                args:
                  - -c
                  - |
                    set -x
                    env
                    echo $HOME
                    ls -lah $HOME
                    mkdir -p $HOME/.config/gcloud

    The build passed:

    Image Raw task output:
    + env
    PWD=/tmp/build/7804a56a
    HOME=/home/non-root-user
    USER=non-root-user
    ATC_EXTERNAL_URL=https://ci.concourse-ci.org
    SHLVL=1
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    _=/usr/bin/env
    + echo /home/non-root-user
    /home/non-root-user
    + ls -lah /home/non-root-user
    total 20K
    drwxr-x--- 2 non-root-user non-root-user 4.0K Jun 15 18:13 .
    drwxr-xr-x 4 root          root          4.0K Jun 15 18:13 ..
    -rw-r--r-- 1 non-root-user non-root-user  220 Feb 13 12:16 .bash_logout
    -rw-r--r-- 1 non-root-user non-root-user 3.7K Feb 13 12:16 .bashrc
    -rw-r--r-- 1 non-root-user non-root-user  807 Feb 13 12:16 .profile
    + ls -lah /home
    total 20K
    drwxr-xr-x 4 root          root          4.0K Jun 15 18:13 .
    drwxr-xr-x 1 root          root          4.0K Jun 15 18:13 ..
    drwxr-x--- 2 non-root-user non-root-user 4.0K Jun 15 18:13 non-root-user
    drwxr-x--- 2 ubuntu        ubuntu        4.0K Jun 15 18:13 ubuntu
    + mkdir -p /home/non-root-user/.config/gcloud
    

    Maybe it's an issue with building the image? Docker and oci-build-task both use buildx to create the container image.

    I'll try building and then using the image in a single job:

    resources:
      - name: build
        type: registry-image
        source:
          repository: docker.io/concourse/oci-build-task
          tag: latest
    
      - name: dockerfile
        type: mock
    
    jobs:
      - name: job
        plan:
          - in_parallel:
            - get: build
            - get: dockerfile
              params:
                create_files_via_params:
                  Dockerfile: |
                    FROM ubuntu
                    RUN useradd non-root-user --shell /bin/bash --create-home
    
          - task: build
            image: build
            privileged: true
            config:
              platform: linux
              inputs:
                - name: dockerfile
                  path: .
              outputs:
                - name: image
              params:
                UNPACK_ROOTFS: true
              run:
                path: build
    
          - task: ubuntu
            image: image
            config:
              platform: linux
              run:
                user: non-root-user
                path: bash
                args:
                  - -c
                  - |
                    set -x
                    env
                    echo $HOME
                    ls -lah $HOME
                    ls -lah /home
                    mkdir -p $HOME/.config/gcloud

    Same result as before, ownership is correct in the final task and build passes.

    Maybe the issue is with the registry-image extracting the rootfs? Feels unlikely at this point as we've separately tested that with the first pipeline, and tested oci-build-task with this second. I guess we can combine the two to see if anything changes. Feels unlikely at this point though.

    resources:
      - name: build
        type: registry-image
        source:
          repository: docker.io/concourse/oci-build-task
          tag: latest
    
      - name: image
        type: registry-image
        source:
          repository: docker.io/USER/issue404
          tag: latest
          username: USER
          password: PWD
    
      - name: dockerfile
        type: mock
    
    jobs:
      - name: build-push
        plan:
          - in_parallel:
            - get: build
            - get: dockerfile
              params:
                create_files_via_params:
                  Dockerfile: |
                    FROM ubuntu
                    RUN useradd non-root-user --shell /bin/bash --create-home
    
          - task: build
            image: build
            privileged: true
            config:
              platform: linux
              inputs:
                - name: dockerfile
                  path: .
              outputs:
                - name: image
              run:
                path: build
    
          - put: image
            no_get: true
            params:
              image: image/image.tar
    
      - name: use-img
        plan:
          - get: image
            passed: [build-push]
          - task: ubuntu
            image: image
            config:
              platform: linux
              run:
                user: non-root-user
                path: bash
                args:
                  - -c
                  - |
                    set -x
                    env
                    echo $HOME
                    ls -lah $HOME
                    ls -lah /home
                    mkdir -p $HOME/.config/gcloud

    Same result, everything works, there's no off-by-one UID for the new user.

    Just re-read the title and noted you have your workers using btrfs. Let's try everything again with that!

    I locally deployed a worker with CONCOURSE_BAGGAGECLAIM_DRIVER: btrfs and ran that last pipeline again. It still worked, couldn't reproduce it.

    @neddp I'm having no luck reproducing your issue even though you gave plenty of details. What version of Concourse are you on? Are there any other non-default settings on your worker? I did all my initial tests on 8.2.3 and did that last one with btrfs with the latest commit on master.

  4. moved this from Backlog to In progress in Concourse Roadmapon Jun 15, 2026
  5. neddp commented on Jun 16, 2026

    @neddp
    Author

    Hi @taylorsilva,

    Thank you for looking into this!

    We are using version 8.2.3 and I need to check the worker settings. In the meantime, I'll work on a minimal repro and repro back.

  6. moved this from In progress to Backlog in Concourse Roadmapon Jun 16, 2026
  7. neddp commented on Jun 22, 2026

    @neddp
    Author

    Hi @taylorsilva, I think I managed to isolate the issue with the help of Claude.

    Minimal reproduction

    Two registry-image resources fetched in in_parallel in the same job causes a uid shift on one of the image volumes:

    jobs:
      - name: probe-uid
        plan:
          - in_parallel:
            - get: img-a   # image with a non-root user at uid 1001
            - get: img-b   # any other registry-image resource
          - task: check
            image: img-a
            config:
              platform: linux
              run:
                user: non-root-user
                path: bash
                args: ["-c", "stat /home/non-root-user; [ -w /home/non-root-user ] && echo WRITABLE || echo NOT"]

    Result: /home/non-root-user is owned by an unexpected uid (shifted from 1001), not writable.

    Replace the in_parallel with sequential get steps, or fetch only img-a alone → correct uid, writable.

    Key observations

    • Single image get: correct uid ✓, writable ✓
    • Two images in in_parallel: uid shifted (+1 or +2 depending on worker state), not writable ✗
    • The bad uid is baked into the btrfs subvolume at extraction time and persists across runs until fly clear-resource-cache forces a fresh extraction
    • The shift amount is non-deterministic — we observed +1 and +2 across different runs on the same worker
    • The uid_map in all containers is 0 4294967294 1 / 1 1 4294967293 (identity for uid 1+), so this is not a runtime namespace issue — the wrong uid is physically on disk in the btrfs subvolume

    Environment

    • Concourse 8.2.4, btrfs baggageclaim driver
    • Worker runs as non-root (gdn-init owned by uid 65534 on the host)
  8. taylorsilva commented on Jun 22, 2026

    @taylorsilva
    Member

    Based on the info you provided I made this pipeline:

    resources:
      - name: img1
        type: registry-image
        source:
          repository: concourse/bash
          tag: latest
    
      - name: img2
        type: registry-image
        source:
          repository: chainguard/bash
          tag: latest
    
    jobs:
      - name: uid
        plan:
          - in_parallel:
              - get: img1
              - get: img2
          - task: img1
            image: img1
            config: &config
              platform: linux
              run:
                user: nonroot
                path: bash
                args:
                  - -c
                  - |
                    set -euo pipefail
                    set -x
                    whoami
                    ls -lah /home
                    echo "home is writeable?" > /home/nonroot/writeable
    
          - task: img2
            image: img2
            config: *config
    

    The two images I'm using are:

    These images are similar, but the concourse/bash one includes apk while chainguard's does not. Both have a nonroot user with the following entry in /etc/passwd:

    nonroot:x:65532:65532:Account created by apko:/home/nonroot:/bin/sh
    

    With this setup I was unable to reproduce the issue. /home/nonroot was properly owned by the nonroot user in both images:

    Image

    The only difference I see here is that my nonroot user has a higher UID than 1001.

    Let's go back to the Dockerfile you initially shared:

    FROM ubuntu
    RUN useradd notroot -u 1001 --shell /bin/bash --create-home

    Update user to notroot in my pipeline and see what happens.

    Image

    Still works. Not seeing shifted UID's here. I made sure I was using the btrfs driver on my worker too. I ran this multiple times, clearing resource cache, but couldn't get it to reproduce.


    I will point out that the registry-image does not do any chown'ing. The only place I know of that does this is in baggageclaim here: https://github.com/concourse/concourse/blob/4874cf0abe2aef98cab79431749f5a0c47e4b50e/worker/baggageclaim/uidgid/translator.go

    If there is a bug, I'd suspect it would be there, not in the registry-image.


    Are you able to make the images you used public? Or share their full Dockerfile content? I'm currently not sure what we're missing here. I think I've replicated your setup but clearly I'm still missing something.

    I did notice this final point in your last comment:

    Worker runs as non-root (gdn-init owned by uid 65534 on the host)

    The worker is not designed or tested to run as a non-root user. I'm not sure what you mean by this point here. I also don't think we ship a gdn-init binary. We ship the gdn binary and an init binary. I don't think we have a gdn-init binary anywhere though.

    More details about your worker setup may help:

    • Kernel version
    • Deployment method (Systemd? Bosh? K8s?)
  9. neddp commented on Jun 30, 2026

    @neddp
    Author

    Hi @taylorsilva,

    I'm still looking into this. Now I'm also unable to reproduce it, will report back once I have any progress.

    Thanks again for your time on this, I really appreciate it.

  10. neddp commented on Jul 24, 2026

    @neddp
    Author

    Hi @taylorsilva,

    I think I was able to find the root cause. It's not btrfs extraction - it's the way baggageclaim streams volumes between workers with tar without --numeric-owner, combined with workers that have divergent /etc/passwd (same username → different uid on each worker VM).

    Analysis with the help of AI:
    What was observed:

    • Image built by oci-build-task with a user non-root-user at uid 1001.
    • Consumed in a downstream job via image: <get-resource> (volume-mounted, not inline image_resource:).
    • Intermittently, $HOME on disk was owned by 1002 / 1003 / 1004 / 1005 (it crept up by one over several days), while /etc/passwd inside the image still said 1001. Process runs as 1001, can't write its own home → failure.

    Crucially:

    • It is driver-independent. We reproduced it on overlay (mountinfo confirmed overlay), not just btrfs. So it's not an extraction quirk of the btrfs driver.
    • uid drifts, gid is preserved (Uid: 1005 / Gid: 1001). A user-namespace remap would move both.
    • The worker's /proc/<worker>/uid_map is identity (0 0 4294967295), so baggageclaim's uid mapper isn't remapping 1001 - it maps 1001→1001.
    • The image is clean at build, in the registry, and on the worker that built it. It only drifts on a different worker after being streamed (streaming volume for image from worker <uuid>).

    Root cause

    baggageclaim streams volumes as tar archives. In worker/baggageclaim/volume/stream_in_out_linux.go, tarCmd builds:

    tar -C /dev/fd/3 -cf -   ...   # StreamOut
    tar -C /dev/fd/3 -xf -   ...   # StreamIn

    with no --numeric-owner. GNU tar therefore records the owner name in the header and re-resolves it against /etc/passwd on extraction. We confirmed this directly by tarring a streamed volume on the source worker:

    $ tar -cf - non-root-user | tar -tvf -
    drwxr-x--- jumpbox/bosh_sshers 0 ... non-root-user/     # <-- name, not 1001/1001

    On our BOSH-deployed workers the same set of named accounts exists on every worker, but each VM assigns them different uids (the uid ordering isn't stable across workers). For example jumpbox is uid 1001 on one worker and 1005 on another:

    uid source worker destination worker
    1001 jumpbox user-a
    1005 user-b jumpbox

    So a file owned by uid 1001 on the source is tarred as jumpbox, then restored to uid 1005 on the destination (where jumpbox = 1005). The image's passwd still says 1001 → mismatch → mkdir: Permission denied.

    This explains every property we saw: driver-independence, uid-only drift (the group bosh_sshers is fixed at gid 1001 on all our workers, so the group name resolves back to 1001 everywhere), the slow +1 climb (more host users added over time).

    Minimal reproduction (no Concourse needed)

    # SOURCE: uid 1001 is named 'non-root-user'
    useradd -u 1001 non-root-user
    mkdir -p /src && echo hi > /src/f && chown 1001:1001 /src/f
    
    # baggageclaim StreamOut: tar -cf  (NO --numeric-owner)
    tar -cf /tmp/vol.tar -C /src f
    tar -tvf /tmp/vol.tar          # header shows: non-root-user/non-root-user (name, not 1001)
    
    # DEST: different /etc/passwd — 'non-root-user' is uid 1005 here
    userdel non-root-user; useradd -u 1002 user-a; useradd -u 1005 non-root-user
    mkdir -p /dst
    tar -xf /tmp/vol.tar -C /dst    # -> /dst/f owned by 1005 (DRIFT)
    stat -c '%u:%g %n' /dst/f
  11. taylorsilva commented on Jul 24, 2026

    @taylorsilva
    Member

    Wow, okay, so the issue is when the worker's /etc/passwd on the host disk is different between workers. If we include --numeric-owner in our tar commands when streaming then we shouldn't have this issue anymore, right?

    Moving this issue over to the concourse/concourse repo.

  12. neddp commented on Jul 25, 2026

    @neddp
    Author

    Hi @taylorsilva,

    Thanks for following up with a PR. It's a small change and it should address the issue.

    I want to add a clarification. Our deployment is running on GCP and I found that we have compute SSH-key metadata entries. It appears those are added by the GCE guest agent on the VMs with no fixed uid and this is where the drift comes from.

    Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions