feat(eks): associate access policies with access entries (#6427)

AssociateAccessPolicy, ListAssociatedAccessPolicies and
DisassociateAccessPolicy had no route, so their requests fell through to
S3's path-style catch-all and came back as an S3 XML error. Terraform's
aws_eks_access_policy_association could not be created.

The three operations follow access entries: they are management
metadata, stored and returned but not enforced in Kubernetes. Each
association is kept on its access entry, so deleting the entry or the
cluster removes it, and entries persisted before this change load with
no policies. ListAccessEntries now honours associatedPolicyArn.

Validation follows the EKS user guide: only STANDARD entries take access
policies, the scope is cluster (no namespaces) or namespace (one or more
names, wildcards kept, a repeated name stored once), and associating a
policy again replaces its scope and keeps its associatedAt. policyArn
must be an EKS cluster access policy ARN in the cluster's partition; the
name is not checked against AWS's list. Listing pages from 1 to 100,
with tokens bound to the entry they came from. Disassociating a policy
the entry does not hold succeeds, since EKS documents no error for it;
a missing entry is still ResourceNotFoundException, and an ARN that
associate would refuse is InvalidParameterException. ListAccessEntries
now pages through the shared Pagination helper too, so a token issued
before this change is refused.

Under IAM enforcement the list and disassociate routes were checked as
DescribeAccessEntry and DeleteAccessEntry, and all three against a
principal ending in /access-policies, so a grant scoped to the entry
never matched. They are now checked as their own actions, against the
entry's ARN.

A DELETE is a disassociate only when a cluster access policy ARN
follows access-policies, in the route, the IAM rule and the resource,
so an entry whose IAM path holds an access-policies segment can still
be deleted. The router matches the encoded path, so a principal sent
URL-encoded, as the SDKs send it, is never split.

Co-authored-by: Robin Baeckman <27041454+RobinBaeckman@users.noreply.github.com>
This commit is contained in:
Robin BaeckmanandRobin Baeckman authored and GitHub committed 2026-10-26 07:54:43 -04:00
1 parent bc75edb4c4
commit 7453011c43
15 files changed
+719 -79

No files matched your search

@@ -39,6 +39,27 @@ class EksAccessEntryTest {
assertThat(eks.describeAccessEntry(builder -> builder.clusterName(cluster).principalArn(first))
.accessEntry().principalArn()).isEqualTo(first);
eks.createAccessEntry(builder -> builder.clusterName(cluster).principalArn(second));
String admin = "arn:aws:eks::aws:cluster-access-policy/AmazonEKSClusterAdminPolicy";
AssociateAccessPolicyResponse associated = eks.associateAccessPolicy(builder -> builder
.clusterName(cluster).principalArn(second).policyArn(admin)
.accessScope(scope -> scope.type(AccessScopeType.NAMESPACE).namespaces("dev-*", "payments")));
assertThat(associated.principalArn()).isEqualTo(second);
assertThat(associated.associatedAccessPolicy().associatedAt()).isNotNull();
ListAssociatedAccessPoliciesResponse policies = eks.listAssociatedAccessPolicies(builder -> builder
.clusterName(cluster).principalArn(second));
assertThat(policies.associatedAccessPolicies()).singleElement().satisfies(policy -> {
assertThat(policy.policyArn()).isEqualTo(admin);
assertThat(policy.accessScope().type()).isEqualTo(AccessScopeType.NAMESPACE);
assertThat(policy.accessScope().namespaces()).containsExactly("dev-*", "payments");
});
assertThatThrownBy(() -> eks.associateAccessPolicy(builder -> builder.clusterName(cluster)
.principalArn(first).policyArn(admin).accessScope(scope -> scope.type(AccessScopeType.CLUSTER))))
.isInstanceOf(InvalidRequestException.class);
eks.disassociateAccessPolicy(builder -> builder.clusterName(cluster).principalArn(second).policyArn(admin));
assertThat(eks.listAssociatedAccessPolicies(builder -> builder.clusterName(cluster).principalArn(second))
.associatedAccessPolicies()).isEmpty();
// Removing a policy the entry no longer holds succeeds, like the first removal.
eks.disassociateAccessPolicy(builder -> builder.clusterName(cluster).principalArn(second).policyArn(admin));
ListAccessEntriesResponse page = eks.listAccessEntries(builder -> builder.clusterName(cluster).maxResults(1));
assertThat(page.accessEntries()).hasSize(1);
assertThat(page.nextToken()).isNotBlank();