fix(iam): check EventBridge Pipes requests on the pipes they name, from the generated table (#9000)

Pipes was built by hand: ResourceArnBuilder read a pipe's name from its
path or a tagging route's ARN, IamEnforcementFilter sent Pipes requests
there without their operation, the request resources table held no Pipes
operation, and nothing gave a policy condition a pipe's tags. pipes
moves from HAND_BUILT to NAMESPACES, so the table gives each operation
the pipe its path's Name names, or the ARN a tagging route carries, from
botocore's REST model, and ResourceArnBuilder's Pipes branch and the
filter's Pipes case go. Only Pipes' operations change in the table.
PipesStoredResourceArns answers a pipe's stored tags; TagResource and
UntagResource give the pipe a new map one call at a time, and its tags
field is volatile.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-19 12:17:15 -04:00
1 parent d8a638e4af
commit 56d8b9aedc
12 files changed
+168 -55

No files matched your search

@@ -1803,7 +1803,7 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
/**
* Logs, Secrets Manager and KMS targets depend on the serving operation and the request's partition, STS
* targets on the serving operation;
* Pipes and DSQL targets on the request's partition, which those services mint their ARNs in, as are
* DSQL targets on the request's partition, which that service mints its ARNs in, as are
* API Gateway's path ARNs; and the
* targets of a namespace the table of request resources reads on {@code operation}, the one the request is
* dispatched as (see {@link RequestResources}).
@@ -1819,7 +1819,7 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
if ("sts".equals(credentialScope)) {
return arnBuilder.buildStsResources(action, ctx);
}
if ("pipes".equals(credentialScope) || "dsql".equals(credentialScope) || "apigateway".equals(credentialScope)) {
if ("dsql".equals(credentialScope) || "apigateway".equals(credentialScope)) {
return arnBuilder.buildResources(credentialScope, ctx, region, accountId, requestPartition());
}
// ARNs the table renders take the request's partition, which a Region Floci does not know cannot be mapped to.
@@ -59,9 +59,10 @@ import java.util.Optional;
* of a landing zone or an enabled control; GuardDuty, for the tags of a detector or a Malware Protection plan; Cloud
* Map, for the tags of a namespace or a service; Elastic Load Balancing, for the tags of a load balancer, a target
* group, a listener, a rule or a Classic Load Balancer; SQS, for the tags of a queue; SNS, for the tags of a topic;
* Kinesis Data Streams, for the tags of a stream or a consumer); looked up lazily by {@code ResourceArnBuilder} and
* {@code IamConditionContextResolver} through {@code Instance<StoredResourceArns>} for the namespace a request or an
* ARN is of, so IAM never depends on that service directly.</p>
* Kinesis Data Streams, for the tags of a stream or a consumer; EventBridge Pipes, for the tags of a pipe); looked up
* lazily by {@code ResourceArnBuilder} and {@code IamConditionContextResolver} through
* {@code Instance<StoredResourceArns>} for the namespace a request or an ARN is of, so IAM never depends on that
* service directly.</p>
*
* <p>Each answer is a lookup of what the service holds, asked for by an entry of the generated table ({@code find},
* {@code through}, a default, {@code forwarded}, a type's {@code resourceTagKeys}): never a fact about what an operation acts on, which the table alone
@@ -159,9 +159,9 @@ public class ResourceArnBuilder {
}
/**
* The resources a request is checked against. Pipes and DSQL ARNs are minted in
* {@code partition}, the request's, as those services mint theirs, so a Region no partition publishes gets
* the deployment's partition rather than {@code aws}.
* The resources a request is checked against. DSQL ARNs are minted in {@code partition}, the request's, as
* that service mints its own, so a Region no partition publishes gets the deployment's partition rather than
* {@code aws}.
*/
public List<String> buildResources(String credentialScope, ContainerRequestContext ctx,
String region, String accountId, String partition) {
@@ -188,7 +188,6 @@ public class ResourceArnBuilder {
case "dynamodb" -> buildDynamoDbArns(ctx, region, accountId);
case "iam" -> buildIamArns(ctx, region, accountId);
case "resource-groups" -> List.of(buildResourceGroupArn(ctx, region, accountId));
case "pipes" -> List.of(buildPipesArn(path, ctx, region, accountId, partition));
case "dsql" -> List.of(buildDsqlArn(path, ctx, region, accountId, partition));
case "eks" -> List.of(buildEksArn(path, ctx, region, accountId));
case "apigateway" -> List.of(buildApiGatewayArn(ctx, region, partition));
@@ -958,16 +957,6 @@ public class ResourceArnBuilder {
return taggedResource(ctx);
}
/** The resource of an EventBridge Pipes route: {@code pipe/<name>}, or the ARN a tagging route names. */
private String buildPipesArn(String path, ContainerRequestContext ctx, String region, String accountId,
String partition) {
String pipe = segmentAfterPrefix(path, "/v1/pipes/");
if (pipe != null) {
return new AwsArnUtils.Arn(partition, "pipes", region, accountId, "pipe/" + pipe).toString();
}
return taggedResource(ctx);
}
/**
* API Gateway authorizes a management call as its HTTP method on the path it names, in the Region serving
* it and with no account: {@code GET /restapis/abc/stages} acts on
@@ -25,6 +25,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
@@ -301,27 +302,43 @@ public class PipesService implements TagHandler, ResourceProvider {
return "pipes";
}
/**
* Gives the pipe a new map holding its tags and {@code tags}. Tag calls run one at a time, so two of them never
* lose one's tags, and a lookup reads one whole set.
*/
@Override
public void tagResource(String region, String arn, Map<String, String> tags) {
public synchronized void tagResource(String region, String arn, Map<String, String> tags) {
Pipe pipe = findByArn(arn, region);
if (pipe.getTags() == null) {
pipe.setTags(new HashMap<>());
}
pipe.getTags().putAll(tags);
Map<String, String> merged = new HashMap<>(pipe.getTags() != null ? pipe.getTags() : Map.of());
merged.putAll(tags);
pipe.setTags(merged);
String key = region + "::" + pipe.getName();
storage.put(key, pipe);
}
/** Gives the pipe a new map without {@code tagKeys}, one tag call at a time, as {@link #tagResource}. */
@Override
public void untagResource(String region, String arn, List<String> tagKeys) {
public synchronized void untagResource(String region, String arn, List<String> tagKeys) {
Pipe pipe = findByArn(arn, region);
if (pipe.getTags() != null && tagKeys != null) {
tagKeys.forEach(pipe.getTags()::remove);
Map<String, String> remaining = new HashMap<>(pipe.getTags());
tagKeys.forEach(remaining::remove);
pipe.setTags(remaining);
}
String key = region + "::" + pipe.getName();
storage.put(key, pipe);
}
/**
* The tags of the pipe whose ARN is {@code arn} in {@code account}, read in place under the key the handlers read,
* its name in the ARN's Region, and matched on the whole ARN it records; none when there is no such pipe.
*/
Map<String, String> pipeTagsInAccount(String account, String arn, String name) {
return AccountAwareStorageBackend.readInAccount(storage, account, AwsArnUtils.parse(arn).region() + "::" + name)
.filter(pipe -> arn.equals(pipe.getArn()))
.map(Pipe::getTags).filter(Objects::nonNull).orElse(Map.of());
}
@Override
public Map<String, String> listTags(String region, String arn) {
Pipe pipe = findByArn(arn, region);
@@ -0,0 +1,59 @@
package io.floci.aws.services.pipes;
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 EventBridge Pipes holds on a pipe, for the {@code pipes} namespace. */
@ApplicationScoped
public class PipesStoredResourceArns implements StoredResourceArns {
private static final String NAMESPACE = "pipes";
private static final String PIPE = "pipe/";
private final PipesService pipes;
private final RegionResolver regionResolver;
@Inject
public PipesStoredResourceArns(PipesService pipes, RegionResolver regionResolver) {
this.pipes = pipes;
this.regionResolver = regionResolver;
}
@Override
public String namespace() {
return NAMESPACE;
}
/** A request names a pipe by the name in its path, or by its ARN: nothing to find. */
@Override
public Optional<String> find(String type, List<String> names, String region) {
return Optional.empty();
}
/**
* The tags of the pipe whose ARN is {@code arn}, in the request's account, where the tag handlers read: an ARN of
* another account names none. The pipe is read in place by the name its ARN ends in, in the ARN's Region, and
* matched on the whole ARN it records. A tag without a value reads as an empty one. Tag calls give the pipe a new
* map, so the read is of one whole set.
*/
@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.resource().startsWith(PIPE)) {
return Map.of();
}
return StoredResourceArns.withEmptyValues(
pipes.pipeTagsInAccount(account, arn, parsed.resource().substring(PIPE.length())));
}
}
@@ -53,7 +53,7 @@ public class Pipe {
private JsonNode enrichmentParameters;
@JsonProperty("Tags")
private Map<String, String> tags;
private volatile Map<String, String> tags;
@JsonProperty("CreationTime")
@JsonFormat(shape = JsonFormat.Shape.NUMBER)