Skip to content

Commit

Permalink
Make user endpoints admin actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joerger committed Dec 12, 2023
1 parent 9c4fa20 commit 054daf2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/auth/users/usersv1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ func (s *Service) CreateUser(ctx context.Context, req *userspb.CreateUserRequest
return nil, trace.Wrap(err)
}

if err := authz.AuthorizeAdminAction(ctx, authzCtx); err != nil {
return nil, trace.Wrap(err)
}

if err = okta.CheckOrigin(authzCtx, req.User); err != nil {
return nil, trace.Wrap(err)
}
Expand Down Expand Up @@ -280,6 +284,10 @@ func (s *Service) UpdateUser(ctx context.Context, req *userspb.UpdateUserRequest
return nil, trace.Wrap(err)
}

if err := authz.AuthorizeAdminAction(ctx, authzCtx); err != nil {
return nil, trace.Wrap(err)
}

if err = okta.CheckOrigin(authzCtx, req.User); err != nil {
return nil, trace.Wrap(err)
}
Expand Down Expand Up @@ -346,6 +354,10 @@ func (s *Service) UpsertUser(ctx context.Context, req *userspb.UpsertUserRequest
return nil, trace.Wrap(err)
}

if err := authz.AuthorizeAdminAction(ctx, authzCtx); err != nil {
return nil, trace.Wrap(err)
}

if createdBy := req.User.GetCreatedBy(); createdBy.IsEmpty() {
req.User.SetCreatedBy(types.CreatedBy{
User: types.UserRef{Name: authzCtx.User.GetName()},
Expand Down Expand Up @@ -418,6 +430,10 @@ func (s *Service) DeleteUser(ctx context.Context, req *userspb.DeleteUserRequest
return nil, trace.Wrap(err)
}

if err := authz.AuthorizeAdminAction(ctx, authzCtx); err != nil {
return nil, trace.Wrap(err)
}

prevUser, err := s.cache.GetUser(ctx, req.Name, false)
var omitEditorEvent bool
if err != nil && !trace.IsNotFound(err) {
Expand Down

0 comments on commit 054daf2

Please sign in to comment.