fix(iam): refuse an account property namespace AWS does not recognise (#9307)

PutAccountProperties stored a property under any namespace whose key satisfied
the Namespace/PropertyName rule, where AWS answers InvalidInput 400 with
"Unsupported namespace: <namespace>", recorded against a real account on
2026-10-25 for a key naming an invented namespace. Accepting it was the worse
of the two ways to be wrong: one bad write left the account answering every
later GetAccountProperties with a key AWS would never have stored, and the
caller was never told.

The set the refusal is held to is published nowhere. Only RoleManager is named,
as an example, in the API Reference's own PutAccountProperties request, in the
user guide's role manager page and in the guide's policy example for
iam:AccountPropertyNamespaces, and the operation's model carries no enum for the
key. So the set is those three pages read together, kept as one set in IamService
to extend when AWS publishes another, and the cost is stated where it lives: a
namespace AWS recognises and has not written down is refused until the set names
it.

The namespace is matched as AWS spells it, and a request mixing two namespaces is
still answered for mixing them whether or not either is recognised, which leaves
every request that was already refused with the answer it already had. Both
readings are this package's own and the docs say so.

The wire tests and the SDK compatibility suite took a made-up namespace per
case so they could not read each other's properties. They now share the one
published namespace and keep that isolation in the property name, which is the
half nothing checks, and the SDK suite pins the new refusal through the SDK's
own model beside the codes it already pins.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-23 21:12:51 -04:00
1 parent 6f5683d654
commit 4198612422
5 files changed
+195 -49

No files matched your search

@@ -41,7 +41,12 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class IamAccountPropertiesTest {
private static final String NAMESPACE = "SdkTestNs";
/**
* The one namespace AWS publishes, which is the only one a property can be stored under: a
* namespace the service does not recognise is refused, so these keys keep what is theirs alone
* in the property name rather than in a namespace of their own.
*/
private static final String NAMESPACE = "RoleManager";
private static IamClient iam() {
return TestFixtures.iamClient();
@@ -52,8 +57,8 @@ class IamAccountPropertiesTest {
@DisplayName("PutAccountProperties and GetAccountProperties round-trip the map")
void propertiesRoundTrip() {
Map<String, String> properties = new LinkedHashMap<>();
properties.put(NAMESPACE + "/Enabled", "true");
properties.put(NAMESPACE + "/Mode", "strict");
properties.put(NAMESPACE + "/SdkRoundTrip", "true");
properties.put(NAMESPACE + "/SdkMode", "strict");
iam().putAccountProperties(PutAccountPropertiesRequest.builder()
.properties(properties)
@@ -64,12 +69,26 @@ class IamAccountPropertiesTest {
assertThat(response.hasProperties()).isTrue();
assertThat(response.properties())
.containsEntry(NAMESPACE + "/Enabled", "true")
.containsEntry(NAMESPACE + "/Mode", "strict");
.containsEntry(NAMESPACE + "/SdkRoundTrip", "true")
.containsEntry(NAMESPACE + "/SdkMode", "strict");
}
/**
* A namespace the service does not recognise is refused rather than stored, and the SDK carries
* the message through its own model: this suite pins the error codes as well as the shapes.
*/
@Test
@Order(2)
@DisplayName("A namespace the service does not recognise is refused")
void unrecognisedNamespaceIsRejected() {
assertThatThrownBy(() -> iam().putAccountProperties(PutAccountPropertiesRequest.builder()
.properties(Map.of("OtherSdkNs/Beta", "2"))
.build()))
.hasMessageContaining("Unsupported namespace: OtherSdkNs");
}
@Test
@Order(2)
@Order(3)
@DisplayName("All keys in one request must share a namespace")
void mixedNamespacesAreRejected() {
Map<String, String> properties = new LinkedHashMap<>();
@@ -83,7 +102,7 @@ class IamAccountPropertiesTest {
}
@Test
@Order(3)
@Order(4)
@DisplayName("SetSecurityTokenServicePreferences takes the version as a typed enum")
void setTokenVersion() {
iam().setSecurityTokenServicePreferences(
@@ -105,7 +124,7 @@ class IamAccountPropertiesTest {
* twice is FeatureDisabled.
*/
@Test
@Order(4)
@Order(5)
@DisplayName("Outbound federation refuses both redundant directions, with typed errors")
void federationSwitch() {
IamClient client = iam();
+23 -8
View File
@@ -1838,7 +1838,7 @@ that has never set one.
### What a bad account property key answers
A property key is read in three layers and two of them are settled by recordings.
A property key is read in three layers.
A key breaking the published shape, `accountPropertyKeyType` at 1 to 50 characters matching
`^[A-Za-z][A-Za-z0-9/_-]*$`, is the declared constraint violation, a `ValidationError` naming the
@@ -1851,13 +1851,28 @@ sentence of its own describing the rule; the rule itself is unchanged, and the t
it refuses, a trailing slash and several slashes, carry the same sentence without a recording of
their own.
The third layer is not implemented and is tracked rather than guessed. AWS also refuses a key whose
namespace it does not recognise, `InvalidInput` 400 with `Unsupported namespace: <namespace>`,
recorded 2026-10-25, where this emulator stores the property under whatever namespace the key
names. Doing it needs the set of namespaces AWS recognises, and the recordings name exactly one
real namespace and one invented one, so a check built from them would refuse namespaces AWS
accepts. That is the wrong direction to be wrong in, so the set has to come from a source that
publishes it.
The third layer is the namespace itself. A key whose namespace AWS does not recognise is
`InvalidInput` 400 with `Unsupported namespace: <namespace>`, recorded 2026-10-25, carrying the
namespace half of the key rather than the whole key, and the refused write leaves every stored
property as it was. Storing it instead was the worse of the two ways to be wrong here: one accepted
bad write left this account answering every later read with a key AWS would never have stored, and
the caller was never told.
What that refusal is held to is the set of namespaces AWS recognises, and no page publishes the
set. Only `RoleManager` is named anywhere: the API Reference's example for `PutAccountProperties`
sets `RoleManager/Enabled`, the user guide has role manager "controlled by the account-level
property RoleManager/Enabled", and the guide's policy example for `iam:AccountPropertyNamespaces`
matches on `RoleManager`. All three introduce it as an example, and the operation's model carries no
enum for the key, so what this package holds is those three pages read together rather than a list
AWS published. The cost is the direction this refusal can be wrong in: a namespace AWS recognises
and has not written down anywhere is refused here until the set in `IamService` names it, which is
one set to extend when AWS publishes another.
Two readings inside it are this package's own. The namespace is matched as AWS spells it, since
nothing published says how AWS reads its case. And a request mixing two namespaces is answered for
mixing them even when neither is recognised, because a request names one namespace before there is
a namespace to look up; that order is also the one that leaves every request already being refused
with the answer it already had.
### Organizations Root Access
@@ -221,6 +221,18 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");
/** globalEndpointTokenVersion's only two values. */
private static final Set<String> GLOBAL_ENDPOINT_TOKEN_VERSIONS = Set.of("v1Token", "v2Token");
/**
* The account property namespaces AWS recognises, as its own pages name them.
*
* <p>Only {@code RoleManager} is named anywhere: in the API Reference's example for
* {@code PutAccountProperties}, in the user guide's role manager page, which has the feature
* "controlled by the account-level property RoleManager/Enabled", and in the guide's policy
* example for {@code iam:AccountPropertyNamespaces}. Each of the three introduces it as an
* example, so the whole set is published nowhere, and a namespace AWS recognises but has not
* written down is refused here until this names it. That is the cost of answering the refusal
* AWS was recorded giving at all; see {@link #putAccountProperties}.
*/
private static final Set<String> ACCOUNT_PROPERTY_NAMESPACES = Set.of("RoleManager");
/** AWS-documented bounds for the account password policy's numeric fields. */
/**
* AWS's documented {@code passwordType} pattern for Create/UpdateLoginProfile: printable
@@ -3714,11 +3726,22 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
}
/**
* Sets account properties, all of which must be in one namespace.
* Sets account properties, all of which must be in one namespace AWS recognises.
*
* <p>The key is {@code Namespace/PropertyName}: AWS requires exactly one {@code /}, forbids a
* leading or trailing one, and states that "all keys must belong to the same namespace". A
* request mixing namespaces is rejected whole rather than partly applied.
*
* <p>The one namespace left is then held to the set AWS recognises, which it refuses with
* {@code Unsupported namespace: <namespace>}, and the rejected write leaves every stored
* property as it was. Storing the property instead left the account holding a key AWS never
* accepted, with the caller never told, and a later read reporting it.
*
* <p>The two refusals are in that order, so a request naming two namespaces is answered for
* mixing them whether or not either is recognised: a request names one namespace before there
* is a namespace to look up. Which one AWS answers first is not recorded, so the order is this
* package's reading, and it is the one that leaves every request already being refused with
* the answer it already had.
*/
public void putAccountProperties(Map<String, String> properties) {
if (properties == null || properties.isEmpty()) {
@@ -3735,6 +3758,13 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
+ "names both " + namespace + " and " + keyNamespace + ".", 400);
}
}
if (!ACCOUNT_PROPERTY_NAMESPACES.contains(namespace)) {
// AWS's own fixed text for this refusal, carrying the namespace half of the key as
// the request spelled it, so nothing here may reword it or fold its case: which
// spellings reach it is this package's reading, since only the one namespace is
// published and nothing says how AWS reads its case.
throw new AwsException("InvalidInput", "Unsupported namespace: " + namespace, 400);
}
synchronized (accountPropertiesLock) {
for (Map.Entry<String, String> entry : properties.entrySet()) {
accountProperties.put(entry.getKey(), entry.getValue());
@@ -18,7 +18,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
* The account property and outbound federation operations over the wire.
*
* <p>These are account-level singletons, so the tests share one account and are written not to
* depend on each other's properties: each uses its own namespace.
* depend on each other's properties: each uses its own property names. The namespace cannot vary
* with them, since a namespace AWS does not recognise is refused.
*/
@QuarkusTest
class AccountPropertiesIntegrationTest {
@@ -30,8 +31,15 @@ class AccountPropertiesIntegrationTest {
return given().header("Authorization", IAM_AUTH).formParam("Action", action);
}
private static String namespace() {
return "Ns" + Long.toString(System.nanoTime(), 36).replace("-", "");
/** The one account property namespace AWS publishes, which is the only one accepted. */
private static final String NAMESPACE = "RoleManager";
/**
* A key unique to the call under that namespace. The property name is the half nothing checks,
* so it is what keeps these tests from reading each other's properties.
*/
private static String key(String property) {
return NAMESPACE + "/" + property + Long.toString(System.nanoTime(), 36).replace("-", "");
}
private static final String PROPERTIES =
@@ -39,40 +47,93 @@ class AccountPropertiesIntegrationTest {
@Test
void propertiesRoundTripThroughPutAndGet() {
String ns = namespace();
String enabled = key("Enabled");
String mode = key("Mode");
iam("PutAccountProperties")
.formParam("Properties.entry.1.key", ns + "/RoleManagerEnabled")
.formParam("Properties.entry.1.key", enabled)
.formParam("Properties.entry.1.value", "true")
.formParam("Properties.entry.2.key", ns + "/Mode")
.formParam("Properties.entry.2.key", mode)
.formParam("Properties.entry.2.value", "strict")
.when().post("/").then().statusCode(200);
iam("GetAccountProperties").when().post("/").then().statusCode(200)
.body(containsString(ns + "/RoleManagerEnabled"))
.body(containsString(ns + "/Mode"))
.body(containsString(enabled))
.body(containsString(mode))
.body(containsString("strict"));
}
/** "All keys must belong to the same namespace." */
/**
* A namespace AWS does not recognise, which it refuses rather than storing: the property is
* absent from the read afterwards and the one already stored still holds its value. Storing it
* left this account answering with a key AWS never took, permanently, from one bad write.
*
* <p>The sentence is AWS's own, recorded against a real account for a key naming an invented
* namespace, and it carries the namespace half of the key rather than the whole key.
*/
@Test
void mixingNamespacesInOneRequestIsRejected() {
String first = namespace();
String second = namespace();
void aNamespaceAwsDoesNotRecogniseIsInvalidInput() {
String kept = key("Kept");
iam("PutAccountProperties")
.formParam("Properties.entry.1.key", first + "/Alpha")
.formParam("Properties.entry.1.key", kept)
.formParam("Properties.entry.1.value", "yes")
.when().post("/").then().statusCode(200);
iam("PutAccountProperties")
.formParam("Properties.entry.1.key", "NotARealProperty/Enabled")
.formParam("Properties.entry.1.value", "true")
.when().post("/").then().statusCode(400)
.body(containsString("InvalidInput"))
.body(containsString("Unsupported namespace: NotARealProperty"))
.body(not(containsString("ValidationError")));
iam("GetAccountProperties").when().post("/").then().statusCode(200)
.body(not(containsString("NotARealProperty")))
.body(containsString(kept));
}
/**
* The namespace is matched as AWS spells it. Nothing published says how AWS reads its case,
* so this is where that reading is pinned rather than left to whichever comparison the code
* happens to use.
*/
@Test
void theNamespaceIsMatchedAsAwsSpellsIt() {
iam("PutAccountProperties")
.formParam("Properties.entry.1.key", "rolemanager/Enabled")
.formParam("Properties.entry.1.value", "true")
.when().post("/").then().statusCode(400)
.body(containsString("InvalidInput"))
.body(containsString("Unsupported namespace: rolemanager"));
}
/**
* "All keys must belong to the same namespace."
*
* <p>The second namespace here is also one AWS does not recognise, and the answer is still
* about mixing them: a request names one namespace before there is a namespace to look up.
* Which refusal AWS reaches first is not recorded, so that order is this package's reading,
* and it is the one that leaves this request answered as it already was.
*/
@Test
void mixingNamespacesInOneRequestIsRejected() {
String alpha = key("Alpha");
iam("PutAccountProperties")
.formParam("Properties.entry.1.key", alpha)
.formParam("Properties.entry.1.value", "1")
.formParam("Properties.entry.2.key", second + "/Beta")
.formParam("Properties.entry.2.key", "Other/Beta")
.formParam("Properties.entry.2.value", "2")
.when().post("/").then().statusCode(400)
.body(containsString("InvalidInput"))
.body(containsString("same namespace"));
.body(containsString("same namespace"))
.body(not(containsString("Unsupported namespace")));
// Rejected whole, not partly applied: neither key was written.
iam("GetAccountProperties").when().post("/").then().statusCode(200)
.body(not(containsString(first + "/Alpha")))
.body(not(containsString(second + "/Beta")));
.body(not(containsString(alpha)))
.body(not(containsString("Other/Beta")));
}
/**
@@ -125,10 +186,9 @@ class AccountPropertiesIntegrationTest {
@Test
void aKeyOrValueOutsideItsLengthBoundsIsRejected() {
String ns = namespace();
// keyLength is 1 to 50.
iam("PutAccountProperties")
.formParam("Properties.entry.1.key", ns + "/" + "P".repeat(60))
.formParam("Properties.entry.1.key", NAMESPACE + "/" + "P".repeat(60))
.formParam("Properties.entry.1.value", "x")
.when().post("/").then().statusCode(400)
.body(containsString("ValidationError"))
@@ -136,7 +196,7 @@ class AccountPropertiesIntegrationTest {
// valueLength is 1 to 1024.
iam("PutAccountProperties")
.formParam("Properties.entry.1.key", ns + "/TooLongValue")
.formParam("Properties.entry.1.key", key("TooLongValue"))
.formParam("Properties.entry.1.value", "v".repeat(1025))
.when().post("/").then().statusCode(400)
.body(containsString("ValidationError"))
@@ -144,7 +204,7 @@ class AccountPropertiesIntegrationTest {
// And the top of the range is accepted, so the bound is not off by one.
iam("PutAccountProperties")
.formParam("Properties.entry.1.key", ns + "/AtTheLimit")
.formParam("Properties.entry.1.key", key("AtTheLimit"))
.formParam("Properties.entry.1.value", "v".repeat(1024))
.when().post("/").then().statusCode(200);
}
@@ -157,19 +217,20 @@ class AccountPropertiesIntegrationTest {
*/
@Test
void entriesTheRequestNumbersWithAGapAreAllStored() {
String ns = namespace();
String first = key("First");
String third = key("Third");
iam("PutAccountProperties")
.formParam("Properties.entry.1.key", ns + "/First")
.formParam("Properties.entry.1.key", first)
.formParam("Properties.entry.1.value", "one")
.formParam("Properties.entry.3.key", ns + "/Third")
.formParam("Properties.entry.3.key", 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(first))
.body(containsString("one"))
.body(containsString(ns + "/Third"))
.body(containsString(third))
.body(containsString("three"));
}
@@ -181,23 +242,23 @@ class AccountPropertiesIntegrationTest {
*/
@Test
void theBareAndMemberSpellingsOfAnEntryAreRead() {
String bare = namespace();
String bare = key("Bare");
iam("PutAccountProperties")
.formParam("Properties.1.key", bare + "/Bare")
.formParam("Properties.1.key", bare)
.formParam("Properties.1.value", "read")
.when().post("/").then().statusCode(200);
String member = namespace();
String member = key("Member");
iam("PutAccountProperties")
.formParam("Properties.member.1.key", member + "/Member")
.formParam("Properties.member.1.key", 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"));
.body(containsString(bare))
.body(containsString(member));
}
/**
@@ -239,4 +239,25 @@ class AccountPropertiesStateTest {
assertEquals(Map.of("RoleManager/Kept", "yes"), service.getAccountProperties(),
"neither key of the rejected request may have landed");
}
/**
* A namespace AWS does not recognise is refused with AWS's own sentence, and the account keeps
* exactly what it held: this is the state half of that refusal, which the wire test cannot
* reach past the response, and the divergence it exists to stop is permanent. One accepted bad
* write leaves every later read reporting a key AWS would never have stored.
*/
@Test
void anUnrecognisedNamespaceWritesNothing() {
IamService service = inMemory(ACCOUNT_A);
service.putAccountProperties(Map.of("RoleManager/Kept", "yes"));
AwsException refused = assertThrows(AwsException.class, () ->
service.putAccountProperties(Map.of("NotARealProperty/Enabled", "true")));
assertEquals("InvalidInput", refused.getErrorCode());
assertEquals(400, refused.getHttpStatus());
assertEquals("Unsupported namespace: NotARealProperty", refused.getMessage());
assertEquals(Map.of("RoleManager/Kept", "yes"), service.getAccountProperties(),
"the refused key may not have landed");
}
}