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

git config safe.directory inside docker containers #2033

Open
EdJoPaTo opened this issue Jul 30, 2022 · 9 comments
Open

git config safe.directory inside docker containers #2033

EdJoPaTo opened this issue Jul 30, 2022 · 9 comments
Labels
bug Something isn't working Runner Bug Bug fix scope to the runner

Comments

@EdJoPaTo
Copy link

EdJoPaTo commented Jul 30, 2022

Describe the bug

Recent versions of git require the .git folder to be owned by the same user. (as described here).

The actions/checkout action sets this for the cloned repo (/usr/bin/git config --global --add safe.directory …). Also see actions/checkout#766

Running a container (via uses: docker://…) however switches the user context and all git commands will fail with an error:

fatal: detected dubious ownership in repository at '/github/workspace'
To add an exception for this directory, call:

	git config --global --add safe.directory /github/workspace

Inspecting the docker run command the HOME variable is set and the home inside the container seems to be /github/home which is mapped to /home/runner/work/_temp/_github_home.
Creating the .gitconfig in this location before running the container resolves this problem:

- name: Fix git safe.directory in container
  run: mkdir -p /home/runner/work/_temp/_github_home && printf "[safe]\n\tdirectory = /github/workspace" > /home/runner/work/_temp/_github_home/.gitconfig

As these paths (HOME and PWD inside the container) are not stable and can be changed any time, the git config … logic should be done by the runner executing the docker command as its the only part in the process knowing these paths.

I do not think this is related to the images as the uses: docker:// logic is handled by the runner itself?

To Reproduce
Steps to reproduce the behavior:

Create this minimal workflow and let it run

on:
  push:

jobs:
  fails:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - uses: docker://docker.io/library/alpine:3.14
        with:
          entrypoint: /bin/ash
          args: -c "apk add git && git status"

(See above for the error message of the git command)

Expected behavior

The container should have a .gitconfig to run git commands normally like it is possible without container.
Stuff like the .git folder is mounted to the container too so a user can expect git to work fine.

Runner Version and Platform

Version of your runner? Hosted Runners on GitHub

@EdJoPaTo EdJoPaTo added the bug Something isn't working label Jul 30, 2022
@nikola-jokic nikola-jokic added the Runner Bug Bug fix scope to the runner label Aug 1, 2022
@nikola-jokic
Copy link
Contributor

Hi @EdJoPaTo,

Thank you for reporting this so clearly! I have applied appropriate labels and added this issue to the backlog ☺️

@mefistotelis
Copy link

Got the same issue, though in different scenario. My workaround was to just change owner of the directory after checkout:

jobs:
  ubuntu-gcc:
    runs-on: ubuntu-20.04
    name: "Linux Ubuntu"
    container:
      image: ubuntu:20.04
    env:
      DEBIAN_FRONTEND: noninteractive
      TZ: Etc/UTC
    steps:
      - name: Install GIT
        run: |
          # install GIT, as without it checkout would use REST API
          apt update
          apt install -y \
            git

      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Set ownership
        run: |
          # this is to fix GIT not liking owner of the checkout dir
          chown -R $(id -u):$(id -g) $PWD

hoefling added a commit to hoefling/xmlsec that referenced this issue Aug 20, 2022
hoefling added a commit to xmlsec/python-xmlsec that referenced this issue Aug 20, 2022
ILLIDOM added a commit to jalapeno-api-gateway/protorepo that referenced this issue Sep 5, 2022
@DanRStevens
Copy link

I've also encountered this issue when running my Docker images on GitHub Actions, and have been able to reproduce while running my container locally.

This seems to be more generally a problem with running a Docker container as the root user, while having data mounted for a regular user account. When testing locally, I can start my Docker container by adding the flag --user="$(id --user):$(id --group)" to the docker run command, and the error won't be shown. As an added bonus, any output generated by the build in the Docker container and written to the mounted folder will end up having correct ownership on the host system once I've exited the Docker container.

ldeluigi added a commit to ldeluigi/markdown-docs that referenced this issue Sep 9, 2022
@rleh rleh mentioned this issue Sep 29, 2022
10 tasks
qcastel added a commit to qcastel/github-actions-maven-release that referenced this issue Oct 4, 2022
As the gitconfig is edited, we hit actions/runner#2033

Fixing it by adding ` /github/workspace`  as safe.directory
vinmassaro added a commit to yalesites-org/yalesites-project that referenced this issue Oct 4, 2022
vinmassaro added a commit to yalesites-org/yalesites-project that referenced this issue Oct 4, 2022
vinmassaro added a commit to yalesites-org/yalesites-project that referenced this issue Oct 4, 2022
vinmassaro added a commit to yalesites-org/yalesites-project that referenced this issue Oct 4, 2022
UnstoppableMango added a commit to UnstoppableMango/the-cluster that referenced this issue Dec 19, 2023
ntsh-oni pushed a commit to ntsh-oni/Radium-Engine that referenced this issue Jan 24, 2024
hamzaremmal added a commit to hamzaremmal/scala3 that referenced this issue Feb 17, 2024
hamzaremmal added a commit to hamzaremmal/scala3 that referenced this issue Feb 17, 2024
hamzaremmal added a commit to scala/scala3 that referenced this issue Feb 17, 2024
…#19720)

Closes #19712 

This PR introduce a workaround for actions/runner#2033. This workaround
was already introduced in #19703 in some of the jobs.

`actions/checkout` has an issue filled about this too:
actions/checkout#1169
garyo added a commit to AcademySoftwareFoundation/openfx that referenced this issue Mar 3, 2024
The CI build issue was an "unsafe" git dir. actions/checkout@v4 is
supposed to fix that; see comments in
actions/runner#2033.

Signed-off-by: Gary Oberbrunner <[email protected]>
Kordyjan pushed a commit to scala/scala3 that referenced this issue Mar 6, 2024
Kordyjan pushed a commit to scala/scala3 that referenced this issue Mar 6, 2024
mattleff added a commit to bountonw/translate that referenced this issue Apr 22, 2024
Uses a technique documented at
actions/runner#2033 (comment) to
run the CI jobs as the `runner` user to fix a log error.
@blafasel42
Copy link

When using a github runner, the problem does not occur. I am using a container to run the action in. The same container and workflow config works with github runner but not with a self-hosted runner. Can anyone explain this? There is no .gitconfig in the container in both cases...

manxorist added a commit to OpenMPT/openmpt that referenced this issue Apr 29, 2024
[New] build: CI: GitHub: Add Fedora builder.
........
[Fix] build: CI: GitHub: Fedora: Fix xz dependency install.
........
[Fix] build: CI: GitHub: Fedora: Workaround GitHub quirks. See <dorny/test-reporter#131 (comment)> and <actions/runner#2033>.
........
[Imp] build: CI: GitHub: Fedora: Add matrix build for dependencies.
........
[New] build: CI: GitHub: Add Fedora Autotools builder.
........
[New] build: CI: GitHub: Add Fedora MinGW cross-compile builder.
........


git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.31@20689 56274372-70c3-4bfc-bfc3-4c3a0b034d27
TheJiahao added a commit to TheJiahao/TheJiahao.github.io that referenced this issue May 30, 2024
zjp added a commit to RBVI/ChimeraX that referenced this issue Aug 12, 2024
Due to a known bug in actions (actions/runner#2033) the user inside
the docker container doesn't have ownership over the repo and adding
the directory as safe is ineffective.
wiktor-k added a commit to wiktor-k/currencies that referenced this issue Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Runner Bug Bug fix scope to the runner
Projects
None yet
Development

No branches or pull requests

11 participants