Is it possible to force actions/checkout
to use SSH rather than HTTPS?
#50130
-
Select Topic AreaQuestion BodyIs it possible to force Some of my actions on self-hosted runners encounter mistakes like
The repository is here: repo According to https://stackoverflow.com/questions/27087483/how-to-resolve-git-pull-fatal-unable-to-access-https-github-com-empty , one of the solutions is to use SSH instead of HTTPS when checking out the repo (unless we want to use a proxy, which we do not). The question is, how to force Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 8 replies
-
Yes, it is possible to force e.g. a sample code - name: Checkout code
uses: actions/checkout@v2
with:
repository: my-org/my-repo
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }} There doesn't seem to be anything inherently wrong with this workflow, but here are a few observations:
|
Beta Was this translation helpful? Give feedback.
-
Thank you @Anmol-Baranwal for the response and detailed suggestions. I will try it. |
Beta Was this translation helpful? Give feedback.
-
Hi @Anmol-Baranwal ! Sorry to bother you with another question. Is this workflow correct regarding the use of ssh key? workflow When running, it failed with Note that this flow is running on GitHub-hosted runners. Workflows on self-hosted runners do run correctly after adding ssh key as you said, for example, this workflow: workflow. Did I overlook something? Many thanks. |
Beta Was this translation helpful? Give feedback.
-
Hi @Anmol-Baranwal , your answer was indeed very helpful. However, I have not figured out how to make things work on GitHub-hosted runners yet. Here is a minimal working example: https://github.com/equipez/testkey Workflow file: https://github.com/equipez/testkey/blob/main/.github/workflows/test.yml A run with failure on ubuntu-latest and success on self-hosted (I hope you have access to the detailed log): https://github.com/equipez/testkey/actions/runs/4453061443/jobs/7821274009 You might like to have a look at it? Thanks. Best regards, |
Beta Was this translation helpful? Give feedback.
-
Follow up question on this : my git repo A need to access two other projects B and C. |
Beta Was this translation helpful? Give feedback.
Yes, it is possible to force
actions/checkout
to use SSH rather than HTTPS. You can specify the ssh-key input parameter toactions/checkout
, which will use the specified private key for authentication with GitHub. Here's an example of how to use it:e.g. a sample code
There doesn't seem to be anything inherently wrong with this workflow, but here are a few observations:
The
pull_request
trigger is commented out with a warning that it must be disabled for self-hosted runners. It's good to see that you are aware of the potential dangers of running untrusted…