-
Notifications
You must be signed in to change notification settings - Fork 901
feat: audit login #5925
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
feat: audit login #5925
Changes from 1 commit
0a0adfd
6ddead2
1acc73c
a75392e
4c754d3
622733c
d9480b6
7308943
e5dbe17
e3a6587
809dc7b
e0a0b38
524e001
b19ae71
244068f
3465617
28f8060
5a25616
e242716
cda0818
9bfc125
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- It's not possible to drop enum values from enum types, so the UP has "IF NOT | ||
-- EXISTS". |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
ALTER TYPE audit_action | ||
ADD VALUE IF NOT EXISTS 'login'; | ||
|
||
ALTER TYPE audit_action | ||
ADD VALUE IF NOT EXISTS 'logout'; | ||
|
||
ALTER TYPE resource_type | ||
ADD VALUE IF NOT EXISTS 'api_key'; | ||
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -995,7 +995,19 @@ func (api *API) organizationByUserAndName(rw http.ResponseWriter, r *http.Reques | |
// @Success 201 {object} codersdk.LoginWithPasswordResponse | ||
// @Router /users/login [post] | ||
func (api *API) postLogin(rw http.ResponseWriter, r *http.Request) { | ||
ctx := r.Context() | ||
var ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a file called There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
ctx = r.Context() | ||
auditor = api.Auditor.Load() | ||
aReq, commitAudit = audit.InitRequest[database.APIKey](rw, &audit.RequestParams{ | ||
Audit: *auditor, | ||
Log: api.Logger, | ||
Request: r, | ||
Action: database.AuditActionLogin, | ||
}) | ||
) | ||
|
||
defer commitAudit() | ||
|
||
var loginWithPassword codersdk.LoginWithPasswordRequest | ||
if !httpapi.Read(ctx, rw, r, &loginWithPassword) { | ||
return | ||
|
@@ -1043,7 +1055,7 @@ func (api *API) postLogin(rw http.ResponseWriter, r *http.Request) { | |
return | ||
} | ||
|
||
cookie, err := api.createAPIKey(ctx, createAPIKeyParams{ | ||
cookie, key, err := api.createAPIKey(ctx, createAPIKeyParams{ | ||
UserID: user.ID, | ||
LoginType: database.LoginTypePassword, | ||
RemoteAddr: r.RemoteAddr, | ||
|
@@ -1056,6 +1068,8 @@ func (api *API) postLogin(rw http.ResponseWriter, r *http.Request) { | |
return | ||
} | ||
|
||
aReq.New = *key | ||
|
||
Kira-Pilot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
http.SetCookie(rw, cookie) | ||
|
||
httpapi.Write(ctx, rw, http.StatusCreated, codersdk.LoginWithPasswordResponse{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -484,6 +484,8 @@ | |
| `delete` | | ||
| `start` | | ||
| `stop` | | ||
| `login` | | ||
| `logout` | | ||
|
||
## codersdk.AuditDiff | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.