Skip to content

feat: enable GitHub OAuth2 login by default on new deployments #16662

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

Merged
merged 7 commits into from
Feb 25, 2025

Conversation

hugodutka
Copy link
Contributor

@hugodutka hugodutka commented Feb 22, 2025

Third and final PR to address #16230.

This PR enables GitHub OAuth2 login by default on new deployments. Combined with #16629, this will allow the first admin user to sign up with GitHub rather than email and password.

We take care not to enable the default on deployments that would upgrade to a Coder version with this change.

To disable the default provider an admin can set the CODER_OAUTH2_GITHUB_DEFAULT_PROVIDER env variable to false.

@hugodutka hugodutka force-pushed the hugodutka/github-oauth2-default branch 7 times, most recently from 66e0aff to 2788eb5 Compare February 22, 2025 16:30
@hugodutka hugodutka marked this pull request as ready for review February 23, 2025 18:08
@hugodutka
Copy link
Contributor Author

Note: before merging, I need to update the embedded GitHub Client ID. I'm still waiting for the app to be properly set up on our side.

@dannykopping
Copy link
Contributor

dannykopping commented Feb 24, 2025

Note: before merging, I need to update the embedded GitHub Client ID. I'm still waiting for the app to be properly set up on our side.

@hugodutka how will users using this embedded client ID? Each GitHub app needs a unique callback URL as far as I understand, so I'm not sure how this will work.

EDIT: nevermind, seems like the redirect URI can be customised.

@hugodutka
Copy link
Contributor Author

hugodutka commented Feb 24, 2025

@dannykopping we’ll be using the device flow here, which I implemented support for a couple of days ago: #16585. This doesn’t use a callback URL.

Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks OK to me mechanically, and the device flow is convenient. What happens to new deployments where GitHub is not accessible though? It looks like this will be enabled and useless to the admin.

Name: "OAuth2 GitHub Default Provider",
Description: "Enable the default GitHub OAuth2 provider managed by Coder.",
Flag: "oauth2-github-default-provider",
Env: "CODER_OAUTH2_GITHUB_DEFAULT_PROVIDER",
Copy link
Member

@johnstcn johnstcn Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: for consistency, this should have the _ENABLE suffix. This is not a blocking change though.

Comment on lines 391 to 405
t.Run("NewDeployment", func(t *testing.T) {
runGitHubProviderTest(t, testCase{
githubEnabled: true,
createUserPreStart: false,
createUserPostRestart: true,
})
})

t.Run("ExistingDeployment", func(t *testing.T) {
runGitHubProviderTest(t, testCase{
githubEnabled: false,
createUserPreStart: true,
createUserPostRestart: false,
})
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a test case as follows:

  • GIVEN an existing deployment with 0 users and CODER_OAUTH2_GITHUB_{CLIENT_ID,CLIENT_SECRET} set
  • WHEN coder starts
  • THEN the new "default" GitHub OAuth2 provider is not enabled

Copy link
Member

@johnstcn johnstcn Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's also an argument to be made against enabling this by default if OIDC login is enabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not make this logic dependent on OIDC config. I think it's not intuitive that setting one up would disable the other.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D It sounds like there's an argument against then. Let's leave it out of this PR so!

cli/server.go Outdated
Comment on lines 1896 to 1898
params.clientID = "Iv23liSBHklRMBNx5lk9"
params.allowEveryone = true
params.deviceFlow = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be extracted to a highly visible variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you consider highly visible? Package level global constant? Just asking to avoid further back and forth on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like that, yeah. We should need to go searching to find the default client ID.
I assume OAuth2 device flow doesn't require a client secret?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, it doesn't require a client secret.

@hugodutka
Copy link
Contributor Author

@johnstcn

What happens to new deployments where GitHub is not accessible though?

What do you mean by not accessible? As in the deployment is airgapped?

@johnstcn
Copy link
Member

@johnstcn

What happens to new deployments where GitHub is not accessible though?

What do you mean by not accessible? As in the deployment is airgapped?

Not necessarily; there have been multiple instances in the past where state actors have blocked GitHub. Or it could be blocked at the corporate network level. What would you say is the best course of action in this case?

@hugodutka
Copy link
Contributor Author

@johnstcn I don't think this would be very common. I think just allowing the admins to disable the default via an env variable is enough in these cases.

Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving pending comments regarding conditionally disabling if existing OAuth2/OIDC authn methods are configured.

@hugodutka hugodutka force-pushed the hugodutka/github-oauth2-default branch 2 times, most recently from eb41f65 to 032150d Compare February 24, 2025 16:56
@hugodutka hugodutka force-pushed the hugodutka/github-oauth2-setup branch 2 times, most recently from 1a67ae7 to dfd49d0 Compare February 24, 2025 16:59
@hugodutka hugodutka force-pushed the hugodutka/github-oauth2-default branch 2 times, most recently from 9a15225 to 407cdd3 Compare February 24, 2025 18:03
@hugodutka
Copy link
Contributor Author

Addressed the feedback and updated the embedded client ID. Should be ready to merge once the base branch is merged.

@hugodutka hugodutka force-pushed the hugodutka/github-oauth2-setup branch from dfd49d0 to 3b36025 Compare February 24, 2025 20:37
@hugodutka hugodutka force-pushed the hugodutka/github-oauth2-default branch from 407cdd3 to 071d6cc Compare February 24, 2025 20:37
@hugodutka hugodutka force-pushed the hugodutka/github-oauth2-default branch from 071d6cc to 1720441 Compare February 24, 2025 20:57
Base automatically changed from hugodutka/github-oauth2-setup to main February 25, 2025 14:54
@hugodutka hugodutka force-pushed the hugodutka/github-oauth2-default branch from 1720441 to 297e90b Compare February 25, 2025 15:16
@hugodutka hugodutka merged commit d3a56ae into main Feb 25, 2025
33 of 35 checks passed
@hugodutka hugodutka deleted the hugodutka/github-oauth2-default branch February 25, 2025 15:31
@github-actions github-actions bot locked and limited conversation to collaborators Feb 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants