Skip to content

No support for custom SSH port #1315

Open
@dieselburner

Description

@dieselburner

Seems like github-server-url is dropping custom SSH port, while URL is valid:

- name: Check out repository code
  uses: actions/checkout@v3
  with:
    github-server-url: ssh://git@git.example.com:12345
    ssh-key: ${{ secrets.SSH_KEY }}

Excerpt from logs:

::save-state name=isPost::true
::add-matcher::/run/act/actions/actions-checkout@v3/dist/problem-matcher.json
Syncing repository: org/repo
::group::Getting Git version info
Working directory is '/org/repo'
[command]/usr/bin/git version
git version 2.30.2
::endgroup::
Temporarily overriding HOME='/tmp/9c8d9181-98bf-45f7-9d40-1aa261a81728' before making global git config changes
Adding repository directory to the temporary git global config as a safe directory
[command]/usr/bin/git config --global --add safe.directory /org/repo
::save-state name=setSafeDirectory::true
Deleting the contents of '/org/repo'
::save-state name=repositoryPath::/org/repo
::group::Initializing the repository
[command]/usr/bin/git init /org/repo
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint: 	git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint: 	git branch -m <name>
Initialized empty Git repository in /org/repo/.git/
[command]/usr/bin/git remote add origin git@git.example.com:org/repo.git
::endgroup::
::group::Disabling automatic garbage collection
[command]/usr/bin/git config --local gc.auto 0
::endgroup::
::group::Setting up auth
[command]/usr/bin/git config --local --name-only --get-regexp core\.sshCommand
[command]/usr/bin/git submodule foreach --recursive git config --local --name-only --get-regexp 'core\.sshCommand' && git config --local --unset-all 'core.sshCommand' || :
[command]/usr/bin/git config --local --name-only --get-regexp http\.https\:\/\/git\.example\.com\:10000\/\.extraheader
[command]/usr/bin/git submodule foreach --recursive git config --local --name-only --get-regexp 'http\.https\:\/\/git\.example\.com\:10000\/\.extraheader' && git config --local --unset-all 'http.https://git.example.com:10000/.extraheader' || :
::save-state name=sshKeyPath::/tmp/5d03bc11-c322-4924-b7e2-a72407dbb54c
::save-state name=sshKnownHostsPath::/tmp/5d03bc11-c322-4924-b7e2-a72407dbb54c_known_hosts
Temporarily overriding GIT_SSH_COMMAND="/usr/bin/ssh" -i "$RUNNER_TEMP/5d03bc11-c322-4924-b7e2-a72407dbb54c" -o StrictHostKeyChecking=yes -o CheckHostIP=no -o "UserKnownHostsFile=$RUNNER_TEMP/5d03bc11-c322-4924-b7e2-a72407dbb54c_known_hosts"
[command]/usr/bin/git config --local core.sshCommand "/usr/bin/ssh" -i "$RUNNER_TEMP/5d03bc11-c322-4924-b7e2-a72407dbb54c" -o StrictHostKeyChecking=yes -o CheckHostIP=no -o "UserKnownHostsFile=$RUNNER_TEMP/5d03bc11-c322-4924-b7e2-a72407dbb54c_known_hosts"
[command]/usr/bin/git config --local http.https://git.example.com:10000/.extraheader AUTHORIZATION: basic ***
::endgroup::
::group::Fetching the repository
[command]/usr/bin/git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin +7965e47f829dbbebb91cd74d815073ced5508a02:refs/remotes/origin/master
ssh: connect to host git.example.com port 22: Network is unreachable
fatal: Could not read from remote repository.
...

Activity

Aurgil

Aurgil commented on Jun 21, 2023

@Aurgil

I have the same problem

linked a pull request that will close this issue on Sep 7, 2023
freeware-superman

freeware-superman commented on Jan 22, 2024

@freeware-superman

Hi,
I have/had the same problem, but was able to fix it with a small hack: In a prior step I modify the ssh config to add a custom port. This is the config for that step.

Note: I'm using this on a gitea/act runner (running ubuntu:latest) so you might have to adjust it a little bit (e.g. paths). I also only tested it with v3, not any older or newer tags like v2 and v4.

    - name: Git Setup
      run: |
        mkdir -p ~/.ssh
        echo 'Host your_host_url ' >> ~/.ssh/config
        echo '    HostName your_host_url' >> ~/.ssh/config
        echo '    Port your_port' >> ~/.ssh/config
        cat  ~/.ssh/config

To use this, you have to replace your_host_url and your_port with, well, your host url and port respectively.
You could use this to also change the user using echo ' User your_user' >> ~/.ssh/config or any other settings that can be modified in a ssh config.

Explanation: mkdir makes sure that the folder .ssh exists. The echo commands append the needed config to the config file. If none exists it will be created automatically. cat prints the contents of the config file for verification. This last command can be left out.

jamesljlster

jamesljlster commented on Oct 18, 2024

@jamesljlster

Thank you, @freeware-superman!

With your suggestion, the checkout v4 action can be successfully run on my self-hosted Gitea instance.
Here is my minimal workflow configuration. I hope this helps someone.

jobs:
  Explore-Gitea-Actions:
    runs-on: ubuntu-latest
    steps:
      - name: Git Setup
        run: |
          mkdir -p ~/.ssh
          echo 'Host gitea.local' >> ~/.ssh/config
          echo '    HostName <gitea_ip>' >> ~/.ssh/config
          echo '    Port <gitea_ssh_port>' >> ~/.ssh/config
          cat  ~/.ssh/config
      - name: Check out repository code
        uses: actions/checkout@v4
        with:
          ssh-key: ${{ secrets.DEPLOY_KEY }}
          github-server-url: 'http://gitea.local'
          ssh-known-hosts: ${{ vars.SSH_KNOWN_HOSTS }}

Pre-requirements:

  • Create an SSH key pair to clone private repositories. Register the public key as a deploy key, and store the private key as a secret named DEPLOY_KEY.
  • In your Gitea instance, navigate to Admin Settings / Actions / Variables and add a variable named SSH_KNOWN_HOSTS. This prevents the SSH host key verification failed error.
joshmgross

joshmgross commented on Oct 21, 2024

@joshmgross
Contributor

I don't believe GHES allows changing the SSH Port - https://docs.github.com/en/enterprise-server@3.10/admin/configuring-settings/configuring-network-settings/network-ports#application-ports-for-end-users

We aren't able to support other git providers with this action at this time. We don't test compatibility with third-party solutions and thus can't maintain or support any features created exclusively for those third-parties.
#1242 (comment)

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

      @dieselburner@joshmgross@jamesljlster@Aurgil@freeware-superman

      Issue actions

        No support for custom SSH port · Issue #1315 · actions/checkout