Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions docs/services/bedrock.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,17 @@ returns the empty policy `{}`. A profile ARN of another account or partition ret
`ResourceNotFoundException`; whether the profile's Region is a destination of the
calling Region is not checked.

With IAM enforcement on, `PutResourcePolicy`, `GetResourcePolicy` and
`DeleteResourcePolicy` are authorized as `bedrock:PutResourcePolicy`,
`bedrock:GetResourcePolicy` and `bedrock:DeleteResourcePolicy` on the ARN the request
names.
With IAM enforcement on, every Bedrock and Bedrock Runtime request is authorized as the action
AWS's Service Reference gives its operation, on the resources its request names, read from the
generated tables like other services' requests: `GetGuardrail` on the guardrail its path names,
`PutResourcePolicy`, `GetResourcePolicy` and `DeleteResourcePolicy` on the ARN the request
names, and `TagResource`, `UntagResource` and `ListTagsForResource` on the guardrail or
application inference profile ARN they carry. A `CreateGuardrail` or `CreateInferenceProfile`
carrying tags also needs `bedrock:TagResource`, with `aws:RequestTag` and `aws:TagKeys` taken
from those tags. The tables do not read the model an `InvokeModel` or
`InvokeModelWithResponseStream` request names, so those two are checked on the account's
`marketplace/model-endpoint/all-access` resource, the one type of their actions that names no
model.

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
Expand Down
30 changes: 28 additions & 2 deletions src/main/java/io/floci/aws/services/bedrock/BedrockService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.floci.aws.core.resource.ExplorerResource;
import io.floci.aws.core.resource.ResourceProvider;
import io.floci.aws.core.resource.SupportedResourceType;
import io.floci.aws.core.storage.AccountAwareStorageBackend;
import io.floci.aws.core.storage.StorageBackend;
import io.floci.aws.core.storage.StorageFactory;
import io.floci.aws.services.bedrock.model.ApplicationInferenceProfile;
Expand Down Expand Up @@ -698,12 +699,37 @@ public synchronized void untagResource(String resourceArn, List<String> tagKeys,
return;
}
Guardrail guardrail = findByArn(resourceArn, region);
if (guardrail.getTags() != null && tagKeys != null) {
tagKeys.forEach(guardrail.getTags()::remove);
Map<String, String> remaining = new HashMap<>(guardrail.getTags() != null ? guardrail.getTags() : Map.of());
if (tagKeys != null) {
tagKeys.forEach(remaining::remove);
}
guardrail.setTags(remaining);
guardrails.put(storageKey(region, guardrail.getGuardrailId(), DRAFT_VERSION), guardrail);
}

/**
* The tags of the guardrail or application inference profile whose ARN is {@code arn} in {@code account}, read in
* place under the key the tag handlers read, in the ARN's Region, and matched on the whole ARN it records; none
* when there is no such resource. Tag calls give the resource a new map, so the read is of one whole set.
*/
Map<String, String> tagsInAccount(String account, String arn) {
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
String resource = parsed.resource();
Optional<Map<String, String>> tags = Optional.empty();
if (resource.startsWith(GUARDRAIL_RESOURCE_PREFIX)) {
tags = AccountAwareStorageBackend.readInAccount(guardrails, account,
storageKey(parsed.region(), resource.substring(GUARDRAIL_RESOURCE_PREFIX.length()), DRAFT_VERSION))
.filter(guardrail -> arn.equals(guardrail.getGuardrailArn())).map(Guardrail::getTags);
} else if (resource.startsWith(APPLICATION_INFERENCE_PROFILE_PREFIX)) {
tags = AccountAwareStorageBackend.readInAccount(applicationInferenceProfiles, account,
applicationProfileKey(parsed.region(),
resource.substring(APPLICATION_INFERENCE_PROFILE_PREFIX.length())))
.filter(profile -> arn.equals(profile.getInferenceProfileArn()))
.map(ApplicationInferenceProfile::getTags);
}
return tags.orElse(Map.of());
}

// Resource discovery (Resource Groups Tagging API, Resource Explorer)

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.floci.aws.services.bedrock;

import io.floci.aws.core.common.AwsArnUtils;
import io.floci.aws.core.common.RegionResolver;
import io.floci.aws.core.common.StoredResourceArns;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
* IAM's lookup of the tags Amazon Bedrock holds on a guardrail or an application inference profile, for the
* {@code bedrock} namespace.
*/
@ApplicationScoped
public class BedrockStoredResourceArns implements StoredResourceArns {

private static final String NAMESPACE = "bedrock";

private final BedrockService bedrock;
private final RegionResolver regionResolver;

@Inject
public BedrockStoredResourceArns(BedrockService bedrock, RegionResolver regionResolver) {
this.bedrock = bedrock;
this.regionResolver = regionResolver;
}

@Override
public String namespace() {
return NAMESPACE;
}

/** A request names what it acts on by its id or its ARN: nothing to find. */
@Override
public Optional<String> find(String type, List<String> names, String region) {
return Optional.empty();
}

/**
* The tags of the guardrail or application inference profile whose ARN is {@code arn}, in the request's account,
* where the tag handlers read: an ARN of another account names none, and neither does one of a type Floci holds
* no tags on. The resource is read in place and matched on the whole ARN it records.
*/
@Override
public Map<String, String> storedTags(String arn) {
if (!AwsArnUtils.isArnFor(arn, NAMESPACE)) {
return Map.of();
}
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
String account = regionResolver.getAccountId();
if (!parsed.accountId().equals(account) || parsed.region().isBlank()) {
return Map.of();
}
return StoredResourceArns.withEmptyValues(bedrock.tagsInAccount(account, arn));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ApplicationInferenceProfile {
private List<String> models;
private Instant createdAt;
private Instant updatedAt;
private Map<String, String> tags;
private volatile Map<String, String> tags;
private String accountId;
private String region;
private String clientRequestToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Guardrail {
private String kmsKeyArn;
private Instant createdAt;
private Instant updatedAt;
private Map<String, String> tags;
private volatile Map<String, String> tags;
private String accountId;
private String resourcePolicy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,6 @@ boolean matches(String scope, String requestMethod, String path, ContainerReques
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
Expand Down
22 changes: 0 additions & 22 deletions src/main/java/io/floci/aws/services/iam/ResourceArnBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ 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";

private final ObjectMapper objectMapper;
/**
Expand Down Expand Up @@ -151,12 +149,10 @@ public List<String> buildResources(String credentialScope, String operation, Con
if (operation != null && operation.startsWith(credentialScope + ":") && RequestResources.reads(operation)) {
return namedResources(credentialScope, operation, ctx, region, accountId, partition);
}
String path = IamActionRegistry.decodedPath(ctx);
return switch (credentialScope) {
case "dynamodb" -> buildDynamoDbArns(ctx, region, accountId);
case "iam" -> buildIamArns(ctx, region, accountId);
case "apigateway" -> List.of(buildApiGatewayArn(ctx, region, partition));
case "bedrock" -> List.of(buildBedrockArn(path, ctx));
default -> namedResources(credentialScope, operation, ctx, region, accountId, partition);
};
}
Expand Down Expand Up @@ -838,24 +834,6 @@ private static String pathSegment(String raw) {
}
}

// ── 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 : "*";
}

// ── DynamoDB ─────────────────────────────────────────────────────────────────
private String buildDynamoDbArn(ContainerRequestContext ctx, String region, String accountId) {
List<String> arns = buildDynamoDbArns(ctx, region, accountId);
Expand Down
68 changes: 68 additions & 0 deletions src/main/resources/aws/iam-authorized-actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,74 @@
],
"account": [],
"apigateway": [],
"bedrock": [
"AgenticRetrieveStream",
"AssociateThirdPartyKnowledgeBase",
"CallWithBearerToken",
"CheckIngestedDocumentAcl",
"CreateAgent",
"CreateAutomatedReasoningPolicy",
"CreateBlueprint",
"CreateCustomModel",
"CreateDataAutomationLibrary",
"CreateDataSourceToken",
"CreateFlow",
"CreateFoundationModelAgreement",
"CreateKnowledgeBase",
"CreateMarketplaceModelEndpoint",
"CreateModelImportJob",
"CreatePrompt",
"CreateRetrievalInstruction",
"CreateSession",
"DeleteEnforcedGuardrailConfiguration",
"DeleteFoundationModelAgreement",
"DeleteMarketplaceModelAgreement",
"DeleteModelInvocationLoggingConfiguration",
"GenerateQuery",
"GetAccountDataRetention",
"GetBlueprintRecommendation",
"GetDataSourceAuthorizationUrl",
"GetDocumentContent",
"GetFoundationModelAvailability",
"GetIngestedDocumentAcl",
"GetModelInvocationLoggingConfiguration",
"GetUseCaseForModelAccess",
"InvokeBuilder",
"InvokeGuardrailChecks",
"InvokeInlineAgent",
"ListAdvancedPromptOptimizationJobs",
"ListAgents",
"ListAsyncInvokes",
"ListCustomModelDeployments",
"ListCustomModels",
"ListEnforcedGuardrailsConfiguration",
"ListEvaluationJobs",
"ListFlows",
"ListFoundationModelAgreementOffers",
"ListFoundationModels",
"ListImportedModels",
"ListInferenceProfiles",
"ListKnowledgeBases",
"ListMarketplaceModelEndpoints",
"ListModelCopyJobs",
"ListModelCustomizationJobs",
"ListModelEvaluationJobs",
"ListModelImportJobs",
"ListModelInvocationJobs",
"ListPromptRouters",
"ListProvisionedModelThroughputs",
"ListRetrievalInstructions",
"ListSessions",
"OptimizePrompt",
"PutAccountDataRetention",
"PutEnforcedGuardrailConfiguration",
"PutFoundationModelEntitlement",
"PutModelInvocationLoggingConfiguration",
"PutUseCaseForModelAccess",
"Rerank",
"RetrieveAndGenerate",
"ValidateFlowDefinition"
],
"cloudfront": [
"CreateAnycastIpList",
"CreateCachePolicy",
Expand Down
Loading
Loading