Skip to content

Checkout breaks symlinked gitconfig on self-hosted runner #650

Open
@msdrigg

Description

@msdrigg

I am running actions on a self-hosted runner and my $HOME/.gitconfig is symlinked somewhere else (thanks to https://github.com/anishathalye/dotbot). When I run github actions, I see that the following lines have been added to my gitconfig.

[http "https://github.com/"]
    extraheader = AUTHORIZATION: basic *** [it was a token]
[url "https://github.com/"]
    insteadOf = git@github.com:
    insteadOf = org-45189381@github.com:

I tracked this down to several lines in the self-hosted runner logs:

2021-12-04T01:29:22.8379527Z Switched to a new branch 'main'
2021-12-04T01:29:22.8380661Z Branch 'main' set up to track remote branch 'main' from 'origin'.
2021-12-04T01:29:22.8382186Z ##[endgroup]
2021-12-04T01:29:22.8383552Z ##[group]Setting up auth for fetching submodules
2021-12-04T01:29:22.8385435Z Copying '/home/user/.gitconfig' to '/home/user/.local/share/actions-runner/_work/_temp/1ccda36a-b42c-42b0-9664-29b4f1e31ba3/.gitconfig'
2021-12-04T01:29:22.8396391Z Temporarily overriding HOME='/home/user/.local/share/actions-runner/_work/_temp/1ccda36a-b42c-42b0-9664-29b4f1e31ba3' before making global git config changes
2021-12-04T01:29:22.8398638Z [command]/usr/bin/git config --global http.https://github.com/.extraheader AUTHORIZATION: basic ***
2021-12-04T01:29:22.8427546Z [command]/usr/bin/git config --global --unset-all url.https://github.com/.insteadOf
2021-12-04T01:29:22.8451850Z [command]/usr/bin/git config --global --add url.https://github.com/.insteadOf git@github.com:
2021-12-04T01:29:22.8473658Z [command]/usr/bin/git config --global --add url.https://github.com/.insteadOf org-45189381@github.com:
2021-12-04T01:29:22.8494913Z ##[endgroup]
2021-12-04T01:29:22.8496341Z ##[group]Fetching submodules
2021-12-04T01:29:22.8497466Z [command]/usr/bin/git submodule sync --recursive

It seems that when the checkout action copies $HOME/.gitconfig to temporarily modify it, it copies the symlink and so the changes propagate to the main file as well.

This is a big issue because the updated .gitconfig cannot push or pull any of my repos. So I have to constantly go back and edit the ~/.gitconfig to fix this problem.

Activity

msdrigg

msdrigg commented on Dec 8, 2021

@msdrigg
Author

Note the line in question is here

await io.cp(gitConfigPath, newGitConfigPath)

I am not familiar enough with github actions io to fix, but there needs to be some check if the file is a symlink and then copy the actual contents of the file rather than the symlink itself.

msdrigg

msdrigg commented on Dec 8, 2021

@msdrigg
Author

Looking at the source for @actions/io, it seems like there needs to be some check like this:

for lines here:

if (configExists) {
core.info(`Copying '${gitConfigPath}' to '${newGitConfigPath}'`)
await io.cp(gitConfigPath, newGitConfigPath)
} else {
await fs.promises.writeFile(newGitConfigPath, '')
}

if (configExists) {
  core.info(`Copying '${gitConfigPath}' to '${newGitConfigPath}'`)
  if ((await ioUtil.lstat(gitConfigPath)).isSymbolicLink()) {
    // get true link
    const symlinkFull: string = await ioUtil.readlink(srcFile)
    await io.cp(symlinkFull, newGitConfigPath)
  } else {
    await io.cp(gitConfigPath, newGitConfigPath)
  }
} else {
  await fs.promises.writeFile(newGitConfigPath, '')
}
linked a pull request that will close this issue on Dec 8, 2021
sdiebolt

sdiebolt commented on Apr 1, 2022

@sdiebolt

Thanks for pointing this out, I've been struggling for some time trying to understand why none of my repos were accessibe anymore: this was caused by the GitHub Actions runner modifying my symlinked .gitconfig file!

msdrigg

msdrigg commented on Apr 2, 2022

@msdrigg
Author

I made a pr but they dont seem too interested

beingminimal

beingminimal commented on Jun 29, 2022

@beingminimal

This Issue is open since last 7 months and @msdrigg has already submitted PR for the same and awaiting for review and merge.
It's an humble request to look into this issue and merge the changes. @thboop @TingluoHuang
Due to this issue, we are not able to setup Github Self hosted runner in our local environment. So for us it is blocker.

archon810

archon810 commented on Mar 27, 2024

@archon810

Does v4 solve this?

msdrigg

msdrigg commented on Mar 27, 2024

@msdrigg
Author

I am not self-hosting runners any more, but it doesn't look like it

await io.cp(gitConfigPath, newGitConfigPath)

(Same line as above that uses io.cp)

danielfrg

danielfrg commented on Nov 7, 2024

@danielfrg

I can confirm v4 doesnt solve the issue.

wespiard

wespiard commented on Jan 25, 2025

@wespiard

This is still causing problems for me, too.

williamsentl

williamsentl commented on Feb 8, 2025

@williamsentl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @archon810@wespiard@danielfrg@sdiebolt@msdrigg

      Issue actions

        Checkout breaks symlinked gitconfig on self-hosted runner · Issue #650 · actions/checkout