ssh-agent icon indicating copy to clipboard operation
ssh-agent copied to clipboard

Windows workflow fails with "Could not read from remote repository"

Open ghost opened this issue 2 years ago • 7 comments

My Github action succeeds on Linux but fails on Windows the error:

Error: fatal: Could not read from remote repository.
Full log:

Run actions/checkout@v3 Syncing repository: workspace/this-repo Getting Git version info Copying 'C:\Users\runneradmin.gitconfig' to 'D:\a_temp\f6554cfe-9833-4920-999d-5ed3c171452b.gitconfig' Temporarily overriding HOME='D:\a_temp\f6554cfe-9833-4920-999d-5ed3c171452b' before making global git config changes Adding repository directory to the temporary git global config as a safe directory "C:\Program Files\Git\bin\git.exe" config --global --add safe.directory D:\a\this-repo\this-repo Deleting the contents of 'D:\a\this-repo\this-repo' Initializing the repository Disabling automatic garbage collection "C:\Program Files\Git\bin\git.exe" config --local gc.auto 0 Setting up auth Fetching the repository Determining the checkout info Checking out the ref Setting up auth for fetching submodules Fetching submodules "C:\Program Files\Git\bin\git.exe" submodule sync "C:\Program Files\Git\bin\git.exe" -c protocol.version=2 submodule update --init --force --depth=1 Submodule 'tests/private-repo' (https://github.com/workspace/private-repo.git) registered for path 'tests/private-repo' Cloning into 'D:/a/this-repo/this-repo/tests/private-repo'... ssh: Could not resolve hostname key-97c23a776206be62d055b3c8c9b8a91b0da7e1aa77e4bb609aaec6076a5583e2.github.com: Name or service not known Error: fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists. Error: fatal: clone of 'https://github.com/workspace/private-repo.git' into submodule path 'D:/a/this-repo/this-repo/tests/private-repo' failed Failed to clone 'tests/private-repo'. Retry scheduled Cloning into 'D:/a/this-repo/this-repo/tests/private-repo'... ssh: Could not resolve hostname key-97c23a776206be62d055b3c8c9b8a91b0da7e1aa77e4bb609aaec6076a5583e2.github.com: Name or service not known Error: fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists. Error: fatal: clone of 'https://github.com/workspace/private-repo.git' into submodule path 'D:/a/this-repo/this-repo/tests/private-repo' failed Failed to clone 'tests/private-repo' a second time, aborting Error: The process 'C:\Program Files\Git\bin\git.exe' failed with exit code 1

My workflow file (with some bits redacted):

jobs:
  build:

    name: Pytest ${{ matrix.python-version }}, ${{matrix.os}}

    runs-on: ${{matrix.os}}

    strategy:
      fail-fast: true
      matrix:
        os: ["ubuntu-latest"]
        python-version: ["3.9", "3.10", "3.11"]
        include:
          - os: "windows-latest"
            python-version: "3.10"

    steps:
    - name: Place SSH private key to grant access to other repos
      uses: webfactory/[email protected]
      with:
          ssh-private-key: ${{ secrets.PRIVATE_KEY_FOR_PRIVATE_REPO }}
    - name: Recursively check out source code
      uses: actions/checkout@v3
      with:
        submodules: true

I also want to note I really like this tool! I am not entirely sure how well Windows is supported and if this should work at all.

Thanks.

ghost avatar Jan 25 '24 12:01 ghost

It's because of recursive submodules, see https://github.com/webfactory/ssh-agent/issues/130#issuecomment-1284043999

The workaround is to use the checkout action, init submodules manually, use this action, clone submodules manually.

sykhro avatar Feb 20 '24 14:02 sykhro

I also having the same issue on Windows without submodules: true on actions/checkout after upgraded from v0.7.0 to v0.9.0. It is working fine on Linux. My Windows workflow:

name: Development Build
on:
  push:
    branches:
    - dev
  pull_request:
    branches:
    - dev
env:
  CARGO_NET_GIT_FETCH_WITH_CLI: true
concurrency: ${{ github.ref }}
permissions:
  contents: read
  id-token: write
jobs:
  windows:
    name: Build (Windows)
    runs-on: windows-latest
    steps:
    - name: Checkout source
      uses: actions/checkout@v4
    - name: Set up SSH agent
      uses: webfactory/[email protected]
      with:
        ssh-private-key: ${{ secrets.REDACED }}

The error:

     Updating git repository `ssh://[email protected]/REDACED/REDACED.git`
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
error: failed to get `REDACED` as a dependency of package `REDACED v0.1.0 (D:\a\REDACED\REDACED\REDACED\REDACED)`
Caused by:
  failed to load source for dependency `REDACED`
Caused by:
  Unable to update ssh://[email protected]/REDACED/REDACED.git#aa65b327
Caused by:
  failed to clone into: C:\Users\runneradmin\.cargo\git\db\REDACED-aaa97381c1f720a7
Caused by:
  process didn't exit successfully: `git fetch --tags --force --update-head-ok ssh://[email protected]/REDACED/REDACED.git +refs/heads/*:refs/remotes/origin/* +HEAD:refs/remotes/origin/HEAD` (exit code: 128)
Error: Process completed with exit code 1.

ultimaweapon avatar Feb 21 '24 07:02 ultimaweapon

@sykhro thanks for your suggestion. It's still not working for me on Windows though. I now have the following workflow (again some bits are redacted):

jobs:
  build:

    name: Pytest ${{ matrix.python-version }}, ${{matrix.os}}

    runs-on: ${{matrix.os}}

    strategy:
      fail-fast: true
      matrix:
        os: ["ubuntu-latest"]
        python-version: ["3.9", "3.10", "3.11"]
        include:
          - os: "windows-latest"
            python-version: "3.11"

    steps:
    - name: Check out source code
      uses: actions/checkout@v4
    - name: Place SSH private key to grant access to other repos
      uses: webfactory/[email protected]
      with:
          ssh-private-key: ${{ secrets.PRIVATE_KEY_FOR_PRIVATE_REPO }}
    - name: Get submodules
      run: |
        git submodule init
        git submodule update

(Same results with checkout@v3 and [email protected].)

Full log of the submodule step:

##[debug]Evaluating condition for step: 'Get submodules' ##[debug]Evaluating: success() ##[debug]Evaluating success: ##[debug]=> true ##[debug]Result: true ##[debug]Starting: Get submodules ##[debug]Loading inputs ##[debug]Loading env Run git submodule init ##[debug]C:\Program Files\PowerShell\7\pwsh.EXE -command ". 'D:\a_temp\a8480a0d-975f-459f-9832-b07bd72e2dee.ps1'" Submodule 'tests/private-repo' (https://github.com/org/private-repo.git) registered for path 'tests/private-repo' Cloning into 'D:/a/repo/repo/tests/private-repo'... Host key verification failed. fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists. fatal: clone of 'https://github.com/org/private-repo.git' into submodule path 'D:/a/repo/repo/tests/private-repo' failed Failed to clone 'tests/private-repo'. Retry scheduled Cloning into 'D:/a/repo/repo/tests/private-repo'... Host key verification failed. fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists. fatal: clone of 'https://github.com/org/private-repo.git' into submodule path 'D:/a/repo/repo/tests/private-repo' failed Failed to clone 'tests/private-repo' a second time, aborting Error: Process completed with exit code 1. ##[debug]Finishing: Get submodules

Looks like it's the same problem as @ultimaweapon

EDIT: replacing git submodule ... with cd <submodule> && git clone <url> . also fails on Windows with the same error as above.

Robert-DEMCON avatar Feb 26 '24 10:02 Robert-DEMCON

We have the same issue, changing ssh-agent version from 0.9.0 to 0.6.0 helps. Magically, if you change it back in the same PR to 0.9.0 – then it still works, but start failing on new PRs.

Galathius avatar Feb 29 '24 14:02 Galathius

I was reading the code, and i think the problem is the "homeSsh" variable which have the the root concat with /.ssh, but on windows path use "" instead of "/" so the ssh-agent are not finding the keys

EdSabino avatar Apr 18 '24 13:04 EdSabino