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

fatal: unsafe repository (REPO is owned by someone else) in other workflow steps after running checkout #766

Open
thboop opened this issue Apr 14, 2022 · 9 comments

Comments

@thboop
Copy link
Contributor

thboop commented Apr 14, 2022

Description

Git recently pushed a change in response to a cve that causes git commands to fail if the parent directory changes ownership from the current directory. You may see errors like

  /usr/bin/git remote add origin https://github.com/wez/wezterm
  Error: fatal: unsafe repository ('/__w/wezterm/wezterm' is owned by someone else)

on self hosted runners, or if your job uses a container.

Workaround: Checkout is failing

This was fixed in the checkout action #760

Please update to the latest version of checkout. v3, v3.0.1, v2 and v2.4.1 all contain the fix for this issue. If you are still seeing the checkout action fail on these versions, please file an issue.

Workaround: Other steps are failing

Since we don't persist that configuration, you may still see this error if your job uses git commands outside of the checkout action. If so, you just need to set the configuration value yourself.

Simply set the GITHUB_WORKSPACE as a safe directory.

git config --global --add safe.directory "$GITHUB_WORKSPACE"

If your github workspace starts off with //, you may need to set it via

git config --global --add safe.directory "%(prefix)/$GITHUB_WORKSPACE"

If you are failing inside a container action, you will need to run this inside your container action script.

Why is the parent directory owned by a different user?

When the runner maps the working directory mounts into your job container or step container they are owned by the runner user, not the container user, causing this issue. While any folders created may be owned by the container user.

Why don't we persist the configuration we use in actions/checkout

We could try to persist this temporary global configuration we set in checkout for the duration of your job, but there are few problems with that:

  1. If you run checkout on the root machine, and you have a container action with git commands, you are still going to fail unless you set the config in that container, which checkout can't do for another step
  2. Overwriting the git global config and not persisting any changes back to the original global config may break some user expectations on self hosted runners.
  3. It only really addresses this issue for checkout users, but this is more of an actions ecosystem problem

Whats next

This is better solved at an actions ecosystem level, rather than solving it in the checkout action. That way, users not using checkout and users using container actions can take advantage of that solution. This is something our team is actively looking into now.

@me-and
Copy link

me-and commented Apr 14, 2022

@thboop I agree with everything you've written here, and thank you for getting the fix for this action sorted so quickly! I think I'm a little confused about why this ticket is here, though; should this be raised and tracked over at actions/runner?

@thboop
Copy link
Contributor Author

thboop commented Apr 14, 2022

@thboop I agree with everything you've written here, and thank you for getting the fix for this action sorted so quickly! I think I'm a little confused about why this ticket is here, though; should this be raised and tracked over at actions/runner?

🏅 Its a good point that this is more appropriate for the runner repository, however given the nature of this breaking workflows, and the overall concern and questions folks had about what is happening and why, I though I would put it closer to where we are seeing the most users comment about this issue. I may move it in the near future over to the runner repo.

JasonGross added a commit to JasonGross/fiat-crypto that referenced this issue Apr 14, 2022
JasonGross added a commit to JasonGross/fiat-crypto that referenced this issue Apr 14, 2022
JasonGross added a commit to JasonGross/fiat-crypto that referenced this issue Apr 14, 2022
rht added a commit to rht/zulip-archive that referenced this issue Apr 14, 2022
This commit:
- updates GH Actions checkout to v3
- apply additional work around stated in actions/checkout#766

This fixes the problem with the following error message:
```
fatal: unsafe repository ('/github/workspace' is owned by someone else)
To add an exception for this directory, call:

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

The problem is due to the security fix from the Git security vulnerability
recently announced:
https://github.blog/2022-04-12-git-security-vulnerability-announced/.

Relevant GH issue: actions/checkout#760
rht added a commit to rht/zulip-archive that referenced this issue Apr 14, 2022
This commit:
- updates GH Actions checkout to v3
- apply additional work around stated in actions/checkout#766

This fixes the problem with the following error message:
```
fatal: unsafe repository ('/github/workspace' is owned by someone else)
To add an exception for this directory, call:

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

The problem is due to the security fix from the Git security vulnerability
recently announced:
https://github.blog/2022-04-12-git-security-vulnerability-announced/.

Relevant GH issue: actions/checkout#760
rht added a commit to rht/zulip-archive that referenced this issue Apr 15, 2022
This commit:
- updates GH Actions checkout to v3
- apply additional work around stated in actions/checkout#766

This fixes the problem with the following error message:
```
fatal: unsafe repository ('/github/workspace' is owned by someone else)
To add an exception for this directory, call:

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

The problem is due to the security fix from the Git security vulnerability
recently announced:
https://github.blog/2022-04-12-git-security-vulnerability-announced/.

Relevant GH issue: actions/checkout#760
luispfonseca added a commit to luispfonseca/ecb-govc-calendar that referenced this issue Apr 15, 2022
rht added a commit to rht/zulip-archive that referenced this issue Apr 15, 2022
This commit:
- updates GH Actions checkout to v3
- apply additional work around stated in actions/checkout#766

This fixes the problem with the following error message:
```
fatal: unsafe repository ('/github/workspace' is owned by someone else)
To add an exception for this directory, call:

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

The problem is due to the security fix from the Git security vulnerability
recently announced:
https://github.blog/2022-04-12-git-security-vulnerability-announced/.

Relevant GH issue: actions/checkout#760
JasonGross added a commit to JasonGross/fiat-crypto that referenced this issue Apr 15, 2022
JasonGross added a commit to JasonGross/fiat-crypto that referenced this issue Apr 15, 2022
benefiction added a commit to benefiction/resume-reader that referenced this issue Apr 15, 2022
@JasonGross
Copy link

JasonGross commented Apr 15, 2022

Simply set the GITHUB_WORKSPACE as a safe directory.

git config --global --add safe.directory "$GITHUB_WORKSPACE"

It seems like this is insufficient if there are submodules? (log)

timabbott pushed a commit to zulip/zulip-archive that referenced this issue Apr 15, 2022
This commit:
- updates GH Actions checkout to v3
- apply additional work around stated in actions/checkout#766

This fixes the problem with the following error message:
```
fatal: unsafe repository ('/github/workspace' is owned by someone else)
To add an exception for this directory, call:

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

The problem is due to the security fix from the Git security vulnerability
recently announced:
https://github.blog/2022-04-12-git-security-vulnerability-announced/.

Relevant GH issue: actions/checkout#760
JasonGross added a commit to mit-plv/fiat-crypto that referenced this issue Apr 15, 2022
JasonGross added a commit to mit-plv/fiat-crypto that referenced this issue Apr 15, 2022
joel-coffman added a commit to joel-coffman/latex-jhu.edu that referenced this issue May 9, 2023
Git 2.35.2 stops directory traversals when ownership changes from the
current user (in response to CVE-2022-24765). Consequently, executing
`git` fails in GitHub Actions for Debian Buster, which runs as a
container within Ubuntu, because the user context changes after
checking out the repository.

This change follows the checkout action's recommended workaround of
marking the repository ($GITHUB_WORKSPACE) as safe.

References

- actions/checkout#766
- actions/runner#2033

(cherry picked from joel-coffman/latex-incubator@5d84884)
vanshg added a commit to smileidentity/android that referenced this issue May 22, 2023
Git 2.35.2 stops directory traversals when ownership changes from the
current user (in response to CVE-2022-24765). Consequently, executing
`git` fails in GitHub Actions for Debian Buster, which runs as a
container within Ubuntu, because the user context changes after
checking out the repository.

This change follows the checkout action's recommended workaround of
marking the repository ($GITHUB_WORKSPACE) as safe.

References

- actions/checkout#766
- actions/runner#2033
vanshg added a commit to smileidentity/android that referenced this issue May 23, 2023
* Add missing quotes around version override

* Mark repository as safe after checkout

Git 2.35.2 stops directory traversals when ownership changes from the
current user (in response to CVE-2022-24765). Consequently, executing
`git` fails in GitHub Actions for Debian Buster, which runs as a
container within Ubuntu, because the user context changes after
checking out the repository.

This change follows the checkout action's recommended workaround of
marking the repository ($GITHUB_WORKSPACE) as safe.

References

- actions/checkout#766
- actions/runner#2033

* Don't use prebuilt action

* Set tag and message in env

* keystore upload password

* Manually bumped version

* Allow for automatic release
guyer added a commit to usnistgov/Docs4NIST that referenced this issue May 25, 2023
guyer added a commit to usnistgov/sphinx-action that referenced this issue May 25, 2023
@rtxa
Copy link

rtxa commented Jul 12, 2023

If you use a Docker container, downgrading to actions/checkout@v1 also fixes the issue. Not sure why isn't mentioned...

guyer added a commit to usnistgov/Docs4NIST that referenced this issue Jul 13, 2023
guyer added a commit to usnistgov/Docs4NIST that referenced this issue Jul 13, 2023
JasonGross added a commit to coq-community/coq-performance-tests that referenced this issue Sep 25, 2023
JasonGross added a commit to coq-community/coq-performance-tests that referenced this issue Sep 25, 2023
JasonGross added a commit to coq-community/coq-performance-tests that referenced this issue Sep 25, 2023
hsaunders1904 added a commit to aurora-multiphysics/hippo that referenced this issue Sep 27, 2023
When attempting to run the pre-commit hooks in the CI, we get this
error:

An error has occurred: FatalError: git failed. Is it installed, and are you in a Git repository directory?

actions/checkout#766 suggests the issue could
be because 'actions/checkout' clones the repository as a different user
than is used in our custom docker container. Git then doesn't trust the
repository and errors when called upon.
hsaunders1904 added a commit to aurora-multiphysics/hippo that referenced this issue Oct 10, 2023
When attempting to run the pre-commit hooks in the CI, we get this
error:

An error has occurred: FatalError: git failed. Is it installed, and are you in a Git repository directory?

actions/checkout#766 suggests the issue could
be because 'actions/checkout' clones the repository as a different user
than is used in our custom docker container. Git then doesn't trust the
repository and errors when called upon.
rickstaa added a commit to rickstaa/action-update-semver that referenced this issue Nov 7, 2023
This commit applies a hotfix for a upstream bug in
[checkout/issues/766](actions/checkout#766).
rickstaa added a commit to rickstaa/action-update-semver that referenced this issue Nov 7, 2023
This commit applies a hotfix for a upstream bug in
[checkout/issues/766](actions/checkout#766).
rickstaa added a commit to rickstaa/action-update-semver that referenced this issue Nov 7, 2023
This commit applies a hotfix for a upstream bug in
[checkout/issues/766](actions/checkout#766).
rickstaa added a commit to rickstaa/action-update-semver that referenced this issue Nov 7, 2023
This commit applies a hotfix for a upstream bug in
[checkout/issues/766](actions/checkout#766).
rickstaa added a commit to rickstaa/action-update-semver that referenced this issue Nov 7, 2023
This commit applies a hotfix for a upstream bug in
[checkout/issues/766](actions/checkout#766).
rickstaa added a commit to rickstaa/action-update-semver that referenced this issue Nov 7, 2023
This commit applies a hotfix for a upstream bug in
[checkout/issues/766](actions/checkout#766).

Co-authored-by: rickstaa <rickstaa@users.noreply.github.com>
@dave-code-ruiz
Copy link

dave-code-ruiz commented Nov 30, 2023

I fixed it with :

git config --global --add safe.directory "*"

but i dont know if it is the correct way

andi34 pushed a commit to andi34/mkdocs-deploy-gh-pages that referenced this issue Jan 17, 2024
More information here: actions/checkout#766

Signed-off-by: Pascal Iske <info@pascaliske.dev>
@x-mass
Copy link

x-mass commented Jan 22, 2024

Even the action marks path as a safe directory, it overrides HOME env before. This was made intentionally (link). I don't know the exact reason though. When you run next step within workflow, HOME env is reset, and the dir becomes unsafe.
Here is a minimal example showing that changing HOME env makes the difference:

Example Workflow
name: Example of Missing Safe Dir

on:
  pull_request:
    branches: [ master ]
  push:
    branches: [ master ]

jobs:
  test-git-config:
    runs-on: ubuntu-22.04
    container: ubuntu:jammy-20240111

    steps:
      - name: Install Git CLI
        run: |
          apt-get update
          apt-get install git -y

      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Test Git Configuration and Environment
        run: |
          # Test as is, fail
          echo "Testing git status command:"
          git status && echo success || echo fail

          # Save HOME value
          ORIGINAL_HOME=$HOME
          echo "Original HOME: $ORIGINAL_HOME"

          # Override HOME value, mark directory as safe
          export HOME=/tmp/newhome
          mkdir -p $HOME
          git config --global --add safe.directory /__w/checkout-action-issue/checkout-action-issue
          echo "Git config added in overridden HOME"

          # Test with overridden HOME, success
          echo "Testing git status command:"
          git status && echo success || echo fail

          # Reset HOME to original value
          export HOME=$ORIGINAL_HOME
          echo "HOME reset to original: $HOME"

          # Test again after resetting HOME
          echo "Testing git status command:"
          git status && echo success || echo fail

          # Mark directory as safe with original HOME
          git config --global --add safe.directory /__w/checkout-action-issue/checkout-action-issue

          # Test after marking directory as safe with original HOME, success
          echo "Testing git status command:"
          git status && echo success || echo fail
Output
Testing git status command:
fatal: detected dubious ownership in repository at '/__w/checkout-action-issue/checkout-action-issue'
To add an exception for this directory, call:

	git config --global --add safe.directory /__w/checkout-action-issue/checkout-action-issue
fail
Original HOME: /github/home
Git config added in overridden HOME
Testing git status command:
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
success
HOME reset to original: /github/home
Testing git status command:
fatal: detected dubious ownership in repository at '/__w/checkout-action-issue/checkout-action-issue'
To add an exception for this directory, call:

	git config --global --add safe.directory /__w/checkout-action-issue/checkout-action-issue
fail
Testing git status command:
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
success

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants