webfactory / ssh-agent

GitHub Action to setup `ssh-agent` with a private key
MIT License
1.19k stars 246 forks source link

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

Open Robert-DEMCON opened 7 months ago

Robert-DEMCON commented 7 months ago

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/ssh-agent@v0.8.0
      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.

sykhro commented 6 months ago

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.

ultimaweapon commented 6 months ago

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/ssh-agent@v0.9.0
      with:
        ssh-private-key: ${{ secrets.REDACED }}

The error:

     Updating git repository `ssh://git@github.com/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://git@github.com/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://git@github.com/REDACED/REDACED.git +refs/heads/*:refs/remotes/origin/* +HEAD:refs/remotes/origin/HEAD` (exit code: 128)
Error: Process completed with exit code 1.
Robert-DEMCON commented 6 months ago

@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/ssh-agent@v0.9.0
      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 ssh-agent@v0.8.)

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.

Galathius commented 6 months ago

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.

EdSabino commented 5 months ago

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