Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run the job.container as the same user of the host VM by default #691

Open
felipecrs opened this issue Sep 2, 2020 · 6 comments
Open

Run the job.container as the same user of the host VM by default #691

felipecrs opened this issue Sep 2, 2020 · 6 comments
Labels
enhancement New feature or request Runner Feature Feature scope to the runner

Comments

@felipecrs
Copy link

Description

Run the containers as the same user running on the host (the VM) by default, or at least provide an option. The related docker option would be docker run --user "$(id -u):$(id -g)".

Containers job.container runs as the container's default user by default, which often is root. This causes some weird behaviors because the workspace on the GitHub runner is mounted to the container, and no other user (other than the Runner user) has permission to write on it. This is what makes @actions/checkout fail when running on containers.

As Jenkins does, this should be made by default. Users who might want to run as a different user can still use the --user docker option.

Workaround

As suggested by @xanantis:

jobs:
  configure:
    runs-on: ubuntu-latest
    outputs:
      uid_gid: ${{ steps.get-user.outputs.uid_gid }}
    steps:
      - id: get-user
        run: echo "::set-output name=uid_gid::$(id -u):$(id -g)"

  clone-and-install:
    needs: configure
    runs-on: ubuntu-latest
    container:
      image: mcr.microsoft.com/vscode/devcontainers/base:ubuntu
      options: --user ${{ needs.configure.outputs.uid_gid }}
    steps:
      - uses: actions/checkout@v2

It's even funny to have to do such a thing.

@felipecrs felipecrs added the enhancement New feature or request label Sep 2, 2020
EddCS added a commit to Sifchain/sifnode that referenced this issue Dec 2, 2020
nmdefries added a commit to cmu-delphi/forecast-eval that referenced this issue Aug 17, 2021
Some data files from a previous run of this action are created with root
as the owner. Because the action runs as a non-root user, such files are
[not able to be deleted](https://github.com/cmu-delphi/forecast-eval/runs/3351290227?check_suite_focus=true)
which is needed for the actions/checkout@v2 step
to install the newest version of the repo.

This seems to be a bug in the actions/checkout@v2 command, perhaps
specific to self-hosted workflows. [Summary of
issue](actions/runner#691) and [suggested
fixes[(actions/checkout#211).
yixinglu added a commit to yixinglu/nebula that referenced this issue Nov 8, 2021
Totktonada added a commit to tarantool/tarantool that referenced this issue Dec 12, 2021
AFAIK we anyway run self-hosted runners from root due to all those
problems like [1]. No reason to include the hack into every workflow
file. If we'll going to start runners from a non-root user, it is better
to pass `--user $PROPER_UID` to all docker jobs instead, see [2]: at
least it does not require to place a boilerplate into all workflow
files.

Didn't touch perf_* jobs: don't want to dig inside this part of the
infrastructure ATM.

It reverts PR #5953.

[1]: actions/checkout#211
[2]: actions/runner#691
locker pushed a commit to tarantool/tarantool that referenced this issue Dec 13, 2021
AFAIK we anyway run self-hosted runners from root due to all those
problems like [1]. No reason to include the hack into every workflow
file. If we'll going to start runners from a non-root user, it is better
to pass `--user $PROPER_UID` to all docker jobs instead, see [2]: at
least it does not require to place a boilerplate into all workflow
files.

Didn't touch perf_* jobs: don't want to dig inside this part of the
infrastructure ATM.

It reverts PR #5953.

[1]: actions/checkout#211
[2]: actions/runner#691
locker pushed a commit to tarantool/tarantool that referenced this issue Dec 22, 2021
AFAIK we anyway run self-hosted runners from root due to all those
problems like [1]. No reason to include the hack into every workflow
file. If we'll going to start runners from a non-root user, it is better
to pass `--user $PROPER_UID` to all docker jobs instead, see [2]: at
least it does not require to place a boilerplate into all workflow
files.

Didn't touch perf_* jobs: don't want to dig inside this part of the
infrastructure ATM.

It reverts PR #5953.

[1]: actions/checkout#211
[2]: actions/runner#691

(cherry picked from commit a0a2e8b)
ylobankov pushed a commit to tarantool/tarantool that referenced this issue Feb 7, 2022
AFAIK we anyway run self-hosted runners from root due to all those
problems like [1]. No reason to include the hack into every workflow
file. If we'll going to start runners from a non-root user, it is better
to pass `--user $PROPER_UID` to all docker jobs instead, see [2]: at
least it does not require to place a boilerplate into all workflow
files.

Didn't touch perf_* jobs: don't want to dig inside this part of the
infrastructure ATM.

It reverts PR #5953.

[1]: actions/checkout#211
[2]: actions/runner#691

(cherry picked from commit a0a2e8b)
yanshtunder pushed a commit to tarantool/tarantool that referenced this issue Feb 8, 2022
AFAIK we anyway run self-hosted runners from root due to all those
problems like [1]. No reason to include the hack into every workflow
file. If we'll going to start runners from a non-root user, it is better
to pass `--user $PROPER_UID` to all docker jobs instead, see [2]: at
least it does not require to place a boilerplate into all workflow
files.

Didn't touch perf_* jobs: don't want to dig inside this part of the
infrastructure ATM.

It reverts PR #5953.

[1]: actions/checkout#211
[2]: actions/runner#691
@ruvceskistefan ruvceskistefan added the Runner Feature Feature scope to the runner label Mar 16, 2022
@BlueskyFR
Copy link

Can reproduce, I know it's been 2 years now but is there any update?

@sulfasTor
Copy link

sulfasTor commented Jun 2, 2022

Description

Run the containers as the same user running on the host (the VM) by default, or at least provide an option. The related docker option would be docker run --user "$(id -u):$(id -g)".

Containers job.container runs as the container's default user by default, which often is root. This causes some weird behaviors because the workspace on the GitHub runner is mounted to the container, and no other user (other than the Runner user) has permission to write on it. This is what makes @actions/checkout fail when running on containers.

As Jenkins does, this should be made by default. Users who might want to run as a different user can still use the --user docker option.

Workaround

As suggested by @xanantis:

jobs:
  configure:
    runs-on: ubuntu-latest
    outputs:
      uid_gid: ${{ steps.get-user.outputs.uid_gid }}
    steps:
      - id: get-user
        run: echo "::set-output name=uid_gid::$(id -u):$(id -g)"

  clone-and-install:
    needs: configure
    runs-on: ubuntu-latest
    container:
      image: mcr.microsoft.com/vscode/devcontainers/base:ubuntu
      options: --user ${{ needs.configure.outputs.uid_gid }}
    steps:
      - uses: actions/checkout@v2

It's even funny to have to do such a thing.

This won't work if you have a pool of self-hosted runners and jobs are dispatched by different runners. ID's may mismatch.

@felipecrs
Copy link
Author

That's true.

@russellsch
Copy link

Does anyone have any suggestions for dealing with this on self-hosted runners?

@xanantis
Copy link

@russellsch There are two options for you:
Rootless Docker
Podman, with podman.socket enabled. You may have to create a symlink for /usr/bin/docker to /usr/bin/podman.

Before rootless docker was available and podman supported interaction over a socket, I used parameter injection to inject --user for create, exec, and run commands.

@jcelerier
Copy link

jcelerier commented Jun 9, 2024

any hope of seeing this little change one day ? there's no correct solution to this right now

schneems added a commit to heroku/docker-heroku-ruby-builder that referenced this issue Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Runner Feature Feature scope to the runner
Projects
None yet
Development

No branches or pull requests

7 participants