Commit 47b9f57e authored by ale's avatar ale

Ensure we always log a user in audit logs

parent 11821eaf
Pipeline #1030 passed with stages
in 1 minute and 27 seconds
......@@ -159,6 +159,11 @@ type PasswordRecoveryRequest struct {
Password string `json:"password"`
}
// NewContext adds logging data to the current request context.
func (r *PasswordRecoveryRequest) NewContext(ctx context.Context) context.Context {
return context.WithValue(ctx, userCtxKey, r.Username)
}
// Validate the request.
func (r *PasswordRecoveryRequest) Validate(ctx context.Context, s *AccountService) error {
return s.fieldValidators.password(ctx, r.Password)
......@@ -782,6 +787,11 @@ type CreateUserRequest struct {
User *User `json:"user"`
}
// NewContext returns a new Context providing log context data.
func (req *CreateUserRequest) NewContext(ctx context.Context) context.Context {
return context.WithValue(ctx, userCtxKey, req.User.Name)
}
// ApplyTemplate fills in default values for the resources in the request.
func (req *CreateUserRequest) ApplyTemplate(ctx context.Context, tx TX, s *AccountService, _ *User) error {
// Some fields should be unset because there are specific
......
......@@ -32,6 +32,9 @@ func (l *syslogAuditLogger) Log(ctx context.Context, resourceID ResourceID, what
if !resourceID.Empty() {
e.ResourceName = resourceID.Name()
e.ResourceType = resourceID.Type()
if u := resourceID.User(); u != "" {
e.User = u
}
}
data, _ := json.Marshal(&e)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment