-
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
Adds Roles for IC resource access requests #49565
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7dace6d
Adds IC Account Assignments to preset `access` role
tcsc 114f00a
Merge branch 'master' into tcsc/idc-roles
tcsc af4448a
Adds IC Account Assignments to preset `access` role
tcsc c043d75
Merge remote-tracking branch 'refs/remotes/origin/tcsc/idc-roles' int…
tcsc 0eb1c5a
Add default roles if not present
tcsc 16b5f33
Merge branch 'master' into tcsc/idc-roles
tcsc 4347058
Add reviewer role
tcsc c6b0a40
Update lib/services/presets.go
tcsc f99a58d
apply feedback
tcsc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -28,8 +28,10 @@ import ( | |||||||||||||||
"github.com/gravitational/teleport/api/constants" | ||||||||||||||||
apidefaults "github.com/gravitational/teleport/api/defaults" | ||||||||||||||||
"github.com/gravitational/teleport/api/types" | ||||||||||||||||
"github.com/gravitational/teleport/api/types/common" | ||||||||||||||||
apiutils "github.com/gravitational/teleport/api/utils" | ||||||||||||||||
"github.com/gravitational/teleport/lib/modules" | ||||||||||||||||
"github.com/gravitational/teleport/lib/utils" | ||||||||||||||||
) | ||||||||||||||||
|
||||||||||||||||
// NewSystemAutomaticAccessApproverRole creates a new Role that is allowed to | ||||||||||||||||
|
@@ -579,6 +581,32 @@ func NewSystemOktaRequesterRole() types.Role { | |||||||||||||||
return role | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// NewSystemIdentityCenterAccessRole creates a role that allows access to AWS | ||||||||||||||||
// IdentityCenter resources via Access Requests | ||||||||||||||||
func NewSystemIdentityCenterAccessRole() types.Role { | ||||||||||||||||
if modules.GetModules().BuildType() != modules.BuildEnterprise { | ||||||||||||||||
return nil | ||||||||||||||||
} | ||||||||||||||||
return &types.RoleV6{ | ||||||||||||||||
Kind: types.KindRole, | ||||||||||||||||
Version: types.V7, | ||||||||||||||||
Metadata: types.Metadata{ | ||||||||||||||||
Name: teleport.SystemIdentityCenterAccessRoleName, | ||||||||||||||||
Namespace: apidefaults.Namespace, | ||||||||||||||||
Description: "Access AWS IAM Identity Center resources", | ||||||||||||||||
Labels: map[string]string{ | ||||||||||||||||
types.TeleportInternalResourceType: types.SystemResource, | ||||||||||||||||
types.OriginLabel: common.OriginAWSIdentityCenter, | ||||||||||||||||
}, | ||||||||||||||||
}, | ||||||||||||||||
Spec: types.RoleSpecV6{ | ||||||||||||||||
Allow: types.RoleConditions{ | ||||||||||||||||
AccountAssignments: defaultAllowAccountAssignments(true)[teleport.SystemIdentityCenterAccessRoleName], | ||||||||||||||||
}, | ||||||||||||||||
}, | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// NewPresetTerraformProviderRole returns a new pre-defined role for the Teleport Terraform provider. | ||||||||||||||||
// This role can edit any Terraform-supported resource. | ||||||||||||||||
func NewPresetTerraformProviderRole() types.Role { | ||||||||||||||||
|
@@ -718,6 +746,7 @@ func defaultAllowAccessRequestConditions(enterprise bool) map[string]*types.Acce | |||||||||||||||
SearchAsRoles: []string{ | ||||||||||||||||
teleport.PresetAccessRoleName, | ||||||||||||||||
teleport.PresetGroupAccessRoleName, | ||||||||||||||||
teleport.SystemIdentityCenterAccessRoleName, | ||||||||||||||||
}, | ||||||||||||||||
}, | ||||||||||||||||
teleport.SystemOktaRequesterRoleName: { | ||||||||||||||||
|
@@ -741,10 +770,12 @@ func defaultAllowAccessReviewConditions(enterprise bool) map[string]*types.Acces | |||||||||||||||
PreviewAsRoles: []string{ | ||||||||||||||||
teleport.PresetAccessRoleName, | ||||||||||||||||
teleport.PresetGroupAccessRoleName, | ||||||||||||||||
teleport.SystemIdentityCenterAccessRoleName, | ||||||||||||||||
}, | ||||||||||||||||
Roles: []string{ | ||||||||||||||||
teleport.PresetAccessRoleName, | ||||||||||||||||
teleport.PresetGroupAccessRoleName, | ||||||||||||||||
teleport.SystemIdentityCenterAccessRoleName, | ||||||||||||||||
}, | ||||||||||||||||
}, | ||||||||||||||||
} | ||||||||||||||||
|
@@ -753,6 +784,21 @@ func defaultAllowAccessReviewConditions(enterprise bool) map[string]*types.Acces | |||||||||||||||
return map[string]*types.AccessReviewConditions{} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
func defaultAllowAccountAssignments(enterprise bool) map[string][]types.IdentityCenterAccountAssignment { | ||||||||||||||||
if enterprise { | ||||||||||||||||
return map[string][]types.IdentityCenterAccountAssignment{ | ||||||||||||||||
teleport.SystemIdentityCenterAccessRoleName: { | ||||||||||||||||
{ | ||||||||||||||||
Account: types.Wildcard, | ||||||||||||||||
PermissionSet: types.Wildcard, | ||||||||||||||||
}, | ||||||||||||||||
}, | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
return map[string][]types.IdentityCenterAccountAssignment{} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// AddRoleDefaults adds default role attributes to a preset role. | ||||||||||||||||
// Only attributes whose resources are not already defined (either allowing or denying) are added. | ||||||||||||||||
func AddRoleDefaults(role types.Role) (types.Role, error) { | ||||||||||||||||
|
@@ -854,18 +900,18 @@ func AddRoleDefaults(role types.Role) (types.Role, error) { | |||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
if role.GetAccessRequestConditions(types.Allow).IsEmpty() { | ||||||||||||||||
arc := defaultAllowAccessRequestConditions(enterprise)[role.GetName()] | ||||||||||||||||
if arc != nil { | ||||||||||||||||
role.SetAccessRequestConditions(types.Allow, *arc) | ||||||||||||||||
changed = true | ||||||||||||||||
} | ||||||||||||||||
if roleUpdated := applyAccessRequestConditionDefaults(role, enterprise); roleUpdated { | ||||||||||||||||
changed = true | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
if role.GetAccessReviewConditions(types.Allow).IsEmpty() { | ||||||||||||||||
arc := defaultAllowAccessReviewConditions(enterprise)[role.GetName()] | ||||||||||||||||
if arc != nil { | ||||||||||||||||
role.SetAccessReviewConditions(types.Allow, *arc) | ||||||||||||||||
if roleUpdated := applyAccessReviewConditionDefaults(role, enterprise); roleUpdated { | ||||||||||||||||
changed = true | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
if len(role.GetIdentityCenterAccountAssignments(types.Allow)) == 0 { | ||||||||||||||||
assignments := defaultAllowAccountAssignments(enterprise)[role.GetName()] | ||||||||||||||||
if assignments != nil { | ||||||||||||||||
role.SetIdentityCenterAccountAssignments(types.Allow, assignments) | ||||||||||||||||
changed = true | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
@@ -877,6 +923,72 @@ func AddRoleDefaults(role types.Role) (types.Role, error) { | |||||||||||||||
return role, nil | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
func mergeStrings(dst, src []string) (merged []string, changed bool) { | ||||||||||||||||
items := utils.NewSet[string](dst...) | ||||||||||||||||
items.Add(src...) | ||||||||||||||||
if len(items) == len(dst) { | ||||||||||||||||
return dst, false | ||||||||||||||||
} | ||||||||||||||||
dst = items.Elements() | ||||||||||||||||
slices.Sort(dst) | ||||||||||||||||
return dst, true | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
func applyAccessRequestConditionDefaults(role types.Role, enterprise bool) bool { | ||||||||||||||||
defaults := defaultAllowAccessRequestConditions(enterprise)[role.GetName()] | ||||||||||||||||
if defaults == nil { | ||||||||||||||||
return false | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
target := role.GetAccessRequestConditions(types.Allow) | ||||||||||||||||
changed := false | ||||||||||||||||
if target.IsEmpty() { | ||||||||||||||||
target = *defaults | ||||||||||||||||
changed = true | ||||||||||||||||
} else { | ||||||||||||||||
var rolesUpdated bool | ||||||||||||||||
|
||||||||||||||||
target.Roles, rolesUpdated = mergeStrings(target.Roles, defaults.Roles) | ||||||||||||||||
changed = changed || rolesUpdated | ||||||||||||||||
|
||||||||||||||||
target.SearchAsRoles, rolesUpdated = mergeStrings(target.SearchAsRoles, defaults.SearchAsRoles) | ||||||||||||||||
changed = changed || rolesUpdated | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
if changed { | ||||||||||||||||
role.SetAccessRequestConditions(types.Allow, target) | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
return changed | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
func applyAccessReviewConditionDefaults(role types.Role, enterprise bool) bool { | ||||||||||||||||
defaults := defaultAllowAccessReviewConditions(enterprise)[role.GetName()] | ||||||||||||||||
if defaults == nil { | ||||||||||||||||
return false | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
target := role.GetAccessReviewConditions(types.Allow) | ||||||||||||||||
changed := false | ||||||||||||||||
if target.IsEmpty() { | ||||||||||||||||
target = *defaults | ||||||||||||||||
changed = true | ||||||||||||||||
} else { | ||||||||||||||||
var rolesUpdated bool | ||||||||||||||||
|
||||||||||||||||
target.Roles, rolesUpdated = mergeStrings(target.Roles, defaults.Roles) | ||||||||||||||||
changed = changed || rolesUpdated | ||||||||||||||||
|
||||||||||||||||
target.PreviewAsRoles, rolesUpdated = mergeStrings(target.PreviewAsRoles, defaults.PreviewAsRoles) | ||||||||||||||||
changed = changed || rolesUpdated | ||||||||||||||||
Comment on lines
+979
to
+983
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.
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
if changed { | ||||||||||||||||
role.SetAccessReviewConditions(types.Allow, target) | ||||||||||||||||
} | ||||||||||||||||
return changed | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
func labelMatchersUnset(role types.Role, kind string) (bool, error) { | ||||||||||||||||
for _, cond := range []types.RoleConditionType{types.Allow, types.Deny} { | ||||||||||||||||
labelMatchers, err := role.GetLabelMatchers(cond, kind) | ||||||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hmm isn't this the equivalent (and cleaner) or am I missing something?
Same below.
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.
If the first
mergeStrings
call changes the roles but the second one doesn't, then thechanged
flag will be incorrectly reset and the change won't be propagated.