From 109e73bf977fb66b39fe841f0502ce0e7694df26 Mon Sep 17 00:00:00 2001 From: Edward Angert Date: Wed, 9 Apr 2025 11:16:00 -0400 Subject: [PATCH] docs: add details on external authentication priority (#17164) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Issue Closes #16875 Clarify how Coder authentication works with Git providers, particularly the order of authentication methods used. ## Changes Made I've updated the External Authentication documentation to: 1. Clarify that Coder first attempts to use external auth provider tokens when available, and only defaults to SSH authentication if no tokens are available 2. Add more detailed explanations about both authentication methods 3. Improve the description of how the `coder gitssh` command works with existing and Coder-generated SSH keys ## Verification Claude verified that this accurately describes the behavior of the codebase by reviewing the `gitssh.go` implementation, which shows how Coder handles SSH authentication as a fallback when external auth is not available. [preview](https://coder.com/docs/@16875-git-workspace-auth/admin/external-auth) 🤖 Generated with https://claude.ai/code --------- Signed-off-by: dependabot[bot] Co-authored-by: EdwardAngert <17991901+EdwardAngert@users.noreply.github.com> Co-authored-by: Ben Potter Co-authored-by: M Atif Ali Co-authored-by: Bruno Quaresma Co-authored-by: Kyle Carberry Co-authored-by: Cian Johnston Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jon Ayers Co-authored-by: Hugo Dutka Co-authored-by: Ethan <39577870+ethanndickson@users.noreply.github.com> Co-authored-by: Michael Smith Co-authored-by: Claude Co-authored-by: Sas Swart --- docs/admin/external-auth.md | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/docs/admin/external-auth.md b/docs/admin/external-auth.md index d894f77bac..6c91a5891f 100644 --- a/docs/admin/external-auth.md +++ b/docs/admin/external-auth.md @@ -71,6 +71,55 @@ Use [`external-auth`](../reference/cli/external-auth.md) in the Coder CLI to acc coder external-auth access-token ``` +## Git Authentication in Workspaces + +Coder provides automatic Git authentication for workspaces through SSH authentication and Git-provider specific env variables. + +When performing Git operations, Coder first attempts to use external auth provider tokens if available. +If no tokens are available, it defaults to SSH authentication. + +### OAuth (external auth) + +For Git providers configured with [external authentication](#configuration), Coder can use OAuth tokens for Git operations. + +When Git operations require authentication, and no SSH key is configured, Coder will automatically use the appropriate external auth provider based on the repository URL. + +For example, if you've configured a GitHub external auth provider and attempt to clone a GitHub repository, Coder will use the OAuth token from that provider for authentication. + +To manually access these tokens within a workspace: + +```shell +coder external-auth access-token +``` + +### SSH Authentication + +Coder automatically generates an SSH key pair for each user that can be used for Git operations. +When you use SSH URLs for Git repositories, for example, `git@github.com:organization/repo.git`, Coder checks for and uses an existing SSH key. +If one is not available, it uses the Coder-generated one. + +The `coder gitssh` command wraps the standard `ssh` command and injects the SSH key during Git operations. +This works automatically when you: + +1. Clone a repository using SSH URLs +1. Pull/push changes to remote repositories +1. Use any Git command that requires SSH authentication + +You must add the SSH key to your Git provider. + +#### Add your Coder SSH key to your Git provider + +1. View your Coder Git SSH key: + + ```shell + coder publickey + ``` + +1. Add the key to your Git provider accounts: + + - [GitHub](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account#adding-a-new-ssh-key-to-your-account) + - [GitLab](https://docs.gitlab.com/user/ssh/#add-an-ssh-key-to-your-gitlab-account) + ## Git-provider specific env variables ### Azure DevOps