Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/services/local/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (

"github.com/gravitational/teleport"
"github.com/gravitational/teleport/api/client/proto"
apidefaults "github.com/gravitational/teleport/api/defaults"
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/backend"
"github.com/gravitational/teleport/lib/services"
Expand Down Expand Up @@ -91,7 +90,9 @@ func (s *AccessService) ListRoles(ctx context.Context, req *proto.ListRolesReque
limit := int(req.Limit)

if limit == 0 {
limit = apidefaults.DefaultChunkSize
// it can take a lot of effort to parse roles and until a page is done
// parsing, it will be held in memory - so keep this reasonably small
limit = 100
}

if limit > maxPageSize {
Expand Down
57 changes: 24 additions & 33 deletions lib/services/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package services

import (
"context"
"encoding/json"
"errors"
"fmt"
"net"
Expand All @@ -34,6 +33,7 @@ import (
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/google/uuid"
"github.com/gravitational/trace"
jsoniter "github.com/json-iterator/go"
log "github.com/sirupsen/logrus"
"github.com/vulcand/predicate"
"golang.org/x/crypto/ssh"
Expand Down Expand Up @@ -3307,47 +3307,38 @@ func UnmarshalRole(bytes []byte, opts ...MarshalOption) (types.Role, error) {

// UnmarshalRoleV6 unmarshals the RoleV6 resource from JSON.
func UnmarshalRoleV6(bytes []byte, opts ...MarshalOption) (*types.RoleV6, error) {
var h types.ResourceHeader
err := json.Unmarshal(bytes, &h)
if err != nil {
return nil, trace.Wrap(err)
}

cfg, err := CollectOptions(opts)
if err != nil {
return nil, trace.Wrap(err)
}

switch h.Version {
case types.V7:
fallthrough
case types.V6:
fallthrough
case types.V5:
fallthrough
case types.V4:
// V4 roles are identical to V3 except for their defaults
fallthrough
case types.V3:
var role types.RoleV6
if err := utils.FastUnmarshal(bytes, &role); err != nil {
return nil, trace.BadParameter(err.Error())
}
version := jsoniter.Get(bytes, "version").ToString()
switch version {
// these are all backed by the same shape of data, they just have different semantics and defaults
case types.V3, types.V4, types.V5, types.V6, types.V7:
default:
return nil, trace.BadParameter("role version %q is not supported", version)
}

if err := ValidateRole(&role); err != nil {
return nil, trace.Wrap(err)
}
var role types.RoleV6
if err := utils.FastUnmarshal(bytes, &role); err != nil {
return nil, trace.BadParameter(err.Error())
}
if role.Version != version {
return nil, trace.BadParameter("inconsistent version in role data, got %q and %q", role.Version, version)
}

if cfg.Revision != "" {
role.SetRevision(cfg.Revision)
}
if !cfg.Expires.IsZero() {
role.SetExpiry(cfg.Expires)
}
return &role, nil
if err := ValidateRole(&role); err != nil {
return nil, trace.Wrap(err)
}

return nil, trace.BadParameter("role version %q is not supported", h.Version)
if cfg.Revision != "" {
role.SetRevision(cfg.Revision)
}
if !cfg.Expires.IsZero() {
role.SetExpiry(cfg.Expires)
}
return &role, nil
}

// MarshalRole marshals the Role resource to JSON.
Expand Down