mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(eks): preserve scoped authorization for deletion waiters (#8580)
Deleting an EKS add-on or Fargate profile now keeps only its ARN for IAM authorization, keyed by the cluster's incarnation, so a deletion waiter with a resource-scoped describe grant receives ResourceNotFoundException instead of AccessDeniedException, while an unrelated grant or an explicit deny still gets 403. Describe and list still report the resource as gone, recreation clears the kept ARN and cluster deletion purges it. Resource tags are not kept. Closes #8494
This commit is contained in:
1 parent
0d6aa45d1f
commit
6eb66cd6bf
6 files changed
+147
-6
No files matched your search
@@ -49,6 +49,7 @@ public class EksAddonService {
|
||||
|
||||
private final StorageBackend<String, StoredAddon> storage;
|
||||
private final StorageBackend<String, StoredUpdate> updatesStorage;
|
||||
private final StorageBackend<String, String> deletedArns;
|
||||
private final EksAddonCatalog catalog;
|
||||
private final IamService iam;
|
||||
private final EksPodIdentityAssociationService podIdentityAssociations;
|
||||
@@ -60,16 +61,20 @@ public class EksAddonService {
|
||||
new TypeReference<Map<String, StoredAddon>>() {}),
|
||||
storageFactory.create("eks", "eks-updates.json",
|
||||
new TypeReference<Map<String, StoredUpdate>>() {}),
|
||||
storageFactory.create("eks", "eks-addon-deleted-arns.json",
|
||||
new TypeReference<Map<String, String>>() {}),
|
||||
catalog, iam, podIdentityAssociations);
|
||||
}
|
||||
|
||||
EksAddonService(StorageBackend<String, StoredAddon> storage,
|
||||
StorageBackend<String, StoredUpdate> updatesStorage,
|
||||
StorageBackend<String, String> deletedArns,
|
||||
EksAddonCatalog catalog,
|
||||
IamService iam,
|
||||
EksPodIdentityAssociationService podIdentityAssociations) {
|
||||
this.storage = storage;
|
||||
this.updatesStorage = updatesStorage;
|
||||
this.deletedArns = deletedArns;
|
||||
this.catalog = catalog;
|
||||
this.iam = iam;
|
||||
this.podIdentityAssociations = podIdentityAssociations;
|
||||
@@ -159,6 +164,7 @@ public class EksAddonService {
|
||||
);
|
||||
|
||||
storage.put(storageKey, new StoredAddon(addon, request.clientRequestToken()));
|
||||
deletedArns.delete(storageKey);
|
||||
LOG.infov("Created EKS addon {0} on cluster {1} with version {2}", addonName, cluster.getName(), version);
|
||||
return addon;
|
||||
}
|
||||
@@ -304,6 +310,7 @@ public class EksAddonService {
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"No addon: " + addonName + " found for cluster: " + cluster.getName(), 404));
|
||||
|
||||
deletedArns.put(storageKey, stored.addon().addonArn());
|
||||
storage.delete(storageKey);
|
||||
if (preserve) {
|
||||
LOG.infov("Deleted EKS addon {0} on cluster {1} (preserve=true)", addonName, cluster.getName());
|
||||
@@ -335,11 +342,23 @@ public class EksAddonService {
|
||||
);
|
||||
}
|
||||
|
||||
/** Retain only the deleted ARN so scoped IAM policies still authorize deletion waiters. */
|
||||
public synchronized Optional<String> authorizationArn(Cluster cluster, String addonName) {
|
||||
requireActiveCluster(cluster);
|
||||
if (addonName == null || addonName.isBlank()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
String key = prefix(cluster) + addonName.trim().toLowerCase(Locale.ROOT);
|
||||
return storage.get(key).map(stored -> stored.addon().addonArn())
|
||||
.or(() -> deletedArns.get(key));
|
||||
}
|
||||
|
||||
public synchronized void deleteClusterAddons(Cluster cluster) {
|
||||
if (cluster != null) {
|
||||
String p = prefix(cluster);
|
||||
storage.keys().stream().filter(k -> k.startsWith(p)).toList().forEach(storage::delete);
|
||||
updatesStorage.keys().stream().filter(k -> k.startsWith(p)).toList().forEach(updatesStorage::delete);
|
||||
deletedArns.keys().stream().filter(k -> k.startsWith(p)).toList().forEach(deletedArns::delete);
|
||||
LOG.infov("Purged all addons and updates for cluster {0}", cluster.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +106,7 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
|
||||
private final StorageBackend<String, Cluster> storage;
|
||||
private final StorageBackend<String, Nodegroup> nodeGroupStorage;
|
||||
private final StorageBackend<String, FargateProfile> fargateProfileStorage;
|
||||
private final StorageBackend<String, String> deletedFargateArns;
|
||||
private final EmulatorConfig config;
|
||||
private final RegionResolver regionResolver;
|
||||
private final EksClusterManager clusterManager;
|
||||
@@ -140,6 +141,8 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
|
||||
this.fargateProfileStorage = storageFactory.create("eks", "eks-fargate-profiles.json",
|
||||
new TypeReference<Map<String, FargateProfile>>() {
|
||||
});
|
||||
this.deletedFargateArns = storageFactory.create("eks", "eks-deleted-fargate-arns.json",
|
||||
new TypeReference<Map<String, String>>() {});
|
||||
this.config = config;
|
||||
this.regionResolver = regionResolver;
|
||||
this.clusterManager = clusterManager;
|
||||
@@ -956,7 +959,7 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
|
||||
* cluster {@code clusterName} when {@code collection} is null, or else the node group, Fargate profile,
|
||||
* add-on, access entry or Pod Identity association {@code name} in that cluster, by the route's
|
||||
* collection segment, or for the update {@code name} the add-on it was made to. Empty when there is none,
|
||||
* or the handler would refuse the lookup.
|
||||
* or the handler would refuse the lookup. Deleted add-ons and Fargate profiles retain their ARN for scoped IAM deletion waiters.
|
||||
*/
|
||||
public Optional<String> findResourceArn(String clusterName, String collection, String name) {
|
||||
Optional<Cluster> cluster = storage.get(requestClusterKey(clusterName));
|
||||
@@ -966,8 +969,8 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
|
||||
try {
|
||||
return Optional.ofNullable(switch (collection) {
|
||||
case "node-groups" -> describeNodeGroup(clusterName, name).getNodegroupArn();
|
||||
case "fargate-profiles" -> describeFargateProfile(clusterName, name).getFargateProfileArn();
|
||||
case "addons" -> addons.describe(cluster.get(), name).addonArn();
|
||||
case "fargate-profiles" -> fargateAuthorizationArn(cluster.get(), name).orElse(null);
|
||||
case "addons" -> addons.authorizationArn(cluster.get(), name).orElse(null);
|
||||
case "access-entries" -> accessEntries.describe(cluster.get(), name).accessEntryArn();
|
||||
case "pod-identity-associations" -> podIdentityAssociations.describe(cluster.get(), name).associationArn();
|
||||
case "updates" -> {
|
||||
@@ -1149,6 +1152,9 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
|
||||
if (addons != null) {
|
||||
addons.deleteClusterAddons(cluster);
|
||||
}
|
||||
String deletedPrefix = deletedFargatePrefix(cluster);
|
||||
deletedFargateArns.keys().stream().filter(key -> key.startsWith(deletedPrefix))
|
||||
.toList().forEach(deletedFargateArns::delete);
|
||||
synchronized (clustersBeingDeleted) {
|
||||
storage.delete(clusterKey(cluster));
|
||||
clearAppliedClusterUserData(cluster, name);
|
||||
@@ -1455,7 +1461,7 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
|
||||
}
|
||||
}
|
||||
|
||||
public FargateProfile createFargateProfile(String clusterName, CreateFargateProfileRequest request) {
|
||||
public synchronized FargateProfile createFargateProfile(String clusterName, CreateFargateProfileRequest request) {
|
||||
Cluster cluster = describeCluster(clusterName);
|
||||
|
||||
String fargateProfileName = request.getFargateProfileName();
|
||||
@@ -1492,6 +1498,7 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
|
||||
profile.setTags(request.getTags() != null ? new HashMap<>(request.getTags()) : new HashMap<>());
|
||||
|
||||
fargateProfileStorage.put(storageKey, profile);
|
||||
deletedFargateArns.delete(deletedFargatePrefix(cluster) + fargateProfileName);
|
||||
return profile;
|
||||
}
|
||||
|
||||
@@ -1510,8 +1517,20 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public FargateProfile deleteFargateProfile(String clusterName, String fargateProfileName) {
|
||||
private static String deletedFargatePrefix(Cluster cluster) {
|
||||
return cluster.getArn() + "/" + Objects.toString(cluster.getCreatedAt()) + "/";
|
||||
}
|
||||
|
||||
private synchronized Optional<String> fargateAuthorizationArn(Cluster cluster, String name) {
|
||||
return fargateProfileStorage.get(fargateProfileKey(clusterKey(cluster), name))
|
||||
.map(FargateProfile::getFargateProfileArn)
|
||||
.or(() -> deletedFargateArns.get(deletedFargatePrefix(cluster) + name));
|
||||
}
|
||||
|
||||
public synchronized FargateProfile deleteFargateProfile(String clusterName, String fargateProfileName) {
|
||||
FargateProfile profile = describeFargateProfile(clusterName, fargateProfileName);
|
||||
deletedFargateArns.put(deletedFargatePrefix(describeCluster(clusterName)) + fargateProfileName,
|
||||
profile.getFargateProfileArn());
|
||||
profile.setStatus(FargateProfileStatus.DELETING);
|
||||
fargateProfileStorage.delete(fargateProfileKey(requestClusterKey(clusterName), fargateProfileName));
|
||||
return profile;
|
||||
|
||||
Reference in new issue
Block a user