question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:42
  • Comments:5

github_iconTop GitHub Comments

2reactions
sulfasTorcommented, 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.

0reactions
xanantiscommented, Dec 14, 2022

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Networking with standalone containers
Use user -defined bridge networks shows how to create and use your own custom bridge networks, to connect containers running on the same...
Read more >
Isolate containers with a user namespace
For containers whose processes must run as the root user within the container, you can re-map this user to a less-privileged user on...
Read more >
Configuring options to run your container
Go to the Create an instance template page. Go to Create an instance template. · In the Container section, select the Deploy a...
Read more >
Containers on Compute Engine
Software containers are a convenient way to run your apps in multiple isolated user-space instances. You can run containers on Linux or Windows...
Read more >
Define container jobs (YAML) - Azure Pipelines
Run pipeline jobs inside of a container. ... By default, jobs run on the host machine where the agent is installed.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found