Skip to content

feat: audit login - #5925

Merged
Kira-Pilot merged 21 commits into
mainfrom
audit-login-logout/kira-pilot
Feb 6, 2023
Merged

Kira-Pilot merged 21 commits into
mainfrom
audit-login-logout/kira-pilot

Conversation

@Kira-Pilot

@Kira-Pilot Kira-Pilot commented Jan 30, 2023 •

Copy link
Copy Markdown
Contributor

Part of #4538
Screen Shot 2023-02-01 at 2 59 13 PM

Logout coming next

Comment thread coderd/users.go Resolved
Comment thread coderd/audit/request.go Resolved
@Kira-Pilot
Kira-Pilot requested review from Emyrk and coadler January 30, 2023 21:45
Comment thread enterprise/audit/table.go Resolved
@Kira-Pilot Kira-Pilot changed the title feat: audit login and logout feat: audit login Feb 1, 2023
Comment thread coderd/users.go Outdated
if !httpapi.Read(ctx, rw, r, &loginWithPassword) {
// We pass a disposable user ID just to force an audit diff
// and generate a log for a failed login
aReq.New = database.APIKey{UserID: uuid.New()}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Down for another approach here. The auditor will skip audit log generation if there's not a valid diff. We don't have a proper UUID on APIKey and anyways, we bail before we actually create the model. I figured generating a garbage UUID was the fastest path forward but admittedly it's kinda gross.

Comment thread coderd/users.go Outdated
// @Router /users/login [post]
func (api *API) postLogin(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var (

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Does this handler handle all authentication paths? What if a user isn't logging with a password?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's a file called userauth.go with all of the other ways to login. This endpoint should probably be in there anyways.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Alright, added auditing for OAuth and OIDC. I am not sure how best to smoke-test locally, but I made sure to update all the auth tests.

@Kira-Pilot
Kira-Pilot marked this pull request as ready for review February 1, 2023 22:54
Comment thread coderd/userauth.go
return xerrors.Errorf("find linked user: %w", err)
}
user = params.User
link = params.Link

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought it was safe to lift finding the user outside of the transaction and into the callers so we can access User.ID in those places. If, in the callers, we don't find a user, we bail early, never entering oauthLogin.

Comment thread coderd/audit/request.go Resolved

@Emyrk Emyrk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we can make things a bit nicer and not repeat aReq.New = database.APIKey{} all the time when we return an error. Feels like a bug waiting to happen since we have to always rememeber to put that.

Comment thread coderd/userauth.go Resolved
Comment thread coderd/userauth.go Resolved

@Emyrk Emyrk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor nits on comments, LG!

Comment thread coderd/audit/request.go Resolved
Comment thread coderd/userauth.go Resolved
Comment thread coderd/userauth.go Resolved
@Kira-Pilot
Kira-Pilot merged commit 46fe59f into main Feb 6, 2023
@Kira-Pilot
Kira-Pilot deleted the audit-login-logout/kira-pilot branch February 6, 2023 20:12
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 6, 2023
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