Add support for mapping AWS root account principals#995
Add support for mapping AWS root account principals#995AndreKurait wants to merge 1 commit intokubernetes-sigs:masterfrom
Conversation
Add a dedicated RootMapping type and rootMap to the file mapper,
mirroring the existing RoleMapping/roleMap and UserMapping/userMap
pattern.
Previously, root account principals (arn:aws:iam::ACCOUNT:root) were
parsed correctly by arn.Canonicalize() (returning the ROOT principal
type), but then fell through all mappers with ErrNotMapped because no
mapper had a code path for root ARNs. The only way a root principal
could authenticate was via AutoMappedAWSAccounts, which grants access
to the entire account without explicit mapping control.
This adds:
- RootMapping struct in config/types.go with rootarn, username, groups
- Validate(), Matches(), Key(), IdentityMapping() methods mirroring
UserMapping
- rootMap in FileMapper with population from Config.RootMappings
- Root lookup in FileMapper.Map() after role and user lookups
Example configuration:
mapRoots:
- rootarn: arn:aws:iam::012345678912:root
username: root-admin
groups:
- system:masters
Signed-off-by: Andre Kurait <akurait@amazon.com>
|
[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 Any feedback based on the successful tests? |
|
Curious about the motivation here — if you have root credentials, you can create any IAM role or user you need, so every case that might seem to require root auth has an alternative (assume a role and use EKS Access Entries (AWS's own replacement for |
What
Add a dedicated
RootMappingtype androotMapto the file mapper, enabling explicit mapping of AWS root account principals (arn:aws:iam::ACCOUNT:root) to Kubernetes usernames and groups.Why
Root account principals are already parsed correctly by
arn.Canonicalize()— it returns theROOTprincipal type and the canonical ARN. The token verification code intoken.goalso handles root correctly (line 755:if principalType == arn.FEDERATED_USER || principalType == arn.USER || principalType == arn.ROOT).However, when the identity reaches the mapper, it falls through with
ErrNotMappedbecause:roleMaponly contains role ARNsuserMaponly contains user ARNsrootMapThe only way a root principal can currently authenticate is via
AutoMappedAWSAccounts, which grants blanket access to the entire account without explicit mapping control. There is no way to map root to specific Kubernetes groups while excluding other principals from the same account.Example
Changes
pkg/config/types.go: NewRootMappingstruct withrootarn,username,groupsfields. NewRootMappings []RootMappingfield onConfig.pkg/config/mapper.go:Validate(),Matches(),Key(),IdentityMapping()methods onRootMapping, mirroringUserMapping.pkg/mapper/file/mapper.go:rootMapfield onFileMapper, populated fromConfig.RootMappingswitharn.Canonicalize()validation. Lookup inMap()after role and user lookups.RootMappingmethods and end-to-endFileMapper.Map()test covering match, cross-account rejection, and cross-resource-type rejection.Design
Mirrors the existing
UserMapping/userMappattern exactly:UserMappingorRoleMapping)userMap)arn.Canonicalize()validation at load timeMap()(root auth is rare, so checked last)Backward Compatibility
RootMappingsdefaults to empty — no root mappings unless explicitly configuredAutoMappedAWSAccountswill continue to work via that path (the root map is checked beforeIsAccountAllowedindoMapping)Testing
All existing tests pass. New tests:
TestRootARNMapping—Validate(),Matches(),Key()methodsTestRootMap— end-to-end throughFileMapper.Map()with match, cross-account rejection, cross-resource-type rejection