mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(iam): select EC2 interface and endpoint authorization resources (#8892)
* fix(iam): select EC2 interface and endpoint authorization resources
This commit is contained in:
1 parent
c91740de85
commit
875794c538
11 files changed
+714
-18
No files matched your search
@@ -328,7 +328,8 @@ public final class RequestResources {
|
||||
for (String id : ids) {
|
||||
String arn = "*";
|
||||
for (Map.Entry<String, String> prefix : targets.prefixes().entrySet()) {
|
||||
if (id.startsWith(prefix.getValue())) {
|
||||
// A longer, uncovered resource prefix must not borrow a shorter covered type's ARN.
|
||||
if (id.startsWith(prefix.getValue()) && id.indexOf('-', prefix.getValue().length()) < 0) {
|
||||
arn = idArn(formats.get(prefix.getKey()).format(), id, partition, region, accountId);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -17425,6 +17425,31 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
return attachment;
|
||||
}
|
||||
|
||||
/** The endpoints of an attachment held in the caller's account and Region, without changing it. */
|
||||
List<String> networkInterfaceAttachmentArns(String region, String attachmentId) {
|
||||
if (attachmentId == null || attachmentId.isBlank()) {
|
||||
return List.of();
|
||||
}
|
||||
String account = callerAccountId();
|
||||
synchronized (attachmentTopologyLock(region)) {
|
||||
List<NetworkInterface> interfaces =
|
||||
networkInterfaces instanceof AccountAwareStorageBackend<NetworkInterface> aware
|
||||
? aware.scanForAccount(account, k -> k.startsWith(region + "::"))
|
||||
: networkInterfaces.scan(k -> k.startsWith(region + "::"));
|
||||
NetworkInterface attached = interfaces.stream()
|
||||
.filter(ni -> ni.getAttachment() != null && attachmentId.equals(ni.getAttachment().getAttachmentId()))
|
||||
.findFirst().orElse(null);
|
||||
if (attached == null) {
|
||||
return List.of();
|
||||
}
|
||||
String instanceId = attached.getAttachment().getInstanceId();
|
||||
String interfaceId = attached.getNetworkInterfaceId();
|
||||
return List.of(AwsArnUtils.Arn.of("ec2", region, account,
|
||||
"instance/" + (instanceId == null ? "*" : instanceId)).toString(),
|
||||
AwsArnUtils.Arn.of("ec2", region, account, "network-interface/" + interfaceId).toString());
|
||||
}
|
||||
}
|
||||
|
||||
/** Detaches a standalone ENI by attachment id, floci-kt9. */
|
||||
public NetworkInterfaceAttachment detachNetworkInterface(String region, String attachmentId, boolean force) {
|
||||
if (attachmentId == null || attachmentId.isBlank()) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.floci.aws.services.ec2;
|
||||
|
||||
import io.floci.aws.core.common.AwsArnUtils;
|
||||
import io.floci.aws.core.common.StoredResourceArns;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -7,7 +8,7 @@ import jakarta.inject.Inject;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/** Resolves the caller's launch-template names to their stored ID-based ARNs. */
|
||||
/** Resolves the caller's launch-template names and network-interface attachments to resource ARNs. */
|
||||
@ApplicationScoped
|
||||
public class Ec2StoredResourceArns implements StoredResourceArns {
|
||||
|
||||
@@ -23,6 +24,16 @@ public class Ec2StoredResourceArns implements StoredResourceArns {
|
||||
return "ec2";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> findByMembers(String type, List<String> names, String region) {
|
||||
if (("instance".equals(type) || "network-interface".equals(type)) && names.size() == 1) {
|
||||
return ec2.networkInterfaceAttachmentArns(region, names.getFirst()).stream()
|
||||
.filter(arn -> AwsArnUtils.parse(arn).resource().startsWith(type + "/"))
|
||||
.findFirst();
|
||||
}
|
||||
return find(type, names, region);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> find(String type, List<String> names, String region) {
|
||||
return "launch-template".equals(type) && names.size() == 1
|
||||
|
||||
Reference in new issue
Block a user