mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
feat(iam): dispatch UpdateRoleDescription, the description half of UpdateRole (#6029)
UpdateRoleDescription answered UnsupportedOperation 400, where the reference publishes it as a role operation of its own: "Use UpdateRole instead", and "modifies only the description of a role. This operation performs the same function as the Description parameter in the UpdateRole operation". So it is that path rather than a second one. updateRole now answers the role it wrote, updateRoleDescription is that call with the session duration left alone, and the roleNameType check comes along rather than being restated. The handler renders the Role the operation answers through the same roleXml fragment GetRole and CreateRole use, detailed, there being no documented exclusion to honour: the page's Response Elements section lists one Role object and says only that it "contains details about the modified role". Both members are required here, where UpdateRole's are optional, and that is the one place this does not simply delegate. Description is read off the request rather than through requireParam, which reads a blank value as an absent member: roleDescriptionType carries a maximum of 1000 and no minimum, so an empty description is a value that clears the description and only a missing one is a refusal. It is rendered the way the handler renders every other missing required member, "Value null at 'description' failed to satisfy constraint: Member must not be null". RoleName is answered for by validateRoleName, which reads a null as "Member must not be null" and a bad shape before any lookup, as the other 21 roleNameType operations have since #5391. A service-linked role takes a description edit, through either action. The user guide says so plainly, "You can edit the description of any role from the IAM console, API, or CLI", its own procedure for editing one is update-role with --description or the UpdateRoleDescription API, and it publishes a policy granting iam:UpdateRoleDescription over arn:aws:iam::*:role/aws-service-role/* for that. Both actions model UnmodifiableEntity, and a modelled error is not a list of what triggers it: the guard now stands on MaxSessionDuration, the only other member UpdateRole takes. So a description-only UpdateRole goes through where it was refused before, a request carrying both is refused whole with neither field written, and the other ten protected role actions are untouched. Authorization needed nothing. AWS gives the action the role resource type in the vendored authorization metadata, NAME_PARAMETERS already maps role to RoleName, and ResourceArnBuilder mints the ARN from the stored role, so the action is authorized against that role rather than against the wildcard. The routing table has carried the name since routing became generated from the model, so what changed there is only that it stops falling through to the unsupported-action arm. A role Description is held to the shape AWS publishes for it, and on every action that takes one rather than only the new one: at most 1000 characters of [\u0009\u000A\u000D -~¡-ÿ], which admits tab, newline and carriage return and no other control character. CreateRole, UpdateRole, UpdateRoleDescription and CreateServiceLinkedRole share one validateRoleDescription, run before the role is looked up or created, so a refused description never reaches a stored role. That is more than strictness. XmlBuilder escapes the five XML entities and passes everything else through, so a control character stored in a description would make the Role these actions and GetRole answer unparsable, which CreateRole could already produce before this. The rendering names neither the offending value nor the set, following the one IAM constraint message a recording covers, which also keeps the refused bytes out of the error body they would otherwise break. Reverting the three call sites fails the maximum, the control character and the sibling cases and nothing else. Sixteen tests. Ten over the wire in IamRoleDescriptionIntegrationTest: the description applied and answered, an empty description clearing it, the session duration and the trust policy untouched, the maximum taken and one character past it refused with the stored description intact, a control character refused while tab and newline are taken, CreateRole and UpdateRole answering the same way with nothing stored, an absent Description refused with the role left as it was, an absent RoleName, a name outside the shape refused ahead of the lookup, and an unknown role answering NoSuchEntity. Four on the service: the role that comes back, the shape across the create and update paths, the name read before the lookup, and a service-linked role taking the edit while refusing the duration. Two in IamServiceLinkedRoleIntegrationTest: that allowance over the wire, and CreateServiceLinkedRole answering ValidationError for a description outside the shape rather than its own InvalidInput. The protected-actions test pins UpdateRole on MaxSessionDuration, which is what AWS protects there. Docs carry the table row, the three ways this differs from UpdateRole, the description constraint and why it matters for the answer, the carve-out in the service-linked section, and the matrix row at 176, which check_service_matrix reads off the handler's own switch rather than taking the number on trust.
This commit is contained in:
1 parent
77c5d74a7d
commit
94b09ff46b
7 files changed
+472
-12
No files matched your search
@@ -207,6 +207,7 @@ public class IamQueryHandler {
|
||||
case "DeleteRole" -> handleDeleteRole(params);
|
||||
case "ListRoles" -> handleListRoles(params);
|
||||
case "UpdateRole" -> handleUpdateRole(params);
|
||||
case "UpdateRoleDescription" -> handleUpdateRoleDescription(params);
|
||||
case "CreateServiceLinkedRole" -> handleCreateServiceLinkedRole(params);
|
||||
case "DeleteServiceLinkedRole" -> handleDeleteServiceLinkedRole(params);
|
||||
case "GetServiceLinkedRoleDeletionStatus" -> handleGetServiceLinkedRoleDeletionStatus(params);
|
||||
@@ -1423,6 +1424,24 @@ public class IamQueryHandler {
|
||||
return Response.ok(AwsQueryResponse.envelopeNoResult("UpdateRole", AwsNamespaces.IAM)).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* The description half of UpdateRole, which AWS's own reference opens by telling callers to use
|
||||
* instead. Both members are required here, where UpdateRole's are optional, and the modified
|
||||
* role comes back, which UpdateRole does not answer at all.
|
||||
*/
|
||||
private Response handleUpdateRoleDescription(MultivaluedMap<String, String> params) {
|
||||
// Read rather than requireParam: roleDescriptionType declares no minimum length, so an
|
||||
// empty Description is a value that clears the description, not an absent member.
|
||||
String description = params.getFirst("Description");
|
||||
if (description == null) {
|
||||
throw SmithyValidationErrors.validationError(
|
||||
"Value null at 'description' failed to satisfy constraint: Member must not be null");
|
||||
}
|
||||
IamRole role = iamService.updateRoleDescription(getParam(params, "RoleName"), description);
|
||||
String result = new XmlBuilder().start("Role").raw(roleXml(role, true)).end("Role").build();
|
||||
return Response.ok(AwsQueryResponse.envelope("UpdateRoleDescription", AwsNamespaces.IAM, result)).build();
|
||||
}
|
||||
|
||||
private Response handleUpdateAssumeRolePolicy(MultivaluedMap<String, String> params) {
|
||||
iamService.updateAssumeRolePolicy(requireParam(params, "RoleName"),
|
||||
requireParam(params, "PolicyDocument"));
|
||||
|
||||
@@ -193,6 +193,17 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
private static final Pattern SERVICE_PRINCIPAL_PATTERN = Pattern.compile("[\\w+=,.@-]{1,128}");
|
||||
/** CustomSuffix as AWS constrains it: 1-64 characters of {@code [\w+=,.@-]}. */
|
||||
private static final Pattern CUSTOM_SUFFIX_PATTERN = Pattern.compile("[\\w+=,.@-]{1,64}");
|
||||
private static final int ROLE_DESCRIPTION_MAX_LENGTH = 1000;
|
||||
/**
|
||||
* roleDescriptionType's character set, which AWS writes as
|
||||
* {@code [\u0009\u000A\u000D\u0020-\u007E\u00A1-\u00FF]*}: tab, newline, carriage
|
||||
* return, printable ASCII and the Latin-1 supplement, and no other control character.
|
||||
* Written here the way {@code java.util.regex} reads it.
|
||||
*/
|
||||
private static final Pattern ROLE_DESCRIPTION_PATTERN = Pattern.compile("[\\t\\n\\r\\x20-\\x7E\\xA1-\\xFF]*");
|
||||
/** AWS's own spelling of that set, for the message, where the regex form would not be AWS's. */
|
||||
private static final String ROLE_DESCRIPTION_PATTERN_TEXT =
|
||||
"[\\u0009\\u000A\\u000D\\u0020-\\u007E\\u00A1-\\u00FF]*";
|
||||
private static final int ROLE_NAME_MAX_LENGTH = 64;
|
||||
/** roleNameType's character set. Excluding {@code :} is what reserves names such as {@code aws:ec2-instance} for AWS. */
|
||||
private static final Pattern ROLE_NAME_PATTERN = Pattern.compile("[\\w+=,.@-]+");
|
||||
@@ -1159,6 +1170,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
String description, int maxSessionDuration, Map<String, String> tags,
|
||||
String permissionsBoundaryArn) {
|
||||
validateRoleName(roleName);
|
||||
validateRoleDescription(description);
|
||||
if (permissionsBoundaryArn != null) {
|
||||
requirePolicy(permissionsBoundaryArn); // validate before anything is created
|
||||
}
|
||||
@@ -1209,6 +1221,36 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
return roles.get(roleName);
|
||||
}
|
||||
|
||||
/**
|
||||
* roleDescriptionType: at most 1000 characters of the set AWS publishes, which admits tab,
|
||||
* newline and carriage return and no other control character. Enforced wherever a role
|
||||
* description is taken, so {@code CreateRole}, {@code UpdateRole},
|
||||
* {@code UpdateRoleDescription} and {@code CreateServiceLinkedRole} answer the same way, and
|
||||
* so a character XML cannot carry never reaches a stored role: {@code XmlBuilder} escapes the
|
||||
* 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
|
||||
* character would break the answer it is being refused for.
|
||||
*/
|
||||
private static void validateRoleDescription(String description) {
|
||||
if (description == null) {
|
||||
return;
|
||||
}
|
||||
String constraint;
|
||||
if (description.length() > ROLE_DESCRIPTION_MAX_LENGTH) {
|
||||
constraint = "Member must have length less than or equal to " + ROLE_DESCRIPTION_MAX_LENGTH;
|
||||
} else if (!ROLE_DESCRIPTION_PATTERN.matcher(description).matches()) {
|
||||
constraint = "Member must satisfy regular expression pattern: " + ROLE_DESCRIPTION_PATTERN_TEXT;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
throw SmithyValidationErrors.validationError(
|
||||
"Value at 'description' failed to satisfy constraint: " + constraint);
|
||||
}
|
||||
|
||||
/** roleNameType: 1-64 characters of {@code [\w+=,.@-]}, reported the way AWS reports a model constraint. */
|
||||
private static void validateRoleName(String roleName) {
|
||||
String constraint;
|
||||
@@ -1258,8 +1300,10 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
|
||||
/**
|
||||
* AWS publishes UnmodifiableEntity on twelve role actions, and its message names the linked
|
||||
* service the caller has to go through instead. This guards the eleven of them the emulator
|
||||
* implements; UpdateRoleDescription is the twelfth and has no handler here. TagRole and
|
||||
* service the caller has to go through instead. This guards the ten of them that refuse a
|
||||
* service-linked role whatever the request asks for. UpdateRole and UpdateRoleDescription are
|
||||
* the other two, and the user guide carves a description out of both, so {@link #updateRole}
|
||||
* reaches for this only where a request asks for more than a description. TagRole and
|
||||
* UntagRole are deliberately not guarded — AWS does not publish the error on either, and
|
||||
* TagRole's reference says the role "can be a regular role or a service-linked role".
|
||||
* Within the IAM API, {@link #deleteServiceLinkedRole} is the only way to remove such a role.
|
||||
@@ -1313,6 +1357,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
throw new AwsException("InvalidInput",
|
||||
"CustomSuffix must be 1-64 characters matching [\\w+=,.@-].", 400);
|
||||
}
|
||||
validateRoleDescription(description);
|
||||
// Most services refuse a suffix outright. The table carries what AWS was recorded
|
||||
// doing, and UNKNOWN keeps taking one rather than refusing on an inference: the name
|
||||
// as the caller sent it, since every recording used the canonical form and the two
|
||||
@@ -1407,13 +1452,40 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
.toList();
|
||||
}
|
||||
|
||||
public void updateRole(String roleName, String description, int maxSessionDuration) {
|
||||
/**
|
||||
* Updates a role's description, its maximum session duration, or both. A service-linked role
|
||||
* takes the description and refuses the duration: "You can edit the description of any role
|
||||
* from the IAM console, API, or CLI", and the user guide's procedure for editing one is this
|
||||
* action, as {@code aws iam update-role --role-name ROLE-NAME --description DESCRIPTION}. So
|
||||
* the protection stands on MaxSessionDuration, the only other member this action takes, and a
|
||||
* request carrying both is refused whole, before the description is written.
|
||||
*/
|
||||
public IamRole updateRole(String roleName, String description, int maxSessionDuration) {
|
||||
validateRoleName(roleName);
|
||||
validateRoleDescription(description);
|
||||
IamRole role = getRole(roleName);
|
||||
requireNotServiceLinked(role, roleName);
|
||||
if (description != null) role.setDescription(description);
|
||||
if (maxSessionDuration > 0) role.setMaxSessionDuration(maxSessionDuration);
|
||||
if (maxSessionDuration > 0) {
|
||||
requireNotServiceLinked(role, roleName);
|
||||
}
|
||||
if (description != null) {
|
||||
role.setDescription(description);
|
||||
}
|
||||
if (maxSessionDuration > 0) {
|
||||
role.setMaxSessionDuration(maxSessionDuration);
|
||||
}
|
||||
roles.put(roleName, role);
|
||||
return role;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies only a role's description. AWS documents UpdateRoleDescription as performing "the
|
||||
* same function as the Description parameter in the UpdateRole operation", so it is that path
|
||||
* with nothing else touched, and it answers the modified role. A service-linked role takes it:
|
||||
* the user guide publishes a policy granting {@code iam:UpdateRoleDescription} on
|
||||
* {@code arn:aws:iam::*:role/aws-service-role/*} for editing the description of one.
|
||||
*/
|
||||
public IamRole updateRoleDescription(String roleName, String description) {
|
||||
return updateRole(roleName, description, 0);
|
||||
}
|
||||
|
||||
public void updateAssumeRolePolicy(String roleName, String policyDocument) {
|
||||
|
||||
Reference in new issue
Block a user