Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: Add OIDC authentication #3314

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 12 commits into from
Aug 1, 2022
Merged

feat: Add OIDC authentication #3314

merged 12 commits into from
Aug 1, 2022

Conversation

kylecarbs
Copy link
Member

@kylecarbs kylecarbs commented Jul 29, 2022

This adds OIDC authentication to the product!

The email and username cannot be used as unique, so we'll have to add an identifier to match a user. See: https://openid.net/specs/openid-connect-core-1_0.html#ClaimStability. #3322 has been created to fix this.

Closes #695.

oidc-2022-07-31_14.28.48.mp4

Most of the diff is extracting the username validation into its package; the OIDC exchange is just a few hundred lines. This was manually tested with Google, but considering the extent of tests, it'll hopefully work with others!

@kylecarbs kylecarbs self-assigned this Jul 29, 2022
@ntimo
Copy link
Contributor

ntimo commented Jul 29, 2022

This PR made my day ♥️ Can‘t wait to use OIDC 👍

@kylecarbs kylecarbs marked this pull request as ready for review July 31, 2022 19:31
@kylecarbs kylecarbs requested a review from a team as a code owner July 31, 2022 19:31
Comment on lines +34 to +38
"docker",
"run",
"--rm",
"--network=host",
"postgres:13",
Copy link
Member Author

Choose a reason for hiding this comment

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

This was a bit out of scope, but makes everything use Docker, which makes changing our versions simpler!

@@ -81,71 +81,6 @@ func TestRead(t *testing.T) {
})
}

func TestReadUsername(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

These have been moved to the username package!

kylecarbs and others added 3 commits July 31, 2022 20:44
}

var user database.User
user, err = api.Database.GetUserByEmailOrUsername(r.Context(), database.GetUserByEmailOrUsernameParams{
Copy link
Collaborator

@sreya sreya Jul 31, 2022

Choose a reason for hiding this comment

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

This is pretty unlikely to happen but if an existing, unrelated user (say with built-in auth) already has this email address, then it's possible for a new OIDC user to impersonate them by providing the same email address.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup. The issue I attached expands on that a bit. We'll have to make the user-identification with account links better.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want to add a column to the users table that indicates the sort of authentication they used? Probably not necessary to do in this PR

Copy link
Member Author

Choose a reason for hiding this comment

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

We will in a future PR, this one just gets it out the door

@@ -0,0 +1,45 @@
package username
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like the idea of extracting validation to a separate package but what sort of precedent do we want to be setting if we have other fields that may be suitable for relocation to a new package? Are we expecting each new field to create its own pkg, to refactor into a common validate pkg or do you feel like username is sufficiently unique to warrant its own pkg and most everything else should be contained to coderd?

Copy link
Member Author

Choose a reason for hiding this comment

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

I feel like this isn't just a case of validation. I extracted this primarily due to the generation that we now need to do with OIDC.

The alternative was exposing httpapi.ValidateUsername or something of the sort, which I'm also mostly fine with. Keep in mind we'd have to have a separate function of httpapi.UsernameFromString or something like it, but I'm also fine with that. I'll think on it, but if you think that sounds cleaner I'll make it happen!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nah I was just bringing it up to get an idea of how we want to structure packages

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually removed the username package. It felt too much like floaty scope with little benefit. That code is in httpapi now, which feels better anyways.

Good comment 👍

@kylecarbs kylecarbs enabled auto-merge (squash) August 1, 2022 02:37
@kylecarbs kylecarbs disabled auto-merge August 1, 2022 03:16
@kylecarbs kylecarbs enabled auto-merge (squash) August 1, 2022 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AuthN / OIDC
4 participants