Skip to content

feat: Add OIDC authentication - #3314

Merged
kylecarbs merged 12 commits into
mainfrom
oidc
Aug 1, 2022
Merged

kylecarbs merged 12 commits into
mainfrom
oidc

Conversation

@kylecarbs

@kylecarbs kylecarbs commented Jul 29, 2022 •

Copy link
Copy Markdown
Member

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

ntimo commented Jul 29, 2022

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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!

})
}

func TestReadUsername(t *testing.T) {

Copy link
Copy Markdown
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!

Comment thread docs/install/auth.md Resolved
Comment thread docs/install/auth.md Resolved
kylecarbs and others added 3 commits July 31, 2022 20:44
Co-authored-by: Ammar Bandukwala <ammar@ammar.io>
Co-authored-by: Ammar Bandukwala <ammar@ammar.io>
Comment thread cli/server.go Resolved
Comment thread coderd/userauth.go
}

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

@sreya sreya Jul 31, 2022 •

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Comment thread coderd/username/username.go Outdated
@@ -0,0 +1,45 @@
package username

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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