Add an internal GitHub repository as a backup GitOps remote¶
Your clone of the GitOps repo is configured with an origin
remote that
points to https://github.com/arrikto/deployments. To access this remote, you
have already configured your management environment with an SSH key provided by
Arrikto.
In order to add a Git remote for backup purposes, that also resides in GitHub, you need first to instruct SSH to select the proper key for each remote. This guide will help you extend your Git/SSH configuration so that you can specify the SSH key to use for the internal GitHub repository.
Overview
What You’ll Need¶
- A configured clone of the GitOps repository.
- A private SSH key that has access to your internal GitHub repository. You
can use either a:
- deployment key (see https://docs.github.com/en/developers/overview/managing-deploy-keys), or
- a personal SSH key (see https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account)
Procedure¶
Specify the name of your internal GitHub repository, for example:
root@rok-tools:/# export GIT_INTERNAL_REPO=internal/deploymentsCopy the private SSH key:
Open a terminal and run:
root@rok-tools:/# cat > /root/.ssh/id_rsa_internalThe above command will appear to hang while it is waiting for user input.
Copy the text from your private SSH key, including the
-----BEGIN OPENSSH PRIVATE KEY-----
and-----END OPENSSH PRIVATE KEY-----
lines.Paste the text into the terminal, including the
-----BEGIN OPENSSH PRIVATE KEY-----
and-----END OPENSSH PRIVATE KEY-----
lines.Press ctrl-d to inform
cat
that there is no more input.Verify that
cat
has saved the key to/root/.ssh/id_rsa_internal
:root@rok-tools:/# ls /root/.ssh/id_rsa_internal
Set the correct permissions for the file:
root@rok-tools:/# chmod 400 /root/.ssh/id_rsa_internalGenerate the public SSH key based on your private key:
root@rok-tools:/# ssh-keygen -yf ~/.ssh/id_rsa_internal > ~/.ssh/id_rsa_internal.pubCreate an extra SSH configuration directory for user
root
, if it doesn’t exist:root@rok-tools:/# mkdir -p /root/.ssh/config.dAdd an SSH configuration file that instructs SSH to use the internal key when it connects to
internal.github.com
:root@rok-tools:/# cat > /root/.ssh/config.d/internal <<EOF > Host internal.github.com > Hostname github.com > IdentitiesOnly yes > IdentityFile /root/.ssh/id_rsa_internal > EOFNote
Host
is a dummy hostname that your Git remote will have, to force SSH use a specific key for it.Hostname
is the actual hostname that SSH will use for the connection.IdentitiesOnly
is a flag that makes SSH use only this specific key for this host.IdentityFile
is the location of the private SSH key.
Create the main SSH configuration file for user
root
, if it doesn’t exist:root@rok-tools:/# touch /root/.ssh/configExtend
/root/.ssh/config
with a directive that includes additional configuration files under the/root/.ssh/config.d
directory:root@rok-tools:/# grep -q '^Include config.d/*' /root/.ssh/config \ > || echo -en "\nInclude config.d/*" >> /root/.ssh/configRun
keychain
to start the SSH agent and use all your SSH identities:root@rok-tools:~# eval "$(keychain --eval id_rsa id_rsa_internal)" * keychain 2.8.2 ~ http://www.funtoo.org * Starting ssh-agent... * Adding 2 ssh key(s): /root/.ssh/id_rsa /root/.ssh/id_rsa_internal * ssh-add: Identities added: /root/.ssh/id_rsa /root/.ssh/id_rsa_internalTroubleshooting
can’t find id_rsa
If the above command shows the following warning message:
Warning: can't find id_rsa; skippingit means that keychain could not find the file
~/.ssh/id_rsa
, which normally contains your private SSH key.To proceed, follow the Configure Git guide to configure your private SSH key.
Cannot find public key for id_rsa
If the above command shows the following warning message:
Warning: Cannot find public key for id_rsait means that keychain clould not find the file
~/.ssh/id_rsa.pub
, which normally contains your public SSH key.To proceed, generate the public SSH key based on your private key:
root@rok-tools:~# ssh-keygen -yf /root/.ssh/id_rsa > /root/.ssh/id_rsa.pubWarning
Whenever you run a guide that runs the
keychain
command, do not forget to add your internal key as well. Use the following command instead of the one displayed in the instructions:root@rok-tools:~# eval "$(keychain --eval id_rsa id_rsa_internal)"Verify that you can connect to
github.com
with the Arrikto deployment key:root@rok-tools:/# ssh -T -o BatchMode=yes git@github.comYou should see the following message:
Hi arrikto/deployments! You've successfully authenticated, but GitHub does not provide shell access.Verify that you can connect to
internal.github.com
with your internal SSH key:root@rok-tools:/# ssh -T -o BatchMode=yes git@internal.github.comYou should see the same message as above, albeit with a different name than
arrikto/deployments
.Change your current directory to the one you cloned the GitOps repository to:
root@rok-tools:/# cd ~/ops/deploymentsCreate a Git remote named
internal
that points to the host you have added in the SSH configuration:root@rok-tools:~/ops/deployments# git remote add internal git@internal.github.com:${GIT_INTERNAL_REPO?}If the above command fails with:
fatal: remote internal already exists.then you already have a Git remote named
internal
. You can update the URL it points to:root@rok-tools:~/ops/deployments# git remote set-url internal git@internal.github.com:${GIT_INTERNAL_REPO?}
Ensure you have read access to all of the remotes:
root@rok-tools:~/ops/deployments# git fetch --all
Summary¶
You have successfully configured access to an internal GitHub repository in your management environment.
What’s Next¶
You can check out the rest of the maintenance operations that you can perform on your cluster.