Skip to content

Multiple OAuth Git provider support #3078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sharkymark opened this issue Jul 20, 2022 · 10 comments
Closed

Multiple OAuth Git provider support #3078

sharkymark opened this issue Jul 20, 2022 · 10 comments
Assignees
Labels
api Area: HTTP API enterprise Enterprise-license / premium functionality site Area: frontend dashboard
Milestone

Comments

@sharkymark
Copy link
Contributor

Sounds like a paid feature but the prospect needs the ability to link more than one instance of git providers to their Coder deployment.

For example, there is one instance of GitHub Enterprise for one part of the organization, and another GitHub Enterprise instance for another part of the organization.

@kylecarbs kylecarbs changed the title feat: prospect requesting enhanced OAuth git provider support like in v1 Enhanced OAuth Git provider support Aug 24, 2022
@kylecarbs
Copy link
Member

The prospect wants functionality similar to v1, where a user would link their GitHub/GitLab/BitBucket account, and the SSH key would be added to automate push/pulling.

@kylecarbs kylecarbs added feature site Area: frontend dashboard api Area: HTTP API labels Aug 24, 2022
@bpmct
Copy link
Member

bpmct commented Sep 1, 2022

Spoke with another prospect who would like this + dual-linking functionality, such as we have in Coder Classic:

Screen Shot 2022-09-01 at 8 47 35 AM

@bpmct
Copy link
Member

bpmct commented Sep 10, 2022

I wrote some ideas here:

coder/docs/secrets.md

Lines 71 to 96 in f3769ea

## Token Management (enterprise)
Coder can manage tokens on behalf of users on the following platforms:
- GitHub
- GitHub Enterprise
- BitBucket
- BitBucket Server
- GitLab.com
- GitLab Self-Managed
- Hasicorp Vault [(coming soon)](https://coder.com/contact)
When users create/update workspaces, Coder will <a href="https://www.kapwing.com/e/631cf6a369c1ee00e55ff6ab" target="_blank">prompt users</a>
to authenticate with the provider if a valid token is not present.
```hcl
resource "coder_user_token" "github-enterprise" {
type = "github"
host = "https://github-enterprise.example.com"
oauth_client_id = var.github_client_id # via environment variable
oauth_client_secret = var.github_client_secret # via environment variable
add_coder_key = true
scopes = ["read:user", "write:public_key", "write:gpg_key", "repo"]
}
```

@bpmct
Copy link
Member

bpmct commented Sep 12, 2022

@kylecarbs and I chatted and he also had some ideas about "hooks" that can prompt users to re-validate their tokens even inside a running workspace as well as support for redirecting to arbitrary coder_apps to store tokens. (I'm sure he can expand)

@bpmct bpmct mentioned this issue Sep 12, 2022
@ammario ammario added this to the EE milestone Sep 14, 2022
@ammario ammario added the enterprise Enterprise-license / premium functionality label Sep 14, 2022
@kconley-sq
Copy link
Contributor

kconley-sq commented Sep 14, 2022

@bpmct can the coder_user_token resource idea you drafted also be made to support short-lived user-to-server access tokens provided by non-OAuth GitHub apps so that customers have that option to avoid the security risks of using GitHub OAuth app tokens which I understand never expire unless explicitly revoked? 🙏

@bpmct
Copy link
Member

bpmct commented Sep 15, 2022

Hey @kconley-sq, we had that in mind when working on the spec 👍🏼

@ammario ammario changed the title Enhanced OAuth Git provider support Multiple OAuth Git provider support Sep 20, 2022
@bpmct
Copy link
Member

bpmct commented Sep 20, 2022

We should also look into how we could support Azure DevOps in this flow

@kylecarbs
Copy link
Member

This can be done by integrating with GIT_ASKPASS.

The only problem is that VS Code Remote will override GIT_ASKPASS unless explicitly configured not to do so. We can add "git.useIntegratedAskPass": false to ~/.vscode-server/data/Machine/settings.json, but this is somewhat brittle due to this directory being movable.

Still, I think we should go ahead with the GIT_ASKPASS direction. We'll be able to configure a set of hosts that work with Git to provide credentials, and we can cache them in the agent to reduce state in coderd.

@kylecarbs
Copy link
Member

I explored some cases for our GIT_ASKPASS solution to ensure that it covers our bases. It seems like it will, but @bpmct please read through and surface any additional stuff that I missed.

Basic Configuration

We'll add a coder.yaml configuration file. Only git providers will be configurable there, but we should deprecate flags and migrate more after this is merged.

git_providers:
  - match: github.com
    type: github
    client_id: xxxxxx
    client_secret: xxxxxx

GIT_ASKPASS will be set by default inside workspaces. Unfortunately, VS Code overrides this value by default. We'll also edit/create ~/.vscode-server/data/Machine/settings.json with { "git.useIntegratedAskPass": false } to allow our behavior by default.

Using Coder for Git authentication can be disabled per template by explicitly setting the GIT_ASKPASS environment variable to an empty string.

For Kubernetes, we'll add a configuration key which is a string to values.yaml. This is standard for PostgreSQL and other applications. If set, we'll create a ConfigMap that will create a coder.yaml in the pods.

Multiple Providers

Multiple Git Providers is an Enterprise feature.

Multiple GitHub (or other platforms') organizations may be in use on the same Coder deployment. The match property is a regex for this reason, and the first matching provider will be used when authenticating with git.

git_providers:
  - match: github.com\/coder
    client_id: xxxxxx
    client_secret: xxxxxx
  - match: github.com\/cdr
    client_id: xxxxxx
    client_secret: xxxxxx

Matching against a custom path requires enabling useHttpPath in the gitconfig of workspaces. This will not be automated since the gitconfig can be in various places, and touching it sounds risky. Maybe in the future we could run:

git config --global credential.useHttpPath true

Git Provider Support

The git provider configuration provides a type property that indicates the upstream provider. We support the following:

  • Azure DevOps
  • GitHub
  • GitHub Apps
  • GitLab
  • BitBucket
  • OAuth2

An OAuth2 provider exists for supporting less popular Git solutions, like gitea.

git_providers:
  - match: bitbucket.org\/coder
    type: oauth2
    client_id: xxxxxxx
    client_secret: xxxxxxx
    authorize_url: <my-url>/login/oauth/authorize
    access_token_url: <my-url>/login/oauth/access_token

For built-in providers, we simply set the authorize_url, access_token_url, and scope for the user.

Startup Script

This is blocked on #2957. We can make this pretty nice by blocking the execution of the startup script until the user authenticates with Git, but it's awkward to do it right now because the startup script output isn't in the UI.

It would be ideal for displaying the Git hosts required when creating a workspace, and we could make this explicit by configuring it inside an agent:

resource "coder_agent" "dev" {
  git_providers = [
    "github.com"
  ]
}

For this UX, we might want to consider blocking SSH access until the startup script completes... otherwise the user could enter a workspace before they authenticate Git, and be confused why a repository hasn't cloned yet.

# I'm not a fan of this, but it's a start.
resource "coder_agent" "dev" {
  await_startup_script = true
}

@bpmct
Copy link
Member

bpmct commented Oct 16, 2022

Just took a pass, I think this seems will cover all our bases. Kind of unfortunate that setting credential.useHttpPath is necessary for multiple git providers, but it's only a one-time thing that can be in the startup script.

We currently have a gitssh utility that gives the user instructions to add their SSH key to a provider. This may be confusing for developers on a Coder deployment with a self-hosted GitLab provider. Could we rewrite the message to inform the user to use an HTTP origin to clone or even help the auto-auth with GitLab?

GIT_ASKPASS will be set by default inside workspaces. Unfortunately, VS Code overrides this value by default. We'll also edit/create ~/.vscode-server/data/Machine/settings.json with { "git.useIntegratedAskPass": false } to allow our behavior by default.

Is there a simple way to support this for code-server too?

# I'm not a fan of this, but it's a start.
resource "coder_agent" "dev" {
  await_startup_script = true
}

I think this is fine actually. Terraform providers commonly have wait_ conditions, although it is slightly odd it depends on user input. Perhaps on workspace creation, we immediately ask the user to authenticate with all providers so that it's less likely for future builds to be in a "waiting" state?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Area: HTTP API enterprise Enterprise-license / premium functionality site Area: frontend dashboard
Projects
None yet
Development

No branches or pull requests

6 participants