Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple GitHub SSH deploy keys #568

Merged

Conversation

eronnen
Copy link
Contributor

@eronnen eronnen commented Sep 6, 2023

This PR's goal is to solve #340, hope it can be a good enough of a solution :)

Background

The webfactory/ssh-agent action handles the issue of authenticating with multiple SSH deploy keys to Github by adding the multiple public keys to the .ssh folder with custom file names, and then using them accordingly by adding url.*.insteadOf git configs.

The problem is that these git configs as well as the SSH public keys are not uploaded to the container, so this mirroring doesn't work in the build.

Changes

  • add sshPublicKeysDirectoryPath input, which is a custom .ssh that should contain the public keys and config file.
  • pass a GIT_CONFIG_EXTENSIONS environment variable to the container, which is a list of key=values configs that can be retrieved from git config --list that the git inside the container will use.

Usage

With these changes, it's possible to fix the multiple SSH keys issue by using the following steps:

- uses: webfactory/ssh-agent@v0.8.0
  with:
  ssh-private-key: |
    ${{ secrets.FIRST_KEY }}
    ${{ secrets.NEXT_KEY }}
    ${{ secrets.ANOTHER_KEY }}

- name: Prepare SSH config for unity builder
  run: |
    mkdir $HOME/.ssh_docker
    cp $HOME/.ssh/config $HOME/.ssh_docker/
    cp $HOME/.ssh/key* $HOME/.ssh_docker/
    cp $HOME/.ssh/known_hosts $HOME/.ssh_docker/
    sed -i 's/\/home\/runner/\/root/g' $HOME/.ssh_docker/config
    sudo chown -R root:root $HOME/.ssh_docker
    GIT_CONFIG_EXTENSIONS=$(git config --list | grep '^url\.')
    {
      echo 'GIT_CONFIG_EXTENSIONS<<EOF'
      echo "$GIT_CONFIG_EXTENSIONS"
      echo EOF
    } >> "$GITHUB_ENV"
  shell: bash

- uses: game-ci/unity-builder@v3
  ...
  with:
    sshAgent: ${{ env.SSH_AUTH_SOCK }}
    sshPublicKeysDirectoryPath: ${{ env.HOME }}/.ssh_docker

Checklist

  • Read the contribution guide and accept the
    code of conduct
  • Docs (If new inputs or outputs have been added or changes to behavior that should be documented. Please make
    a PR in the documentation repo)
  • Readme (updated or not needed)
  • Tests (added, updated or not needed)

…hat adds git configs and mounts .ssh/config and public keys to the container, in order to allow multiple sh deploy key trick by webplatform@ssh-agent
@github-actions
Copy link

github-actions bot commented Sep 6, 2023

Cat Gif

@codecov-commenter
Copy link

codecov-commenter commented Sep 6, 2023

Codecov Report

Merging #568 (779fd3a) into main (a073719) will increase coverage by 0.00%.
The diff coverage is 28.57%.

❗ Current head 779fd3a differs from pull request most recent head f96046d. Consider uploading reports for the commit f96046d to get more accurate results

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the GitHub App Integration for your organization. Read more.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #568   +/-   ##
=======================================
  Coverage   36.96%   36.96%           
=======================================
  Files          77       77           
  Lines        3033     3038    +5     
  Branches      637      641    +4     
=======================================
+ Hits         1121     1123    +2     
- Misses       1912     1915    +3     
Files Changed Coverage Δ
src/model/build-parameters.ts 89.39% <ø> (ø)
src/model/docker.ts 10.63% <0.00%> (-0.73%) ⬇️
src/model/input.ts 90.75% <100.00%> (+0.15%) ⬆️

Copy link
Member

@webbertakken webbertakken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach looks elegant enough if you ask me.

What do you think @GabLeRoux @davidmfinol @AndrewKahr?

${sshAgent ? `--volume ${sshAgent}:c:/ssh-agent` : ''} \
${
sshAgent && !sshPublicKeysDirectoryPath
? `--volume c:/Users/Administrator/.ssh/known_hosts:c:/root/.ssh/known_hosts`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain where c:/root comes from? Have you tested that this works?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested only for linux runner, tried to port to windows as best as I can...
but looking at it again seems that sshAgent isn't used in Windows anyway so probably I should remove these windows changes enitrely

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea better to have working software with missing features than the added complexity of a non working piece of which nobody knows how much of it was intended to work.

Thanks.

@davidmfinol
Copy link
Member

Looks good to me.
Just need to raise a PR to update the docs page as well: https://github.com/game-ci/documentation/blob/main/docs/03-github/04-builder.mdx

@eronnen
Copy link
Contributor Author

eronnen commented Sep 6, 2023

Thank you for the response!

added complementary documentation and unity-test-runner PRs:

@webbertakken webbertakken merged commit 2190fd5 into game-ci:main Sep 6, 2023
31 checks passed
BryanLeongMBG added a commit to MightyBear/unity-builder that referenced this pull request Sep 20, 2023
* add sshPublicKeysDirectoryPath and GIT_CONFIG_EXTENSIONS parameters that adds git configs and mounts .ssh/config and public keys to the container, in order to allow multiple sh deploy key trick by webplatform@ssh-agent

* remove sshPublicKeysDirectoryPath and GIT_CONFIG_EXTENSIONS from windows runner for now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants