fix(iam): read every Query list and map off the indices the request numbers (#7547)

The Query protocol numbers a list's members rather than ordering them, and the constraint walk
reads every index a request names. The handler read a run from 1 that stopped at the first gap, so
the two halves disagreed about what a request carried: a request numbering tags 1 and 3 was held to
both tags and then stored the first alone, and a simulator whose first action is numbered 2 answered
`At least one ActionNames member is required.` for a list that had a member in it.

Every list and map `IamQueryHandler` reads now goes through `AwsQueryLists.members`, the same call
with the same arguments the constraints read them with: tags and tag keys with the count each is
held to, the two generic value readers, which had the same body once both read indices and are one
reader now, the context entries at both of their levels, and the `Properties` map of
`PutAccountProperties`. The last site was the reader a delegation request's policy parameters had to
themselves, which read its indices but only in the generic spelling: those parameters take the bare
form with it, and the handler reads a list in one place rather than three.

A member numbered only under a deeper key carries no value of its own and is no member of a list of
values, and a tag or a property numbered with a value and no key is nothing a map could hold, so
neither is counted nor stored.

The tags a create is authorized with are read the same way. `TagOnCreate` says how each Query
handler numbers a create's tag list, so the policy is checked with the tags the resource will get,
and it had IAM reading `Tags.member` to the first gap, as this handler did. On its own this change
would have left the authorizer reading a different list than the one stored: a tag numbered only at
2 met no policy requiring it, the model saying the handler applies none, and tags split across the
two spellings were a set each, where a deny naming both keys matched neither.

IAM reads there by the rule the handler reads by, rather than by a copy of it: the member comes from
the generated tag-on-create table and the spellings from `AwsQueryLists.memberKeys`, so no spelling
is written twice and a later change to that rule moves both sides at once. The handlers that number
a list their own way keep their own readings, untouched.

Seventeen wire tests over four classes, one for each reader, one for each spelling it missed, and
three holding the authorization. The provider one deletes what it creates: the emulator is shared
between test classes, so the next class to list providers unscoped would read it. Fifteen of them fail against the readings this replaces. The
reading is recorded in `docs/services/iam.md`, in the list section and beside the account properties
map.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-04 17:10:00 -06:00
1 parent 09132855a6
commit 4abccec0c8
7 files changed
+558 -86

No files matched your search

@@ -146,6 +146,71 @@ class AccountPropertiesIntegrationTest {
.when().post("/").then().statusCode(200);
}
/**
* The protocol numbers a map's entries, it does not run them from 1 without a gap, and the
* constraints read every index the request carries. So a request numbering 1 and 3 is held to
* both entries and has to store both: stopping at the gap held a caller to an entry it was
* then not given.
*/
@Test
void entriesTheRequestNumbersWithAGapAreAllStored() {
String ns = namespace();
iam("PutAccountProperties")
.formParam("Properties.entry.1.key", ns + "/First")
.formParam("Properties.entry.1.value", "one")
.formParam("Properties.entry.3.key", ns + "/Third")
.formParam("Properties.entry.3.value", "three")
.when().post("/").then().statusCode(200);
iam("GetAccountProperties").when().post("/").then().statusCode(200)
.body(containsString(ns + "/First"))
.body(containsString("one"))
.body(containsString(ns + "/Third"))
.body(containsString("three"));
}
/**
* The bare {@code Properties.N} spelling, which the shared reader takes alongside
* {@code Properties.entry.N} and {@code Properties.member.N}. The constraints read it, so a
* request sending it carries a map: reading only the one spelling left it an empty map and the
* refusal for a member that never arrived.
*/
@Test
void theBareAndMemberSpellingsOfAnEntryAreRead() {
String bare = namespace();
iam("PutAccountProperties")
.formParam("Properties.1.key", bare + "/Bare")
.formParam("Properties.1.value", "read")
.when().post("/").then().statusCode(200);
String member = namespace();
iam("PutAccountProperties")
.formParam("Properties.member.1.key", member + "/Member")
.formParam("Properties.member.1.value", "read")
.when().post("/").then().statusCode(200);
iam("GetAccountProperties").when().post("/").then().statusCode(200)
.body(containsString(bare + "/Bare"))
.body(containsString(member + "/Member"));
}
/**
* An entry numbered with a value and no key, which is no entry the map could hold: the
* constraint walk neither counts nor answers it, and nothing is stored under a null key. The
* request carries that one entry alone, so what is left is an empty map.
*/
@Test
void anEntryNumberedWithNoKeyIsNoEntry() {
iam("PutAccountProperties")
.formParam("Properties.entry.1.value", "orphan")
.when().post("/").then().statusCode(400)
.body(containsString("ValidationError"))
.body(containsString("Member must not be null"));
}
@Test
void anAbsentPropertiesMapIsRejected() {
iam("PutAccountProperties").when().post("/").then().statusCode(400)
@@ -383,6 +383,34 @@ class DelegationRequestIntegrationTest {
equalTo("reports"));
}
@Test
void aPolicyParameterListSentBareKeepsItsEntries() {
// The bare List.N spelling, which the constraints ahead of this operation read alongside
// the generic one: reading only the generic form left the parameters it carried unread.
String id = iam(PARTNER_AUTH)
.formParam("Action", "CreateDelegationRequest")
.formParam("Description", "d")
.formParam("NotificationChannel", TOPIC)
.formParam("RequestorWorkflowId", workflowId())
.formParam("SessionDuration", "3600")
.formParam("Permissions.PolicyTemplateArn", TEMPLATE)
.formParam("Permissions.Parameters.2.Name", "BucketName")
.formParam("Permissions.Parameters.2.Type", "string")
.formParam("Permissions.Parameters.2.Values.4", "reports")
.when().post("/").then().statusCode(200)
.extract().path("CreateDelegationRequestResponse.CreateDelegationRequestResult"
+ ".DelegationRequestId");
byId(PARTNER_AUTH, "GetDelegationRequest", id)
.statusCode(200)
.body("GetDelegationRequestResponse.GetDelegationRequestResult"
+ ".DelegationRequest.Permissions.Parameters.member.Name",
equalTo("BucketName"))
.body("GetDelegationRequestResponse.GetDelegationRequestResult"
+ ".DelegationRequest.Permissions.Parameters.member.Values.member",
equalTo("reports"));
}
@Test
void theCustomerReleasesTheTokenAndTheRequestFinalizes() {
String id = createdId();
@@ -0,0 +1,258 @@
package io.github.hectorvent.floci.services.iam;
import io.github.hectorvent.floci.testing.PartitionCleanup;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.not;
/**
* Every list these operations read is read off the indices the request numbers its members with,
* not off a run from 1 that stops at the first gap. The Query protocol numbers a list's members,
* and the constraints ahead of each operation read every index the request names, so a request
* numbering 1 and 3 was held to both members and then given one. The bare {@code List.N} spelling
* the constraints read is read here too.
*/
@QuarkusTest
class IamQueryListIndicesIntegrationTest {
private static final String IAM_AUTH =
"AWS4-HMAC-SHA256 Credential=test/20261103/us-east-1/iam/aws4_request";
private static final String CODE = "ErrorResponse.Error.Code";
private static final String MESSAGE = "ErrorResponse.Error.Message";
private static final String TAGS = "ListUserTagsResponse.ListUserTagsResult.Tags.member.Key";
/** 40 characters, the only length `thumbprintType` accepts. */
private static final String THUMBPRINT = "9e99a48a9960b14926bb7f3b02e22da2b0ab7280";
private static final String OTHER_THUMBPRINT = "a1b2c3d4e5f60718293a4b5c6d7e8f9012345678";
private static final String ALLOW_GET_OBJECT =
"{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","
+ "\"Action\":\"s3:GetObject\",\"Resource\":\"*\"}]}";
/** The provider below outlives this class otherwise, and the next class to list providers reads it. */
@RegisterExtension
final PartitionCleanup cleanup = new PartitionCleanup();
private static RequestSpecification iam(String action) {
return given().header("Authorization", IAM_AUTH).formParam("Action", action);
}
private static String unique(String prefix) {
return prefix + "-" + System.nanoTime();
}
private static String createUser(String prefix) {
String name = unique(prefix);
iam("CreateUser").formParam("UserName", name).when().post("/").then().statusCode(200);
return name;
}
private static RequestSpecification listTags(String user) {
return iam("ListUserTags").formParam("UserName", user);
}
/**
* A request numbering tags 1 and 3 carries two tags: the constraints hold it to both, so
* storing the first alone left the caller a tag short of what it was answered for.
*/
@Test
void tagsTheRequestNumbersWithAGapAreAllStored() {
String user = createUser("gap-tags");
iam("TagUser").formParam("UserName", user)
.formParam("Tags.member.1.Key", "team").formParam("Tags.member.1.Value", "platform")
.formParam("Tags.member.3.Key", "owner").formParam("Tags.member.3.Value", "ops")
.when().post("/").then().statusCode(200);
listTags(user).when().post("/").then().statusCode(200)
.body(TAGS, hasItems("team", "owner"));
}
/**
* A tag numbered with a value and no key never reaches the operation: {@code Key} is required, so the
* constraints ahead of it answer under the index the request spelled, and nothing is attached. The skip
* inside the reader sits behind that gate, for a member the model requires nothing of.
*/
@Test
void aTagNumberedWithAValueAndNoKeyIsRefusedBeforeTheOperation() {
String user = createUser("no-key-tags");
iam("TagUser").formParam("UserName", user)
.formParam("Tags.member.1.Value", "blue")
.when().post("/").then().statusCode(400)
.body(CODE, equalTo("ValidationError"))
.body(MESSAGE, containsString("Value at 'tags.1.member.key' failed to satisfy constraint: "
+ "Member must not be null"));
listTags(user).when().post("/").then().statusCode(200)
.body(not(containsString("blue")));
}
/** The duplicate check reads every tag the request carries, so a repeat past a gap is one. */
@Test
void aDuplicateTagKeyPastAGapIsStillRefused() {
String user = createUser("gap-dup-tags");
iam("TagUser").formParam("UserName", user)
.formParam("Tags.member.1.Key", "team").formParam("Tags.member.1.Value", "platform")
.formParam("Tags.member.3.Key", "Team").formParam("Tags.member.3.Value", "payments")
.when().post("/").then().statusCode(400)
.body(CODE, equalTo("InvalidInput"))
.body(MESSAGE, equalTo("Duplicate tag keys found. Please note that Tag keys are case insensitive."));
listTags(user).when().post("/").then().statusCode(200)
.body(not(containsString("platform")));
}
/** The bare spelling of a tag, which the constraints read and the operation now reads with them. */
@Test
void theBareSpellingOfATagIsRead() {
String user = createUser("bare-tags");
iam("TagUser").formParam("UserName", user)
.formParam("Tags.1.Key", "bare").formParam("Tags.1.Value", "read")
.when().post("/").then().statusCode(200);
listTags(user).when().post("/").then().statusCode(200)
.body(TAGS, equalTo("bare"));
}
/** The keys an untag request numbers, where dropping the second left its tag behind. */
@Test
void tagKeysTheRequestNumbersWithAGapAreAllRemoved() {
String user = createUser("gap-untag");
iam("TagUser").formParam("UserName", user)
.formParam("Tags.member.1.Key", "team").formParam("Tags.member.1.Value", "platform")
.formParam("Tags.member.2.Key", "owner").formParam("Tags.member.2.Value", "ops")
.when().post("/").then().statusCode(200);
iam("UntagUser").formParam("UserName", user)
.formParam("TagKeys.member.1", "team")
.formParam("TagKeys.member.3", "owner")
.when().post("/").then().statusCode(200);
listTags(user).when().post("/").then().statusCode(200)
.body(not(containsString("team")))
.body(not(containsString("owner")));
}
/**
* A key past a gap is held to `tagKeyType`, where it used to be dropped unchecked and the
* request went on to remove the keys ahead of it.
*/
@Test
void aTagKeyPastAGapIsHeldToItsConstraints() {
String user = createUser("gap-untag-bad");
iam("TagUser").formParam("UserName", user)
.formParam("Tags.member.1.Key", "team").formParam("Tags.member.1.Value", "platform")
.when().post("/").then().statusCode(200);
iam("UntagUser").formParam("UserName", user)
.formParam("TagKeys.member.1", "team")
.formParam("TagKeys.member.3", "cost#center")
.when().post("/").then().statusCode(400)
.body(CODE, equalTo("ValidationError"))
.body(MESSAGE, containsString("Value at 'tagKeys' failed to satisfy constraint"));
listTags(user).when().post("/").then().statusCode(200)
.body(TAGS, equalTo("team"));
}
/** `tagKeyListType` binds the keys as sent, so a fifty-first key numbered past a gap is one. */
@Test
void theTagKeyCountIsTakenOverTheIndicesTheRequestNumbers() {
String user = createUser("gap-untag-count");
RequestSpecification request = iam("UntagUser").formParam("UserName", user);
for (int i = 1; i <= 50; i++) {
request.formParam("TagKeys.member." + i, "key" + i);
}
request.formParam("TagKeys.member.52", "key52")
.when().post("/").then().statusCode(400)
.body(CODE, equalTo("ValidationError"))
.body(MESSAGE, containsString("Value at 'tagKeys' failed to satisfy constraint: "
+ "Member must have length less than or equal to 50"));
}
/**
* A provider's thumbprints and client IDs, the generic spelling numbered with a gap and the
* bare one beside it: both lists reach the store with every member the request carried.
*/
@Test
void aProvidersThumbprintsAndClientIdsAreReadOffTheirIndices() {
String arn = iam("CreateOpenIDConnectProvider")
.formParam("Url", "https://oidc.query-indices.example.com/" + unique("provider"))
.formParam("ThumbprintList.member.1", THUMBPRINT)
.formParam("ThumbprintList.member.3", OTHER_THUMBPRINT)
.formParam("ClientIDList.2", "sts.amazonaws.com")
.when().post("/").then().statusCode(200)
.extract().xmlPath().getString(
"CreateOpenIDConnectProviderResponse.CreateOpenIDConnectProviderResult.OpenIDConnectProviderArn");
cleanup.register(() -> iam("DeleteOpenIDConnectProvider")
.formParam("OpenIDConnectProviderArn", arn).when().post("/").then().statusCode(200));
iam("GetOpenIDConnectProvider").formParam("OpenIDConnectProviderArn", arn)
.when().post("/").then().statusCode(200)
.body("GetOpenIDConnectProviderResponse.GetOpenIDConnectProviderResult.ThumbprintList.member",
hasItems(THUMBPRINT, OTHER_THUMBPRINT))
.body("GetOpenIDConnectProviderResponse.GetOpenIDConnectProviderResult.ClientIDList.member",
equalTo("sts.amazonaws.com"));
}
/**
* A simulation evaluates every action the request numbers, and reads its documents off the
* bare spelling too. A list whose first member is numbered 2 is a list with a member, where
* reading from 1 answered it as the list that never arrived.
*/
@Test
void everyActionTheRequestNumbersIsSimulated() {
iam("SimulateCustomPolicy")
.formParam("PolicyInputList.1", ALLOW_GET_OBJECT)
.formParam("ActionNames.member.2", "s3:GetObject")
.formParam("ActionNames.member.4", "ec2:RunInstances")
.formParam("ResourceArns.member.1", "*")
.when().post("/").then().statusCode(200)
.body("SimulateCustomPolicyResponse.SimulateCustomPolicyResult.EvaluationResults"
+ ".member.find { it.EvalActionName == 's3:GetObject' }.EvalDecision",
equalTo("allowed"))
.body("SimulateCustomPolicyResponse.SimulateCustomPolicyResult.EvaluationResults"
+ ".member.find { it.EvalActionName == 'ec2:RunInstances' }.EvalDecision",
equalTo("implicitDeny"));
}
/**
* A context entry numbered past a gap, with its own values numbered past gaps of their own.
* Dropping the entry dropped its key and every value with it, and a set operator over a key
* the request did supply then decided on a context it never saw.
*/
@Test
void aContextEntryPastAGapIsReadWithEveryValueItCarries() {
String policy = """
{"Version":"2012-10-17","Statement":[
{"Effect":"Allow","Action":"dynamodb:GetItem","Resource":"*",
"Condition":{"ForAnyValue:StringEquals":{"dynamodb:LeadingKeys":["USER_alice"]}}}
]}""";
iam("SimulateCustomPolicy")
.formParam("PolicyInputList.member.1", policy)
.formParam("ActionNames.member.1", "dynamodb:GetItem")
.formParam("ResourceArns.member.1", "*")
.formParam("ContextEntries.member.3.ContextKeyName", "dynamodb:LeadingKeys")
.formParam("ContextEntries.member.3.ContextKeyValues.member.2", "USER_bob")
.formParam("ContextEntries.member.3.ContextKeyValues.member.4", "USER_alice")
.when().post("/").then().statusCode(200)
.body("SimulateCustomPolicyResponse.SimulateCustomPolicyResult.EvaluationResults"
+ ".member.EvalDecision", equalTo("allowed"));
}
}
@@ -41,6 +41,8 @@ class IamTagOnCreateEnforcementIntegrationTest {
private static final String ADMIN = "test";
private static final String ACCOUNT = "000000000000";
private static final String IMAGE = "ami-0abcdef1234567890";
private static final String TRUST = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","
+ "\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}";
private static final ObjectMapper CBOR_MAPPER = new ObjectMapper(new CBORFactory());
@TestHTTPResource("/")
@@ -260,19 +262,74 @@ class IamTagOnCreateEnforcementIntegrationTest {
void aRoleCreatedWithTagsNeedsTagRole() {
User user = user("tag-role");
String role = "tag-role-" + suffix();
String trust = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","
+ "\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}";
user.policy(allow("iam:CreateRole"));
refused(user.query("iam", "CreateRole").formParam("RoleName", role).formParam("AssumeRolePolicyDocument", trust)
refused(user.query("iam", "CreateRole").formParam("RoleName", role).formParam("AssumeRolePolicyDocument", TRUST)
.formParam("Tags.member.1.Key", "team").formParam("Tags.member.1.Value", "blue").post("/").then(),
"iam:TagRole");
user.policy(allow("iam:CreateRole") + "," + allow("iam:TagRole"));
user.query("iam", "CreateRole").formParam("RoleName", role).formParam("AssumeRolePolicyDocument", trust)
user.query("iam", "CreateRole").formParam("RoleName", role).formParam("AssumeRolePolicyDocument", TRUST)
.formParam("Tags.member.1.Key", "team").formParam("Tags.member.1.Value", "blue").post("/").then()
.statusCode(200);
cleanup.register(() -> admin("iam").formParam("Action", "DeleteRole").formParam("RoleName", role).post("/"));
deleteRoleLater(role);
}
/**
* IAM's handler reads every index a request numbers, bare or under {@code member}, so the tags its create is
* checked with are the tags the role gets. A tag numbered only at 2 meets a policy that requires it, where a
* reading that stopped at the first gap saw none and refused a create the handler would have tagged.
*/
@Test
void anIamTagPastAGapMeetsAPolicyRequiringIt() {
User user = user("tag-role-gap");
String role = "tag-role-gap-" + suffix();
user.policy("{\"Effect\":\"Allow\",\"Action\":\"iam:CreateRole\",\"Resource\":\"*\","
+ "\"Condition\":{\"StringEquals\":{\"aws:RequestTag/team\":\"blue\"}}}," + allow("iam:TagRole"));
user.query("iam", "CreateRole").formParam("RoleName", role).formParam("AssumeRolePolicyDocument", TRUST)
.formParam("Tags.2.Key", "team").formParam("Tags.2.Value", "blue").post("/").then().statusCode(200);
deleteRoleLater(role);
admin("iam").formParam("Action", "ListRoleTags").formParam("RoleName", role).post("/").then()
.statusCode(200).body(containsString("team"));
}
/**
* Tags split across the two spellings are one list to the handler, so they are one set to the policy: a deny
* naming both keys holds, where a set per spelling matched neither and let the create through with both tags.
*/
@Test
void iamTagsSplitAcrossSpellingsAreCheckedAsOneSet() {
User user = user("tag-role-split");
String role = "tag-role-split-" + suffix();
user.policy(allow("iam:CreateRole") + "," + allow("iam:TagRole")
+ ",{\"Effect\":\"Deny\",\"Action\":\"iam:CreateRole\",\"Resource\":\"*\",\"Condition\":"
+ "{\"StringEquals\":{\"aws:RequestTag/team\":\"blue\",\"aws:RequestTag/env\":\"prod\"}}}");
refused(user.query("iam", "CreateRole").formParam("RoleName", role)
.formParam("AssumeRolePolicyDocument", TRUST)
.formParam("Tags.member.1.Key", "team").formParam("Tags.member.1.Value", "blue")
.formParam("Tags.2.Key", "env").formParam("Tags.2.Value", "prod").post("/").then(), "iam:CreateRole");
admin("iam").formParam("Action", "GetRole").formParam("RoleName", role).post("/").then().statusCode(404);
}
/**
* A key that is blank but not empty is a key IAM takes, {@code tagKeyType} admitting a separator, so the
* policy is checked with it: a deny naming it holds rather than passing over a key the role would get.
*/
@Test
void anIamTagKeyThatIsBlankIsReadForThePolicyToo() {
User user = user("tag-role-blank");
String role = "tag-role-blank-" + suffix();
user.policy(allow("iam:CreateRole") + "," + allow("iam:TagRole")
+ ",{\"Effect\":\"Deny\",\"Action\":\"iam:CreateRole\",\"Resource\":\"*\",\"Condition\":"
+ "{\"StringEquals\":{\"aws:RequestTag/ \":\"blue\",\"aws:RequestTag/env\":\"prod\"}}}");
refused(user.query("iam", "CreateRole").formParam("RoleName", role)
.formParam("AssumeRolePolicyDocument", TRUST)
.formParam("Tags.member.1.Key", " ").formParam("Tags.member.1.Value", "blue")
.formParam("Tags.2.Key", "env").formParam("Tags.2.Value", "prod").post("/").then(), "iam:CreateRole");
admin("iam").formParam("Action", "GetRole").formParam("RoleName", role).post("/").then().statusCode(404);
}
@Test
@@ -426,6 +483,10 @@ class IamTagOnCreateEnforcementIntegrationTest {
.formParam("InstanceId.1", instanceId).post("/"));
}
private void deleteRoleLater(String role) {
cleanup.register(() -> admin("iam").formParam("Action", "DeleteRole").formParam("RoleName", role).post("/"));
}
private void deleteQueueLater(Response created) {
String url = created.then().statusCode(200).extract().xmlPath()
.getString("CreateQueueResponse.CreateQueueResult.QueueUrl");