Compare Solutions for Checkout Additional Repo in CI/CD

In many cases, you need the content of another private repository to test the current repository. For example, your main repository is a public repo, but you need a secret config file from a private repository, how do you securely setup your CI/CD environment?

Assume:

  • your github organization account = MyORG

Goal:

  1. Your main repo’s CI/CD environment should be able to check out the private repo.

  2. Anyone who has access to the public repo should not able to access anything from the private repo.

Solution 2 (We have to trust 3rd party CICD)

You can grant CI/CD GitHub User Key of your GitHub account (in CircleCI, it is at Project settings -> Checkout SSH Keys -> Authorize with GitHub`. In other words, you grant your CI/CD system equivalent power as your GitHub Account.

Pro:

  • Convenient and fast.

Con:

  • If your CI/CD environment been hacked, then the hacker can do everything you can do.

Reference:

Solution 3 (Too much work)

  1. Manually create a ssh key pair, paste the public key to Repository Setting -> Deploy Key -> Add new Key.

  2. Use a hacky way to include the private key into CICD system, put it at $HOME/.ssh.id_rsa_deploy_key or specify that key for git clone command.

Reference:

Pro:

  • per repo / per ssh level of grained access.

Con:

  • Too much work to setup everything, especially managing and injecting the private key.

Reference:

Solution 4 (Doable)

Use bash script to use ssh agent to create a temp key pair in CICD system, add the public key to Github repo via Github Oauth API, and use that key pair to ssh git clone the repo.

Since you could set Personal Access Token to admin:public_key only, so you can securely use that token in your CICD system to dynamically upload public_key.

Con:

  • Still much setup in your CICD scripts.

Reference: