mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
perf(build): keep the managed policy catalog files out of the native image (#3489)
* perf(build): keep the managed policy catalog files out of the native image AwsManagedPolicies parses iam/managed-policies.yaml, iam/managed-policy-documents.json and iam/managed-policy-versions.json while the image is built, so the parsed catalog is already in the image heap. Listing the files under quarkus.native.resources.includes embedded a second copy of the same 3.5 MB as byte[] resources that nothing reads at run time. Measured on macOS arm64 with Oracle GraalVM 25.0.4.1, two builds each: image heap 102.37 MB to 98.63 MB, resources 386 to 383, binary 215.9 MB to 212.2 MB, gzip -0.39 MB. The native binary still serves all 1566 policies (GetPolicy, GetPolicyVersion, ListPolicies Scope=AWS, AttachUserPolicy) and rejects unknown ARNs with NoSuchEntity. The IAM test classes pass in JVM mode, where the files stay on the classpath. * test(iam): cover AWS managed policies in the Java SDK compatibility suite No suite exercised arn:aws:iam::aws:policy/* against the native image. The catalog is parsed while the image is built and served from the image heap, and the source files are no longer embedded, so a regression there only shows up in a native run. CI runs this suite against the native image on both architectures. Covers GetPolicy for a root path and a service-role path policy, GetPolicyVersion of the default version with an intact document, ListPolicies with Scope=AWS, AttachUserPolicy plus ListAttachedUserPolicies with a managed ARN, and NoSuchEntity for an unknown managed ARN. Passed 40 of 40 against the native binary built from the previous commit. * test(iam): comment * test(iam): declare type explicitly
This commit is contained in:
1 parent
809ce40f1e
commit
24e13f3831
2 files changed
+103
-9
No files matched your search
@@ -35,6 +35,8 @@ import software.amazon.awssdk.services.iam.model.GetInstanceProfileRequest;
|
||||
import software.amazon.awssdk.services.iam.model.GetInstanceProfileResponse;
|
||||
import software.amazon.awssdk.services.iam.model.GetPolicyRequest;
|
||||
import software.amazon.awssdk.services.iam.model.GetPolicyResponse;
|
||||
import software.amazon.awssdk.services.iam.model.GetPolicyVersionRequest;
|
||||
import software.amazon.awssdk.services.iam.model.GetPolicyVersionResponse;
|
||||
import software.amazon.awssdk.services.iam.model.GetRoleRequest;
|
||||
import software.amazon.awssdk.services.iam.model.GetRoleResponse;
|
||||
import software.amazon.awssdk.services.iam.model.GetRolePolicyRequest;
|
||||
@@ -58,6 +60,7 @@ import software.amazon.awssdk.services.iam.model.ListUserTagsRequest;
|
||||
import software.amazon.awssdk.services.iam.model.ListUserTagsResponse;
|
||||
import software.amazon.awssdk.services.iam.model.ListUsersResponse;
|
||||
import software.amazon.awssdk.services.iam.model.NoSuchEntityException;
|
||||
import software.amazon.awssdk.services.iam.model.PolicyScopeType;
|
||||
import software.amazon.awssdk.services.iam.model.PutRolePolicyRequest;
|
||||
import software.amazon.awssdk.services.iam.model.RemoveRoleFromInstanceProfileRequest;
|
||||
import software.amazon.awssdk.services.iam.model.RemoveUserFromGroupRequest;
|
||||
@@ -67,6 +70,10 @@ import software.amazon.awssdk.services.iam.model.TagUserRequest;
|
||||
import software.amazon.awssdk.services.iam.model.UntagUserRequest;
|
||||
import software.amazon.awssdk.services.iam.model.UpdateAccessKeyRequest;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
@DisplayName("IAM Identity and Access Management")
|
||||
@@ -79,6 +86,11 @@ class IamTest {
|
||||
private static final String ROLE_NAME = "sdk-test-role";
|
||||
private static final String POLICY_NAME = "sdk-test-policy";
|
||||
private static final String INSTANCE_PROFILE_NAME = "sdk-test-profile";
|
||||
private static final String AWS_MANAGED_POLICY_PREFIX = "arn:aws:iam::aws:policy/";
|
||||
private static final String ADMIN_POLICY_ARN = AWS_MANAGED_POLICY_PREFIX + "AdministratorAccess";
|
||||
private static final String READ_ONLY_POLICY_ARN = AWS_MANAGED_POLICY_PREFIX + "ReadOnlyAccess";
|
||||
private static final String LAMBDA_BASIC_POLICY_ARN =
|
||||
AWS_MANAGED_POLICY_PREFIX + "service-role/AWSLambdaBasicExecutionRole";
|
||||
private static final String TRUST_POLICY = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","
|
||||
+ "\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}";
|
||||
private static final String POLICY_DOCUMENT = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","
|
||||
@@ -131,6 +143,12 @@ class IamTest {
|
||||
iam.deletePolicy(DeletePolicyRequest.builder().policyArn(policyArn).build());
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
try {
|
||||
iam.detachUserPolicy(DetachUserPolicyRequest.builder()
|
||||
.userName(USER_NAME).policyArn(READ_ONLY_POLICY_ARN).build());
|
||||
} catch (Exception ignored) {
|
||||
// The policy may not have been attached if the test failed before reaching cleanup.
|
||||
}
|
||||
try {
|
||||
iam.removeUserFromGroup(RemoveUserFromGroupRequest.builder()
|
||||
.groupName(GROUP_NAME).userName(USER_NAME).build());
|
||||
@@ -524,4 +542,80 @@ class IamTest {
|
||||
.userName("nonexistent-user-xyz").build()))
|
||||
.isInstanceOf(NoSuchEntityException.class);
|
||||
}
|
||||
|
||||
// ── AWS managed policies ───────────────────────────────────────────
|
||||
// The catalog is parsed while the native image is built and lives in its
|
||||
// heap, so only a run against a native binary proves the documents survived.
|
||||
|
||||
@Test
|
||||
@Order(33)
|
||||
void getAwsManagedPolicy() {
|
||||
GetPolicyResponse response = iam.getPolicy(GetPolicyRequest.builder().policyArn(ADMIN_POLICY_ARN).build());
|
||||
|
||||
assertThat(response.policy().policyName()).isEqualTo("AdministratorAccess");
|
||||
assertThat(response.policy().arn()).isEqualTo(ADMIN_POLICY_ARN);
|
||||
assertThat(response.policy().path()).isEqualTo("/");
|
||||
assertThat(response.policy().defaultVersionId()).matches("v[1-9][0-9]*");
|
||||
assertThat(response.policy().isAttachable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(34)
|
||||
void getAwsManagedPolicyWithServiceRolePath() {
|
||||
GetPolicyResponse response =
|
||||
iam.getPolicy(GetPolicyRequest.builder().policyArn(LAMBDA_BASIC_POLICY_ARN).build());
|
||||
|
||||
assertThat(response.policy().policyName()).isEqualTo("AWSLambdaBasicExecutionRole");
|
||||
assertThat(response.policy().path()).isEqualTo("/service-role/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(35)
|
||||
void getAwsManagedPolicyVersionDocument() {
|
||||
String versionId = iam.getPolicy(GetPolicyRequest.builder().policyArn(ADMIN_POLICY_ARN).build())
|
||||
.policy().defaultVersionId();
|
||||
GetPolicyVersionResponse response = iam.getPolicyVersion(GetPolicyVersionRequest.builder()
|
||||
.policyArn(ADMIN_POLICY_ARN).versionId(versionId).build());
|
||||
|
||||
assertThat(response.policyVersion().versionId()).isEqualTo(versionId);
|
||||
assertThat(response.policyVersion().isDefaultVersion()).isTrue();
|
||||
String document = URLDecoder.decode(response.policyVersion().document(), StandardCharsets.UTF_8);
|
||||
assertThat(document).startsWith("{").contains("\"Statement\"").contains("\"Effect\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(36)
|
||||
void listAwsManagedPolicies() {
|
||||
List<String> names = iam.listPoliciesPaginator(request -> request.scope(PolicyScopeType.AWS))
|
||||
.policies().stream().map(policy -> policy.policyName()).toList();
|
||||
|
||||
assertThat(names).hasSizeGreaterThan(1000)
|
||||
.contains("AdministratorAccess", "ReadOnlyAccess", "AWSLambdaBasicExecutionRole");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(37)
|
||||
void attachAwsManagedPolicyToUser() {
|
||||
iam.attachUserPolicy(AttachUserPolicyRequest.builder()
|
||||
.userName(USER_NAME).policyArn(READ_ONLY_POLICY_ARN).build());
|
||||
|
||||
ListAttachedUserPoliciesResponse response = iam.listAttachedUserPolicies(ListAttachedUserPoliciesRequest.builder()
|
||||
.userName(USER_NAME).build());
|
||||
|
||||
assertThat(response.attachedPolicies())
|
||||
.anyMatch(p -> READ_ONLY_POLICY_ARN.equals(p.policyArn())
|
||||
&& "ReadOnlyAccess".equals(p.policyName()));
|
||||
|
||||
iam.detachUserPolicy(DetachUserPolicyRequest.builder()
|
||||
.userName(USER_NAME).policyArn(READ_ONLY_POLICY_ARN).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(38)
|
||||
void attachUnknownAwsManagedPolicyThrows() {
|
||||
assertThatThrownBy(() -> iam.attachUserPolicy(AttachUserPolicyRequest.builder()
|
||||
.userName(USER_NAME)
|
||||
.policyArn(AWS_MANAGED_POLICY_PREFIX + "NoSuchManagedPolicyXyz").build()))
|
||||
.isInstanceOf(NoSuchEntityException.class);
|
||||
}
|
||||
}
|
||||
@@ -38,20 +38,20 @@ quarkus:
|
||||
add-all-charsets: true
|
||||
resources:
|
||||
# The Pricing service reads its bundled snapshot, EC2 reads its image
|
||||
# catalog (ec2/image-catalog.yaml), IAM reads its AWS managed-policy
|
||||
# catalog (iam/managed-policies.yaml, iam/managed-policy-documents.json and
|
||||
# iam/managed-policy-versions.json), AppSync's GraphQL parser reads its
|
||||
# catalog (ec2/image-catalog.yaml), AppSync's GraphQL parser reads its
|
||||
# message bundles, and API Gateway's Velocity engine reads its default
|
||||
# properties at runtime via
|
||||
# ClassLoader#getResourceAsStream. Quarkus's static resource analysis
|
||||
# cannot detect these dynamically-built paths, so they are registered
|
||||
# explicitly to ensure GraalVM includes every file in the native image.
|
||||
# properties at runtime via ClassLoader#getResourceAsStream. Quarkus's
|
||||
# static resource analysis cannot detect these dynamically-built paths,
|
||||
# so they are registered explicitly to ensure GraalVM includes every
|
||||
# file in the native image.
|
||||
# The IAM managed-policy catalog (iam/*) is not listed on purpose.
|
||||
# AwsManagedPolicies parses it while the image is built and the parsed
|
||||
# catalog lives in the image heap, so the 3.5 MB of source files would
|
||||
# only be a second copy of the same data.
|
||||
includes:
|
||||
- pricing-snapshots/**
|
||||
- ui/*.html
|
||||
- ec2/*.yaml
|
||||
- iam/*.yaml
|
||||
- iam/*.json
|
||||
- i18n/*.properties
|
||||
- org/apache/velocity/runtime/defaults/*.properties
|
||||
# DriverManager finds the JDBC drivers through ServiceLoader, and the MySQL
|
||||
|
||||
Reference in new issue
Block a user