From b987e822be8c230f2c85c53b53eceb71af98aec5 Mon Sep 17 00:00:00 2001 From: galsuchetzky-act Date: Sun, 1 Nov 2026 14:23:49 +0200 Subject: [PATCH] feat(bedrock): add PutResourcePolicy, GetResourcePolicy and DeleteResourcePolicy for guardrails (#7188) --- docs/services/bedrock.md | 30 +++ docs/services/index.md | 2 +- .../services/bedrock/BedrockController.java | 36 ++++ .../services/bedrock/BedrockService.java | 168 +++++++++++++++++ .../services/bedrock/model/Guardrail.java | 9 + .../floci/services/iam/IamActionRegistry.java | 5 + .../services/iam/ResourceArnBuilder.java | 22 +++ .../resources/aws/iam-request-resources.json | 4 +- ...cePolicyIamEnforcementIntegrationTest.java | 90 +++++++++ .../BedrockResourcePolicyIntegrationTest.java | 172 ++++++++++++++++++ .../services/bedrock/BedrockServiceTest.java | 39 ++++ .../services/iam/IamActionRegistryTest.java | 15 ++ .../services/iam/ResourceArnBuilderTest.java | 22 +++ tools/aws/regen_iam_request_resources.py | 3 +- 14 files changed, 612 insertions(+), 5 deletions(-) create mode 100644 src/test/java/io/github/hectorvent/floci/services/bedrock/BedrockResourcePolicyIamEnforcementIntegrationTest.java create mode 100644 src/test/java/io/github/hectorvent/floci/services/bedrock/BedrockResourcePolicyIntegrationTest.java diff --git a/docs/services/bedrock.md b/docs/services/bedrock.md index 516bcc60b5..bf5cef730b 100644 --- a/docs/services/bedrock.md +++ b/docs/services/bedrock.md @@ -17,6 +17,9 @@ that shares the same signing name: see [Bedrock Runtime](bedrock-runtime.md). | `CreateGuardrailVersion` | Snapshot the `DRAFT` under the next numerical version | | `DeleteGuardrail` | Delete one numerical version, or the guardrail and all its versions | | `ListGuardrails` | List every guardrail's `DRAFT`, or every version of one guardrail | +| `PutResourcePolicy` | Attach a resource-based policy to a guardrail (`POST /resource-policy`) | +| `GetResourcePolicy` | Read a guardrail's resource-based policy | +| `DeleteResourcePolicy` | Remove a guardrail's resource-based policy | | `TagResource` | Tag a guardrail (`POST /tagResource`) | | `UntagResource` | Remove tags from a guardrail (`POST /untagResource`) | | `ListTagsForResource` | List a guardrail's tags (`POST /listTagsForResource`) | @@ -67,6 +70,26 @@ request, so `CreateGuardrail` and `TagResource` both raise `TooManyTagsException the resulting total would pass 50. Replacing the value of a tag key the guardrail already carries does not add to that total. +A resource-based policy is attached to a guardrail by its full ARN. The policy is held to the restricted language the +[Bedrock user guide](https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails-resource-based-policies.html) +documents, and anything else is rejected with `ValidationException`: it is one JSON object +of 1 to 20480 characters with nothing after it, every statement is an `Allow` on the ARN the policy is attached to, +its actions are `bedrock:ApplyGuardrail` and `bedrock:GetGuardrail`, and its principal is either the +account root (`{"AWS": "arn:aws:iam:::root"}` and no other principal) or `*` under a `StringEquals` condition on +`aws:PrincipalOrgID`. The only conditions accepted are that one and +`ForAnyValue:StringLike` on `aws:PrincipalOrgPaths`, each with a string or an array of strings. The policy is stored as given; it is +not evaluated against callers. + +A guardrail's policy lives on the guardrail. `GetResourcePolicy` on a guardrail with no +policy returns a response without `resourcePolicy`, and deleting the guardrail deletes +its policy. An ARN that names no guardrail of the caller's account and Region, including +a guardrail profile ARN or another Bedrock resource, returns `ResourceNotFoundException`. + +With IAM enforcement on, `PutResourcePolicy`, `GetResourcePolicy` and +`DeleteResourcePolicy` are authorized as `bedrock:PutResourcePolicy`, +`bedrock:GetResourcePolicy` and `bedrock:DeleteResourcePolicy` on the ARN the request +names. + Guardrails are listed by the Resource Groups Tagging API (resource type `bedrock:guardrail`) and Resource Explorer with their own tags, and `TagResources` / `UntagResources` there change those tags, as `TagResource` and `UntagResource` do. @@ -113,5 +136,12 @@ aws bedrock tag-resource \ --resource-arn arn:aws:bedrock:us-east-1:000000000000:guardrail/abc123def456 \ --tags key=team,value=ai +aws bedrock put-resource-policy \ + --resource-arn arn:aws:bedrock:us-east-1:000000000000:guardrail/abc123def456 \ + --resource-policy '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"AWS":"arn:aws:iam::000000000000:root"},"Action":["bedrock:ApplyGuardrail","bedrock:GetGuardrail"],"Resource":"arn:aws:bedrock:us-east-1:000000000000:guardrail/abc123def456"}]}' + +aws bedrock get-resource-policy \ + --resource-arn arn:aws:bedrock:us-east-1:000000000000:guardrail/abc123def456 + aws bedrock delete-guardrail --guardrail-identifier abc123def456 ``` diff --git a/docs/services/index.md b/docs/services/index.md index cc4308d004..ca7c1be18c 100644 --- a/docs/services/index.md +++ b/docs/services/index.md @@ -97,7 +97,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac | [AppConfig](appconfig.md) | `/applications/...`, `/deploymentstrategies/...` | REST JSON | 16 | | [AppConfigData](appconfig.md#data-plane) | `/configurationsessions`, `/configuration` | REST JSON | 2 | | [AppSync](appsync.md) | `/v1/apis/...` | REST JSON | 33 | -| [Amazon Bedrock](bedrock.md) | `/guardrails`, `/guardrails/{guardrailIdentifier}`, `/tagResource`, `/untagResource`, `/listTagsForResource` | REST JSON | 9 | +| [Amazon Bedrock](bedrock.md) | `/guardrails`, `/guardrails/{guardrailIdentifier}`, `/resource-policy`, `/resource-policy/{resourceArn}`, `/tagResource`, `/untagResource`, `/listTagsForResource` | REST JSON | 12 | | [Bedrock Runtime](bedrock-runtime.md) | `/model/{modelId}/converse`, `/model/{modelId}/invoke` | REST JSON | 2 (stub; streaming returns 501) | | [Bedrock AgentCore Control](bedrock-agentcore.md) | `/runtimes/*`, `/gateways/*`, `/memories/*`, `/identities/*`, `/browsers*`, `/browser-profiles*`, `/code-interpreters*`, `/resourcepolicy/*`, `/tags/{resourceArn}` | REST JSON | 65 (+ 3 tagging via shared `/tags/{arn}` route) | | [Bedrock AgentCore](bedrock-agentcore.md#data-plane-invokeagentruntime) | `/runtimes/{agentRuntimeArn}/invocations` | REST JSON (binary payload) | 1 (canned-response stub) | diff --git a/src/main/java/io/github/hectorvent/floci/services/bedrock/BedrockController.java b/src/main/java/io/github/hectorvent/floci/services/bedrock/BedrockController.java index 414033d375..0e353dc335 100644 --- a/src/main/java/io/github/hectorvent/floci/services/bedrock/BedrockController.java +++ b/src/main/java/io/github/hectorvent/floci/services/bedrock/BedrockController.java @@ -142,6 +142,42 @@ public class BedrockController { return Response.ok(response).build(); } + // Resource policies + + @POST + @Path("/resource-policy") + public Response putResourcePolicy(@Context HttpHeaders headers, String body) { + String region = regionResolver.resolveRegion(headers); + JsonNode request = readTree(body); + String resourceArn = textOrNull(request, "resourceArn"); + bedrockService.putResourcePolicy(resourceArn, textOrNull(request, "resourcePolicy"), region); + + ObjectNode response = objectMapper.createObjectNode(); + response.put("resourceArn", resourceArn); + return Response.status(201).entity(response).build(); + } + + @GET + @Path("/resource-policy/{resourceArn: .+}") + public Response getResourcePolicy(@PathParam("resourceArn") String resourceArn, @Context HttpHeaders headers) { + String region = regionResolver.resolveRegion(headers); + String policy = bedrockService.getResourcePolicy(resourceArn, region); + + ObjectNode response = objectMapper.createObjectNode(); + if (policy != null) { + response.put("resourcePolicy", policy); + } + return Response.ok(response).build(); + } + + @DELETE + @Path("/resource-policy/{resourceArn: .+}") + public Response deleteResourcePolicy(@PathParam("resourceArn") String resourceArn, @Context HttpHeaders headers) { + String region = regionResolver.resolveRegion(headers); + bedrockService.deleteResourcePolicy(resourceArn, region); + return Response.ok().build(); + } + // Tags @POST diff --git a/src/main/java/io/github/hectorvent/floci/services/bedrock/BedrockService.java b/src/main/java/io/github/hectorvent/floci/services/bedrock/BedrockService.java index 68d9d8f788..3a457929ea 100644 --- a/src/main/java/io/github/hectorvent/floci/services/bedrock/BedrockService.java +++ b/src/main/java/io/github/hectorvent/floci/services/bedrock/BedrockService.java @@ -1,6 +1,8 @@ package io.github.hectorvent.floci.services.bedrock; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -88,6 +90,18 @@ public class BedrockService implements ResourceProvider { "piiEntitiesConfig", "piiEntities", "regexesConfig", "regexes"); + /** {@code ResourcePolicyResourceArn} from the AWS model: min 1, max 255. */ + private static final int RESOURCE_POLICY_ARN_MAX = 255; + + /** {@code ResourcePolicyDocument} from the AWS model: min 1, max 20480. */ + private static final int RESOURCE_POLICY_MAX = 20480; + + private static final String GUARDRAIL_RESOURCE_PREFIX = "guardrail/"; + + /** The actions the Bedrock user guide lets a guardrail resource-based policy grant. */ + private static final Set GUARDRAIL_POLICY_ACTIONS = + Set.of("bedrock:ApplyGuardrail", "bedrock:GetGuardrail"); + private final StorageBackend guardrails; private final RegionResolver regionResolver; private final ObjectMapper objectMapper; @@ -245,6 +259,35 @@ public class BedrockService implements ResourceProvider { return snapshot; } + // Resource policies + + /** The policy attached to a guardrail, or null when it holds none. */ + public String getResourcePolicy(String resourceArn, String region) { + requireResourcePolicyArn(resourceArn); + return findGuardrailForPolicy(resourceArn, region).getResourcePolicy(); + } + + public synchronized void putResourcePolicy(String resourceArn, String policy, String region) { + requireResourcePolicyArn(resourceArn); + if (policy == null || policy.isEmpty() || policy.length() > RESOURCE_POLICY_MAX) { + throw new AwsException("ValidationException", + "resourcePolicy must be between 1 and " + RESOURCE_POLICY_MAX + " characters.", 400); + } + validateResourcePolicy(policy, resourceArn); + Guardrail guardrail = findGuardrailForPolicy(resourceArn, region); + guardrail.setResourcePolicy(policy); + guardrails.put(storageKey(region, guardrail.getGuardrailId(), DRAFT_VERSION), guardrail); + LOG.infov("Put resource policy on Bedrock guardrail: {0}", guardrail.getGuardrailId()); + } + + public synchronized void deleteResourcePolicy(String resourceArn, String region) { + requireResourcePolicyArn(resourceArn); + Guardrail guardrail = findGuardrailForPolicy(resourceArn, region); + guardrail.setResourcePolicy(null); + guardrails.put(storageKey(region, guardrail.getGuardrailId(), DRAFT_VERSION), guardrail); + LOG.infov("Deleted resource policy of Bedrock guardrail: {0}", guardrail.getGuardrailId()); + } + // Tags public Map listTags(String resourceArn, String region) { @@ -418,6 +461,131 @@ public class BedrockService implements ResourceProvider { "Resource " + resourceArn + " does not exist.", 404)); } + private static void requireResourcePolicyArn(String resourceArn) { + if (resourceArn == null || resourceArn.isEmpty() || resourceArn.length() > RESOURCE_POLICY_ARN_MAX) { + throw new AwsException("ValidationException", + "resourceArn must be between 1 and " + RESOURCE_POLICY_ARN_MAX + " characters.", 400); + } + } + + /** The guardrail a resource policy names, found by its exact ARN only, never by a bare id. */ + private Guardrail findGuardrailForPolicy(String resourceArn, String region) { + if (!AwsArnUtils.isArnFor(resourceArn, "bedrock") + || !AwsArnUtils.parse(resourceArn).resource().startsWith(GUARDRAIL_RESOURCE_PREFIX)) { + throw new AwsException("ResourceNotFoundException", "Resource " + resourceArn + " does not exist.", 404); + } + return findByArn(resourceArn, region); + } + + /** + * Holds a policy to the restricted language the Bedrock user guide gives guardrail resource-based + * policies: Allow statements on the resource the policy is attached to, granting only the supported + * actions, either to the account's root or to {@code *} under an {@code aws:PrincipalOrgID} condition, + * with no condition but that one and {@code aws:PrincipalOrgPaths}. + */ + private void validateResourcePolicy(String policy, String resourceArn) { + JsonNode document; + try { + document = objectMapper.reader().with(DeserializationFeature.FAIL_ON_TRAILING_TOKENS).readTree(policy); + } catch (JsonProcessingException e) { + throw invalidResourcePolicy("resourcePolicy is not a JSON policy document."); + } + if (document == null || !document.isObject()) { + throw invalidResourcePolicy("resourcePolicy is not a JSON policy document."); + } + List statements = elements(document.path("Statement")); + if (statements.isEmpty()) { + throw invalidResourcePolicy("resourcePolicy has no Statement."); + } + String accountRoot = regionResolver.buildGlobalArn("iam", "root"); + for (JsonNode statement : statements) { + if (!"Allow".equals(statement.path("Effect").asText())) { + throw invalidResourcePolicy("Every statement must have Effect Allow."); + } + List resources = elements(statement.path("Resource")); + if (resources.isEmpty() + || resources.stream().anyMatch(resource -> !resourceArn.equals(resource.asText()))) { + throw invalidResourcePolicy("Every statement's Resource must be " + resourceArn + "."); + } + List actions = elements(statement.path("Action")); + if (actions.isEmpty() + || actions.stream().anyMatch(action -> !GUARDRAIL_POLICY_ACTIONS.contains(action.asText()))) { + throw invalidResourcePolicy("Every statement's Action must be among " + + String.join(", ", GUARDRAIL_POLICY_ACTIONS.stream().sorted().toList()) + "."); + } + validatePrincipalAndCondition(statement.path("Principal"), statement.path("Condition"), accountRoot); + } + } + + private static void validatePrincipalAndCondition(JsonNode principal, JsonNode condition, String accountRoot) { + if (principal.isTextual() && "*".equals(principal.asText())) { + List organizations = strings(condition.path("StringEquals").path("aws:PrincipalOrgID")); + if (organizations == null || organizations.size() != 1 || organizations.getFirst().isBlank() + || organizations.getFirst().contains("*")) { + throw invalidResourcePolicy("A statement with Principal * needs a StringEquals condition on " + + "aws:PrincipalOrgID naming one organization."); + } + } else { + List roots = principal.isObject() && principal.size() == 1 ? strings(principal.path("AWS")) : null; + if (roots == null || roots.stream().anyMatch(root -> !accountRoot.equals(root))) { + throw invalidResourcePolicy("Principal must be * or {\"AWS\": \"" + accountRoot + "\"}."); + } + } + if (condition.isMissingNode()) { + return; + } + if (!condition.isObject()) { + throw invalidResourcePolicy("Condition must be an object."); + } + for (Map.Entry operator : condition.properties()) { + String key = switch (operator.getKey()) { + case "StringEquals" -> "aws:PrincipalOrgID"; + case "ForAnyValue:StringLike" -> "aws:PrincipalOrgPaths"; + default -> null; + }; + if (key == null || !operator.getValue().isObject() || operator.getValue().size() != 1 + || strings(operator.getValue().path(key)) == null) { + throw invalidResourcePolicy("The only supported conditions are StringEquals on aws:PrincipalOrgID " + + "and ForAnyValue:StringLike on aws:PrincipalOrgPaths."); + } + } + } + + /** A string or a non-empty array of strings, as a list; null for any other value, or none. */ + private static List strings(JsonNode node) { + if (node.isTextual()) { + return List.of(node.asText()); + } + if (!node.isArray() || node.isEmpty()) { + return null; + } + List values = new ArrayList<>(); + for (JsonNode value : node) { + if (!value.isTextual()) { + return null; + } + values.add(value.asText()); + } + return values; + } + + /** A policy element that may be one value or an array of them; empty when absent. */ + private static List elements(JsonNode node) { + if (node.isMissingNode() || node.isNull()) { + return List.of(); + } + if (!node.isArray()) { + return List.of(node); + } + List values = new ArrayList<>(); + node.forEach(values::add); + return values; + } + + private static AwsException invalidResourcePolicy(String reason) { + return new AwsException("ValidationException", "Invalid resource policy: " + reason, 400); + } + private String resolveGuardrailId(String identifier) { if (identifier == null || identifier.isBlank()) { throw new AwsException("ValidationException", "guardrailIdentifier is required", 400); diff --git a/src/main/java/io/github/hectorvent/floci/services/bedrock/model/Guardrail.java b/src/main/java/io/github/hectorvent/floci/services/bedrock/model/Guardrail.java index be18d77905..0b8b2e53ca 100644 --- a/src/main/java/io/github/hectorvent/floci/services/bedrock/model/Guardrail.java +++ b/src/main/java/io/github/hectorvent/floci/services/bedrock/model/Guardrail.java @@ -21,6 +21,7 @@ public class Guardrail { private Instant updatedAt; private Map tags; private String accountId; + private String resourcePolicy; private JsonNode topicPolicy; private JsonNode contentPolicy; @@ -126,6 +127,14 @@ public class Guardrail { this.accountId = accountId; } + public String getResourcePolicy() { + return resourcePolicy; + } + + public void setResourcePolicy(String resourcePolicy) { + this.resourcePolicy = resourcePolicy; + } + public JsonNode getTopicPolicy() { return topicPolicy; } diff --git a/src/main/java/io/github/hectorvent/floci/services/iam/IamActionRegistry.java b/src/main/java/io/github/hectorvent/floci/services/iam/IamActionRegistry.java index 76aa562081..3bd2e2f971 100644 --- a/src/main/java/io/github/hectorvent/floci/services/iam/IamActionRegistry.java +++ b/src/main/java/io/github/hectorvent/floci/services/iam/IamActionRegistry.java @@ -413,6 +413,11 @@ public class IamActionRegistry { rule("eks", "POST", "^/tags(/.+)?$", "eks:TagResource"), rule("eks", "DELETE", "^/tags(/.+)?$", "eks:UntagResource"), + // ── Bedrock ──────────────────────────────────────────────────────────── + rule("bedrock", "POST", "^/resource-policy$", "bedrock:PutResourcePolicy"), + rule("bedrock", "GET", "^/resource-policy/.+", "bedrock:GetResourcePolicy"), + rule("bedrock", "DELETE", "^/resource-policy/.+", "bedrock:DeleteResourcePolicy"), + // ── SES v2 ───────────────────────────────────────────────────────────── // SES v1 is a Query API and resolves from its Action like any other; v2 is REST-JSON under // /v2/email, so every operation needs its own rule. One rule per operation in the SES v2 diff --git a/src/main/java/io/github/hectorvent/floci/services/iam/ResourceArnBuilder.java b/src/main/java/io/github/hectorvent/floci/services/iam/ResourceArnBuilder.java index e683284169..ec5398f3e3 100644 --- a/src/main/java/io/github/hectorvent/floci/services/iam/ResourceArnBuilder.java +++ b/src/main/java/io/github/hectorvent/floci/services/iam/ResourceArnBuilder.java @@ -78,6 +78,9 @@ public class ResourceArnBuilder { /** The segment a tagging route names before the ARN it tags, which it captures whole, slashes included. */ private static final String API_GATEWAY_TAGS_SEGMENT = "tags"; + /** The route of Bedrock's resource-policy actions, which the ARN of the resource they act on may follow. */ + private static final String BEDROCK_RESOURCE_POLICY_ROUTE = "/resource-policy"; + /** The SSM actions whose {@code ResourceArn} names the parameter they act on, in place of {@code Name}. */ private static final Set SSM_RESOURCE_POLICY_ACTIONS = Set.of("PutResourcePolicy", "GetResourcePolicies", "DeleteResourcePolicy"); @@ -207,6 +210,7 @@ public class ResourceArnBuilder { || "route53:DeleteReusableDelegationSet".equals(operation) ? List.of(buildRoute53DelegationSetArn(ctx, partition)) : namedResources(credentialScope, operation, ctx, region, accountId, partition); + case "bedrock" -> List.of(buildBedrockArn(path, ctx)); default -> namedResources(credentialScope, operation, ctx, region, accountId, partition); }; } @@ -1496,6 +1500,24 @@ public class ResourceArnBuilder { .orElse(null); } + // ── Bedrock ────────────────────────────────────────────────────────────────── + + /** + * The resource of a Bedrock route. The resource-policy actions act on the resource whose ARN they carry, + * in the path, or in the body's {@code resourceArn} for {@code PutResourcePolicy}, as the Service + * Authorization Reference gives them; every other route, and a value that is not an ARN, is {@code *}. + */ + private String buildBedrockArn(String path, ContainerRequestContext ctx) { + String resourceArn = null; + if (path.startsWith(BEDROCK_RESOURCE_POLICY_ROUTE + "/")) { + resourceArn = path.substring(BEDROCK_RESOURCE_POLICY_ROUTE.length() + 1); + } else if (BEDROCK_RESOURCE_POLICY_ROUTE.equals(path) && "POST".equalsIgnoreCase(ctx.getMethod())) { + JsonNode body = readJsonBody(ctx); + resourceArn = body == null ? null : body.path("resourceArn").asText(null); + } + return AwsArnUtils.isArn(resourceArn) ? resourceArn : "*"; + } + // ── SQS ───────────────────────────────────────────────────────────────────── private String buildSqsArn(ContainerRequestContext ctx, String region, String accountId) { String queueUrl = firstFormParam(ctx, "QueueUrl"); diff --git a/src/main/resources/aws/iam-request-resources.json b/src/main/resources/aws/iam-request-resources.json index 6092fe7d28..841f06c246 100644 --- a/src/main/resources/aws/iam-request-resources.json +++ b/src/main/resources/aws/iam-request-resources.json @@ -2,8 +2,8 @@ "_source": {"generator": "tools/aws/regen_iam_request_resources.py", "reference": "https://servicereference.us-east-1.amazonaws.com/", "botocore": "botocore 1.43.113 (installed package)", "retrieved": "2026-10-31", "note": "make iam-request-resources-check re-derives every operation's resources from botocore; make iam-request-resources-verify checks every action, type and format against AWS."}, "namespaces": {"acm": ["acm"], "athena": ["athena"], "bcm-data-exports": ["bcm-data-exports"], "bcm-pricing-calculator": ["bcm-pricing-calculator"], "budgets": ["budgets"], "ce": ["ce"], "cloudtrail": ["cloudtrail"], "codebuild": ["codebuild"], "codepipeline": ["codepipeline"], "cognito-identity": ["cognito-identity"], "cognito-idp": ["cognito-idp"], "cur": ["cur"], "ecr": ["ecr"], "elasticloadbalancing": ["elb", "elbv2"], "events": ["events"], "firehose": ["firehose"], "globalaccelerator": ["globalaccelerator"], "kinesisanalytics": ["kinesisanalyticsv2"], "servicediscovery": ["servicediscovery"], "servicequotas": ["service-quotas"], "states": ["stepfunctions"], "textract": ["textract"], "timestream-influxdb": ["timestream-influxdb"], "translate": ["translate"]}, "clientsNotRead": {"eventbridgev2": "EventBridge V2, the AWSEventsV2 target over Smithy RPC v2 CBOR on the eventsv2 endpoint, which Floci does not serve; its operations share EventBridge's names and name their resources by other members", "kinesisanalytics": "Kinesis Data Analytics v1, SQL applications on the KinesisAnalytics_20150814 target, which Floci does not serve (it serves v2, kinesisanalyticsv2); its operations share v2's names and name their resources by other members"}, - "handBuilt": ["apigateway", "dsql", "dynamodb", "eks", "iam", "kinesis", "kms", "lambda", "logs", "pipes", "resource-groups", "s3", "scheduler", "secretsmanager", "sns", "sqs", "ssm", "sts"], - "notCovered": {"access-analyzer": "REST: its requests name their resources in the path, which RequestResources does not read yet", "account": "REST: its requests name their resources in the path, which RequestResources does not read yet", "airflow": "REST: its requests name their resources in the path, which RequestResources does not read yet", "app-integrations": "REST: its requests name their resources in the path, which RequestResources does not read yet", "appconfig": "REST: its requests name their resources in the path, which RequestResources does not read yet", "application-autoscaling": "not read yet: a scalable target's ARN ends in an id the service mints, `scalable-target/`, while its requests name the target by ServiceNamespace, ResourceId and ScalableDimension, so its resource is the stored ARN those three find, which RequestResources has no lookup for yet; read as a member, ResourceId would fill that id", "appsync": "REST: its requests name their resources in the path, which RequestResources does not read yet", "aps": "REST: its requests name their resources in the path, which RequestResources does not read yet", "autoscaling": "not read yet: AWS's group and launch configuration ARNs carry an id the service mints, `autoScalingGroup::autoScalingGroupName/`, while Floci mints `autoScalingGroup:`, which other services (ECS capacity providers) read back; the mint is fixed first", "aws-marketplace": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "backup": "REST: its requests name their resources in the path, which RequestResources does not read yet", "batch": "REST: its requests name their resources in the path, which RequestResources does not read yet", "bedrock": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "bedrock-agentcore": "REST: its requests name their resources in the path, which RequestResources does not read yet", "cloudformation": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "cloudfront": "REST: its requests name their resources in the path, which RequestResources does not read yet", "cloudhsm": "not read yet: its ARN formats end in ${CloudHsmClusterInstanceName} and ${CloudHsmBackupInstanceName}, names, while its requests give ClusterId and BackupId, ids, which the rule does not fill a name from, so nearly every operation needs a correction", "cloudwatch": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "codeartifact": "REST: its requests name their resources in the path, which RequestResources does not read yet", "codedeploy": "not read yet: the Service Reference gives an on-premises instance's ARN as `instance:${InstanceName}`, while the CodeDeploy permissions reference gives arn:aws:codedeploy:region:account-id:instance/instance-ID and AWS's GetOnPremisesInstance example answers instance/_, an id the service mints after the name; reading it needs that format corrected", "codeguru-reviewer": "REST: its requests name their resources in the path, which RequestResources does not read yet", "comprehend": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "config": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "connect": "REST: its requests name their resources in the path, which RequestResources does not read yet", "controlcatalog": "REST: its requests name their resources in the path, which RequestResources does not read yet", "controltower": "REST: its requests name their resources in the path, which RequestResources does not read yet", "datasync": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "detective": "REST: its requests name their resources in the path, which RequestResources does not read yet", "dlm": "REST: its requests name their resources in the path, which RequestResources does not read yet", "dms": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "ec2": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "ecs": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "elasticache": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "elasticbeanstalk": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "elasticfilesystem": "REST: its requests name their resources in the path, which RequestResources does not read yet", "elasticmapreduce": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "emr-serverless": "REST: its requests name their resources in the path, which RequestResources does not read yet", "es": "REST: its requests name their resources in the path, which RequestResources does not read yet", "execute-api": "REST: its requests name their resources in the path, which RequestResources does not read yet", "fis": "REST: its requests name their resources in the path, which RequestResources does not read yet", "glue": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "guardduty": "REST: its requests name their resources in the path, which RequestResources does not read yet", "identitystore": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "inspector2": "REST: its requests name their resources in the path, which RequestResources does not read yet", "iot": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "kafka": "REST: its requests name their resources in the path, which RequestResources does not read yet", "lightsail": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "macie2": "REST: its requests name their resources in the path, which RequestResources does not read yet", "memorydb": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "mq": "REST: its requests name their resources in the path, which RequestResources does not read yet", "network-firewall": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "oam": "REST: its requests name their resources in the path, which RequestResources does not read yet", "organizations": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "ram": "REST: its requests name their resources in the path, which RequestResources does not read yet", "rds": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "rds-data": "REST: its requests name their resources in the path, which RequestResources does not read yet", "redshift": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "redshift-data": "not read yet: a serverless workgroup's ARN ends in an id the service mints, `workgroup/`, while its requests name the workgroup by WorkgroupName, a name or an ARN, so its resource is the stored ARN that name finds, which RequestResources has no lookup for yet", "redshift-serverless": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "rekognition": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "resource-explorer-2": "REST: its requests name their resources in the path, which RequestResources does not read yet", "route53": "REST: its requests name their resources in the path, which RequestResources does not read yet", "route53resolver": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "rum": "REST: its requests name their resources in the path, which RequestResources does not read yet", "s3tables": "REST: its requests name their resources in the path, which RequestResources does not read yet", "s3vectors": "REST: its requests name their resources in the path, which RequestResources does not read yet", "sagemaker": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "securityhub": "REST: its requests name their resources in the path, which RequestResources does not read yet", "servicecatalog": "not read yet: CreatePortfolioShare, UpdatePortfolioShare and DeletePortfolioShare give in AccountId the account a portfolio is shared with, which the rule reads as the portfolio's; a portfolio or product imported from another account keeps its owner's account in its ARN while requests name it by its id alone; and AppRegistry's applications and attribute groups are named in the path", "ses": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "signin": "REST: its requests name their resources in the path, which RequestResources does not read yet", "sso": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "sso-oauth": "REST: its requests name their resources in the path, which RequestResources does not read yet", "swf": "not read yet: the Service Reference gives a domain's ARN no Region, `swf:::/domain/`, while the SWF Developer Guide gives it as arn:aws:swf:Region:AccountID:/domain/DomainName, as Floci mints it; reading it needs that format corrected", "transcribe": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "transfer": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "verifiedpermissions": "not read yet: a policyStoreId may name its store by an alias, `policy-store-alias/`, which AWS authorizes as the action on the store the alias points to and GetPolicyStoreAlias on the alias, and an aliasName carries the `policy-store-alias/` its format already gives; reading it needs both", "wafv2": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint"}, + "handBuilt": ["apigateway", "bedrock", "dsql", "dynamodb", "eks", "iam", "kinesis", "kms", "lambda", "logs", "pipes", "resource-groups", "s3", "scheduler", "secretsmanager", "sns", "sqs", "ssm", "sts"], + "notCovered": {"access-analyzer": "REST: its requests name their resources in the path, which RequestResources does not read yet", "account": "REST: its requests name their resources in the path, which RequestResources does not read yet", "airflow": "REST: its requests name their resources in the path, which RequestResources does not read yet", "app-integrations": "REST: its requests name their resources in the path, which RequestResources does not read yet", "appconfig": "REST: its requests name their resources in the path, which RequestResources does not read yet", "application-autoscaling": "not read yet: a scalable target's ARN ends in an id the service mints, `scalable-target/`, while its requests name the target by ServiceNamespace, ResourceId and ScalableDimension, so its resource is the stored ARN those three find, which RequestResources has no lookup for yet; read as a member, ResourceId would fill that id", "appsync": "REST: its requests name their resources in the path, which RequestResources does not read yet", "aps": "REST: its requests name their resources in the path, which RequestResources does not read yet", "autoscaling": "not read yet: AWS's group and launch configuration ARNs carry an id the service mints, `autoScalingGroup::autoScalingGroupName/`, while Floci mints `autoScalingGroup:`, which other services (ECS capacity providers) read back; the mint is fixed first", "aws-marketplace": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "backup": "REST: its requests name their resources in the path, which RequestResources does not read yet", "batch": "REST: its requests name their resources in the path, which RequestResources does not read yet", "bedrock-agentcore": "REST: its requests name their resources in the path, which RequestResources does not read yet", "cloudformation": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "cloudfront": "REST: its requests name their resources in the path, which RequestResources does not read yet", "cloudhsm": "not read yet: its ARN formats end in ${CloudHsmClusterInstanceName} and ${CloudHsmBackupInstanceName}, names, while its requests give ClusterId and BackupId, ids, which the rule does not fill a name from, so nearly every operation needs a correction", "cloudwatch": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "codeartifact": "REST: its requests name their resources in the path, which RequestResources does not read yet", "codedeploy": "not read yet: the Service Reference gives an on-premises instance's ARN as `instance:${InstanceName}`, while the CodeDeploy permissions reference gives arn:aws:codedeploy:region:account-id:instance/instance-ID and AWS's GetOnPremisesInstance example answers instance/_, an id the service mints after the name; reading it needs that format corrected", "codeguru-reviewer": "REST: its requests name their resources in the path, which RequestResources does not read yet", "comprehend": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "config": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "connect": "REST: its requests name their resources in the path, which RequestResources does not read yet", "controlcatalog": "REST: its requests name their resources in the path, which RequestResources does not read yet", "controltower": "REST: its requests name their resources in the path, which RequestResources does not read yet", "datasync": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "detective": "REST: its requests name their resources in the path, which RequestResources does not read yet", "dlm": "REST: its requests name their resources in the path, which RequestResources does not read yet", "dms": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "ec2": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "ecs": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "elasticache": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "elasticbeanstalk": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "elasticfilesystem": "REST: its requests name their resources in the path, which RequestResources does not read yet", "elasticmapreduce": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "emr-serverless": "REST: its requests name their resources in the path, which RequestResources does not read yet", "es": "REST: its requests name their resources in the path, which RequestResources does not read yet", "execute-api": "REST: its requests name their resources in the path, which RequestResources does not read yet", "fis": "REST: its requests name their resources in the path, which RequestResources does not read yet", "glue": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "guardduty": "REST: its requests name their resources in the path, which RequestResources does not read yet", "identitystore": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "inspector2": "REST: its requests name their resources in the path, which RequestResources does not read yet", "iot": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "kafka": "REST: its requests name their resources in the path, which RequestResources does not read yet", "lightsail": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "macie2": "REST: its requests name their resources in the path, which RequestResources does not read yet", "memorydb": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "mq": "REST: its requests name their resources in the path, which RequestResources does not read yet", "network-firewall": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "oam": "REST: its requests name their resources in the path, which RequestResources does not read yet", "organizations": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "ram": "REST: its requests name their resources in the path, which RequestResources does not read yet", "rds": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "rds-data": "REST: its requests name their resources in the path, which RequestResources does not read yet", "redshift": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "redshift-data": "not read yet: a serverless workgroup's ARN ends in an id the service mints, `workgroup/`, while its requests name the workgroup by WorkgroupName, a name or an ARN, so its resource is the stored ARN that name finds, which RequestResources has no lookup for yet", "redshift-serverless": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "rekognition": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "resource-explorer-2": "REST: its requests name their resources in the path, which RequestResources does not read yet", "route53": "REST: its requests name their resources in the path, which RequestResources does not read yet", "route53resolver": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "rum": "REST: its requests name their resources in the path, which RequestResources does not read yet", "s3tables": "REST: its requests name their resources in the path, which RequestResources does not read yet", "s3vectors": "REST: its requests name their resources in the path, which RequestResources does not read yet", "sagemaker": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "securityhub": "REST: its requests name their resources in the path, which RequestResources does not read yet", "servicecatalog": "not read yet: CreatePortfolioShare, UpdatePortfolioShare and DeletePortfolioShare give in AccountId the account a portfolio is shared with, which the rule reads as the portfolio's; a portfolio or product imported from another account keeps its owner's account in its ARN while requests name it by its id alone; and AppRegistry's applications and attribute groups are named in the path", "ses": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "signin": "REST: its requests name their resources in the path, which RequestResources does not read yet", "sso": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "sso-oauth": "REST: its requests name their resources in the path, which RequestResources does not read yet", "swf": "not read yet: the Service Reference gives a domain's ARN no Region, `swf:::/domain/`, while the SWF Developer Guide gives it as arn:aws:swf:Region:AccountID:/domain/DomainName, as Floci mints it; reading it needs that format corrected", "transcribe": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "transfer": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "verifiedpermissions": "not read yet: a policyStoreId may name its store by an alias, `policy-store-alias/`, which AWS authorizes as the action on the store the alias points to and GetPolicyStoreAlias on the alias, and an aliasName carries the `policy-store-alias/` its format already gives; reading it needs both", "wafv2": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint"}, "otherNamespaces": ["a4b", "account-access", "acm-pca", "aco-automation", "agent-registry", "aidevops", "aiops", "airflow-serverless", "amplify", "amplifybackend", "amplifyuibuilder", "aoss", "appfabric", "appflow", "application-signals", "application-signals-mcp", "appmesh", "appmesh-preview", "apprunner", "appstream", "apptest", "arc-region-switch", "arc-zonal-shift", "artifact", "assurance", "auditmanager", "aws-external-anthropic", "b2bi", "backup-gateway", "backup-search", "bedrock-mantle", "bedrock-websearch", "billing", "billingconductor", "braket", "bugbust", "cases", "cassandra", "chatbot", "chime", "cleanrooms", "cleanrooms-ml", "cloud9", "clouddirectory", "cloudfront-keyvaluestore", "cloudsearch", "cloudshell", "cloudtrail-data", "codecatalyst", "codecommit", "codeconnections", "codeguru-profiler", "codeguru-security", "codestar-connections", "codestar-notifications", "codewhisperer", "cognito-sync", "connect-campaigns", "consoleapp", "continuum", "databrew", "dataexchange", "datapipeline", "datazone", "dax", "deadline", "devicefarm", "devops-guru", "directconnect", "docdb-elastic", "drs", "ds", "ds-data", "ebs", "ec2-instance-connect", "ecr-public", "eks-auth", "elastictranscoder", "elemental-appliances-software", "elemental-inference", "elemental-support-cases", "emr-containers", "end-user-messaging", "entityresolution", "evs", "finspace", "finspace-api", "fms", "forecast", "frauddetector", "freertos", "fsx", "gamelift", "gameliftstreams", "geo", "geo-maps", "geo-places", "geo-routes", "glacier", "grafana", "greengrass", "groundstation", "health", "health-agent", "healthlake", "honeycode", "identity-sync", "imagebuilder", "interconnect", "internetmonitor", "invoicing", "iotanalytics", "iotdeviceadvisor", "iotfleethub", "iotfleetwise", "iotjobsdata", "iotmanagedintegrations", "iotsitewise", "iottwinmaker", "iotwireless", "iq", "iq-permission", "ivs", "ivschat", "kafka-cluster", "kafkaconnect", "kendra", "kendra-ranking", "kinesisvideo", "launchwizard", "lex", "license-manager", "license-manager-linux-subscriptions", "license-manager-user-subscriptions", "lookoutequipment", "lookoutmetrics", "lookoutvision", "m2", "machinelearning", "managedblockchain", "mapcredits", "mediaconnect", "mediaconvert", "medialive", "mediapackage", "mediapackage-vod", "mediapackagev2", "mediastore", "mediatailor", "medical-imaging", "mgh", "mgn", "migrationhub-orchestrator", "mobiletargeting", "monitron", "mpa", "neptune-db", "neptune-graph", "network-security-manager", "networkflowmonitor", "networkmanager", "networkmonitor", "nimble", "notifications", "notifications-contacts", "nova-act", "observabilityadmin", "odb", "omics", "one", "opensearch", "opsworks", "osis", "outposts", "panorama", "partnercentral", "payment-cryptography", "payments", "pca-connector-ad", "pca-connector-scep", "pcs", "personalize", "pi", "polly", "private-networks", "profile", "proton", "purchase-orders", "q", "qapps", "qbusiness", "qdeveloper", "qldb", "quicksight", "rbin", "rds-db", "refactor-spaces", "repostspace", "resiliencehub", "robomaker", "rolesanywhere", "route53-recovery-cluster", "route53-recovery-control-config", "route53-recovery-readiness", "route53globalresolver", "route53profiles", "rtbfabric", "s3-object-lambda", "s3-outposts", "s3express", "s3files", "sagemaker-geospatial", "sagemaker-mlflow", "savingsplans", "schemas", "scn", "sdb", "security-ir", "securityagent", "securitylake", "serverlessrepo", "shield", "signer", "simspaceweaver", "sms-voice", "snow-device-management", "social-messaging", "sqlworkbench", "ssm-contacts", "ssm-incidents", "ssm-quicksetup", "ssm-sap", "storagegateway", "supportauthz", "synthetics", "thinclient", "timestream", "tnb", "transform", "transform-custom", "trustedadvisor", "ts", "vendor-insights", "voiceid", "vpc-lattice", "vpc-lattice-svcs", "vpce", "waf", "waf-regional", "wellarchitected", "wickr", "wisdom", "workdocs", "worklink", "workmail", "workmailmessageflow", "workspaces", "workspaces-instances", "workspaces-web", "xray"], "arnFormats": {"acm": {"acme-domain-validation": "arn:${Partition}:acm:${Region}:${Account}:acme-endpoint/${AcmeEndpointId}/acme-domain-validation/${AcmeDomainValidationId}", "acme-endpoint": "arn:${Partition}:acm:${Region}:${Account}:acme-endpoint/${AcmeEndpointId}", "acme-external-account-binding": "arn:${Partition}:acm:${Region}:${Account}:acme-endpoint/${AcmeEndpointId}/acme-external-account-binding/${ExternalAccountBindingId}", "certificate": "arn:${Partition}:acm:${Region}:${Account}:certificate/${CertificateId}"}, "athena": {"capacity-reservation": "arn:${Partition}:athena:${Region}:${Account}:capacity-reservation/${CapacityReservationName}", "datacatalog": "arn:${Partition}:athena:${Region}:${Account}:datacatalog/${DataCatalogName}", "session": "arn:${Partition}:athena:${Region}:${Account}:workgroup/${WorkGroupName}/session/${SessionId}", "workgroup": "arn:${Partition}:athena:${Region}:${Account}:workgroup/${WorkGroupName}"}, "bcm-data-exports": {"billingview": "arn:${Partition}:billing::${Account}:billingview/${ResourceId}", "export": "arn:${Partition}:bcm-data-exports:${Region}:${Account}:export/${Identifier}", "table": "arn:${Partition}:bcm-data-exports:${Region}:${Account}:table/${Identifier}"}, "bcm-pricing-calculator": {"bill-estimate": "arn:${Partition}:bcm-pricing-calculator::${Account}:bill-estimate/${BillEstimateId}", "bill-scenario": "arn:${Partition}:bcm-pricing-calculator::${Account}:bill-scenario/${BillScenarioId}", "workload-estimate": "arn:${Partition}:bcm-pricing-calculator::${Account}:workload-estimate/${WorkloadEstimateId}"}, "budgets": {"budget": "arn:${Partition}:budgets::${Account}:budget/${BudgetName}", "budgetAction": "arn:${Partition}:budgets::${Account}:budget/${BudgetName}/action/${ActionId}"}, "ce": {"anomalymonitor": "arn:${Partition}:ce::${Account}:anomalymonitor/${Identifier}", "anomalysubscription": "arn:${Partition}:ce::${Account}:anomalysubscription/${Identifier}", "billingview": "arn:${Partition}:billing::${Account}:billingview/${ResourceId}", "costcategory": "arn:${Partition}:ce::${Account}:costcategory/${Identifier}"}, "cloudtrail": {"channel": "arn:${Partition}:cloudtrail:${Region}:${Account}:channel/${ChannelId}", "dashboard": "arn:${Partition}:cloudtrail:${Region}:${Account}:dashboard/${DashboardName}", "eventdatastore": "arn:${Partition}:cloudtrail:${Region}:${Account}:eventdatastore/${EventDataStoreId}", "trail": "arn:${Partition}:cloudtrail:${Region}:${Account}:trail/${TrailName}"}, "codebuild": {"build": "arn:${Partition}:codebuild:${Region}:${Account}:build/${BuildId}", "build-batch": "arn:${Partition}:codebuild:${Region}:${Account}:build-batch/${BuildBatchId}", "fleet": "arn:${Partition}:codebuild:${Region}:${Account}:fleet/${FleetName}:${FleetId}", "project": "arn:${Partition}:codebuild:${Region}:${Account}:project/${ProjectName}", "report": "arn:${Partition}:codebuild:${Region}:${Account}:report/${ReportGroupName}:${ReportId}", "report-group": "arn:${Partition}:codebuild:${Region}:${Account}:report-group/${ReportGroupName}", "sandbox": "arn:${Partition}:codebuild:${Region}:${Account}:sandbox/${SandboxId}"}, "codepipeline": {"action": "arn:${Partition}:codepipeline:${Region}:${Account}:${PipelineName}/${StageName}/${ActionName}", "actiontype": "arn:${Partition}:codepipeline:${Region}:${Account}:actiontype:${Owner}/${Category}/${Provider}/${Version}", "pipeline": "arn:${Partition}:codepipeline:${Region}:${Account}:${PipelineName}", "stage": "arn:${Partition}:codepipeline:${Region}:${Account}:${PipelineName}/${StageName}", "webhook": "arn:${Partition}:codepipeline:${Region}:${Account}:webhook:${WebhookName}"}, "cognito-identity": {"identitypool": "arn:${Partition}:cognito-identity:${Region}:${Account}:identitypool/${IdentityPoolId}"}, "cognito-idp": {"userpool": "arn:${Partition}:cognito-idp:${Region}:${Account}:userpool/${UserPoolId}", "webacl": "arn:${Partition}:wafv2:${Region}:${Account}:${Scope}/webacl/${Name}/${Id}"}, "cur": {"cur": "arn:${Partition}:cur:${Region}:${Account}:definition/${ReportName}"}, "ecr": {"repository": "arn:${Partition}:ecr:${Region}:${Account}:repository/${RepositoryName}"}, "elasticloadbalancing": {"listener-rule/app": "arn:${Partition}:elasticloadbalancing:${Region}:${Account}:listener-rule/app/${LoadBalancerName}/${LoadBalancerId}/${ListenerId}/${ListenerRuleId}", "listener-rule/net": "arn:${Partition}:elasticloadbalancing:${Region}:${Account}:listener-rule/net/${LoadBalancerName}/${LoadBalancerId}/${ListenerId}/${ListenerRuleId}", "listener/app": "arn:${Partition}:elasticloadbalancing:${Region}:${Account}:listener/app/${LoadBalancerName}/${LoadBalancerId}/${ListenerId}", "listener/gwy": "arn:${Partition}:elasticloadbalancing:${Region}:${Account}:listener/gwy/${LoadBalancerName}/${LoadBalancerId}/${ListenerId}", "listener/net": "arn:${Partition}:elasticloadbalancing:${Region}:${Account}:listener/net/${LoadBalancerName}/${LoadBalancerId}/${ListenerId}", "loadbalancer": "arn:${Partition}:elasticloadbalancing:${Region}:${Account}:loadbalancer/${LoadBalancerName}", "loadbalancer/app/": "arn:${Partition}:elasticloadbalancing:${Region}:${Account}:loadbalancer/app/${LoadBalancerName}/${LoadBalancerId}", "loadbalancer/gwy/": "arn:${Partition}:elasticloadbalancing:${Region}:${Account}:loadbalancer/gwy/${LoadBalancerName}/${LoadBalancerId}", "loadbalancer/net/": "arn:${Partition}:elasticloadbalancing:${Region}:${Account}:loadbalancer/net/${LoadBalancerName}/${LoadBalancerId}", "targetgroup": "arn:${Partition}:elasticloadbalancing:${Region}:${Account}:targetgroup/${TargetGroupName}/${TargetGroupId}", "truststore": "arn:${Partition}:elasticloadbalancing:${Region}:${Account}:truststore/${TrustStoreName}/${TrustStoreId}"}, "events": {"alias": "arn:${Partition}:kms:${Region}:${Account}:alias/${Alias}", "api-destination": "arn:${Partition}:events:${Region}:${Account}:api-destination/${ApiDestinationName}", "archive": "arn:${Partition}:events:${Region}:${Account}:archive/${ArchiveName}", "connection": "arn:${Partition}:events:${Region}:${Account}:connection/${ConnectionName}", "create-snapshot": "arn:${Partition}:events:${Region}:${Account}:target/create-snapshot", "endpoint": "arn:${Partition}:events:${Region}:${Account}:endpoint/${EndpointName}", "event-bus": "arn:${Partition}:events:${Region}:${Account}:event-bus/${EventBusName}", "event-busv2": "arn:${Partition}:events:${Region}:${Account}:event-busv2/${EventBusName}/${OpaqueId}", "event-source": "arn:${Partition}:events:${Region}::event-source/${EventSourceName}", "event-sourcev2": "arn:${Partition}:events:${Region}:${Account}:event-sourcev2/${SourceType}/${EventSourceName}/${OpaqueId}", "key": "arn:${Partition}:kms:${Region}:${Account}:key/${KeyId}", "reboot-instance": "arn:${Partition}:events:${Region}:${Account}:target/reboot-instance", "replay": "arn:${Partition}:events:${Region}:${Account}:replay/${ReplayName}", "rule-on-custom-event-bus": "arn:${Partition}:events:${Region}:${Account}:rule/${EventBusName}/${RuleName}", "rule-on-default-event-bus": "arn:${Partition}:events:${Region}:${Account}:rule/${RuleName}", "stop-instance": "arn:${Partition}:events:${Region}:${Account}:target/stop-instance", "subscriber": "arn:${Partition}:events:${Region}:${Account}:subscriber/${SubscriberName}/${OpaqueId}", "terminate-instance": "arn:${Partition}:events:${Region}:${Account}:target/terminate-instance"}, "firehose": {"deliverystream": "arn:${Partition}:firehose:${Region}:${Account}:deliverystream/${DeliveryStreamName}"}, "globalaccelerator": {"accelerator": "arn:${Partition}:globalaccelerator::${Account}:accelerator/${ResourceId}", "attachment": "arn:${Partition}:globalaccelerator::${Account}:attachment/${ResourceId}", "endpointgroup": "arn:${Partition}:globalaccelerator::${Account}:accelerator/${ResourceId}/listener/${ListenerId}/endpoint-group/${EndpointGroupId}", "listener": "arn:${Partition}:globalaccelerator::${Account}:accelerator/${ResourceId}/listener/${ListenerId}"}, "kinesisanalytics": {"application": "arn:${Partition}:kinesisanalytics:${Region}:${Account}:application/${ApplicationName}"}, "servicediscovery": {"namespace": "arn:${Partition}:servicediscovery:${Region}:${Account}:namespace/${NamespaceId}", "service": "arn:${Partition}:servicediscovery:${Region}:${Account}:service/${ServiceId}"}, "servicequotas": {"quota": "arn:${Partition}:servicequotas:${Region}:${Account}:${ServiceCode}/${QuotaCode}"}, "states": {"activity": "arn:${Partition}:states:${Region}:${Account}:activity:${ActivityName}", "execution": "arn:${Partition}:states:${Region}:${Account}:execution:${StateMachineName}:${ExecutionId}", "express": "arn:${Partition}:states:${Region}:${Account}:express:${StateMachineName}:${ExecutionId}:${ExpressId}", "labelled execution": "arn:${Partition}:states:${Region}:${Account}:execution:${StateMachineName}/${MapRunLabel}:${ExecutionId}", "labelled express": "arn:${Partition}:states:${Region}:${Account}:express:${StateMachineName}/${MapRunLabel}:${ExecutionId}:${ExpressId}", "maprun": "arn:${Partition}:states:${Region}:${Account}:mapRun:${StateMachineName}/${MapRunLabel}:${MapRunId}", "statemachine": "arn:${Partition}:states:${Region}:${Account}:stateMachine:${StateMachineName}", "statemachinealias": "arn:${Partition}:states:${Region}:${Account}:stateMachine:${StateMachineName}:${StateMachineAliasName}", "statemachineversion": "arn:${Partition}:states:${Region}:${Account}:stateMachine:${StateMachineName}:${StateMachineVersionId}"}, "textract": {"adapter": "arn:${Partition}:textract:${Region}:${Account}:/adapters/${AdapterId}", "adapterversion": "arn:${Partition}:textract:${Region}:${Account}:/adapters/${AdapterId}/versions/${AdapterVersion}"}, "timestream-influxdb": {"db-backup": "arn:${Partition}:timestream-influxdb:${Region}:${Account}:db-backup/${DbBackupId}", "db-cluster": "arn:${Partition}:timestream-influxdb:${Region}:${Account}:db-cluster/${DbClusterId}", "db-instance": "arn:${Partition}:timestream-influxdb:${Region}:${Account}:db-instance/${DbInstanceIdentifier}", "db-parameter-group": "arn:${Partition}:timestream-influxdb:${Region}:${Account}:db-parameter-group/${DbParameterGroupIdentifier}"}, "translate": {"parallel-data": "arn:${Partition}:translate:${Region}:${Account}:parallel-data/${ResourceName}", "terminology": "arn:${Partition}:translate:${Region}:${Account}:terminology/${ResourceName}"}}, "unqualified": {"states": ["statemachine"]}, diff --git a/src/test/java/io/github/hectorvent/floci/services/bedrock/BedrockResourcePolicyIamEnforcementIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/bedrock/BedrockResourcePolicyIamEnforcementIntegrationTest.java new file mode 100644 index 0000000000..82bc94a4cb --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/bedrock/BedrockResourcePolicyIamEnforcementIntegrationTest.java @@ -0,0 +1,90 @@ +package io.github.hectorvent.floci.services.bedrock; + +import io.github.hectorvent.floci.testing.AwsTestClients; +import io.github.hectorvent.floci.testing.EnforcementFixtures; +import io.github.hectorvent.floci.testing.IamEnforcementProfile; +import io.github.hectorvent.floci.testing.PartitionCleanup; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.TestProfile; +import io.restassured.RestAssured; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.api.function.Executable; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.bedrock.BedrockClient; +import software.amazon.awssdk.services.bedrock.model.BedrockException; +import software.amazon.awssdk.services.bedrock.model.CreateGuardrailResponse; + +import java.util.List; +import java.util.UUID; + +import static io.github.hectorvent.floci.testing.EnforcementFixtures.auth; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** The resource policy actions are checked against the guardrail their {@code resourceArn} names. */ +@QuarkusTest +@TestProfile(IamEnforcementProfile.class) +class BedrockResourcePolicyIamEnforcementIntegrationTest { + + private static final String ACCOUNT = "000000000000"; + + @RegisterExtension + final PartitionCleanup cleanup = new PartitionCleanup(); + + @Test + void aDenyOnOneGuardrailRefusesThePolicyActionsOnItAndNotOnAnother() { + try (BedrockClient root = AwsTestClients.create(BedrockClient.builder(), ACCOUNT, Region.US_EAST_1)) { + CreateGuardrailResponse denied = create(root); + CreateGuardrailResponse allowed = create(root); + try { + String userName = "bedrock-policy-" + UUID.randomUUID(); + EnforcementFixtures.UserCredentials credentials = EnforcementFixtures.createUser( + cleanup, RestAssured.port, auth(ACCOUNT, "iam"), userName); + EnforcementFixtures.putUserPolicy(RestAssured.port, auth(ACCOUNT, "iam"), userName, "p", """ + {"Version":"2012-10-17","Statement":[ + {"Effect":"Allow","Action":"bedrock:*","Resource":"*"}, + {"Effect":"Deny","Action":["bedrock:PutResourcePolicy","bedrock:GetResourcePolicy", + "bedrock:DeleteResourcePolicy"],"Resource":"%s"}]}""" + .formatted(denied.guardrailArn())); + try (BedrockClient user = AwsTestClients.create(BedrockClient.builder(), credentials.accessKeyId(), + Region.US_EAST_1)) { + String allowedArn = allowed.guardrailArn(); + String allowedPolicy = policy(allowedArn); + assertDoesNotThrow(() -> user.putResourcePolicy(r -> r.resourceArn(allowedArn) + .resourcePolicy(allowedPolicy))); + assertEquals(allowedPolicy, user.getResourcePolicy(r -> r.resourceArn(allowedArn)).resourcePolicy()); + assertDoesNotThrow(() -> user.deleteResourcePolicy(r -> r.resourceArn(allowedArn))); + + String deniedArn = denied.guardrailArn(); + String deniedPolicy = policy(deniedArn); + root.putResourcePolicy(r -> r.resourceArn(deniedArn).resourcePolicy(deniedPolicy)); + List refused = List.of( + () -> user.putResourcePolicy(r -> r.resourceArn(deniedArn).resourcePolicy(deniedPolicy)), + () -> user.getResourcePolicy(r -> r.resourceArn(deniedArn)), + () -> user.deleteResourcePolicy(r -> r.resourceArn(deniedArn))); + for (Executable call : refused) { + BedrockException error = assertThrows(BedrockException.class, call); + assertEquals("AccessDeniedException", error.awsErrorDetails().errorCode()); + } + assertEquals(deniedPolicy, root.getResourcePolicy(r -> r.resourceArn(deniedArn)).resourcePolicy()); + } + } finally { + root.deleteGuardrail(r -> r.guardrailIdentifier(denied.guardrailId())); + root.deleteGuardrail(r -> r.guardrailIdentifier(allowed.guardrailId())); + } + } + } + + private static CreateGuardrailResponse create(BedrockClient client) { + return client.createGuardrail(r -> r.name("iam-rp-" + UUID.randomUUID()) + .blockedInputMessaging("blocked").blockedOutputsMessaging("blocked")); + } + + private static String policy(String guardrailArn) { + return """ + {"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"AWS":"arn:aws:iam::%s:root"},\ + "Action":"bedrock:ApplyGuardrail","Resource":"%s"}]}""".formatted(ACCOUNT, guardrailArn); + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/bedrock/BedrockResourcePolicyIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/bedrock/BedrockResourcePolicyIntegrationTest.java new file mode 100644 index 0000000000..fab0ea4afd --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/bedrock/BedrockResourcePolicyIntegrationTest.java @@ -0,0 +1,172 @@ +package io.github.hectorvent.floci.services.bedrock; + +import io.github.hectorvent.floci.testing.AwsTestClients; +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.bedrock.BedrockClient; +import software.amazon.awssdk.services.bedrock.model.BedrockException; +import software.amazon.awssdk.services.bedrock.model.CreateGuardrailResponse; +import software.amazon.awssdk.services.bedrock.model.PutResourcePolicyResponse; +import software.amazon.awssdk.services.bedrock.model.ResourceNotFoundException; +import software.amazon.awssdk.services.bedrock.model.ValidationException; + +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@QuarkusTest +class BedrockResourcePolicyIntegrationTest { + + private static final String ACCOUNT = "741623800011"; + private static final String OTHER_ACCOUNT = "741623800012"; + + @Test + void putGetAndDeleteRoundTripOnAGuardrail() { + try (BedrockClient client = client(ACCOUNT, Region.US_EAST_1)) { + CreateGuardrailResponse created = create(client); + String arn = created.guardrailArn(); + try { + assertNull(client.getResourcePolicy(r -> r.resourceArn(arn)).resourcePolicy()); + + String policy = rootPolicy(arn, "\"bedrock:ApplyGuardrail\",\"bedrock:GetGuardrail\""); + PutResourcePolicyResponse put = + client.putResourcePolicy(r -> r.resourceArn(arn).resourcePolicy(policy)); + assertEquals(201, put.sdkHttpResponse().statusCode()); + assertEquals(arn, put.resourceArn()); + assertEquals(policy, client.getResourcePolicy(r -> r.resourceArn(arn)).resourcePolicy()); + + String organizationPolicy = organizationPolicy(arn); + client.putResourcePolicy(r -> r.resourceArn(arn).resourcePolicy(organizationPolicy)); + assertEquals(organizationPolicy, client.getResourcePolicy(r -> r.resourceArn(arn)).resourcePolicy()); + + assertEquals(200, client.deleteResourcePolicy(r -> r.resourceArn(arn)).sdkHttpResponse().statusCode()); + assertNull(client.getResourcePolicy(r -> r.resourceArn(arn)).resourcePolicy()); + } finally { + client.deleteGuardrail(r -> r.guardrailIdentifier(created.guardrailId())); + } + } + } + + @ParameterizedTest + @ValueSource(strings = {"not-json", "empty", "too-long", "no-statement", "deny", "other-resource", + "unsupported-action", "public-principal", "wildcard-organization", "other-account-principal", + "unsupported-condition", "trailing-content", "extra-principal", "org-paths-object"}) + void aPolicyOutsideTheGuardrailPolicyLanguageIsRejected(String invalid) { + try (BedrockClient client = client(ACCOUNT, Region.US_EAST_1)) { + CreateGuardrailResponse created = create(client); + String arn = created.guardrailArn(); + try { + String valid = rootPolicy(arn, "\"bedrock:ApplyGuardrail\""); + String policy = switch (invalid) { + case "not-json" -> "not json"; + case "empty" -> ""; + case "too-long" -> valid + " ".repeat(20481 - valid.length()); + case "no-statement" -> "{\"Version\":\"2012-10-17\",\"Statement\":[]}"; + case "deny" -> valid.replace("\"Allow\"", "\"Deny\""); + case "other-resource" -> valid.replace("\"Resource\":\"" + arn + "\"", + "\"Resource\":\"" + arn + "-other\""); + case "unsupported-action" -> rootPolicy(arn, "\"bedrock:InvokeModel\""); + case "public-principal" -> + valid.replace("{\"AWS\":\"arn:aws:iam::" + ACCOUNT + ":root\"}", "\"*\""); + case "wildcard-organization" -> organizationPolicy(arn).replace("o-exampleorgid", "o-*"); + case "other-account-principal" -> valid.replace(ACCOUNT + ":root", OTHER_ACCOUNT + ":root"); + case "trailing-content" -> valid + " {}"; + case "extra-principal" -> valid.replace(ACCOUNT + ":root\"}", + ACCOUNT + ":root\",\"Service\":\"lambda.amazonaws.com\"}"); + case "org-paths-object" -> organizationPolicy(arn).replace( + "[\"o-exampleorgid/*/ou-ab12-cdefgh34/*\"]", "{}"); + default -> valid.replace("\"Resource\"", + "\"Condition\":{\"Bool\":{\"aws:SecureTransport\":\"true\"}},\"Resource\""); + }; + ValidationException error = assertThrows(ValidationException.class, + () -> client.putResourcePolicy(r -> r.resourceArn(arn).resourcePolicy(policy))); + assertEquals(400, error.statusCode()); + assertNull(client.getResourcePolicy(r -> r.resourceArn(arn)).resourcePolicy()); + } finally { + client.deleteGuardrail(r -> r.guardrailIdentifier(created.guardrailId())); + } + } + } + + @Test + void anArnNamingNoGuardrailIsNotFound() { + try (BedrockClient client = client(ACCOUNT, Region.US_EAST_1); + BedrockClient otherAccount = client(OTHER_ACCOUNT, Region.US_EAST_1)) { + String unknown = "arn:aws:bedrock:us-east-1:" + ACCOUNT + ":guardrail/0123456789ab"; + String policy = rootPolicy(unknown, "\"bedrock:ApplyGuardrail\""); + assertEquals(404, assertThrows(ResourceNotFoundException.class, + () -> client.getResourcePolicy(r -> r.resourceArn(unknown))).statusCode()); + assertEquals(404, assertThrows(ResourceNotFoundException.class, + () -> client.deleteResourcePolicy(r -> r.resourceArn(unknown))).statusCode()); + BedrockException put = assertThrows(BedrockException.class, + () -> client.putResourcePolicy(r -> r.resourceArn(unknown).resourcePolicy(policy))); + assertEquals(404, put.statusCode()); + assertEquals("ResourceNotFoundException", put.awsErrorDetails().errorCode()); + String profile = "arn:aws:bedrock:us-east-1:" + ACCOUNT + ":guardrail-profile/us.guardrail.v1:0"; + assertEquals(404, assertThrows(ResourceNotFoundException.class, + () -> client.getResourcePolicy(r -> r.resourceArn(profile))).statusCode()); + + CreateGuardrailResponse created = create(client); + try { + assertThrows(ResourceNotFoundException.class, + () -> otherAccount.getResourcePolicy(r -> r.resourceArn(created.guardrailArn()))); + } finally { + client.deleteGuardrail(r -> r.guardrailIdentifier(created.guardrailId())); + } + } + } + + @Test + void deletingTheGuardrailDeletesItsPolicy() { + try (BedrockClient client = client(ACCOUNT, Region.US_EAST_1)) { + String name = "rp-" + UUID.randomUUID(); + CreateGuardrailResponse created = create(client, name); + String arn = created.guardrailArn(); + String policy = rootPolicy(arn, "\"bedrock:ApplyGuardrail\""); + client.putResourcePolicy(r -> r.resourceArn(arn).resourcePolicy(policy)); + + client.deleteGuardrail(r -> r.guardrailIdentifier(created.guardrailId())); + + assertThrows(ResourceNotFoundException.class, () -> client.getResourcePolicy(r -> r.resourceArn(arn))); + CreateGuardrailResponse recreated = create(client, name); + try { + assertNull(client.getResourcePolicy(r -> r.resourceArn(recreated.guardrailArn())).resourcePolicy()); + } finally { + client.deleteGuardrail(r -> r.guardrailIdentifier(recreated.guardrailId())); + } + } + } + + private static CreateGuardrailResponse create(BedrockClient client) { + return create(client, "rp-" + UUID.randomUUID()); + } + + private static CreateGuardrailResponse create(BedrockClient client, String name) { + return client.createGuardrail(r -> r.name(name) + .blockedInputMessaging("blocked").blockedOutputsMessaging("blocked")); + } + + private static String rootPolicy(String resourceArn, String actions) { + return """ + {"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"AWS":"arn:aws:iam::%s:root"},\ + "Action":[%s],"Resource":"%s"}]}""".formatted(ACCOUNT, actions, resourceArn); + } + + private static String organizationPolicy(String resourceArn) { + return """ + {"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":"*",\ + "Action":["bedrock:ApplyGuardrail","bedrock:GetGuardrail"],"Resource":"%s",\ + "Condition":{"StringEquals":{"aws:PrincipalOrgID":"o-exampleorgid"},\ + "ForAnyValue:StringLike":{"aws:PrincipalOrgPaths":["o-exampleorgid/*/ou-ab12-cdefgh34/*"]}}}]}""" + .formatted(resourceArn); + } + + private static BedrockClient client(String account, Region region) { + return AwsTestClients.create(BedrockClient.builder(), account, region); + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/bedrock/BedrockServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/bedrock/BedrockServiceTest.java index 58126d33b5..66085e181b 100644 --- a/src/test/java/io/github/hectorvent/floci/services/bedrock/BedrockServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/bedrock/BedrockServiceTest.java @@ -561,4 +561,43 @@ class BedrockServiceTest { () -> service.getGuardrail(created.getGuardrailId(), null, "eu-west-1")); assertTrue(service.listGuardrails(null, null, null, "eu-west-1").items().isEmpty()); } + + private static String rootPolicy(String resourceArn, String action) { + return """ + {"Version":"2012-10-17","Statement":[{"Effect":"Allow", + "Principal":{"AWS":"arn:aws:iam::%s:root"},"Action":"%s","Resource":"%s"}]} + """.formatted(ACCOUNT, action, resourceArn); + } + + @Test + void guardrailResourcePolicyLivesOnTheDraftAndNotOnItsVersions() { + Guardrail created = create("with-policy"); + String policy = rootPolicy(created.getGuardrailArn(), "bedrock:ApplyGuardrail"); + + assertNull(service.getResourcePolicy(created.getGuardrailArn(), REGION)); + service.putResourcePolicy(created.getGuardrailArn(), policy, REGION); + Guardrail version = service.createGuardrailVersion(created.getGuardrailId(), null, REGION); + + assertEquals(policy, service.getResourcePolicy(created.getGuardrailArn(), REGION)); + assertNull(version.getResourcePolicy()); + service.deleteResourcePolicy(created.getGuardrailArn(), REGION); + assertNull(service.getResourcePolicy(created.getGuardrailArn(), REGION)); + } + + @Test + void guardrailResourcePolicyIsFoundByItsExactArnOnly() { + Guardrail created = create("exact-arn"); + String policy = rootPolicy(created.getGuardrailArn(), "bedrock:ApplyGuardrail"); + + for (String other : List.of(created.getGuardrailId(), + created.getGuardrailArn().replace(ACCOUNT, "111122223333"), + created.getGuardrailArn().replace(":guardrail/", ":custom-model/"), + "arn:aws:bedrock:" + REGION + ":" + ACCOUNT + ":guardrail-profile/us.guardrail.v1:0")) { + AwsException e = assertThrows(AwsException.class, () -> service.getResourcePolicy(other, REGION)); + assertEquals("ResourceNotFoundException", e.getErrorCode(), other); + } + AwsException otherRegion = assertThrows(AwsException.class, + () -> service.putResourcePolicy(created.getGuardrailArn(), policy, "eu-west-1")); + assertEquals("ResourceNotFoundException", otherRegion.getErrorCode()); + } } diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/IamActionRegistryTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/IamActionRegistryTest.java index 2833f10441..85fe2aa4ce 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iam/IamActionRegistryTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iam/IamActionRegistryTest.java @@ -367,6 +367,21 @@ class IamActionRegistryTest { assertEquals("lambda:DeleteResourcePolicy", lambdaAction("DELETE", "/2025-03-07/resource-policy/" + arn)); } + @Test + void bedrockResourcePolicyRoutesResolveToTheirActions() { + String arn = "arn%3Aaws%3Abedrock%3Aus-east-1%3A000000000000%3Aguardrail%2Fabc123def456"; + assertEquals("bedrock:PutResourcePolicy", bedrockAction("POST", "/resource-policy")); + assertEquals("bedrock:GetResourcePolicy", bedrockAction("GET", "/resource-policy/" + arn)); + assertEquals("bedrock:DeleteResourcePolicy", bedrockAction("DELETE", "/resource-policy/" + arn)); + assertNull(bedrockAction("GET", "/resource-policy")); + assertNull(bedrockAction("POST", "/resource-policy/" + arn)); + } + + private String bedrockAction(String method, String path) { + return registry.resolveRoute("bedrock", + mockCtx(method, path, new MultivaluedHashMap<>(), MediaType.APPLICATION_JSON_TYPE, "{}")); + } + private String lambdaAction(String method, String path) { return registry.resolveRoute("lambda", mockCtx(method, path, new MultivaluedHashMap<>(), MediaType.APPLICATION_JSON_TYPE, "{}")); diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/ResourceArnBuilderTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/ResourceArnBuilderTest.java index 946cc64bc6..a3ab0725a0 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iam/ResourceArnBuilderTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iam/ResourceArnBuilderTest.java @@ -1931,6 +1931,28 @@ class ResourceArnBuilderTest { builder.buildResources("dsql", ctx, "polygondwanaland-west-1", "000000000000", "aws-cn")); } + @Test + void bedrockResourcePolicyRoutesResolveTheArnTheyCarry() { + String guardrail = "arn:aws:bedrock:us-east-1:000000000000:guardrail/abc123def456"; + for (String method : List.of("GET", "DELETE")) { + when(ctx.getMethod()).thenReturn(method); + when(uriInfo.getPath()).thenReturn("/resource-policy/" + guardrail); + assertEquals(List.of(guardrail), builder.buildResources("bedrock", ctx, "us-east-1", ACCOUNT), method); + } + when(ctx.getMethod()).thenReturn("POST"); + when(uriInfo.getPath()).thenReturn("/resource-policy"); + setJsonBody("{\"resourceArn\":\"" + guardrail + "\",\"resourcePolicy\":\"{}\"}"); + assertEquals(List.of(guardrail), builder.buildResources("bedrock", ctx, "us-east-1", ACCOUNT)); + // A value that is not an ARN, and every other Bedrock route, name no resource. + setJsonBody("{\"resourceArn\":\"abc123def456\",\"resourcePolicy\":\"{}\"}"); + assertEquals(List.of("*"), builder.buildResources("bedrock", ctx, "us-east-1", ACCOUNT)); + when(ctx.getMethod()).thenReturn("GET"); + when(uriInfo.getPath()).thenReturn("/resource-policy/abc123def456"); + assertEquals(List.of("*"), builder.buildResources("bedrock", ctx, "us-east-1", ACCOUNT)); + when(uriInfo.getPath()).thenReturn("/guardrails/abc123def456"); + assertEquals(List.of("*"), builder.buildResources("bedrock", ctx, "us-east-1", ACCOUNT)); + } + @Test void apiGatewayRoutesResolveThePathTheyNameWithNoAccount() { request("/restapis/abc123/stages"); diff --git a/tools/aws/regen_iam_request_resources.py b/tools/aws/regen_iam_request_resources.py index 9279b36701..88de30514c 100644 --- a/tools/aws/regen_iam_request_resources.py +++ b/tools/aws/regen_iam_request_resources.py @@ -136,7 +136,7 @@ CLIENTS_NOT_READ: dict[str, str] = { } # The namespaces whose resources ResourceArnBuilder builds itself. -HAND_BUILT = ("apigateway", "dsql", "dynamodb", "eks", "iam", "kinesis", "kms", "lambda", "logs", "pipes", +HAND_BUILT = ("apigateway", "bedrock", "dsql", "dynamodb", "eks", "iam", "kinesis", "kms", "lambda", "logs", "pipes", "resource-groups", "s3", "scheduler", "secretsmanager", "sns", "sqs", "ssm", "sts") _LATER = "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint" @@ -162,7 +162,6 @@ NOT_COVERED: dict[str, str] = { "aws-marketplace": _LATER, "backup": _REST, "batch": _REST, - "bedrock": _LATER, "bedrock-agentcore": _REST, "cloudformation": _LATER, "cloudfront": _REST,