-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filter IC Permission Sets based on access #49936
Changes from 2 commits
5b55287
fc4b0b3
113135a
009d6aa
aef3a56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -40,6 +40,8 @@ import ( | |||
"github.com/gravitational/teleport/api/constants" | ||||
apidefaults "github.com/gravitational/teleport/api/defaults" | ||||
auditlogpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/auditlog/v1" | ||||
headerv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/header/v1" | ||||
identitycenterv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/identitycenter/v1" | ||||
mfav1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/mfa/v1" | ||||
"github.com/gravitational/teleport/api/internalutils/stream" | ||||
"github.com/gravitational/teleport/api/metadata" | ||||
|
@@ -1272,7 +1274,7 @@ func (c *resourceAccess) checkAccess(resource types.ResourceWithLabels, filter s | |||
return false, nil | ||||
} | ||||
|
||||
// check access normally if base checker doesnt exist | ||||
// check access normally if base checker doesn't exist | ||||
if c.baseAuthChecker == nil { | ||||
if err := c.accessChecker.CanAccess(resource); err != nil { | ||||
if trace.IsAccessDenied(err) { | ||||
|
@@ -1474,6 +1476,11 @@ func (a *ServerWithRoles) ListUnifiedResources(ctx context.Context, req *proto.L | |||
} | ||||
r.Logins = logins | ||||
} else if d := r.GetAppServer(); d != nil { | ||||
if err := a.filterICPermissionSets(r, d.GetApp(), resourceAccess); err != nil { | ||||
tcsc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
log.WithError(err).WithField("resource", d.GetApp().GetName()).Warn("Unable to filter ") | ||||
continue | ||||
} | ||||
|
||||
logins, err := checker.GetAllowedLoginsForResource(d.GetApp()) | ||||
if err != nil { | ||||
log.WithError(err).WithField("resource", d.GetApp().GetName()).Warn("Unable to determine logins for app") | ||||
|
@@ -1490,6 +1497,56 @@ func (a *ServerWithRoles) ListUnifiedResources(ctx context.Context, req *proto.L | |||
}, nil | ||||
} | ||||
|
||||
func (a *ServerWithRoles) filterICPermissionSets(r *proto.PaginatedResource, app types.Application, checker *resourceAccess) error { | ||||
appV3, isApp := app.(*types.AppV3) | ||||
if !isApp { | ||||
tcsc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
return trace.BadParameter("resource must be an app") | ||||
} | ||||
|
||||
pss := appV3.Spec.IdentityCenter.GetPermissionSets() | ||||
if pss == nil { | ||||
return nil | ||||
} | ||||
|
||||
assignment := services.IdentityCenterAccountAssignment{ | ||||
AccountAssignment: &identitycenterv1.AccountAssignment{ | ||||
Kind: types.KindIdentityCenterAccountAssignment, | ||||
Version: types.V1, | ||||
Metadata: &headerv1.Metadata{}, | ||||
Spec: &identitycenterv1.AccountAssignmentSpec{ | ||||
AccountId: appV3.GetName(), | ||||
PermissionSet: &identitycenterv1.PermissionSetInfo{}, | ||||
}, | ||||
}, | ||||
} | ||||
permissionSetQuery := assignment.Spec.PermissionSet | ||||
checkable := types.Resource153ToResourceWithLabels(assignment) | ||||
|
||||
var output []*types.IdentityCenterPermissionSet | ||||
for _, ps := range pss { | ||||
assignment.Metadata.Name = ps.AssignmentID | ||||
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. Why the 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. Yes - when it writes to the |
||||
permissionSetQuery.Arn = ps.ARN | ||||
|
||||
hasAccess, err := checker.checkAccess(checkable, services.MatchResourceFilter{ | ||||
ResourceKind: types.KindIdentityCenterAccountAssignment, | ||||
}) | ||||
if err != nil { | ||||
return trace.Wrap(err) | ||||
} | ||||
|
||||
if !hasAccess { | ||||
continue | ||||
} | ||||
output = append(output, ps) | ||||
if _, requestable := checker.requestableMap[ps.AssignmentID]; requestable { | ||||
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. Why the teleport/lib/auth/auth_with_roles.go Line 1457 in 5b55287
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. The access check for the 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. Ah, Thanks. I had in mind the previous logic model but for this flow where the |
||||
r.RequiresRequest = true | ||||
} | ||||
} | ||||
appV3.Spec.IdentityCenter.PermissionSets = output | ||||
|
||||
return nil | ||||
} | ||||
|
||||
func (a *ServerWithRoles) GetNodes(ctx context.Context, namespace string) ([]types.Server, error) { | ||||
if err := a.actionNamespace(namespace, types.KindNode, types.VerbList); err != nil { | ||||
return nil, trace.Wrap(err) | ||||
|
@@ -1831,8 +1888,18 @@ func (r resourceChecker) CanAccess(resource types.Resource) error { | |||
return r.CheckAccess(rr, state) | ||||
|
||||
case types.Resource153Unwrapper: | ||||
if checkable, ok := rr.(services.AccessCheckable); ok { | ||||
return r.CheckAccess(checkable, state) | ||||
checkable, isCheckable := rr.(services.AccessCheckable) | ||||
if isCheckable { | ||||
switch unwrapped := rr.Unwrap().(type) { | ||||
case services.IdentityCenterAccount: | ||||
return r.CheckAccess(checkable, state, services.NewIdentityCenterAccountMatcher(unwrapped)) | ||||
|
||||
case services.IdentityCenterAccountAssignment: | ||||
return r.CheckAccess(checkable, state, services.NewIdentityCenterAccountAssignmentMatcher(unwrapped)) | ||||
|
||||
default: | ||||
return r.CheckAccess(checkable, state) | ||||
} | ||||
} | ||||
} | ||||
|
||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not related to "Filter IC Permission Sets based on access" right ?
Just want to make sure that this is not leftover from local stash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed to change the name value of the "app" to be the account ID - for two reasons:
The knock-on effect of this is that the friendly name is now pulled from the app description.