mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(iam): answer three refusals with their captured codes (#7364)
Captures from a real account on issue 6042 answer three refusals this emulator had written for itself, each wrong in its code or its status rather than only in its wording. ChangePassword answered InvalidParameterValue 400 naming the user for a wrong old password. AWS answers AccessDenied 403 and "Either the new password does not conform to the account password policy or the old password was incorrect.", which is now what it sends, as captured. The sentence names both of the operation's causes without saying which one refused the call, so a caller who cannot prove the current password learns nothing about the policy either. That it names the policy half does not settle the policy half. The capture covers a wrong old password with a conforming new one, nothing records AWS answering it for a password the policy refuses, and the model declares PasswordPolicyViolation on this operation for exactly that case, so a new password the account policy refuses keeps that error and the rule it names, as it does on CreateLoginProfile and UpdateLoginProfile. The old password is still read first, so a request with both halves wrong answers the capture. PolicySourceArn on SimulatePrincipalPolicy and GetContextKeysForPrincipalPolicy resolved an entity out of whatever followed the last slash, so arn:aws:iam:user/bob simulated as the user bob. It is now held to AwsArnUtils.isArn before either simulator resolves it, answering InvalidInput "Invalid ARN provided in the request: <value>". A valid ARN that names neither a user nor a role still answers the entity-type refusal it answered before. GetAccessKeyInfo answered InvalidParameterValue quoting an id the account never issued. AWS answers ValidationError "Access key ID is not valid.", for an AKIA and an ASIA id alike, which also settles that it refuses such an id rather than decoding the account out of it. The wire and unit tests pin the two halves of the password refusal answering differently and the order they are read in, both simulators against three unparseable values and a well-formed one, and the key refusal over both id formats. One enforcement test had pinned the unparseable ARN resolving, which the capture overturns. docs/services/iam.md and docs/services/sts.md carry the three answers, what each capture covers, and what it leaves open. Three comments that described these answers before the captures are corrected with them: handleGetAccessKeyInfo's Javadoc, which still called its old refusal a documented deviation, StsAccessKeyInfoIntegrationTest's class comment, which said the same, and validatedPolicySourceArn's, which said a value clearing 20 characters and parsing as no ARN is left alone and that what AWS answers for one is not recorded.
This commit is contained in:
1 parent
ad8cd14724
commit
96fafbd4dc
12 files changed
+246
-64
No files matched your search
+21
-3
@@ -38,6 +38,9 @@ class IamChangePasswordIntegrationTest {
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String PASSWORD = "Sup3r$ecret!";
|
||||
private static final String NEW_PASSWORD = "An0ther$ecret!";
|
||||
/** Captured: what a wrong old password is refused with, both of the causes named. */
|
||||
private static final String WRONG_OLD_PASSWORD = "Either the new password does not conform to "
|
||||
+ "the account password policy or the old password was incorrect.";
|
||||
|
||||
@RegisterExtension
|
||||
final PartitionCleanup cleanup = new PartitionCleanup();
|
||||
@@ -53,8 +56,8 @@ class IamChangePasswordIntegrationTest {
|
||||
// Nothing echoes a password back, so the proof the write took is the next call: the old
|
||||
// password is no longer the current one and the new one is.
|
||||
signedAs(accessKeyId, Map.of("OldPassword", PASSWORD, "NewPassword", "Th1rd$ecret!"))
|
||||
.statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("InvalidParameterValue"));
|
||||
.statusCode(403)
|
||||
.body("ErrorResponse.Error.Code", equalTo("AccessDenied"));
|
||||
signedAs(accessKeyId, Map.of("OldPassword", NEW_PASSWORD, "NewPassword", "Th1rd$ecret!"))
|
||||
.statusCode(200);
|
||||
}
|
||||
@@ -104,6 +107,12 @@ class IamChangePasswordIntegrationTest {
|
||||
.body("ErrorResponse.Error.Message", containsString("'oldPassword'"));
|
||||
}
|
||||
|
||||
/**
|
||||
* The two halves of the refusal answer differently, which is what the capture of 2026-10-31
|
||||
* settles and what it leaves alone: a new password the account policy refuses is told which
|
||||
* rule it broke, where a wrong old password gets the captured sentence, which names both
|
||||
* causes without saying which one applied.
|
||||
*/
|
||||
@Test
|
||||
void theNewPasswordIsHeldToTheAccountPasswordPolicy() {
|
||||
String accessKeyId = userWithAConsolePassword("policy");
|
||||
@@ -113,7 +122,16 @@ class IamChangePasswordIntegrationTest {
|
||||
|
||||
signedAs(accessKeyId, Map.of("OldPassword", PASSWORD, "NewPassword", "sh0rt!"))
|
||||
.statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("PasswordPolicyViolation"));
|
||||
.body("ErrorResponse.Error.Code", equalTo("PasswordPolicyViolation"))
|
||||
.body("ErrorResponse.Error.Type", equalTo("Sender"))
|
||||
.body("ErrorResponse.Error.Message", containsString("a minimum length of 20"));
|
||||
|
||||
signedAs(accessKeyId,
|
||||
Map.of("OldPassword", "N0tTheOne!", "NewPassword", "L0ngEn0ugh$ecret!!!!"))
|
||||
.statusCode(403)
|
||||
.body("ErrorResponse.Error.Code", equalTo("AccessDenied"))
|
||||
.body("ErrorResponse.Error.Type", equalTo("Sender"))
|
||||
.body("ErrorResponse.Error.Message", equalTo(WRONG_OLD_PASSWORD));
|
||||
|
||||
signedAs(accessKeyId,
|
||||
Map.of("OldPassword", PASSWORD, "NewPassword", "L0ngEn0ugh$ecret!!!!"))
|
||||
|
||||
@@ -412,7 +412,9 @@ class IamConcurrencyTest {
|
||||
iam.changePassword("racer", "Passw0rd$start", candidate);
|
||||
winners.add(candidate);
|
||||
} catch (AwsException e) {
|
||||
if (!"InvalidParameterValue".equals(e.getErrorCode())) {
|
||||
// The losers hold a password that is no longer current, which
|
||||
// is what AccessDenied answers.
|
||||
if (!"AccessDenied".equals(e.getErrorCode())) {
|
||||
unexpected.add(e.getErrorCode());
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
@@ -562,8 +562,8 @@ class IamIntegrationTest {
|
||||
* simulated against a user named after its tail. IAM answers that minimum with a
|
||||
* {@code ValidationError} naming the length, which is what both principal readers answer now.
|
||||
*
|
||||
* <p>A value that clears 20 characters and still parses as no ARN is deliberately untouched:
|
||||
* the member publishes no pattern and nothing records what AWS answers for one.
|
||||
* <p>What AWS answers for a value that clears 20 characters and parses as no ARN is
|
||||
* {@link #aPolicySourceArnThatParsesAsNoArnIsInvalidInput} below, captured since.
|
||||
*/
|
||||
@Test
|
||||
@Order(88)
|
||||
@@ -597,6 +597,46 @@ class IamIntegrationTest {
|
||||
.body("ErrorResponse.Error.Message", equalTo(expected));
|
||||
}
|
||||
|
||||
/**
|
||||
* The other half of the member, captured from a real account: a value long enough to clear
|
||||
* {@code arnType}'s minimum and malformed enough to parse as no ARN answers
|
||||
* {@code InvalidInput} quoting it, where the simulator used to resolve the user its tail
|
||||
* named. The length violation above is read first, since the shape runs before the operation.
|
||||
*/
|
||||
@Test
|
||||
@Order(89)
|
||||
void aPolicySourceArnThatParsesAsNoArnIsInvalidInput() {
|
||||
String malformed = "arn:aws:iam:user/simulate-user";
|
||||
|
||||
given()
|
||||
.formParam("Action", "SimulatePrincipalPolicy")
|
||||
.formParam("PolicySourceArn", malformed)
|
||||
.formParam("ActionNames.member.1", "s3:GetObject")
|
||||
.header("Authorization",
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260227/us-east-1/iam/aws4_request")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("InvalidInput"))
|
||||
.body("ErrorResponse.Error.Type", equalTo("Sender"))
|
||||
.body("ErrorResponse.Error.Message",
|
||||
equalTo("Invalid ARN provided in the request: " + malformed));
|
||||
|
||||
given()
|
||||
.formParam("Action", "GetContextKeysForPrincipalPolicy")
|
||||
.formParam("PolicySourceArn", malformed)
|
||||
.header("Authorization",
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260227/us-east-1/iam/aws4_request")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("InvalidInput"))
|
||||
.body("ErrorResponse.Error.Message",
|
||||
equalTo("Invalid ARN provided in the request: " + malformed));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(41)
|
||||
void getContextKeysForPrincipalPolicyMergesAttachedAndExtraPolicies() {
|
||||
|
||||
@@ -56,6 +56,10 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class IamServiceTest {
|
||||
|
||||
/** Captured 2026-10-31: what a wrong old password is refused with, both causes named. */
|
||||
private static final String PASSWORD_CHANGE_REFUSAL = "Either the new password does not "
|
||||
+ "conform to the account password policy or the old password was incorrect.";
|
||||
|
||||
private IamService iamService;
|
||||
|
||||
@BeforeEach
|
||||
@@ -1180,7 +1184,7 @@ class IamServiceTest {
|
||||
// The proof the write took is behavioural rather than a read of the stored field: the
|
||||
// new password is now the current one and the old one is not.
|
||||
iamService.changePassword("alice", "An0ther$ecret!", "Th1rd$ecret!");
|
||||
assertEquals("InvalidParameterValue", assertThrows(AwsException.class,
|
||||
assertEquals("AccessDenied", assertThrows(AwsException.class,
|
||||
() -> iamService.changePassword("alice", "An0ther$ecret!", "F0urth$ecret!"))
|
||||
.getErrorCode());
|
||||
}
|
||||
@@ -1193,8 +1197,9 @@ class IamServiceTest {
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> iamService.changePassword("alice", "N0tTheOne!", "An0ther$ecret!"));
|
||||
|
||||
assertEquals("InvalidParameterValue", ex.getErrorCode());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
assertEquals("AccessDenied", ex.getErrorCode());
|
||||
assertEquals(403, ex.getHttpStatus());
|
||||
assertEquals(PASSWORD_CHANGE_REFUSAL, ex.getMessage());
|
||||
// The refusal left the password alone, so the original still changes it.
|
||||
iamService.changePassword("alice", "Sup3r$ecret!", "An0ther$ecret!");
|
||||
}
|
||||
@@ -1209,10 +1214,23 @@ class IamServiceTest {
|
||||
|
||||
// Both halves of the request are wrong. A caller who cannot prove the current password is
|
||||
// told that and nothing about what the policy would have required.
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
AwsException both = assertThrows(AwsException.class,
|
||||
() -> iamService.changePassword("alice", "N0tTheOne!", "short"));
|
||||
assertEquals("AccessDenied", both.getErrorCode());
|
||||
assertEquals(403, both.getHttpStatus());
|
||||
assertEquals(PASSWORD_CHANGE_REFUSAL, both.getMessage());
|
||||
|
||||
assertEquals("InvalidParameterValue", ex.getErrorCode());
|
||||
// The same new password on its own is refused by the policy and named the rule it
|
||||
// broke, so the answer above is the order the two checks run in rather than a policy
|
||||
// that had nothing to say.
|
||||
AwsException policyOnly = assertThrows(AwsException.class,
|
||||
() -> iamService.changePassword("alice", "Sup3r$ecret!", "short"));
|
||||
assertEquals("PasswordPolicyViolation", policyOnly.getErrorCode());
|
||||
assertEquals(400, policyOnly.getHttpStatus());
|
||||
assertTrue(policyOnly.getMessage().contains("a minimum length of 12"),
|
||||
policyOnly.getMessage());
|
||||
// The password is untouched by both, so the original still changes it.
|
||||
iamService.changePassword("alice", "Sup3r$ecret!", "An0ther$ecret!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1230,6 +1248,11 @@ class IamServiceTest {
|
||||
|
||||
assertEquals("PasswordPolicyViolation", ex.getErrorCode());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
// The rule the password broke is named, the same as it is to an administrator setting it.
|
||||
assertTrue(ex.getMessage().contains("a minimum length of 12"), ex.getMessage());
|
||||
assertTrue(assertThrows(AwsException.class,
|
||||
() -> iamService.updateLoginProfile("alice", "short", null))
|
||||
.getMessage().contains("a minimum length of 12"));
|
||||
iamService.changePassword("alice", "Sup3r$ecret!", "An0ther$ecret!");
|
||||
}
|
||||
|
||||
@@ -2797,6 +2820,30 @@ class IamServiceTest {
|
||||
assertNotNull(iamService.resolvePrincipalContext(user.getArn()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Captured from a real account: a value over the member's 20-character minimum that parses as
|
||||
* no ARN is refused, where this service used to take whatever followed the last slash and
|
||||
* simulate against a user of that name. Both principal readers answer it, since both take the
|
||||
* same member.
|
||||
*/
|
||||
@Test
|
||||
void aPolicySourceArnThatParsesAsNoArnIsRefused() {
|
||||
iamService.createUser("bob", "/");
|
||||
|
||||
for (String malformed : List.of("arn:aws:iam:user/bob", "arn:aws:iam::user/bob",
|
||||
"not-an-arn-but-long-enough:user/bob")) {
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> iamService.resolvePrincipalContext(malformed));
|
||||
assertEquals("InvalidInput", ex.getErrorCode());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
assertEquals("Invalid ARN provided in the request: " + malformed, ex.getMessage());
|
||||
assertEquals("InvalidInput", assertThrows(AwsException.class,
|
||||
() -> iamService.resolveAttachedPrincipalContext(malformed)).getErrorCode());
|
||||
}
|
||||
// The user the tail named exists, so the refusal is the parse rather than the lookup.
|
||||
assertNotNull(iamService.resolvePrincipalContext("arn:aws:iam::000000000000:user/bob"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void simulatePrincipalPolicyRejectsUnsupportedPrincipalArnType() {
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
|
||||
+16
-5
@@ -352,13 +352,15 @@ class PasswordSelfServiceGrantEnforcementIntegrationTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@code PolicySourceArn} that names a user without being an ARN this emulator can parse is
|
||||
* resolved by its trailing name, as it was before the principal keys were populated, so the
|
||||
* account they carry comes from the identity that resolved rather than from the text of the
|
||||
* call.
|
||||
* A {@code PolicySourceArn} that names a user without being an ARN is refused rather than
|
||||
* resolved by its trailing name, which is what a capture from a real account answers and what
|
||||
* this class used to pin the other way: the grant is read from the identity the ARN resolves
|
||||
* to, so there is nothing to resolve from a value that parses as no ARN. The same user under
|
||||
* a well-formed ARN simulates as allowed, which is what says the refusal is the shape of the
|
||||
* value rather than the grant.
|
||||
*/
|
||||
@Test
|
||||
void aPolicySourceArnItCannotParseStillSimulates() {
|
||||
void aPolicySourceArnItCannotParseIsRefused() {
|
||||
allowUsersToChangePassword(true);
|
||||
String userName = "pw-oddarn-" + suffix();
|
||||
userWithAConsolePassword(userName);
|
||||
@@ -367,6 +369,15 @@ class PasswordSelfServiceGrantEnforcementIntegrationTest {
|
||||
"PolicySourceArn", "arn:aws:iam:user/" + userName,
|
||||
"ActionNames.member.1", "iam:ChangePassword",
|
||||
"ResourceArns.member.1", "arn:aws:iam::" + ACCOUNT + ":user/" + userName))
|
||||
.statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("InvalidInput"))
|
||||
.body("ErrorResponse.Error.Message",
|
||||
equalTo("Invalid ARN provided in the request: arn:aws:iam:user/" + userName));
|
||||
|
||||
admin("SimulatePrincipalPolicy", Map.of(
|
||||
"PolicySourceArn", "arn:aws:iam::" + ACCOUNT + ":user/" + userName,
|
||||
"ActionNames.member.1", "iam:ChangePassword",
|
||||
"ResourceArns.member.1", "arn:aws:iam::" + ACCOUNT + ":user/" + userName))
|
||||
.statusCode(200)
|
||||
.body(decisionPath(), equalTo("allowed"));
|
||||
}
|
||||
|
||||
+16
-5
@@ -6,6 +6,8 @@ import io.restassured.response.ValidatableResponse;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -21,7 +23,8 @@ import static org.hamcrest.Matchers.startsWith;
|
||||
* errors at all. Its one explicit behaviour is what it does not do: "this operation does not
|
||||
* indicate the state of the access key. The key might be active, inactive, or deleted", so an
|
||||
* inactive key still answers its account. A key Floci does not hold is the answer the reference
|
||||
* leaves open, and {@code docs/services/sts.md} carries that deviation.
|
||||
* leaves open, and a capture from a real account answers it {@code ValidationError} "Access key ID
|
||||
* is not valid." over both id formats, which {@code docs/services/sts.md} carries.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class StsAccessKeyInfoIntegrationTest {
|
||||
@@ -98,10 +101,18 @@ class StsAccessKeyInfoIntegrationTest {
|
||||
containsString("Value null at 'accessKeyId'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aWellFormedKeyNobodyHoldsIsRefused() {
|
||||
sts("GetAccessKeyInfo", Map.of("AccessKeyId", "AKIAABSENTKEY0000000")).statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("InvalidParameterValue"));
|
||||
/**
|
||||
* Captured from a real account against a long-term and a temporary id alike: an id the account
|
||||
* never issued is a {@code ValidationError} whose sentence names neither the id nor a
|
||||
* violation count, so AWS refuses it rather than reading the account out of it.
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"AKIAABSENTKEY0000000", "ASIAABSENTKEY0000000"})
|
||||
void aWellFormedKeyNobodyHoldsIsRefused(String accessKeyId) {
|
||||
sts("GetAccessKeyInfo", Map.of("AccessKeyId", accessKeyId)).statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
|
||||
.body("ErrorResponse.Error.Type", equalTo("Sender"))
|
||||
.body("ErrorResponse.Error.Message", equalTo("Access key ID is not valid."));
|
||||
}
|
||||
|
||||
private String user(String label) {
|
||||
|
||||
@@ -835,21 +835,27 @@ class StsQueryHandlerTest {
|
||||
verify(service, never()).resolveAccountId(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAccessKeyInfoRefusesAKeyNobodyHolds() {
|
||||
// The operation models no error at all, and the page says only that a deleted key "might
|
||||
// return an error that the key doesn't exist", so this is the published common error
|
||||
// nearest that sentence rather than a reading.
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"AKIAABSENTKEY0000000", "ASIAABSENTKEY0000000"})
|
||||
void getAccessKeyInfoRefusesAKeyNobodyHolds(String accessKeyId) {
|
||||
// The operation models no error, and the page says only that a deleted key "might return
|
||||
// an error that the key doesn't exist". A capture from a real account answers both id
|
||||
// formats the same way: ValidationError with a sentence that quotes neither the id nor a
|
||||
// violation count, rather than an account decoded out of the id.
|
||||
IamService service = mock(IamService.class);
|
||||
when(service.findAccountForAccessKeyId(anyString())).thenReturn(Optional.empty());
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
params.add("AccessKeyId", "AKIAABSENTKEY0000000");
|
||||
params.add("AccessKeyId", accessKeyId);
|
||||
|
||||
Response response = newHandler(service, new RegionResolver(REGION, "000000000000"))
|
||||
.handle("GetAccessKeyInfo", params);
|
||||
|
||||
assertEquals(400, response.getStatus());
|
||||
assertTrue(response.getEntity().toString().contains("<Code>InvalidParameterValue</Code>"));
|
||||
String body = response.getEntity().toString();
|
||||
assertTrue(body.contains("<Code>ValidationError</Code>"), body);
|
||||
assertTrue(body.contains("<Message>Access key ID is not valid.</Message>"), body);
|
||||
assertTrue(body.contains("<Type>Sender</Type>"), body);
|
||||
assertFalse(body.contains(accessKeyId), body);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
|
||||
Reference in new issue
Block a user