fix(iam): match status validation errors for credential updates (#7174)

This commit is contained in:
Jimmy Liu Jia authored and GitHub committed 2026-11-01 09:12:08 -04:00
1 parent a707cb3260
commit a54ca5e0c9
10 files changed
+109 -50

No files matched your search

+9 -7
View File
@@ -294,9 +294,10 @@ Some refusals stay as this service answers them, and the members behind them are
vendored shapes so the walk cannot reword them. A service-linked role's principal and suffix answer
`InvalidInput` rather than a validation error at all, and so does an empty `ServiceNamespaces` on
`ListPoliciesGrantingServiceAccess`. An account alias carries AWS's own sentence about its own
bounds, which is why neither alias operation is read at all. `statusType`, on all four operations
that take it, is answered without the offending value and without the permitted set, which is what
the recorded refusal carries and what the walk would spell out. `Encoding` on `GetSSHPublicKey`
bounds, which is why neither alias operation is read at all. For `statusType` on the four credential
updates, a missing `Status` answers `Member must not be null`; an invalid value answers `Member must
satisfy enum value set: [Expired, Active, Inactive]` without echoing that value. These wordings
follow the newer AWS capture. `Encoding` on `GetSSHPublicKey`
answers the modelled `UnrecognizedPublicKeyEncoding` rather than a constraint violation. And
`TagKeys` on the eight untag operations is answered against the list as a whole, `Value at
'tagKeys' failed to satisfy constraint: Member must satisfy constraint: [...]`, where the walk
@@ -321,10 +322,11 @@ was already this service's choice for a list over its limit, and it is now what
whatever it breaks. Other services do quote a list, Lambda's `Value '[x86_64, arm64]' at
'architectures'` being a captured one, which is why this is IAM's reading and not a rule.
The one message that still carries a word where the value would go is the required member a request
leaves out, `Value null at '<member>'`, which no capture covers in either form. The form is chosen
in one place, so a direct capture that ever shows IAM carrying its values again moves it back in one
edit rather than across the service.
A captured missing `Status` on the four credential updates reads `Value at 'status' failed to satisfy
constraint: Member must not be null`, without `null` after `Value`. Other omitted required members
may still use `Value null at '<member>'`; this capture does not settle their wording. IAM's form for
violations with a supplied value is chosen in one place, so a future capture that shows IAM carrying
those values again moves it back in one edit rather than across the service.
### Permission Boundaries
@@ -168,9 +168,9 @@ public final class SmithyValidationErrors {
* what {@code docs/services/iam.md} records as the reading. Choosing a form here rather than at
* each message means a later capture changes one object instead of a package.
*
* <p>Only the violations that carry a value differ. A required member the request leaves out
* ({@link #notNull}), a list held to its member count ({@link #sizeOutOfRange}) and a list
* checked as a whole ({@link #notAllInEnum}) read the same either way.
* <p>This form applies only to violations that carry a value. Required-member omissions use
* {@link #notNull} or {@link #notNullWithoutValue}, depending on the operation. List size and
* whole-list checks use {@link #sizeOutOfRange} and {@link #notAllInEnum} separately.
*/
public static final class Violations {
@@ -1274,9 +1274,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
* five entities and passes everything else through, which would make the {@code Role} this
* action and {@code GetRole} answer unparsable.
*
* <p>The rendering names neither the offending value nor the set, the way
* {@link #requireStatusFromEnum} does, which is the one IAM constraint rendering a recording
* covers. It also keeps the refused description out of the error body, where a control
* <p>The rendering keeps the refused description out of the error body, where a control
* character would break the answer it is being refused for.
*/
private static void validateRoleDescription(String description) {
@@ -3452,17 +3450,18 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
// =========================================================================
/**
* {@code statusType}, shared by UpdateAccessKey, UpdateSigningCertificate, UpdateSSHPublicKey
* and UpdateServiceSpecificCredential. One rendering serves all four because one front end
* validates one shape: the recording is of UpdateServiceSpecificCredential, and AWS names
* neither the offending value nor the permitted set, unlike this message elsewhere in the
* tree. Matched rather than made uniform.
* {@code statusType} is shared by four credential updates. AWS distinguishes a missing member
* from an invalid value and lists the permitted values in its recorded error-message order.
*/
private void requireStatusFromEnum(String status) {
if (status == null || !CREDENTIAL_STATUSES.contains(status)) {
if (status == null) {
throw SmithyValidationErrors.validationError(
"Value at 'status' failed to satisfy "
+ "constraint: Member must satisfy enum value set");
SmithyValidationErrors.notNullWithoutValue("status"));
}
if (!CREDENTIAL_STATUSES.contains(status)) {
throw SmithyValidationErrors.validationError(
IamValidationErrors.MESSAGES.notInEnum(status, "status",
List.of(CREDENTIAL_STATUS_EXPIRED, CREDENTIAL_STATUS_ACTIVE, "Inactive")));
}
}
@@ -10,9 +10,9 @@ import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
* where the older ones quoted the value, and STS still quotes it, so this names IAM's side of that
* split in one place. {@code docs/services/iam.md} records the reading and the captures behind it.
*
* <p>A message AWS itself writes with the value is not forced through here: a list checked as a
* whole carries the list, and a required member the request leaves out reads
* {@code Value null at '<member>'}, which no capture here covers either way.
* <p>A list checked as a whole can carry the list and is not forced through here. Required-member
* omissions use operation-specific wording: the captured missing {@code Status} on credential
* updates reads {@code Value at 'status'} without {@code null}.
*/
final class IamValidationErrors {
@@ -25,9 +25,8 @@ import static org.hamcrest.Matchers.equalTo;
* implicitly based on the AWS access key ID used to sign the request", the sentence this operation
* shares with DeleteAccessKey and ListAccessKeys.
*
* <p>The refusal is the rendering {@code IamService.requireStatusFromEnum} already answers for the
* other three operations that take this shape, which names neither the offending value nor the
* permitted set, as AWS's own recording of one of them does not.
* <p>The four operations share {@code IamService.requireStatusFromEnum}; the latest AWS captures
* distinguish an absent status from a present value outside the enum.
*/
@QuarkusTest
class IamAccessKeyStatusIntegrationTest {
@@ -61,19 +60,22 @@ class IamAccessKeyStatusIntegrationTest {
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
.body("ErrorResponse.Error.Message",
equalTo("1 validation error detected: Value at 'status' failed to satisfy "
+ "constraint: Member must satisfy enum value set"));
+ "constraint: Member must satisfy enum value set: "
+ "[Expired, Active, Inactive]"));
assertStatusStillActive(userName);
}
@Test
void anAbsentStatusIsAnsweredTheSameWay() {
void anAbsentStatusNamesTheMissingMember() {
String userName = user("absent-status");
String accessKeyId = accessKeyFor(userName);
update(ACCOUNT, Map.of("UserName", userName, "AccessKeyId", accessKeyId)).statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
.body("ErrorResponse.Error.Message", containsString("at 'status'"));
.body("ErrorResponse.Error.Message",
equalTo("1 validation error detected: Value at 'status' failed to satisfy "
+ "constraint: Member must not be null"));
assertStatusStillActive(userName);
}
@@ -0,0 +1,62 @@
package io.github.hectorvent.floci.services.iam;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
/** IAM's four statusType updates share the validation behavior captured for issue #6042. */
@QuarkusTest
class IamCredentialStatusValidationIntegrationTest {
private static final String MESSAGE = "ErrorResponse.Error.Message";
private static final String PREFIX = "1 validation error detected: Value at 'status' failed "
+ "to satisfy constraint: ";
@ParameterizedTest(name = "{0} without Status")
@CsvSource({
"UpdateAccessKey, AccessKeyId, AKIAIOSFODNN7EXAMPLE",
"UpdateSigningCertificate, CertificateId, ABCDEFGHIJKLMNOPQRSTUVWX",
"UpdateSSHPublicKey, SSHPublicKeyId, APKAEXAMPLEEXAMPLE12",
"UpdateServiceSpecificCredential, ServiceSpecificCredentialId, ACCAEXAMPLEEXAMPLE12"
})
void omittedStatusIsReportedAsNull(String action, String idMember, String id) {
update(action, idMember, id, null).statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
.body(MESSAGE, equalTo(PREFIX + "Member must not be null"));
}
@ParameterizedTest(name = "{0} with Status=Enabled")
@CsvSource({
"UpdateAccessKey, AccessKeyId, AKIAIOSFODNN7EXAMPLE",
"UpdateSigningCertificate, CertificateId, ABCDEFGHIJKLMNOPQRSTUVWX",
"UpdateSSHPublicKey, SSHPublicKeyId, APKAEXAMPLEEXAMPLE12",
"UpdateServiceSpecificCredential, ServiceSpecificCredentialId, ACCAEXAMPLEEXAMPLE12"
})
void invalidStatusListsAllowedValues(String action, String idMember, String id) {
update(action, idMember, id, "Enabled").statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
.body(MESSAGE, equalTo(PREFIX
+ "Member must satisfy enum value set: [Expired, Active, Inactive]"));
}
private static ValidatableResponse update(String action, String idMember, String id,
String status) {
RequestSpecification request = given()
.header("Authorization", "AWS4-HMAC-SHA256 Credential=000000000912/20261101/"
+ "us-east-1/iam/aws4_request")
.contentType("application/x-www-form-urlencoded")
.formParam("Action", action)
.formParam("Version", "2010-05-08")
.formParam("UserName", "status-validation-missing-user")
.formParam(idMember, id);
if (status != null) {
request.formParam("Status", status);
}
return request.when().post("/").then();
}
}
@@ -2191,16 +2191,14 @@ class IamServiceTest {
() -> iamService.updateAccessKey("alice", "AKIANOSUCHKEY00000", "Disabled"));
assertEquals("ValidationError", error.getErrorCode());
// The rendering the three sibling operations already answer with, taken from a recording
// of UpdateServiceSpecificCredential: AWS names neither the value nor the permitted set.
// AWS lists the allowed values in its error message, even when the key is unknown.
assertEquals("1 validation error detected: Value at 'status' failed to satisfy "
+ "constraint: Member must satisfy enum value set", error.getMessage());
+ "constraint: Member must satisfy enum value set: [Expired, Active, Inactive]",
error.getMessage());
}
@Test
void anAbsentAccessKeyStatusIsAnsweredLikeAnInvalidOne() {
// The shared helper reads a null as a value outside the enum, which is how the other three
// statusType operations answer one. Changing that would change all four, so it stays.
void anAbsentAccessKeyStatusNamesTheMissingMember() {
iamService.createUser("alice", "/");
AccessKey key = iamService.createAccessKey("alice");
@@ -2209,7 +2207,7 @@ class IamServiceTest {
assertEquals("ValidationError", error.getErrorCode());
assertEquals("1 validation error detected: Value at 'status' failed to satisfy "
+ "constraint: Member must satisfy enum value set", error.getMessage());
+ "constraint: Member must not be null", error.getMessage());
// And the key is as it was: the status is read before the lookup, so nothing is written.
assertEquals("Active", iamService.listAccessKeys("alice").getFirst().getStatus());
}
@@ -587,10 +587,9 @@ class ServiceSpecificCredentialIntegrationTest {
.when().post("/").then().statusCode(400)
.body(containsString("ValidationError"))
.body(containsString("1 validation error detected"))
.body(containsString("Member must satisfy enum value set"))
// AWS names neither the offending value nor the permitted set. The trailing colon
// is the tell for the set, and "Deleted" for the value.
.body(not(containsString("enum value set:")))
.body(containsString("Member must satisfy enum value set: "
+ "[Expired, Active, Inactive]"))
// The error lists the set but does not echo the rejected value.
.body(not(containsString("Deleted")));
}
@@ -140,11 +140,10 @@ class SigningCertificateIntegrationTest {
.formParam("Status", "Revoked")
.when().post("/").then().statusCode(400)
.body(containsString("ValidationError"))
// statusType is one shape across the three operations that take it, and AWS renders it
// without the offending value or the permitted set.
// The AWS capture lists the set but does not echo the offending value.
.body(containsString("1 validation error detected"))
.body(containsString("Member must satisfy enum value set"))
.body(not(containsString("enum value set:")))
.body(containsString("Member must satisfy enum value set: "
+ "[Expired, Active, Inactive]"))
.body(not(containsString("Revoked")));
}
@@ -218,9 +218,7 @@ class SshPublicKeyIntegrationTest {
}
/**
* And nothing outside the enum. {@code statusType} is one shape across the three operations
* that take it, so this is the same answer AWS gives on UpdateServiceSpecificCredential, where
* it was recorded: the offending value and the permitted set are both absent.
* And nothing outside the enum. AWS lists the permitted set without echoing the value.
*/
@Test
void theStatusTakesNothingOutsideTheEnum() {
@@ -235,8 +233,8 @@ class SshPublicKeyIntegrationTest {
.when().post("/").then().statusCode(400)
.body(containsString("ValidationError"))
.body(containsString("1 validation error detected"))
.body(containsString("Member must satisfy enum value set"))
.body(not(containsString("enum value set:")))
.body(containsString("Member must satisfy enum value set: "
+ "[Expired, Active, Inactive]"))
.body(not(containsString("Revoked")));
}
}