Skip to content

Support wildcard patterns in RoleARN mappings#994

Open
AndreKurait wants to merge 1 commit intokubernetes-sigs:masterfrom
AndreKurait:wildcard-role-matching
Open

Support wildcard patterns in RoleARN mappings#994
AndreKurait wants to merge 1 commit intokubernetes-sigs:masterfrom
AndreKurait:wildcard-role-matching

Conversation

@AndreKurait
Copy link

What

Extend RoleMapping.Matches() to use ArnLike() for wildcard matching when the RoleARN contains * or ? characters.

Why

The ArnLike matching infrastructure already exists in the codebase (used for SSO role matching via SSOArnLike()) but is not wired up for regular RoleARN mappings, which only support exact string matching via strings.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 the ArnLike approach works — this PR generalizes it to regular role mappings.

Example

mapRoles:
- rolearn: "arn:aws:iam::012345678912:role/dev-*"
  username: "dev-{{SessionName}}"
  groups:
  - developers
- rolearn: "arn:aws:iam::012345678912:role/*"
  username: "{{SessionName}}"
  groups:
  - all-roles

Changes

  • pkg/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)
  • pkg/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

Backward Compatibility

  • Non-wildcard RoleARN mappings are completely unchanged (exact strings.EqualFold path)
  • No new feature flags required — wildcard detection is automatic based on the presence of * or ? in the configured RoleARN
  • The ArnLike function is already well-tested in the existing SSO code path

Testing

All existing tests pass. New tests added:

  • TestWildcardRoleARNMapping — full wildcard role/*, cross-account rejection, cross-resource-type rejection
  • TestWildcardRoleARNPrefixMapping — prefix wildcard role/dev-*
  • TestWildcardRoleMap — end-to-end through FileMapper.Map()

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>
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 4, 2026

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: AndreKurait / name: Andre Kurait (b0e0129)

@k8s-ci-robot
Copy link
Contributor

Welcome @AndreKurait!

It looks like this is your first PR to kubernetes-sigs/aws-iam-authenticator 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/aws-iam-authenticator has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: AndreKurait
Once this PR has been reviewed and has the lgtm label, please assign yue9944882 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions 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.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Mar 4, 2026
@k8s-ci-robot k8s-ci-robot requested a review from haoranleo March 4, 2026 23:10
@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Mar 4, 2026
@k8s-ci-robot k8s-ci-robot requested a review from yue9944882 March 4, 2026 23:10
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Mar 4, 2026
@bryantbiggs
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 16, 2026
@AndreKurait
Copy link
Author

@bryantbiggs did the test finish? Any other changes needed to get this in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants