Skip to content

Commit

Permalink
fix: set request page size in ListUsers rpc handler
Browse files Browse the repository at this point in the history
  • Loading branch information
rosstimothy committed Feb 21, 2025
1 parent 0ff672b commit a3fd56f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 5 additions & 0 deletions lib/auth/users/usersv1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,11 @@ func (s *Service) ListUsers(ctx context.Context, req *userspb.ListUsersRequest)
return nil, trace.Wrap(err)
}

// Adjust page size, so it can't be too large.
if req.PageSize <= 0 || req.PageSize > apidefaults.DefaultChunkSize {
req.PageSize = apidefaults.DefaultChunkSize
}

if req.WithSecrets {
// TODO(fspmarshall): replace admin requirement with VerbReadWithSecrets once we've
// migrated to that model.
Expand Down
3 changes: 3 additions & 0 deletions lib/cache/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func (c *Cache) GetUser(ctx context.Context, name string, withSecrets bool) (typ

u, err := c.collections.users.store.get("name", name)
if err != nil {
// release read lock early
rg.Release()

// fallback is sane because method is never used
// in construction of derivative caches.
if trace.IsNotFound(err) {
Expand Down
6 changes: 0 additions & 6 deletions lib/services/local/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import (

"github.com/gravitational/teleport"
"github.com/gravitational/teleport/api/constants"
apidefaults "github.com/gravitational/teleport/api/defaults"
userspb "github.com/gravitational/teleport/api/gen/proto/go/teleport/users/v1"
"github.com/gravitational/teleport/api/internalutils/stream"
"github.com/gravitational/teleport/api/types"
Expand Down Expand Up @@ -115,11 +114,6 @@ func (s *IdentityService) ListUsers(ctx context.Context, req *userspb.ListUsersR
rangeEnd := backend.RangeEnd(backend.ExactKey(webPrefix, usersPrefix))
pageSize := req.PageSize

// Adjust page size, so it can't be too large.
if pageSize <= 0 || pageSize > apidefaults.DefaultChunkSize {
pageSize = apidefaults.DefaultChunkSize
}

// Artificially inflate the limit to account for user secrets
// which have the same prefix.
limit := int(pageSize) * 4
Expand Down

0 comments on commit a3fd56f

Please sign in to comment.