Issue
Let’s say you have a repository which has a private repository (submodule) inside it (dependency). You want to access this private repository in your CI/CD pipeline, but how?
Let’s dive into the solution.
Solution

In our case we have a public repository (parent) which has a private repository (submodule) inside it. The goal is to access the private repository in our CI/CD pipeline. We will use GitHub Actions as our CI/CD pipeline.
-
Generate SSH Key: Generate a new
ed25519SSH key pair without a passphrase. This key will be used to access the private repository. What ssh-agent doesn’t mention, is that the key must be generated with the-Coption, which is used to add a comment to the key. This comment should be the URL of the private repository you want to access. So in short, it should point to the private repository you want to access. -
Add Private Key to Parent Repository: Add the private key as a
Secretto the parent repository. This will allow theCI/CDpipeline to access the private key. Let’s name itSSH_PRIVATE_KEY. -
Add Public Key to Submodule: Add the public key to the
Deploy Keysof the private repository (submodule). This will allow theCI/CDpipeline to access the private repository using the private key. Name itDeploy Key. -
Configure CI/CD Pipeline: In the
deploy.yml, add the usage ofssh-agentto load the private key and then checkout the repository with the submodule usingSSH.In my case, it’s:
jobs: build: runs-on: ubuntu-22.04 steps: # start ssh-agent & load the key - name: Load SSH key uses: webfactory/ssh-agent@v0.9.1 with: ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} - name: Checkout source and submodules uses: actions/checkout@v4 with: fetch-depth: 0 submodules: recursive # here we load the submodule # ...