fix(iam): seed the full AWS managed policy catalog (#2194)

* fix(iam): seed the full AWS managed policy catalog

AttachRolePolicy and GetPolicy resolved arn:aws:iam::aws:policy/* against a
hand-maintained list of 59 entries, so any policy outside it returned
NoSuchEntity even though AWS publishes it. Real Terraform and CloudFormation
configurations failed for a reason unrelated to the user's setup — attaching
AmazonEC2ReadOnlyAccess or service-role/AmazonElasticMapReduceRole was enough
to break a stack — and the list could only be extended one policy per PR.

The catalog now carries the full published list (1566 entries), loaded from
iam/managed-policies.yaml following the existing ec2/image-catalog.yaml
pattern. AwsManagedPolicies keeps its POLICIES and ManagedPolicyDef surface,
so callers and tests are unaffected.

Unknown ARNs still return NoSuchEntity/404. That matters as much as the
additions: resolving every well-formed ARN would accept typos that real AWS
rejects and would stop CloudFormation rolling a stack back on a bad
attachment. Seeding the real catalog is what makes the check faithful in both
directions rather than trading one wrong answer for another.

The catalog is a union with the previously seeded entries, so a policy AWS has
since retired but which Floci already resolved — AWSLambdaFullAccess — keeps
working. Curated descriptions are preserved.

seedAwsManagedPolicies no longer mirrors the catalog into the account store.
That copy was never read back, since listPolicies filters AWS-managed ARNs out
of the local scan and serves them from the catalog, and writing 1566 entries on
every start cost ~1.4 MB of persisted state and ~3.7s of persistent-mode
startup.

Policy names and paths derive from the public AWS managed policy list via
https://github.com/iann0036/iam-dataset (MIT); only names and paths are used.
Regenerate against a real account with `aws iam list-policies --scope AWS`.

* fix(iam): register the managed-policy catalog for native image builds

AwsManagedPolicies reads iam/managed-policies.yaml through
ClassLoader#getResourceAsStream, which Quarkus's static resource analysis
cannot see. Without an explicit registration the file is absent from the
native image, the stream comes back null and IAM aborts startup — taking the
whole application with it.

Registered in both places the EC2 image catalog already uses:
quarkus.native.resources.includes in application.yml, and the resources
pattern in META-INF/native-image/resource-config.json.

Verified against the native binary rather than the build alone, since a
successful build does not prove the resource is embedded: the native image
starts, ListPolicies(Scope=AWS) reports all 1566 entries, previously missing
policies attach, and a misspelled ARN still returns NoSuchEntity.

Reported by Greptile on #2194.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-08-12 17:49:57 -05:00
1 parent cdb2c36dfe
commit 527615bdf0
8 files changed
+3450 -172

No files matched your search

@@ -436,3 +436,25 @@ resource "aws_ses_active_receipt_rule_set" "compat" {
output "ses_rule_set_name" {
value = aws_ses_receipt_rule_set.compat.rule_set_name
}
# -- IAM managed-policy attachment ---------------------------------------------
# These policies sit outside the small curated set Floci used to ship, so the
# attachments below only succeed once the full AWS managed-policy catalog is seeded.
resource "aws_iam_role" "managed_policy_attach" {
name = "floci-compat-managed-policy-role"
assume_role_policy = data.aws_iam_policy_document.lambda_assume_role.json
}
resource "aws_iam_role_policy_attachment" "ec2_read_only" {
role = aws_iam_role.managed_policy_attach.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess"
}
resource "aws_iam_role_policy_attachment" "emr_service_role" {
role = aws_iam_role.managed_policy_attach.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceRole"
}
output "managed_policy_role_arn" {
value = aws_iam_role.managed_policy_attach.arn
}
@@ -278,3 +278,20 @@ setup() {
fi
[ "$status" -eq 0 ]
}
@test "Terraform: IAM role attaches managed policies outside the curated set" {
run aws_cmd iam list-attached-role-policies --role-name floci-compat-managed-policy-role \
--query "sort_by(AttachedPolicies, &PolicyArn)[].PolicyArn" --output text
assert_success
assert_output --partial "arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess"
assert_output --partial "arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceRole"
}
# A policy AWS does not publish must still be rejected, otherwise a typo silently
# "succeeds" and Terraform/CloudFormation never surface the mistake.
@test "Terraform: attaching a nonexistent managed policy still fails" {
run aws_cmd iam attach-role-policy --role-name floci-compat-managed-policy-role \
--policy-arn "arn:aws:iam::aws:policy/AmazonS3FullAcess"
assert_failure
assert_output --partial "NoSuchEntity"
}
@@ -1,16 +1,38 @@
package io.github.hectorvent.floci.services.iam;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.quarkus.runtime.annotations.RegisterForReflection;
import org.jboss.logging.Logger;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.List;
/**
* Catalog of commonly-used AWS managed policies seeded at startup.
* Policy documents use a permissive wildcard because floci does not
* enforce IAM policy evaluation.
* Catalog of AWS managed policies, loaded from {@code iam/managed-policies.yaml}.
*
* <p>Floci resolves {@code arn:aws:iam::aws:policy/*} ARNs against this catalog, so an ARN
* that is absent returns {@code NoSuchEntity} — the same as real AWS. Carrying the full
* published list is what keeps that faithful in both directions: policies AWS actually
* publishes attach cleanly, while typos and invented names are still rejected. A curated
* subset would reject valid configurations; resolving every well-formed ARN would accept
* invalid ones.
*
* <p>Policy documents are not modelled. Floci does not evaluate IAM by default, so every
* entry shares {@link #PERMISSIVE_DOCUMENT} and only the name, path and description matter.
*/
final class AwsManagedPolicies {
private static final Logger LOG = Logger.getLogger(AwsManagedPolicies.class);
static final String ARN_PREFIX = "arn:aws:iam::aws:policy";
private static final String CATALOG_RESOURCE_NAME = "iam/managed-policies.yaml";
static final String PERMISSIVE_DOCUMENT =
"{\"Version\":\"2012-10-17\",\"Statement\":"
+ "[{\"Effect\":\"Allow\",\"Action\":\"*\",\"Resource\":\"*\"}]}";
@@ -21,163 +43,45 @@ final class AwsManagedPolicies {
}
}
static final List<ManagedPolicyDef> POLICIES = List.of(
// General access policies
new ManagedPolicyDef("AdministratorAccess", "/",
"Provides full access to AWS services and resources."),
new ManagedPolicyDef("PowerUserAccess", "/",
"Provides full access to AWS services and resources, but does not allow management of Users and groups."),
new ManagedPolicyDef("ReadOnlyAccess", "/",
"Provides read-only access to AWS services and resources."),
new ManagedPolicyDef("SecurityAudit", "/",
"The security audit template grants access to read security configuration metadata. "
+ "It is useful for software that audits the configuration of an AWS account."),
new ManagedPolicyDef("IAMFullAccess", "/",
"Provides full access to IAM."),
new ManagedPolicyDef("AmazonS3FullAccess", "/",
"Provides full access to all buckets via the AWS Management Console."),
new ManagedPolicyDef("AmazonS3ReadOnlyAccess", "/",
"Provides read-only access to all buckets via the AWS Management Console."),
new ManagedPolicyDef("AmazonDynamoDBFullAccess", "/",
"Provides full access to Amazon DynamoDB via the AWS Management Console."),
new ManagedPolicyDef("AmazonEC2FullAccess", "/",
"Provides full access to Amazon EC2 via the AWS Management Console."),
new ManagedPolicyDef("AmazonEC2ContainerRegistryReadOnly", "/",
"Provides read-only access to Amazon EC2 Container Registry repositories."),
new ManagedPolicyDef("AmazonSQSFullAccess", "/",
"Provides full access to Amazon SQS via the AWS Management Console."),
new ManagedPolicyDef("AmazonSNSFullAccess", "/",
"Provides full access to Amazon SNS via the AWS Management Console."),
new ManagedPolicyDef("AmazonVPCFullAccess", "/",
"Provides full access to Amazon VPC via the AWS Management Console."),
new ManagedPolicyDef("CloudWatchFullAccess", "/",
"Provides full access to CloudWatch."),
new ManagedPolicyDef("CloudWatchAgentServerPolicy", "/",
"Provides permissions required to use the CloudWatch agent on servers."),
new ManagedPolicyDef("AWSLambdaFullAccess", "/",
"Provides full access to Lambda, S3, DynamoDB, CloudWatch Metrics and Logs."),
new ManagedPolicyDef("AWSCloudFormationReadOnlyAccess", "/",
"Provides access to AWS CloudFormation via the AWS Management Console."),
new ManagedPolicyDef("AWSCloudFormationFullAccess", "/",
"Provides full access to AWS CloudFormation."),
new ManagedPolicyDef("AWSXRayDaemonWriteAccess", "/",
"Allows write permissions to the AWS X-Ray daemon."),
new ManagedPolicyDef("AmazonElasticFileSystemClientFullAccess", "/",
"Provides root client access to an Amazon EFS file system."),
// Attached by the roles `cdk bootstrap` creates, so without it the CDKToolkit stack
// rolls back and no CDK app can be deployed.
new ManagedPolicyDef("AmazonAthenaFullAccess", "/",
"Provide full access to Amazon Athena and scoped access to the dependencies "
+ "needed to enable querying, writing results, and data management."),
new ManagedPolicyDef("AmazonRedshiftFullAccess", "/",
"Provides full access to Amazon Redshift via the AWS Management Console."),
new ManagedPolicyDef("AmazonS3TablesReadOnlyAccess", "/",
"Provides read only access to all S3 table buckets."),
new ManagedPolicyDef("AWSCloudTrail_FullAccess", "/",
"Provides full access to AWS CloudTrail."),
new ManagedPolicyDef("AWSCloudTrail_ReadOnlyAccess", "/",
"Provides read-only access to AWS CloudTrail."),
static final List<ManagedPolicyDef> POLICIES = load();
// Lambda execution role policies
new ManagedPolicyDef("AWSLambdaBasicExecutionRole", "/service-role/",
"Provides write permissions to CloudWatch Logs."),
new ManagedPolicyDef("AWSLambdaBasicDurableExecutionRolePolicy", "/service-role/",
"Provides write permissions to CloudWatch Logs and read/write permissions to durable execution APIs for Lambda durable functions."),
new ManagedPolicyDef("AWSLambdaDynamoDBExecutionRole", "/service-role/",
"Provides list and read access to DynamoDB streams and write permissions to CloudWatch Logs."),
new ManagedPolicyDef("AWSLambdaKinesisExecutionRole", "/service-role/",
"Provides list and read access to Kinesis streams and write permissions to CloudWatch Logs."),
new ManagedPolicyDef("AWSLambdaMSKExecutionRole", "/service-role/",
"Provides permissions required to access an MSK cluster within a VPC, manage network interfaces, and write to CloudWatch Logs."),
new ManagedPolicyDef("AWSLambdaSQSQueueExecutionRole", "/service-role/",
"Provides receive message, delete message, and read attribute access to SQS queues, and write permissions to CloudWatch Logs."),
new ManagedPolicyDef("AWSLambdaVPCAccessExecutionRole", "/service-role/",
"Provides minimum permissions for a Lambda function to execute while accessing a resource within a VPC."),
private AwsManagedPolicies() {
}
// ECS / EKS execution role policies
new ManagedPolicyDef("AmazonECSTaskExecutionRolePolicy", "/service-role/",
"Provides the Amazon ECS container agent and Fargate agent permissions to make AWS API calls on your behalf."),
new ManagedPolicyDef("AmazonEKSFargatePodExecutionRolePolicy", "/",
"Provides access to other AWS service resources required to run Amazon EKS pods on AWS Fargate."),
private static List<ManagedPolicyDef> load() {
try (InputStream in = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(CATALOG_RESOURCE_NAME)) {
if (in == null) {
throw new IllegalStateException(
"AWS managed policy catalog not found on the classpath: " + CATALOG_RESOURCE_NAME);
}
Catalog catalog = new ObjectMapper(new YAMLFactory()).readValue(in, Catalog.class);
List<ManagedPolicyDef> defs = new ArrayList<>();
for (CatalogEntry entry : catalog.policies == null ? List.<CatalogEntry>of() : catalog.policies) {
if (entry.name == null || entry.name.isBlank() || entry.path == null || entry.path.isBlank()) {
continue;
}
defs.add(new ManagedPolicyDef(entry.name, entry.path, entry.description));
}
LOG.debugv("Loaded {0} AWS managed policies from {1}", defs.size(), CATALOG_RESOURCE_NAME);
return List.copyOf(defs);
} catch (IOException e) {
throw new UncheckedIOException(
"Failed to read the AWS managed policy catalog: " + CATALOG_RESOURCE_NAME, e);
}
}
// EKS cluster and node group policies (required by the EKS console/SDK and
// the terraform-aws-modules/eks module — see #1092).
new ManagedPolicyDef("AmazonEKSClusterPolicy", "/",
"Provides Kubernetes the permissions it requires to manage resources on your behalf."),
new ManagedPolicyDef("AmazonEKSServicePolicy", "/",
"This policy allows Amazon Elastic Container Service for Kubernetes to create and manage the necessary resources to operate EKS Clusters."),
new ManagedPolicyDef("AmazonEKSVPCResourceController", "/",
"Policy used by VPC Resource Controller to manage ENI and IPs for worker nodes."),
new ManagedPolicyDef("AmazonEKSWorkerNodePolicy", "/",
"This policy allows Amazon EKS worker nodes to connect to Amazon EKS Clusters."),
new ManagedPolicyDef("AmazonEKS_CNI_Policy", "/",
"Provides the Amazon VPC CNI Plugin the permissions it requires to modify the IP address configuration on your EKS worker nodes."),
@RegisterForReflection
@JsonIgnoreProperties(ignoreUnknown = true)
static final class Catalog {
public List<CatalogEntry> policies;
}
// RDS execution role policy
new ManagedPolicyDef("AmazonRDSEnhancedMonitoringRole", "/service-role/",
"Provides permissions required for Amazon RDS Enhanced Monitoring."),
// S3 Object Lambda execution role policy
new ManagedPolicyDef("AmazonS3ObjectLambdaExecutionRolePolicy", "/service-role/",
"Provides write permissions to CloudWatch Logs for S3 Object Lambda access points."),
// CloudWatch Lambda execution role policies
new ManagedPolicyDef("CloudWatchLambdaInsightsExecutionRolePolicy", "/",
"Allows Lambda Insights to create and write to CloudWatch Logs log groups for Lambda Insights monitoring."),
new ManagedPolicyDef("CloudWatchLambdaApplicationSignalsExecutionRolePolicy", "/",
"Provides write access to X-Ray and CloudWatch Application Signals log group."),
// API Gateway execution role policy
new ManagedPolicyDef("AmazonAPIGatewayPushToCloudWatchLogs", "/service-role/",
"Allows API Gateway to push logs to CloudWatch Logs."),
// Config execution role policy
new ManagedPolicyDef("AWSConfigRulesExecutionRole", "/service-role/",
"Allows AWS Config Rules Lambda functions to call AWS services and read the configuration of AWS resources."),
// MSK replicator execution role policy
new ManagedPolicyDef("AWSMSKReplicatorExecutionRole", "/service-role/",
"Grants permissions to Amazon MSK Replicator to replicate data between MSK Clusters."),
// SSM Automation execution role policies
new ManagedPolicyDef("AWS-SSM-DiagnosisAutomation-ExecutionRolePolicy", "/",
"Provides permissions for AWS Systems Manager diagnosis automation execution."),
new ManagedPolicyDef("AWS-SSM-RemediationAutomation-ExecutionRolePolicy", "/",
"Provides permissions for AWS Systems Manager remediation automation execution."),
new ManagedPolicyDef("AmazonSSMManagedInstanceCore", "/",
"Provides permissions required for instances to use AWS Systems Manager core service functionality."),
// SageMaker execution role policies
new ManagedPolicyDef("AmazonSageMakerGeospatialExecutionRole", "/service-role/",
"Provides full access to Amazon SageMaker Geospatial capabilities and related services."),
new ManagedPolicyDef("AmazonSageMakerCanvasEMRServerlessExecutionRolePolicy", "/",
"Provides access for Amazon SageMaker Canvas to manage EMR Serverless resources."),
// SageMaker Studio execution role policies
new ManagedPolicyDef("SageMakerStudioBedrockFunctionExecutionRolePolicy", "/service-role/",
"Provides permissions for SageMaker Studio Bedrock function execution role."),
new ManagedPolicyDef("SageMakerStudioDomainExecutionRolePolicy", "/service-role/",
"Provides permissions for the SageMaker Studio domain execution role."),
new ManagedPolicyDef("SageMakerStudioQueryExecutionRolePolicy", "/service-role/",
"Provides permissions for SageMaker Studio query execution role."),
// Amazon DataZone execution role policy
new ManagedPolicyDef("AmazonDataZoneDomainExecutionRolePolicy", "/service-role/",
"Provides permissions for the Amazon DataZone domain execution role."),
// Amazon Bedrock policies
new ManagedPolicyDef("AmazonBedrockFullAccess", "/",
"Provides full access to Amazon Bedrock as well as limited access to related services "
+ "that are required by it"),
new ManagedPolicyDef("AmazonBedrockReadOnly", "/",
"Provides read only access to Amazon Bedrock"),
new ManagedPolicyDef("AmazonBedrockAgentCoreMemoryBedrockModelInferenceExecutionRolePolicy", "/",
"Provides Bedrock Model inference permissions to Bedrock agent core memory."),
// AWS Partner Central execution role policy
new ManagedPolicyDef("AWSPartnerCentralSellingResourceSnapshotJobExecutionRolePolicy", "/",
"Provides permissions for AWS Partner Central resource snapshot job execution role.")
);
private AwsManagedPolicies() {}
@RegisterForReflection
@JsonIgnoreProperties(ignoreUnknown = true)
static final class CatalogEntry {
public String name;
public String path;
public String description;
}
}
@@ -175,20 +175,19 @@ public class IamService implements SessionAccountLookup {
return catalog;
}
/**
* Makes the AWS-managed policy catalog available.
*
* <p>The catalog itself is the single source of truth: {@link #getPolicy} resolves
* {@code arn:aws:iam::aws:policy/*} from it directly, and {@link #listPolicies} reads
* the AWS scope from it too. Earlier versions also mirrored every entry into the
* default-account store, but that copy was never read back — {@code listPolicies}
* explicitly filters AWS-managed ARNs out of the local scan to avoid listing them
* twice — and writing the full published catalog to disk on every start costs about a
* megabyte of persisted state and several seconds of startup for nothing.
*/
void seedAwsManagedPolicies() {
// Managed policies are served globally from the catalog (see getPolicy); this also
// mirrors them into the default-account store so ListPolicies(Scope=AWS) lists them.
int seeded = 0;
for (Map.Entry<String, IamPolicy> entry : awsManagedPolicies.entrySet()) {
if (policies.get(entry.getKey()).isPresent()) {
continue;
}
policies.put(entry.getKey(), entry.getValue());
seeded++;
}
if (seeded > 0) {
LOG.infov("Seeded {0} AWS managed policies", seeded);
}
LOG.debugv("AWS managed policy catalog available: {0} policies", awsManagedPolicies.size());
}
private void seedDefaultDeployerPrincipal() {
@@ -3,6 +3,7 @@
"includes": [
{"pattern": "META-INF/services/java.security.Provider"},
{"pattern": "ec2/.*\\.yaml"},
{"pattern": "iam/.*\\.yaml"},
{"pattern": "org/apache/velocity/runtime/defaults/velocity.properties"}
]
},
+3 -1
View File
@@ -22,7 +22,8 @@ quarkus:
native:
resources:
# The Pricing service reads its bundled snapshot, EC2 reads its image
# catalog (ec2/image-catalog.yaml), AppSync's GraphQL parser reads its
# catalog (ec2/image-catalog.yaml), IAM reads its AWS managed-policy
# catalog (iam/managed-policies.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
@@ -32,6 +33,7 @@ quarkus:
- pricing-snapshots/**
- ui/*.html
- ec2/*.yaml
- iam/*.yaml
- i18n/*.properties
- org/apache/velocity/runtime/defaults/*.properties
additional-build-args:
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,128 @@
package io.github.hectorvent.floci.services.iam;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.services.iam.model.IamPolicy;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* The managed-policy catalog carries the full published AWS list rather than a curated
* subset, so that attaching a real policy succeeds and attaching an invented one still
* fails the way it does on AWS.
*
* <p>A subset produced false negatives — {@code AttachRolePolicy} returned
* {@code NoSuchEntity} for policies AWS genuinely publishes, breaking valid Terraform and
* CloudFormation configurations. Resolving every well-formed ARN instead would produce
* false positives, silently accepting typos that real AWS rejects and defeating stack
* rollback. Both directions matter, so both are asserted here.
*/
class IamManagedPolicyCatalogTest {
private IamService iamService;
@BeforeEach
void setUp() {
iamService = new IamService(
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
new InMemoryStorage<>(),
new RegionResolver("us-east-1", "000000000000"));
}
@Test
void catalogCarriesTheFullPublishedListNotAHandfulOfEntries() {
assertTrue(AwsManagedPolicies.POLICIES.size() > 1000,
"expected the full AWS catalog, found " + AwsManagedPolicies.POLICIES.size());
}
/** Policies a real ECS/EMR estate attaches; every one of these used to 404. */
@ParameterizedTest
@ValueSource(strings = {
"arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess",
"arn:aws:iam::aws:policy/AmazonSSMFullAccess",
"arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM",
"arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceRole",
"arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceforEC2Role",
"arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceforAutoScalingRole",
"arn:aws:iam::aws:policy/service-role/AmazonEMRServicePolicy_v2",
})
void realWorldPoliciesResolveAndAttach(String policyArn) {
IamPolicy policy = assertDoesNotThrow(() -> iamService.getPolicy(policyArn));
assertEquals(policyArn, policy.getArn());
iamService.createRole("attach-target", "/", "{}", null, 3600, null);
assertDoesNotThrow(() -> iamService.attachRolePolicy("attach-target", policyArn));
}
@Test
void everyPathPrefixAwsUsesIsRepresented() {
for (String path : new String[] {"/", "/service-role/", "/aws-service-role/", "/job-function/"}) {
assertTrue(AwsManagedPolicies.POLICIES.stream().anyMatch(p -> path.equals(p.path())),
"no policy carries the " + path + " path");
}
}
@Test
void arnsAreBuiltFromNameAndPath() {
AwsManagedPolicies.ManagedPolicyDef def = AwsManagedPolicies.POLICIES.stream()
.filter(p -> "AmazonEC2RoleforSSM".equals(p.name()))
.findFirst().orElseThrow();
assertEquals("/service-role/", def.path());
assertEquals("arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM", def.arn());
}
@Test
void curatedDescriptionsSurviveTheBulkCatalog() {
IamPolicy policy = iamService.getPolicy("arn:aws:iam::aws:policy/AdministratorAccess");
assertEquals("Provides full access to AWS services and resources.", policy.getDescription());
}
/**
* A policy AWS has since retired but which Floci previously resolved: keeping it means
* upgrading the catalog never takes away something that already worked.
*/
@Test
void policiesRetiredByAwsButPreviouslyResolvableAreRetained() {
assertDoesNotThrow(() -> iamService.getPolicy("arn:aws:iam::aws:policy/AWSLambdaFullAccess"));
}
@Test
void inventedManagedPolicyIsRejectedTheWayAwsRejectsIt() {
AwsException e = assertThrows(AwsException.class,
() -> iamService.getPolicy("arn:aws:iam::aws:policy/DefinitelyNotARealPolicy"));
assertEquals("NoSuchEntity", e.getErrorCode());
assertEquals(404, e.getHttpStatus(),
"AWS answers GetPolicy for a nonexistent policy with NoSuchEntity/404");
}
@Test
void attachingAnInventedManagedPolicyFails() {
iamService.createRole("typo-role", "/", "{}", null, 3600, null);
AwsException e = assertThrows(AwsException.class, () -> iamService.attachRolePolicy(
"typo-role", "arn:aws:iam::aws:policy/AmazonS3FullAcess"));
assertEquals("NoSuchEntity", e.getErrorCode(),
"a typo must still fail, otherwise CloudFormation never rolls back");
}
@Test
void unknownCustomerPolicyStillReturnsNoSuchEntity() {
AwsException e = assertThrows(AwsException.class,
() -> iamService.getPolicy("arn:aws:iam::000000000000:policy/nope"));
assertEquals("NoSuchEntity", e.getErrorCode());
}
}