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

/github/home/.gitconfig does not exist for container runs #1169

Open
arbourd opened this issue Feb 11, 2023 · 15 comments
Open

/github/home/.gitconfig does not exist for container runs #1169

arbourd opened this issue Feb 11, 2023 · 15 comments

Comments

@arbourd
Copy link

arbourd commented Feb 11, 2023

Issue

If running a job that uses a container like the below, the file /github/home/.gitconfig will not exist, even after checkout runs a config command.

  example:
    runs-on: ubuntu-latest
    container:
      image: alpine

Here is a demo:

  1. Checkout runs, and runs /usr/bin/git config --global --add safe.directory /__w/sat/sat
  2. The global .gitconfig does not exist
  3. Any calls to git remain unsafe/dubious

The safe.directory settings set by the command git config --global --add safe.directory <path> is a no-op.

Workaround

Use the --system scope over --global:

$ git config --system --add safe.directory <path>
  example:
    runs-on: ubuntu-latest
    container:
      image: alpine

    steps:
      - uses: actions/checkout@v3
      - run: git config --system --add safe.directory <path>
kobaltcore added a commit to kobaltcore/renpyfmt that referenced this issue Feb 11, 2023
kobaltcore added a commit to kobaltcore/renpyfmt that referenced this issue Feb 11, 2023
* Print some debug information

* Try potential fix

Via actions/checkout#1169 (comment)

* Would be great if I didn't fat-finger the fix, rip

* Remove debug prints
fracpete added a commit to waikato-ufdl/waikato-ufdl.github.io that referenced this issue Feb 13, 2023
@destroyersrt
Copy link

I tried the workaround but it doesn't seem to work in my case.

image

image

@arbourd
Copy link
Author

arbourd commented Feb 15, 2023

I tried the workaround but it doesn't seem to work in my case.

image image

Try without the sudo? Might ahve something to do with the Slither action itself too and if it spins up containers.

@destroyersrt
Copy link

At first I tried without sudo but got permission denied error.

@destroyersrt
Copy link

slither-action had issue crytic/slither-action#50. Thanks.

jagot added a commit to attoyss2023/attoyss2023.github.io that referenced this issue Feb 16, 2023
jagot added a commit to attoyss2023/attoyss2023.github.io that referenced this issue Feb 16, 2023
kamikazechaser added a commit to grassrootseconomics/cic-custodial that referenced this issue Feb 20, 2023
Erope added a commit to Erope/nezha that referenced this issue Mar 1, 2023
facebook-github-bot pushed a commit to facebook/CacheLib that referenced this issue Mar 2, 2023
Summary:
1. Workaround for Debian Docker image bug that is breaking Debian build on GitHub (Explicitly mark Git repo as safe).
2. Pin zstd to a commit that resolves problems with older CMakes (note: affects all OSes, not just Debian)

Context for 1: In latest Debian Docker image , there is a regression that affects the checkout action.

From actions/checkout#1169:
> - Checkout runs, and runs /usr/bin/git config --global --add safe.directory <path>
> - The global .gitconfig does not exist
> - Any calls to git remain unsafe/dubious

The suggested workaround was to use --system instead of --global.

Pull Request resolved: #200

Test Plan: See if GitHub Action Debian build is fixed.

Reviewed By: therealgymmy

Differential Revision: D43720363

Pulled By: jaesoo-fb

fbshipit-source-id: 54f3586cc7f8e72045e60d8dd454c7a77725e6b2
@LecrisUT
Copy link

Should note that the workaround described here is only for container runs

ZeroChaos- added a commit to ZeroChaos-/pkgcheck-action that referenced this issue Jan 17, 2024
pkgcheck uses git for some of it's checks, however, the github.workspace
directory not being marked safe causes a failure
See also: actions/checkout#1169
See also: https://github.com/pentoo/pentoo-overlay/actions/runs/7560749313/job/20587445443
Closes: pkgcore#18
Signed-off-by: Zero_Chaos <[email protected]>
arthurzam pushed a commit to pkgcore/pkgcheck-action that referenced this issue Jan 17, 2024
pkgcheck uses git for some of it's checks, however, the github.workspace
directory not being marked safe causes a failure
See also: actions/checkout#1169
See also: https://github.com/pentoo/pentoo-overlay/actions/runs/7560749313/job/20587445443
Closes: #18
Signed-off-by: Zero_Chaos <[email protected]>
Closes: #19
Signed-off-by: Arthur Zamarin <[email protected]>
@theory
Copy link

theory commented Jan 20, 2024

I banged my head on what I think is this issue all day. Consider this config:

name: Test Git
on:
  push:
jobs:
  bundle:
    name: Git
    runs-on: ubuntu-latest
    container: alpine/git
    steps:
    - uses: actions/checkout@v4
    - run: git archive -v --format zip --prefix foo/ --output foo.zip HEAD

This results in this error:

fatal: detected dubious ownership in repository at '/__w/test-pgxn-tools/test-pgxn-tools'
To add an exception for this directory, call:

	git config --global --add safe.directory /__w/test-pgxn-tools/test-pgxn-tools

Shouldn't we be able to do Git stuff with the repo in a container? Curious, I tried changing the last line to:

    - run: git config safe.directory

It simply exits with no error message, as in this run:

Run git config safe.directory
  git config safe.directory
  shell: sh -e {0}
Error: Process completed with exit code 1.

Is that because the global config file is missing? I find it simply wild that there is no error message.

Anyway, I then tried setting the global config:

    - run: git config --global --add safe.directory "$PWD"

And that works. But I admit I'm pretty confused about why this isn't set up by default when an action starts.

So fine, I can manually put this line into my workflow YAML files, but I'm mystified as to why it's necessary. Is it this issue or am I missing something?

Thanks for bearing with my examples.

@theory
Copy link

theory commented Jan 20, 2024

It simply exits with no error message, as in this run:

FWIW I see the same error using actions/checkout@v3 in this build an using actions/checkout@v2 in this build. Color me confused.

@theory
Copy link

theory commented Jan 22, 2024

I'm fixing the issue in pgxn-tools by adding this line to the Dockerfile to disable the check inside the running container:

git config --system --add safe.directory '*'

Is there any reason that is likely to be a security issue?

@feltech
Copy link

feltech commented Aug 15, 2024

Thanks for this. Adding a step to our job with git config --system --add safe.directory $(pwd) works around the "dubious ownership" error.

For info, did a little experiment and added a step to print the id and owner of pwd - for some reason actions/checkout@v4 checks out the repo as user 1001, even though there is no such user in the container. Output from CI

Run id
  id
  ls -ld $(pwd)
  shell: sh -e {0}
uid=0(root) gid=0(root) groups=0(root)
drwxr-xr-x 7 1001 127 4096 Aug 15 15:40 /__w/OpenAssetIO-Test-CMake/OpenAssetIO-Test-CMake

For reference, the upstream change to git that performs the "dubious ownership" check appears to be git/git@f4aa8c8

cybersonik added a commit to cybersonik/github-stats that referenced this issue Aug 30, 2024
Add workaround for test-reporting issue [1169](actions/checkout#1169)
cybersonik added a commit to cybersonik/github-stats that referenced this issue Sep 7, 2024
Split job into macOS and Ubuntu specific jobs
Add concurrency setting to GHA so only one per branch will run at a time
Update GH actions to their latest versions
Replace setup-swift action with xcode-select-version-action and update
    to Xcode 16 on macOS
Build tests when building package
Use --skip testGetPullRequestsPerformance to not run long running tests
Set TEST_GITHUB_TOKEN environment variable at the swift test level
Update test-reporting path to new swift-testing results file path
Add workaround for test-reporting
    issue [1169](actions/checkout#1169)

Switch swift-testing package to use newly released v0.12.0

Update missed Swift Testing migration of XCTSkip to @suite(.disabled())
    in EndpointTests
Change testGetPullRequestsPerformance timeout to 3 minutes

TODO: Collapse macOS and Ubuntu jobs back into one
cybersonik added a commit to cybersonik/github-stats that referenced this issue Oct 23, 2024
Split job into macOS and Ubuntu specific jobs
Add concurrency setting to GHA so only one per branch will run at a time
Update GH actions to their latest versions
Update GH runner to latest Swift Ubuntu image
Update GH runner to macOS 15
Replace setup-swift action with xcode-select-version-action and update
    to Xcode 16 on macOS
Build tests when building package
Use --skip testGetPullRequestsPerformance to not run long running tests
Set TEST_GITHUB_TOKEN environment variable at the swift test level
Update test-reporting path to new swift-testing results file path
Add workaround for test-reporting
    issue [1169](actions/checkout#1169)

Switch swift-testing package to use newly released v0.12.0

Update missed Swift Testing migration of XCTSkip to @suite(.disabled())
    in EndpointTests
Change testGetPullRequestsPerformance timeout to 3 minutes

TODO: Collapse macOS and Ubuntu jobs back into one
cybersonik added a commit to cybersonik/github-stats that referenced this issue Oct 23, 2024
* test: Migrate to Swift Testing

Add swift-testing package to project
Upgrade devcontainer image to use nightly-6.0-jammy for swift-testing
    support on Linux
Convert the following XCTests to Swift Testing:
- RepoTests
- EndpointSessionTests
- EndpointTests

Move EndpointTests performance test into new EndpointPerformanceTests
    XCTestCase
Delete redundant GitHubStatsCore and associated XCTests

* test: Update GHA jobs to support new Swift Testing

Split job into macOS and Ubuntu specific jobs
Add concurrency setting to GHA so only one per branch will run at a time
Update GH actions to their latest versions
Update GH runner to latest Swift Ubuntu image
Update GH runner to macOS 15
Replace setup-swift action with xcode-select-version-action and update
    to Xcode 16 on macOS
Build tests when building package
Use --skip testGetPullRequestsPerformance to not run long running tests
Set TEST_GITHUB_TOKEN environment variable at the swift test level
Update test-reporting path to new swift-testing results file path
Add workaround for test-reporting
    issue [1169](actions/checkout#1169)

Switch swift-testing package to use newly released v0.12.0

Update missed Swift Testing migration of XCTSkip to @suite(.disabled())
    in EndpointTests
Change testGetPullRequestsPerformance timeout to 3 minutes

TODO: Collapse macOS and Ubuntu jobs back into one
ansasaki added a commit to ansasaki/rust-keylime that referenced this issue Dec 9, 2024
Instead of manually running the docker command to obtain the test image
and run, setup the CI job to run all steps on the CI container image.

This also set the current working directory as safe to workaround:
actions/checkout#1169

Signed-off-by: Anderson Toshiyuki Sasaki <[email protected]>
ansasaki added a commit to ansasaki/rust-keylime that referenced this issue Dec 9, 2024
Set the current working directory as safe to workaround:
actions/checkout#1169

Signed-off-by: Anderson Toshiyuki Sasaki <[email protected]>
@mxw-sec
Copy link

mxw-sec commented Jan 9, 2025

Any working arounds for this, I am seeing the same /github/home/.gitconfig doesn't exist message on Terraform-docs/gh-actions.

ericonr added a commit to lnls-dig/uhal that referenced this issue Jan 15, 2025
Use a matrix with jobs in order to parallelize running different tools.

The check for GITHUB_HEAD_REF is used so the same workflow works for PRs
and for branches.

We ignore some files with cppcheck due to issues with Catch2. An example
of an error generated by cppcheck with Catch2:

  util/tests/bits-test.cc:36:5: error: There is an unknown macro here
  somewhere. Configuration is required. If _catch_sr is a macro then
  please configure it. [unknownMacro]
    CHECK_THROWS_AS(clear_and_insert(reg, 1000U, range_mask), std::runtime_error);

The issue causing git-config(1) to be necessary is tracked in [1].

[1] actions/checkout#1169
ericonr added a commit to lnls-dig/uhal that referenced this issue Jan 15, 2025
Use a matrix with jobs in order to parallelize running different tools.

The check for GITHUB_HEAD_REF is used so the same workflow works for PRs
and for branches.

We ignore some files with cppcheck due to issues with Catch2. An example
of an error generated by cppcheck with Catch2:

  util/tests/bits-test.cc:36:5: error: There is an unknown macro here
  somewhere. Configuration is required. If _catch_sr is a macro then
  please configure it. [unknownMacro]
    CHECK_THROWS_AS(clear_and_insert(reg, 1000U, range_mask), std::runtime_error);

The issue causing git-config(1) to be necessary is tracked in [1].

[1] actions/checkout#1169
ericonr added a commit to lnls-dig/uhal that referenced this issue Jan 15, 2025
Use a matrix with jobs in order to parallelize running different tools.

The check for GITHUB_HEAD_REF is used so the same workflow works for PRs
and for branches.

We ignore some files with cppcheck due to issues with Catch2. An example
of an error generated by cppcheck with Catch2:

  util/tests/bits-test.cc:36:5: error: There is an unknown macro here
  somewhere. Configuration is required. If _catch_sr is a macro then
  please configure it. [unknownMacro]
    CHECK_THROWS_AS(clear_and_insert(reg, 1000U, range_mask), std::runtime_error);

The issue causing git-config(1) to be necessary is tracked in [1].

[1] actions/checkout#1169
ericonr added a commit to lnls-dig/uhal that referenced this issue Jan 15, 2025
Use a matrix with jobs in order to parallelize running different tools.

The check for GITHUB_HEAD_REF is used so the same workflow works for PRs
and for branches.

We ignore some files with cppcheck due to issues with Catch2. An example
of an error generated by cppcheck with Catch2:

  util/tests/bits-test.cc:36:5: error: There is an unknown macro here
  somewhere. Configuration is required. If _catch_sr is a macro then
  please configure it. [unknownMacro]
    CHECK_THROWS_AS(clear_and_insert(reg, 1000U, range_mask), std::runtime_error);

The issue causing git-config(1) to be necessary is tracked in [1].

Meson supports a clang-tidy target of its own, but it's not really
usable for our purposes [2].

[1] actions/checkout#1169
[2] mesonbuild/meson#2383
ericonr added a commit to lnls-dig/uhal that referenced this issue Jan 16, 2025
Use a matrix with jobs in order to parallelize running different tools.

The check for GITHUB_HEAD_REF is used so the same workflow works for PRs
and for branches.

We ignore some files with cppcheck due to issues with Catch2. An example
of an error generated by cppcheck with Catch2:

  util/tests/bits-test.cc:36:5: error: There is an unknown macro here
  somewhere. Configuration is required. If _catch_sr is a macro then
  please configure it. [unknownMacro]
    CHECK_THROWS_AS(clear_and_insert(reg, 1000U, range_mask), std::runtime_error);

The issue causing git-config(1) to be necessary is tracked in [1].

Meson supports a clang-tidy target of its own, but it's not really
usable for our purposes [2].

[1] actions/checkout#1169
[2] mesonbuild/meson#2383
ericonr added a commit to lnls-dig/uhal that referenced this issue Jan 16, 2025
Use a matrix with jobs in order to parallelize running different tools.

The check for GITHUB_HEAD_REF is used so the same workflow works for PRs
and for branches.

We ignore some files with cppcheck due to issues with Catch2. An example
of an error generated by cppcheck with Catch2:

  util/tests/bits-test.cc:36:5: error: There is an unknown macro here
  somewhere. Configuration is required. If _catch_sr is a macro then
  please configure it. [unknownMacro]
    CHECK_THROWS_AS(clear_and_insert(reg, 1000U, range_mask), std::runtime_error);

The issue causing git-config(1) to be necessary is tracked in [1].

Meson supports a clang-tidy target of its own, but it's not really
usable for our purposes [2].

[1] actions/checkout#1169
[2] mesonbuild/meson#2383
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

Successfully merging a pull request may close this issue.

8 participants