fix(iam): authorize sts:AssumeRole against the role it names (#6334)

IAM enforcement evaluated every STS action against resource *, so a
policy allowing sts:AssumeRole on specific role ARNs never matched and
the call was denied. sts:AssumeRole is now authorized against the
request's RoleArn, as on AWS. Every other STS action stays at *: like
Logs and Secrets Manager, the resource follows the serving operation,
so a RoleArn added to a call that never reads it, such as
GetFederationToken, cannot make a role-scoped Allow grant that call.

Query-protocol parameters were only read from the URL, never from the
form body the SDKs and CLI POST, so SQS and SNS resource ARNs fell back
to a wildcard the same way. For a form POST they are now read from the
body alone: AwsQueryController dispatches on the body and never sees the
URL query, so authorizing a URL value would check one resource and act
on another. SQS preferred a QueueUrl in the URL over the body's, so it
now reads the body first as well.

A resource field with an invalid percent escape is read as absent, so
the check falls back to the default resource instead of throwing out of
the filter; the request then fails in the form reader exactly as it does
without the resource check. The RoleArn is checked untrimmed, as the
handler uses it. docs/services/sts.md no longer lists the * check as a
known limitation.

Co-authored-by: Robin Baeckman <27041454+RobinBaeckman@users.noreply.github.com>
This commit is contained in:
Robin BaeckmanandRobin Baeckman authored and GitHub committed 2026-10-24 08:55:41 -04:00
1 parent 1476b0e219
commit b4c71b9e25
6 files changed
+237 -16

No files matched your search

@@ -1505,7 +1505,8 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
}
/**
* Logs and Secrets Manager targets depend on the serving operation and the request's partition;
* Logs and Secrets Manager targets depend on the serving operation and the request's partition, STS
* targets on the serving operation;
* Scheduler and Pipes targets on the request's partition, which those services mint their ARNs in.
*/
private List<String> targetResources(String credentialScope, String action, ContainerRequestContext ctx,
@@ -1516,6 +1517,9 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
if ("secretsmanager".equals(credentialScope)) {
return arnBuilder.buildSecretsManagerResources(action, ctx, region, accountId, requestPartition());
}
if ("sts".equals(credentialScope)) {
return arnBuilder.buildStsResources(action, ctx);
}
if ("scheduler".equals(credentialScope) || "pipes".equals(credentialScope) || "dsql".equals(credentialScope)) {
return arnBuilder.buildResources(credentialScope, ctx, region, accountId, requestPartition());
}
@@ -46,16 +46,21 @@ public final class RequestBodyReader {
return body;
}
static boolean isForm(ContainerRequestContext ctx) {
MediaType mt = ctx.getMediaType();
return mt != null
&& "application".equalsIgnoreCase(mt.getType())
&& "x-www-form-urlencoded".equalsIgnoreCase(mt.getSubtype());
}
public static String formField(ContainerRequestContext ctx, String key) {
if ("GET".equalsIgnoreCase(ctx.getMethod()) && IamActionRegistry.isQueryRequest(ctx)) {
return ctx.getUriInfo().getQueryParameters().getFirst(key);
}
MediaType mt = ctx.getMediaType();
if (mt == null
|| !"application".equalsIgnoreCase(mt.getType())
|| !"x-www-form-urlencoded".equalsIgnoreCase(mt.getSubtype())) {
if (!isForm(ctx)) {
return null;
}
MediaType mt = ctx.getMediaType();
byte[] body = buffer(ctx);
if (body.length == 0) {
return null;
@@ -1243,11 +1243,7 @@ public class ResourceArnBuilder {
// ── SQS ─────────────────────────────────────────────────────────────────────
private String buildSqsArn(ContainerRequestContext ctx, String region, String accountId) {
String queueUrl = ctx.getUriInfo().getQueryParameters().getFirst("QueueUrl");
if (queueUrl == null) {
// Try form param for Query-protocol
queueUrl = firstFormParam(ctx, "QueueUrl");
}
String queueUrl = firstFormParam(ctx, "QueueUrl");
if (queueUrl == null) {
JsonNode json = readJsonBody(ctx);
if (json != null && json.isObject()) {
@@ -1586,9 +1582,37 @@ public class ResourceArnBuilder {
return slash > 0 ? after.substring(0, slash) : after;
}
// ── STS ─────────────────────────────────────────────────────────────────────
/**
* Uses the serving operation, as {@link #buildLogResources} does: {@code AssumeRole} is
* authorized against the role it names, so a policy can allow assuming one role and not another.
* Every other operation keeps {@code *}, so a {@code RoleArn} it never reads cannot choose its resource.
*/
public List<String> buildStsResources(String action, ContainerRequestContext ctx) {
return List.of("sts:AssumeRole".equals(action) ? buildAssumeRoleArn(ctx) : "*");
}
private String buildAssumeRoleArn(ContainerRequestContext ctx) {
String roleArn = firstFormParam(ctx, "RoleArn");
// Untrimmed: the handler assumes the role named by this exact string.
return roleArn == null || roleArn.isBlank() ? "*" : roleArn;
}
/**
* A Query-protocol parameter, read from the same place the handler reads it. For a form POST
* that is the body alone: {@code AwsQueryController} dispatches on the form parameters and never
* sees the URL query, so authorizing a URL value would check one resource and act on another.
* A value with an invalid percent escape is read as absent, so the resource stays the default
* and the request goes on to be answered as it is without enforcement.
*/
private String firstFormParam(ContainerRequestContext ctx, String name) {
// Form params are typically available as query params in REST-Assured / JAX-RS
String v = ctx.getUriInfo().getQueryParameters().getFirst(name);
return v;
if (RequestBodyReader.isForm(ctx)) {
try {
return RequestBodyReader.formField(ctx, name);
} catch (IllegalArgumentException malformed) {
return null;
}
}
return ctx.getUriInfo().getQueryParameters().getFirst(name);
}
}