From 5185d87f83b6f8f433c718bf0db58842a7c1b77b Mon Sep 17 00:00:00 2001 From: Michael Lin Date: Tue, 24 Sep 2024 15:58:37 -0700 Subject: [PATCH] Update ssh repo clone docs --- docs/admin/code_hosts/aws_codecommit.mdx | 18 ++++++++++++ docs/admin/repo/auth.mdx | 37 ++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/docs/admin/code_hosts/aws_codecommit.mdx b/docs/admin/code_hosts/aws_codecommit.mdx index cc1fff525..5875fb8b1 100644 --- a/docs/admin/code_hosts/aws_codecommit.mdx +++ b/docs/admin/code_hosts/aws_codecommit.mdx @@ -87,6 +87,24 @@ To add CodeCommit repositories in Docker Container: 1. Follow the rest of the steps detailed in the [AWS SSH setup guide](https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-ssh-unixes.html) to make sure you can connect to the code host locally. 1. Confirm you have the connection by running the following ssh command locally: `ssh git-codecommit.us-west-1.amazonaws.com` (Update link with your server region) 1. Confirm you can clone the repository locally. + +### Configuring SSH credentials in the Web UI + +```json +{ + "gitURLType": "ssh", + "gitSSHKeyID": "", + "gitSSHCredential": { + // make sure the key is base64 encoded + // $ cat ~/.ssh/id_rsa | base64 + "privateKey": "", + "passphrase": "" + } +} +``` + +### Mounting SSH keys into the container + 1. Copy all the files at your `$HOME/.ssh directory` to `$HOME/.sourcegraph/config/ssh` directory. See [docs](/admin/deploy/docker-single-container/#ssh-authentication-config-keys-knownhosts) for more information about our ssh file system. 1. Read our [guide here](/admin/deploy/docker-compose/#git-ssh-configuration) for Docker Compose deployments 1. Read our [guide here](/admin/deploy/kubernetes/configure#ssh-for-cloning) for Kubernetes deployments diff --git a/docs/admin/repo/auth.mdx b/docs/admin/repo/auth.mdx index 1c0d77e9e..a3b293bc2 100644 --- a/docs/admin/repo/auth.mdx +++ b/docs/admin/repo/auth.mdx @@ -4,16 +4,47 @@ If authentication (HTTP(S) or SSH) is required to `git clone` a repository then First, ensure your **Site admin > Manage code hosts** code host configuration is configured to use SSH. For example, by setting the `gitURLType` field to "ssh". Alternatively, you may use the "Generic Git host" code host type, which allows you to directly specify Git repository URLs for cloning. -Then, follow the directions below depending on your deployment type: +Then, you need to supply the SSH keys and passphrase to Sourcegraph if applicable. You have two options: + +- **Option 1**: Configure the SSH credentials in code host configuration in the Web UI. (Recommended) +- **Option 2**: Mount the SSH keys into the container. + +## Configuring SSH credentials in the Web UI (Recommended) + +In supported code hosts configuration, you can provide the credentials in the JSON configuration. For example: + +```json +{ + "url": "https://github.com", + "token": "", + "gitURLType": "ssh", + "gitSSHCredential": { + // make sure the key is base64 encoded + // $ cat ~/.ssh/id_rsa | base64 + "privateKey": "", + "passphrase": "" + } +} +``` + +Some providers may require additional configuration, consult the [code host specific documentation](/admin/code_hosts/) for more information. + +## Mounting SSH keys into the container - [Sourcegraph with Docker Compose](/admin/deploy/docker-compose/): See [the Docker Compose git configuration guide](/admin/deploy/docker-compose/#git-configuration). - [Sourcegraph with Kubernetes](/admin/deploy/kubernetes/): See [Configure repository cloning via SSH](/admin/deploy/kubernetes/configure#ssh-for-cloning). - [Single-container Sourcegraph](/admin/deploy/docker-single-container/): See [the single-container git configuration guide](/admin/deploy/docker-single-container/#git-configuration-and-authentication). ->NOTE: Repository access over SSH is not yet supported on [Sourcegraph Cloud](/cloud/). - ## Troubleshooting +### Error: `illegal base64 data at input byte 0` + +This error indicates that the provided private key is not base64-encoded. Ensure that the private key is base64-encoded before providing it to Sourcegraph. + +```bash +cat ~/.ssh/id_rsa | base64 +``` + ### What should be included in my config file? We recommend adding the `StrictHostKeyChecking no` and `AddKeysToAgent yes` flags to prevent the need to give permission interactively when cloning from a new host.