- Notifications
You must be signed in to change notification settings - Fork1k
fix(coderd): add audit log on creating a new session key#19672
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -131,8 +131,19 @@ func (api *API) postToken(rw http.ResponseWriter, r *http.Request) { | ||
// @Success 201 {object} codersdk.GenerateAPIKeyResponse | ||
// @Router /users/{user}/keys [post] | ||
func (api *API) postAPIKey(rw http.ResponseWriter, r *http.Request) { | ||
var ( | ||
ctx = r.Context() | ||
user = httpmw.UserParam(r) | ||
auditor = api.Auditor.Load() | ||
aReq, commitAudit = audit.InitRequest[database.APIKey](rw, &audit.RequestParams{ | ||
Audit: *auditor, | ||
Log: api.Logger, | ||
Request: r, | ||
Action: database.AuditActionCreate, | ||
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. Won't be visible in the UI iffilter will specify 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. Correct, typically that gets logged when users authenticate via the Web UI. | ||
}) | ||
) | ||
aReq.Old = database.APIKey{} | ||
defer commitAudit() | ||
// TODO(Cian): System users technically just have the 'member' role | ||
// and we don't want to disallow all members from creating API keys. | ||
@@ -142,7 +153,7 @@ func (api *API) postAPIKey(rw http.ResponseWriter, r *http.Request) { | ||
return | ||
} | ||
cookie,key, err := api.createAPIKey(ctx, apikey.CreateParams{ | ||
UserID: user.ID, | ||
DefaultLifetime: api.DeploymentValues.Sessions.DefaultTokenDuration.Value(), | ||
LoginType: database.LoginTypePassword, | ||
@@ -156,6 +167,7 @@ func (api *API) postAPIKey(rw http.ResponseWriter, r *http.Request) { | ||
return | ||
} | ||
aReq.New = *key | ||
// We intentionally do not set the cookie on the response here. | ||
// Setting the cookie will couple the browser session to the API | ||
// key we return here, meaning logging out of the website would | ||
Uh oh!
There was an error while loading.Please reload this page.