AWS CodeCommit
Supported on Enterprise plans.
Available via the Web app.
Site admins can sync Git repositories hosted on AWS CodeCommit with Sourcegraph so that users can search and navigate the repositories.
To connect AWS CodeCommit to Sourcegraph:
- Go to Site admin > Manage code hosts > Add repositories
- Select AWS CodeCommit repositories.
- Configure the connection to AWS CodeCommit using the action buttons above the text field, and additional fields can be added using
Cmd/Ctrl+Space
for auto-completion. See the configuration documentation below. - Press Add repositories.
AWS CodeCommit Git credentials
Since version 3.4 of Sourcegraph, the AWS CodeCommit service requires Git credentials in order to clone repositories via HTTPS. Git credentials consist of a username and a password that you can create in AWS IAM.
For detailed instructions on how to create the credentials in IAM, see: Setup for HTTPS Users Using Git Credentials
Configuration
AWS CodeCommit connections support the following configuration options, which are specified in the JSON editor in the site admin "Manage code hosts" area.
admin/code_hosts/aws_codecommit.schema.json
JSON{ "$schema": "http://json-schema.org/draft-07/schema#", "$id": "aws_codecommit.schema.json#", "title": "AWSCodeCommitConnection", "description": "Configuration for a connection to AWS CodeCommit.", "allowComments": true, "type": "object", "additionalProperties": false, "required": ["region", "accessKeyID", "secretAccessKey", "gitCredentials"], "properties": { "region": { "description": "The AWS region in which to access AWS CodeCommit. See the list of supported regions at https://docs.aws.amazon.com/codecommit/latest/userguide/regions.html#regions-git.", "type": "string", "default": "us-east-1", "pattern": "^[a-z\\d-]+$", "enum": [ "ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "eu-central-1", "eu-west-1", "eu-west-2", "eu-west-3", "sa-east-1", "us-east-1", "us-east-2", "us-west-1", "us-west-2" ] }, "accessKeyID": { "description": "The AWS access key ID to use when listing and updating repositories from AWS CodeCommit. Must have the AWSCodeCommitReadOnly IAM policy.", "type": "string" }, "secretAccessKey": { "description": "The AWS secret access key (that corresponds to the AWS access key ID set in `accessKeyID`).", "type": "string" }, "gitCredentials": { "title": "AWSCodeCommitGitCredentials", "description": "The Git credentials used for authentication when cloning an AWS CodeCommit repository over HTTPS.\n\nSee the AWS CodeCommit documentation on Git credentials for CodeCommit: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_ssh-keys.html#git-credentials-code-commit.\nFor detailed instructions on how to create the credentials in IAM, see this page: https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-gc.html", "type": "object", "required": ["username", "password"], "properties": { "username": { "description": "The Git username", "type": "string", "minLength": 1 }, "password": { "description": "The Git password", "type": "string", "minLength": 1 } } }, "gitURLType": { "description": "The type of Git URLs to use for cloning and fetching Git repositories.", "type": "string", "enum": ["http", "ssh"], "default": "http" }, "gitSSHKeyID": { "description": "The ID of the SSH key created for your IAM users. It is required when using SSH to clone repositories.", "type": "string" }, "gitSSHCredential": { "description": "SSH keys to use when cloning Git repo.", "$ref": "git.schema.json#/definitions/gitSSHCredential" }, "gitSSHCipher": { "description": "SSH cipher to use when cloning via SSH. Must be a valid choice from `ssh -Q cipher`.", "$ref": "git.schema.json#/definitions/gitSSHCipher" }, "repositoryPathPattern": { "description": "The pattern used to generate a the corresponding Sourcegraph repository name for an AWS CodeCommit repository. In the pattern, the variable \"{name}\" is replaced with the repository's name.\n\nFor example, if your Sourcegraph instance is at https://src.example.com, then a repositoryPathPattern of \"awsrepos/{name}\" would mean that a AWS CodeCommit repository named \"myrepo\" is available on Sourcegraph at https://src.example.com/awsrepos/myrepo.\n\nIt is important that the Sourcegraph repository name generated with this pattern be unique to this code host. If different code hosts generate repository names that collide, Sourcegraph's behavior is undefined.", "type": "string", "default": "{name}", "examples": ["git-codecommit.us-west-1.amazonaws.com/{name}", "git-codecommit.eu-central-1.amazonaws.com/{name}"] }, "initialRepositoryEnablement": { "description": "Deprecated and ignored field which will be removed entirely in the next release. AWS CodeCommit repositories can no longer be enabled or disabled explicitly. Configure which repositories should not be mirrored via \"exclude\" instead.", "type": "boolean", "default": false }, "exclude": { "description": "A list of repositories to never mirror from AWS CodeCommit. \n\nSupports excluding by name ({\"name\": \"git-codecommit.us-west-1.amazonaws.com/repo-name\"}) or by ARN ({\"id\": \"arn:aws:codecommit:us-west-1:999999999999:name\"}).", "type": "array", "minItems": 1, "items": { "type": "object", "title": "ExcludedAWSCodeCommitRepo", "additionalProperties": false, "anyOf": [{ "required": ["name"] }, { "required": ["id"] }], "properties": { "name": { "description": "The name of an AWS CodeCommit repository (\"repo-name\") to exclude from mirroring.", "type": "string", "pattern": "^[\\w.-]+$" }, "id": { "description": "The ID of an AWS Code Commit repository (as returned by the AWS API) to exclude from mirroring. Use this to exclude the repository, even if renamed, or to differentiate between repositories with the same name in multiple regions.", "type": "string", "pattern": "^[\\w-]+$" } } }, "examples": [ [{ "name": "go-monorepo" }, { "id": "f001337a-3450-46fd-b7d2-650c0EXAMPLE" }], [{ "name": "go-monorepo" }, { "name": "go-client" }] ] }, "maxDeletions": { "description": "The maximum number of repos that will be deleted per sync. A value of 0 or less indicates no maximum.", "type": "integer", "default": 0 } } }
Setup steps for SSH connections to AWS CodeCommit repositories
To add CodeCommit repositories in Docker Container:
- Generate a public/private rsa key pair that does not require passphrase as listed in the Step 3.1 of the AWS SSH setup guide. Sourcegraph does not work with the key pair that requires passphrase.
- Follow the rest of the steps detailed in the AWS SSH setup guide to make sure you can connect to the code host locally.
- 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) - Confirm you can clone the repository locally.
Configuring SSH credentials in the Web UI
JSON{ "gitURLType": "ssh", "gitSSHKeyID": "<SSH key ID>", "gitSSHCredential": { // make sure the key is base64 encoded // $ cat ~/.ssh/id_rsa | base64 "privateKey": "<base64 encoded of the SSH private key>", "passphrase": "<passphrase if applicable, omit if none is needed>" } }
Mounting SSH keys into the container
- Copy all the files at your
$HOME/.ssh directory
to$HOME/.sourcegraph/config/ssh
directory. See docs for more information about our ssh file system.- Read our guide here for Docker Compose deployments
- Read our guide here for Kubernetes deployments
- Start (or restart) the container.
- Connect Sourcegraph to AWS CodeCommit by going to Sourcegraph > Site Admin > Manage code hosts > Generic Git host and add the following:
JSON"url": "ssh://git-codecommit.us-west-1.amazonaws.com", //Please replace the 'us-east-1' region with yours "repos": [ "v1/repos/REPO_NAME_1", "v1/repos/REPO_NAME_2", ]