Skip to content

Chown bind-mount volumes when running as non-root user - #9593

Merged
taylorsilva merged 9 commits into
masterfrom
403-chown
Jun 15, 2026
Merged

taylorsilva merged 9 commits into
masterfrom
403-chown

Conversation

@taylorsilva

@taylorsilva taylorsilva commented Jun 8, 2026 •

Copy link
Copy Markdown
Member

Changes proposed by this PR

closes #403

When a container runs as a non-root user, any input/output/cache volumes will be chown'd to the non-root user. This means every file and directory inside the volume will be owned by the non-root user, as well as the mount point the volume is mounted at inside the container. This will allow tasks running with non-root users to easily interact with volumes made from other steps that would previously remain owned by root. See the issue for workarounds users made. These workarounds should no longer be necessary after this change.

I'm labelling this as a breaking change since this is something Concourse will do automatically that may break existing workflows IF you're running tasks as a nonroot user. We can add an opt-out toggle in the future if deemed necessary. Based on #403 though, it seems like most users would appreciate the change proposed in this PR.

For anyone that runs stuff as root all the time, things should continue to work as-is.

This does introduce a potential footgun for any tasks that output a volume.

# this is a task config, I'm omitting most fields
platform: linux

outputs:
- name: some-output

run:
  user: nonroot

If the step(s) that follow this task run as root, they'll receive some-output unchanged. It won't be owned by root, it'll still be owned as nonroot. If the user doesn't exist in their container then they'll see the raw UID/GID of the nonroot user.

I made this pipeline to test some basic scenarios. All jobs pass when using this PR:

Click to expand and view pipeline
resources:
  - name: image
    type: mock
    source:
      mirror_self: true
    version:
      version: mock

  - name: version
    type: mock
    source:
      no_initial_version: true

jobs:
  - name: root
    plan:
      - get: image
      - task: root
        image: image
        config:
          platform: linux
          inputs:
            - name: image
          outputs:
            - name: empty
          run:
            path: bash
            args:
              - -c
              - |
                set -x
                whoami
                ls -lah .
                ls -lah /
                echo "hello world" > ./empty/file
                echo "hello image" > ./image/image

  - name: root-privileged
    plan:
      - get: image
      - task: root
        privileged: true
        image: image
        config:
          platform: linux
          inputs:
            - name: image
          outputs:
            - name: empty
          run:
            path: bash
            args:
              - -c
              - |
                set -x
                whoami
                ls -lah .
                ls -lah /
                echo "hello world" > ./empty/file
                echo "hello image" > ./image/image

  - name: nonroot
    plan:
      - get: image
      - task: nonroot
        image: image
        config:
          platform: linux
          inputs:
            - name: image
          outputs:
            - name: empty
          run:
            user: nonroot
            path: bash
            args:
              - -c
              - |
                set -x
                whoami
                ls -lah .
                ls -lah /
                echo "hello world" > ./empty/file
                echo "hello image" > ./image/image

  - name: nonroot-privileged
    plan:
      - get: image
      - task: nonroot
        privileged: true
        image: image
        config:
          platform: linux
          inputs:
            - name: image
          outputs:
            - name: empty
          run:
            user: nonroot
            path: bash
            args:
              - -c
              - |
                set -x
                whoami
                ls -lah .
                ls -lah /
                echo "hello world" > ./empty/file
                echo "hello image" > ./image/image

  - name: different-users
    plan:
      - get: image
      - task: nonroot
        image: image
        config:
          platform: linux
          outputs:
            - name: empty
          run:
            user: nonroot
            path: bash
            args:
              - -c
              - |
                set -x
                whoami
                ls -lah .
                echo "hello from nonroot" > ./empty/file

      - task: adm
        image: image
        config:
          platform: linux
          inputs:
            - name: empty
          outputs:
            - name: empty
          run:
            user: adm
            path: bash
            args:
              - -c
              - |
                set -x
                whoami
                ls -lah .
                ls -lah ./empty
                cat ./empty/file
                echo "hello from adm" > ./empty/file

      - task: daemon
        image: image
        config:
          platform: linux
          inputs:
            - name: empty
          run:
            user: daemon
            path: bash
            args:
              - -c
              - |
                set -x
                whoami
                ls -lah .
                ls -lah ./empty
                cat ./empty/file
                echo "hello from daemon" > ./empty/file

      - task: news
        image: image
        config:
          platform: linux
          inputs:
            - name: empty
          outputs:
            - name: empty
          run:
            user: news
            path: bash
            args:
              - -c
              - |
                set -x
                whoami
                ls -lah .
                ls -lah ./empty
                cat ./empty/file
                echo "hello from news" > ./empty/file

  - name: put
    plan:
      - get: image
      - task: nonroot
        image: image
        config:
          platform: linux
          outputs:
            - name: empty
          run:
            user: nonroot
            path: bash
            args:
              - -c
              - |
                set -x
                whoami
                ls -lah .
                ls -lah /
                echo "hello from nonroot" > ./empty/file
      - put: version
        params:
          file: empty/file

  - name: nonroot-to-root
    plan:
      - get: image
      - task: nonroot
        image: image
        config:
          platform: linux
          outputs:
            - name: empty
          run:
            user: nonroot
            path: bash
            args:
              - -c
              - |
                set -x
                whoami
                ls -lah .
                echo "hello from nonroot" > ./empty/file

      - task: root
        image: image
        config:
          platform: linux
          inputs:
            - name: empty
          run:
            user: root
            path: bash
            args:
              - -c
              - |
                set -x
                whoami
                ls -lah .
                ls -lah ./empty
                cat ./empty/file
                echo "hello from root" > ./empty/file
Details

was only referenced in the test suites and didn't expand on the
interface. Added an interface check since maybe that was the original
intention of adding that wrapper.

Signed-off-by: Taylor Silva <[email protected]>
The rootfs of the container is left as-is in all cases, but is still
namespaced.

When UID/GID are `-1` in the VolumeRequest, the volumes existing
owner/group are left as-is and namespaced to the containers user
namespace.

When UID/GID are >= 0, the volume is namespaced and chown'd to the
desired UID/GID.

Signed-off-by: Taylor Silva <[email protected]>
Signed-off-by: Taylor Silva <[email protected]>
Signed-off-by: Taylor Silva <[email protected]>
we get different timeout errors depending on which dependency is
inspecting the context

Signed-off-by: Taylor Silva <[email protected]>
@taylorsilva
taylorsilva requested a review from a team June 8, 2026 18:10
@taylorsilva

Copy link
Copy Markdown
Member Author

I added an integration test under the testflight suite that's a more refined version of the pipeline in my PR description, testing for specific folder permissions and ability to write to various volumes.

@taylorsilva taylorsilva added this to the v8.3.0 milestone Jun 11, 2026
@taylorsilva
taylorsilva merged commit c1b8e73 into master Jun 15, 2026
11 of 12 checks passed
@taylorsilva
taylorsilva deleted the 403-chown branch June 15, 2026 18:01
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.

When executing a task with non-root user, inputs should be owned by that user

1 participant