mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(iam): answer an assumed-role session's ChangePassword as AWS does (#9181)
ChangePassword answered 400 InvalidUserType to every caller with no stored user behind the signing key, reading the CLI reference's sentence for account root credentials. An assumed-role session is not that caller: recorded against a real account on 2026-10-29, it is answered NoSuchEntity 404, a code this operation's model declares alongside InvalidUserType, so the two are not one case and that session was being given root's error. The recording is the whole of the change. That session answers the missing key, with the message this package already gives wherever a signing key resolves to no user, which keeps one situation to one wording rather than minting a second. Every other caller keeps InvalidUserType: a session AssumeRoot minted acts as the account root, which is what that error is published for however root signs, and what AWS answers the remaining session kinds is not recorded.
This commit is contained in:
1 parent
48b95fc8c7
commit
eb6998ed2e
3 files changed
+236
-11
No files matched your search
@@ -408,8 +408,7 @@ public class IamQueryHandler {
|
||||
"No access key could be determined from the request.", 404);
|
||||
}
|
||||
return iamService.findUserNameByAccessKeyId(accessKeyId)
|
||||
.orElseThrow(() -> new AwsException("NoSuchEntity",
|
||||
"The Access Key with id " + accessKeyId + " cannot be found.", 404));
|
||||
.orElseThrow(() -> accessKeyNotFound(accessKeyId));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -640,7 +639,8 @@ public class IamQueryHandler {
|
||||
* the CLI reference adds that it "can be called by IAM users only. If this command is called
|
||||
* using AWS account (root) credentials, the command returns an InvalidUserType error". A
|
||||
* signing key that belongs to no stored user is Floci's stand-in for exactly that caller, so
|
||||
* it answers the same way rather than reporting the key as missing.
|
||||
* it answers the same way rather than reporting the key as missing; an assumed-role session
|
||||
* answers {@code NoSuchEntity}, which {@link #callingIamUser} sets out.
|
||||
*/
|
||||
private Response handleChangePassword(MultivaluedMap<String, String> params,
|
||||
String authorization) {
|
||||
@@ -656,16 +656,52 @@ public class IamQueryHandler {
|
||||
|
||||
/**
|
||||
* The IAM user whose access key signed the request, for the one operation that acts on the
|
||||
* caller and gives no way to name anyone else. Unlike {@link #resolveUserName}, a key with no
|
||||
* user behind it is not a missing entity here: the caller is not an IAM user, which is the
|
||||
* case {@code InvalidUserType} is published for.
|
||||
* caller and gives no way to name anyone else. A key with no user behind it is not one caller
|
||||
* but several, and AWS does not answer them all the same way.
|
||||
*
|
||||
* <p>Credentials that belong to no stored user are Floci's stand-in for account root, and the
|
||||
* CLI reference publishes that case: the operation "can be called by IAM users only. If this
|
||||
* command is called using AWS account (root) credentials, the command returns an
|
||||
* InvalidUserType error". That stays the answer for every caller but the one recorded below,
|
||||
* a session minted for the account root included: the error is published for root, however
|
||||
* root signs, and {@code AssumeRoot} mints a session that acts as the account root.
|
||||
*
|
||||
* <p>An assumed-role session is the recorded exception. Taken against a real account on
|
||||
* 2026-10-29, {@code ChangePassword} under one answers {@code NoSuchEntity} 404, a code this
|
||||
* operation's model declares alongside {@code InvalidUserType}, so the two are not one case
|
||||
* and that session must not be given root's error. The recording names the code and not the
|
||||
* sentence, so the sentence is {@link #accessKeyNotFound}'s, the one this package already
|
||||
* answers wherever a signing key resolves to no user, which keeps one situation to one
|
||||
* wording. What AWS answers the other session kinds is not recorded, so they keep the error
|
||||
* they had.
|
||||
*/
|
||||
private String callingIamUser(String authorization) {
|
||||
String accessKeyId = accountResolver.extractAccessKeyId(authorization);
|
||||
return iamService.findUserNameByAccessKeyId(accessKeyId)
|
||||
.orElseThrow(() -> new AwsException("InvalidUserType",
|
||||
"The request was rejected because the type of user for the transaction "
|
||||
+ "was incorrect.", 400));
|
||||
.orElseThrow(() -> signedByAnAssumedRole(accessKeyId)
|
||||
? accessKeyNotFound(accessKeyId)
|
||||
: new AwsException("InvalidUserType",
|
||||
"The request was rejected because the type of user for the "
|
||||
+ "transaction was incorrect.", 400));
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether an assumed-role session signed the request, the one caller with no stored user
|
||||
* behind it that is answered a missing key rather than root's error. The principal type is
|
||||
* what separates them rather than the key's own prefix, which every session shares: a
|
||||
* privileged session and a session the root credential minted each report the account,
|
||||
* being the root they act as.
|
||||
*/
|
||||
private boolean signedByAnAssumedRole(String accessKeyId) {
|
||||
return iamService.resolveCallerArns(accessKeyId)
|
||||
.filter(caller -> IamService.CallerArns.TYPE_ASSUMED_ROLE.equals(caller.principalType()))
|
||||
.isPresent();
|
||||
}
|
||||
|
||||
/** The error a signing key that resolves to no stored user answers, wherever one is read. */
|
||||
private static AwsException accessKeyNotFound(String accessKeyId) {
|
||||
return new AwsException("NoSuchEntity",
|
||||
"The Access Key with id " + accessKeyId + " cannot be found.", 404);
|
||||
}
|
||||
|
||||
private String loginProfileXml(LoginProfile profile) {
|
||||
|
||||
Reference in new issue
Block a user