Support wildcard patterns in RoleARN mappings#994
Support wildcard patterns in RoleARN mappings#994AndreKurait wants to merge 1 commit intokubernetes-sigs:masterfrom
Conversation
Extend RoleMapping.Matches() to use ArnLike() for wildcard matching
when the RoleARN contains '*' or '?' characters. The ArnLike matching
infrastructure already existed in the codebase (used for SSO role
matching) but was not wired up for regular RoleARN mappings, which
only supported exact string matching via strings.EqualFold().
This enables configurations like:
rolearn: arn:aws:iam::012345678912:role/dev-*
username: dev-{{SessionName}}
groups:
- developers
Changes:
- config/mapper.go: RoleMapping.Matches() now delegates to arn.ArnLike()
when the RoleARN contains wildcard characters, falling back to exact
match for non-wildcard ARNs (no behavior change for existing configs)
- mapper/file/mapper.go: NewFileMapper skips arn.Canonicalize() for
wildcard RoleARNs (the AWS ARN parser rejects wildcards) and stores
them lowercased instead
- Tests added for both unit (Matches) and integration (FileMapper.Map)
levels covering prefix wildcards, full wildcards, cross-account
rejection, and cross-resource-type rejection
Signed-off-by: Andre Kurait <akurait@amazon.com>
|
|
|
Welcome @AndreKurait! |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: AndreKurait The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @AndreKurait. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/ok-to-test |
|
@bryantbiggs did the test finish? Any other changes needed to get this in? |
What
Extend
RoleMapping.Matches()to useArnLike()for wildcard matching when theRoleARNcontains*or?characters.Why
The
ArnLikematching infrastructure already exists in the codebase (used for SSO role matching viaSSOArnLike()) but is not wired up for regularRoleARNmappings, which only support exact string matching viastrings.EqualFold().This means there is no way to map a pattern of roles (e.g., all roles with a
dev-prefix, or all roles in an account) without enumerating each one individually. The SSO feature (issue #333) proved theArnLikeapproach works — this PR generalizes it to regular role mappings.Example
Changes
pkg/config/mapper.go:RoleMapping.Matches()now delegates toarn.ArnLike()when theRoleARNcontains wildcard characters, falling back to exact match for non-wildcard ARNs (no behavior change for existing configs)pkg/mapper/file/mapper.go:NewFileMapperskipsarn.Canonicalize()for wildcardRoleARNs (the AWS ARN parser rejects wildcards) and stores them lowercased insteadMatches) and integration (FileMapper.Map) levels covering prefix wildcards, full wildcards, cross-account rejection, and cross-resource-type rejectionBackward Compatibility
RoleARNmappings are completely unchanged (exactstrings.EqualFoldpath)*or?in the configuredRoleARNArnLikefunction is already well-tested in the existing SSO code pathTesting
All existing tests pass. New tests added:
TestWildcardRoleARNMapping— full wildcardrole/*, cross-account rejection, cross-resource-type rejectionTestWildcardRoleARNPrefixMapping— prefix wildcardrole/dev-*TestWildcardRoleMap— end-to-end throughFileMapper.Map()