Troubleshooting Git SSH Clone Issues with Submodules on Different Hosts

When cloning a Git repository that contains submodules from another server using SSH, I encounter an error:

Host key verification failed. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

The repository is hosted on Server A, but it includes submodules cloned from Server B.

How can I resolve this issue?

To overcome the host key verification failure when cloning a Git repository with submodules using SSH, you can override the installer’s known_hosts file by creating a custom Docker image.

Here are the steps to follow:

  1. Create a new directory and navigate into it.

  2. Create a Dockerfile in this directory with the following content:

    FROM okteto/pipeline-runner:1.0.4
    COPY --chmod=0600 known_hosts /root/.ssh/known_hosts
    
  3. Run the command below to generate and save the SSH host keys for your repository to a file named known_hosts:

    ssh-keyscan gitsubmodule.server.domain -p 2222 > known_hosts
    

    Replace gitsubmodule.server.domain with the actual hostname or IP address of Server B, and 2222 with the port number used for SSH connections.

  4. Build the Docker image and push it to a container registry accessible by your Kubernetes cluster:

    docker build -t <your-container-registry.com/path/to/your/image>:tag_name .
    
  5. Update your Okteto self-hosted Helm release values with the following snippet and upgrade your installation:

    installer:
      runner: <your-container-registry.com/path/to/your/image>:tag_name
    

By following these steps, you should be able to resolve the host key verification issue and successfully clone your Git repository with submodules using SSH.