fix(iam): authorize an operation as the action AWS checks for it (#5604)

Under enforcement a request naming its operation, in a Query Action or an
X-Amz-Target header, was authorized as <namespace>:<Operation>, the operation's
own name. AWS authorizes some operations as an action of another name: SQS
SendMessageBatch, DeleteMessageBatch and ChangeMessageVisibilityBatch as
sqs:SendMessage, sqs:DeleteMessage and sqs:ChangeMessageVisibility, and SNS
PublishBatch as sns:Publish. None of the batch names is an IAM action, so a policy
AWS honours for a batch call was denied, and a policy naming the batch operation
granted something AWS does not check.

AWS publishes the mapping in the Operations of each Service Reference file.
tools/aws/regen_iam_authorized_actions.py vendors the operations authorized by
exactly one action of their own namespace under another name, 235 over 33
namespaces, into src/main/resources/aws/iam-authorized-actions.json. Everything else
keeps its own name. The generator leaves out operations that list:
- several actions, whose extras apply only when tags or a role are passed;
- no action, which is missing data;
- an action of another namespace;
- another action while one of the operation's own name exists;
- a tagging action alone;
- the same action for several SDK clients, which AWS can authorize differently,
  as S3 and S3 Control's GetPublicAccessBlock;
or whose name is listed again with another answer. A record of the wrong shape
fails the run instead of being skipped.
make iam-authorized-actions-check gates the file's shape on pull requests that touch it, and
iam-authorized-actions-verify, run by the IAM Data Drift workflow, checks every
entry against AWS.

IamAuthorizedActions reads the file through the new core.common
VendoredResources, rather than adding one more copy of the read-or-fail block a
dozen catalogs carry, and the Query and X-Amz-Target paths ask it for the action.
DynamoDB TransactGetItems, which AWS authorizes as dynamodb:GetItem, keeps its own
name: the transaction check recognizes the call by it and checks every Get as
dynamodb:GetItem on its own table, with its own dynamodb:LeadingKeys. Renamed, the
call would skip that check and be authorized as one GetItem whose body has no
top-level Key, which a ForAllValues condition accepts, so a fine-grained policy
would grant every key.

The check for operations AWS serves without credentials reads the Query action
directly, rather than through resolve with a placeholder scope, now that resolve
returns the authorized action. A Query request naming no action is not one of them.

An SDK compatibility test covers SendMessageBatch and PublishBatch, granted by
the single-item action and refused under the batch name, with enforcement on.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-13 22:29:06 -05:00
1 parent c6c2c609c3
commit eba058266b
15 files changed
+1618 -17

No files matched your search

@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.core.common;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.cloudtrail.CloudTrailService;
import io.github.hectorvent.floci.services.iam.IamActionRegistry;
import io.github.hectorvent.floci.services.iam.IamAuthorizedActions;
import io.github.hectorvent.floci.services.iam.IamPolicyEvaluator;
import io.github.hectorvent.floci.services.iam.IamPolicyEvaluator.Decision;
import io.github.hectorvent.floci.services.iam.IamPolicyEvaluator.ResourceAccountRelationship;
@@ -561,7 +562,8 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
String servingScope = catalog.byExternalKey(service)
.map(descriptor -> iamServiceScope(descriptor, claimedScope))
.orElseGet(() -> catalog.canonicalCredentialScope(service));
return new ResolvedAuthorization(servingScope, servingScope + ":" + queryAction);
return new ResolvedAuthorization(servingScope,
IamAuthorizedActions.actionFor(servingScope, queryAction));
}
ResolvedAuthorization routeAuthorization = restRouteAuthorization(ctx);
@@ -1403,7 +1405,8 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
/** Whether the operation this request names is one AWS serves without credentials. */
private boolean servesWithoutCredentials(ProtocolClaim claim, ContainerRequestContext ctx) {
if (claim.protocol() == WireProtocol.AWS_QUERY) {
return NO_AUTH_QUERY_OPERATIONS.contains(queryOperation(ctx));
String operation = queryOperation(ctx);
return operation != null && NO_AUTH_QUERY_OPERATIONS.contains(operation);
}
if (claim.service() == null || claim.operation() == null) {
// Nothing names the operation, so there is nothing to match against the list. Refusing
@@ -1418,12 +1421,10 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
/**
* The {@code Action} a Query request names, via the registry so the form body is read and put
* back the one way this codebase already does it. The scope passed in is a placeholder: for a
* Query request the registry returns {@code <scope>:<Action>} and only the suffix is wanted.
* back the one way this codebase already does it.
*/
private String queryOperation(ContainerRequestContext ctx) {
String resolved = actionRegistry.resolve("", ctx);
return resolved == null ? null : resolved.substring(resolved.indexOf(':') + 1);
return actionRegistry.queryAction(ctx);
}
/**
@@ -0,0 +1,34 @@
package io.github.hectorvent.floci.core.common;
import java.io.IOException;
import java.io.InputStream;
/**
* Reads a file vendored on the classpath, such as the IAM data generated from AWS's Service
* Reference. A missing or unreadable resource is a build defect, not a runtime condition, so it
* fails with {@link IllegalStateException} rather than leaving the caller to degrade to an empty
* catalog.
*/
public final class VendoredResources {
/** Reads the resource's content into what the caller keeps. */
@FunctionalInterface
public interface Parser<T> {
T parse(InputStream in) throws IOException;
}
private VendoredResources() {
}
/** The resource {@code name} as {@code parser} reads it; {@code description} names it in a failure. */
public static <T> T read(String name, String description, Parser<T> parser) {
try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(name)) {
if (in == null) {
throw new IllegalStateException(description + " resource not found: " + name);
}
return parser.parse(in);
} catch (IOException e) {
throw new IllegalStateException("Failed to read the " + description + " " + name, e);
}
}
}
@@ -251,15 +251,15 @@ public class IamActionRegistry {
if (isQueryRequest(ctx)) {
String queryAction = queryAction(ctx);
if (queryAction != null && !queryAction.isBlank()) {
return credentialScope + ":" + queryAction;
return IamAuthorizedActions.actionFor(credentialScope, queryAction);
}
}
// JSON 1.1: X-Amz-Target → service:OperationName
// JSON 1.1: X-Amz-Target → the action AWS checks for the operation it names
String target = ctx.getHeaderString("X-Amz-Target");
if (target != null && target.contains(".")) {
String operationName = target.substring(target.lastIndexOf('.') + 1);
return credentialScope + ":" + operationName;
return IamAuthorizedActions.actionFor(credentialScope, operationName);
}
return resolveRoute(credentialScope, ctx);
@@ -0,0 +1,101 @@
package io.github.hectorvent.floci.services.iam;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.VendoredResources;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
/**
* The IAM action AWS checks for an operation whose action is not the operation's own name, read once
* from the vendored {@code aws/iam-authorized-actions.json}.
*
* <p>A request that names its operation, in a Query {@code Action} or an {@code X-Amz-Target}
* header, is authorized as {@code <namespace>:<Operation>}. For most operations that is the action
* AWS checks, but not for all: SQS {@code SendMessageBatch} is
* authorized as {@code sqs:SendMessage} and SNS {@code PublishBatch} as {@code sns:Publish}, and
* neither batch name is an IAM action at all. Authorized as its own name, such a call is denied
* under a least-privilege policy AWS honours, and granted by a policy naming something AWS does not
* check.
*
* <p>The file is generated by {@code tools/aws/regen_iam_authorized_actions.py} from the
* {@code Operations} AWS's Service Reference publishes per service, which name the actions each SDK
* operation is authorized by. It carries only operations authorized by exactly one action of their
* own namespace under another name; the generator documents the shapes it leaves out and why.
* {@code make iam-authorized-actions-check} gates its shape offline and
* {@code make iam-authorized-actions-verify} checks every entry against AWS. A namespace Floci
* authorizes under a name other than the IAM namespace matches nothing here, and its operations keep
* their own names.
*
* <p>A missing or malformed resource is a build defect, not a runtime condition, so loading fails
* with {@link IllegalStateException} rather than degrading to an empty map, which would silently put
* every operation back on its own name.
*/
public final class IamAuthorizedActions {
static final String RESOURCE_NAME = "aws/iam-authorized-actions.json";
/**
* Operations kept on their own name because another check recognizes them by it. AWS authorizes
* DynamoDB {@code TransactGetItems} as {@code dynamodb:GetItem}, and Floci does too, item by
* item: the transaction check in {@code IamConditionContextResolver} picks the call out by its own
* name and checks every {@code Get} as {@code dynamodb:GetItem} on its own table, with its own
* {@code dynamodb:LeadingKeys}. Renamed here, the call would skip that check and be authorized as
* a single {@code GetItem} whose body has no top-level {@code Key}, so no
* {@code dynamodb:LeadingKeys}, which a {@code ForAllValues} condition accepts: a fine-grained
* policy would grant every key.
*/
private static final Set<String> KEPT_FOR_ITEM_CHECKS = Set.of("dynamodb:TransactGetItems");
private static final ObjectMapper MAPPER = new ObjectMapper();
private static final class Holder {
static final Map<String, String> ACTIONS = VendoredResources.read(RESOURCE_NAME,
"IAM authorized action map", IamAuthorizedActions::parse);
}
private IamAuthorizedActions() {
}
/**
* The action AWS checks for {@code operation} under {@code namespace}: the one the vendored file
* names for it, or else the operation's own name.
*/
public static String actionFor(String namespace, String operation) {
String own = namespace + ":" + operation;
if (KEPT_FOR_ITEM_CHECKS.contains(own)) {
return own;
}
return Holder.ACTIONS.getOrDefault(own, own);
}
/** The file's entries, keyed by {@code <namespace>:<Operation>}. */
static Map<String, String> parse(InputStream in) throws IOException {
JsonNode namespaces = MAPPER.readTree(in).path("authorizedActions");
if (!namespaces.isObject() || namespaces.isEmpty()) {
throw new IllegalStateException(RESOURCE_NAME + " carries no authorizedActions");
}
Map<String, String> actions = new LinkedHashMap<>();
namespaces.properties().forEach(namespace -> {
if (!namespace.getValue().isObject()) {
throw new IllegalStateException(RESOURCE_NAME + " has authorizedActions."
+ namespace.getKey() + " as something other than a map");
}
namespace.getValue().properties().forEach(operation -> {
String action = operation.getValue().asText("");
if (!action.startsWith(namespace.getKey() + ":")
|| action.length() == namespace.getKey().length() + 1) {
throw new IllegalStateException(RESOURCE_NAME + " maps " + namespace.getKey() + ":"
+ operation.getKey() + " to " + operation.getValue()
+ ", which is not an action of " + namespace.getKey());
}
actions.put(namespace.getKey() + ":" + operation.getKey(), action);
});
});
return Map.copyOf(actions);
}
}