fix(iam): read a status and a service principal from the model (#7265)

Two members were held back from the vendored shapes because this service was
read as answering them in a wording of its own. Captures from a real account,
posted on issue #6042, answer both, and neither reading holds.

`statusType` is shared by `UpdateAccessKey`, `UpdateSigningCertificate`,
`UpdateSSHPublicKey` and `UpdateServiceSpecificCredential`. One hand-written
check answered all four, naming neither the offending value nor the permitted
set, which is what a 2025 recording of one of them carries. AWS names the set,
`Member must satisfy enum value set: [Expired, Active, Inactive]`, and answers
an omitted status as the required member it is rather than as a value outside
the set, which one check reading a null as a bad value could not tell apart.
Both are the model's own wording, so all four read it through the Query front
door and the check comes out.

The set is listed in the order AWS lists it, which is not the order botocore
declares. The values are the model's and the generator holds them to it: only
their order is read from the capture.

`AWSServiceName` on `CreateServiceLinkedRole` answered `InvalidInput` with a
sentence about its own bounds, where AWS answers a constraint violation naming
the declared pattern. A principal that satisfies the pattern and names no
service AWS has is still `InvalidInput`, so the layering the capture leaves in
place is the shape first and then whether the service exists.

The required-member message loses the word that stood where the value would
go. IAM names a member and leaves its value out everywhere, and the one
message carrying `Value null at` did so for want of a capture either way; the
capture answers `Value at 'status'`. The form moves in the one object that
decides it, so the eight refusals this package writes by hand move with the
walk, and the services that do quote their values keep the word.

The message quotes the pattern AWS quotes, which is not the one the shape
declares. botocore aliases that member to the shape it gives a group name,
`[\w+=,.@-]+` at 1 to 128 characters, where AWS's message gives
`[\w+=.@-]*`: the comma is gone and a `*` stands where the minimum is 1.
Only the message is in hand rather than the shape, so the generator records
AWS's text beside the model's and one object decides which text any
violation quotes, the way the enum order is read from the capture while the
values stay the model's. A comma is still admitted and an empty principal
still refused, and an empty one now breaks the minimum and the pattern at
once, as every other string member here does. The comma is what a second
capture would settle, and the difference is recorded in
`docs/services/iam.md`.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-02 07:53:11 -06:00
1 parent 9fc5be5ceb
commit b4c539d009
26 files changed
+502 -194

No files matched your search

@@ -255,7 +255,7 @@ public final class QueryConstraintCheck {
.filter(entry -> params.getFirst(entry.prefix() + ".key") != null)
.toList();
if (entries.isEmpty()) {
return required ? List.of(SmithyValidationErrors.notNull(path)) : List.of();
return required ? List.of(messages.notNull(path)) : List.of();
}
String valueShape = shape.path("value").asText();
boolean structure = "structure".equals(shapes.path(valueShape).path("type").asText());
@@ -291,7 +291,7 @@ public final class QueryConstraintCheck {
JsonNode shape = shapes.path(shapeName);
return List.of(messages.mapKeys(path, key, SmithyValidationErrors.constraintSet(
shape.path("min").asInt(0), shape.path("max").asInt(Integer.MAX_VALUE),
shape.path("pattern").asText(null), allowedValues(shape))));
VendoredPatterns.quoted(shape), allowedValues(shape))));
}
/**
@@ -302,7 +302,7 @@ public final class QueryConstraintCheck {
boolean required, MultivaluedMap<String, String> params) {
String value = params == null ? null : params.getFirst(param);
if (value == null) {
return required ? List.of(SmithyValidationErrors.notNull(path)) : List.of();
return required ? List.of(messages.notNull(path)) : List.of();
}
return violations(shapeName, value, path);
}
@@ -325,7 +325,7 @@ public final class QueryConstraintCheck {
.filter(member -> !scalar || params.getFirst(member.prefix()) != null)
.toList();
if (members.isEmpty()) {
return required ? List.of(SmithyValidationErrors.notNull(path)) : List.of();
return required ? List.of(messages.notNull(path)) : List.of();
}
List<String> violations = new ArrayList<>();
violations.addAll(single(SmithyValidationErrors.sizeOutOfRange(path, members.size(),
@@ -352,7 +352,7 @@ public final class QueryConstraintCheck {
boolean present = params != null
&& params.keySet().stream().anyMatch(key -> key.startsWith(param + "."));
if (!present) {
return required ? List.of(SmithyValidationErrors.notNull(path)) : List.of();
return required ? List.of(messages.notNull(path)) : List.of();
}
return structureViolations(shape, param + ".", path + ".", params, Map.of());
}
@@ -382,8 +382,10 @@ public final class QueryConstraintCheck {
Pattern pattern = patterns.get(shapeName);
if (pattern != null && !pattern.matcher(value).matches()) {
// Quoted as the model declares it, which is what AWS answers and what the service docs
// carry, rather than as it was compiled: a wide escape is rewritten to match on.
violations.add(messages.pattern(path, value, shape.path("pattern").asText()));
// carry, rather than as it was compiled: a wide escape is rewritten to match on. One
// member is quoted from a capture instead, where AWS gives a pattern of its own for a
// shape botocore shares, and one object decides which text that is.
violations.add(messages.pattern(path, value, VendoredPatterns.quoted(shape)));
}
violations.addAll(single(enumViolation(shape, value, path)));
return violations;
@@ -96,7 +96,7 @@ public final class RequestConstraintCheck {
throw messages.bounds(path, type, min, max, size);
}
if (patterns.containsKey(name) && !patterns.get(name).matcher(value.asText()).matches()) {
throw messages.pattern(path, shape.get("pattern").asText());
throw messages.pattern(path, VendoredPatterns.quoted(shape));
}
if (shape.has("enum")) {
boolean known = false;
@@ -168,9 +168,12 @@ 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>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.
* <p>A required member the request leaves out differs too, the word {@code null} sitting where
* the value would: a service that quotes its values carries it and one that does not leaves the
* member named alone, which is what {@link #notNull(String)} picks between. A list held to its
* member count and a list checked as a whole read the same either way, the list being what AWS
* names there rather than a value, so {@link SmithyValidationErrors#sizeOutOfRange} and
* {@link SmithyValidationErrors#notAllInEnum} stay outside this form.
*/
public static final class Violations {
@@ -186,6 +189,18 @@ public final class SmithyValidationErrors {
this.quoted = quoted;
}
/**
* The violation for a required member the request leaves out. The word {@code null} stands
* where the value would, so a form that quotes its values writes it and a form that does
* not names the member alone, "Value at 'status' failed to satisfy constraint: Member must
* not be null", which is what IAM was captured answering for an omitted {@code Status}.
*/
public String notNull(String path) {
return quoted
? SmithyValidationErrors.notNull(path)
: SmithyValidationErrors.notNullWithoutValue(path);
}
/** One violation naming {@code constraint}, carrying {@code value} where this form does. */
public String constraint(String path, String value, String constraint) {
String member = quoted ? "Value '" + value + "' at '" : "Value at '";
@@ -1,11 +1,13 @@
package io.github.hectorvent.floci.core.common;
import com.fasterxml.jackson.databind.JsonNode;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Compiles a pattern a vendored AWS model declares, in the dialect the model writes it in rather
* than in Java's.
* than in Java's, and answers which text a violation on it quotes.
*
* <p>One thing differs between the two. A model writes a code point above U+FFFF as a backslash-u
* escape of five or six hex digits, the U+10000 to U+10FFFF range on STS's {@code arnType} among
@@ -36,6 +38,21 @@ public final class VendoredPatterns {
return Pattern.compile(rewrite(pattern));
}
/**
* The pattern a violation on {@code shape} quotes: the text AWS quotes for that member where
* the vendored shape records one, and the pattern the model declares everywhere else, which is
* also what a value is matched against either way.
*
* <p>The two differ where AWS's message gives a pattern of its own for a member botocore
* aliases to a shape it shares, IAM's {@code AWSServiceName} on {@code CreateServiceLinkedRole}
* being the one such member vendored today: AWS quotes a class without the comma the shape
* admits. Only the message is in hand rather than the shape, so the generator records AWS's
* text beside the model's and what the request is held to stays the model's own.
*/
public static String quoted(JsonNode shape) {
return shape.path("quotedPattern").asText(shape.path("pattern").asText(null));
}
/**
* {@code pattern} with every wide escape written in Java's form. The digits are read longest
* first, so six of them name the top of Unicode rather than five of them and a stray F, and a
@@ -5,7 +5,6 @@ import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.AwsRegionFacts;
import io.github.hectorvent.floci.core.common.AwsRegions;
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.iam.model.DelegationPermission;
@@ -753,7 +752,7 @@ public class DelegationRequestService {
*/
private static AwsException constraintViolation(String value, String member, String constraint) {
if (value == null) {
return SmithyValidationErrors.validationError(SmithyValidationErrors.notNull(member));
return IamValidationErrors.notNull(member);
}
return IamValidationErrors.validationError(member, value, constraint);
}
@@ -1409,8 +1409,7 @@ public class IamQueryHandler {
// empty Description is a value that clears the description, not an absent member.
String description = params.getFirst("Description");
if (description == null) {
throw SmithyValidationErrors.validationError(
SmithyValidationErrors.notNull("description"));
throw IamValidationErrors.notNull("description");
}
IamRole role = iamService.updateRoleDescription(getParam(params, "RoleName"), description);
String result = new XmlBuilder().start("Role").raw(roleXml(role, true)).end("Role").build();
@@ -3616,8 +3615,7 @@ public class IamQueryHandler {
private String requireParam(MultivaluedMap<String, String> params, String name) {
String value = params.getFirst(name);
if (value == null || value.isBlank()) {
throw SmithyValidationErrors.validationError(
SmithyValidationErrors.notNull(memberPath(name)));
throw IamValidationErrors.notNull(memberPath(name));
}
return value;
}
@@ -186,8 +186,6 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
/** CSPRNG for long-term secret access keys; ordinary resource IDs keep using {@link ThreadLocalRandom}. */
private final SecureRandom secureRandom = new SecureRandom();
/** AWSServiceName as AWS constrains it: 1-128 characters of {@code [\w+=,.@-]}. */
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;
@@ -284,16 +282,9 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
private static final Set<String> SSH_PUBLIC_KEY_ENCODINGS = Set.of("SSH", "PEM");
/** certificateIdType is 24 to 128 of [\w]+, so a 32-character id sits inside that. */
private static final int SIGNING_CERTIFICATE_ID_LENGTH = 32;
/** Two of {@code statusType}'s values, which this service writes itself where the model reads the set. */
private static final String CREDENTIAL_STATUS_ACTIVE = "Active";
private static final String CREDENTIAL_STATUS_EXPIRED = "Expired";
/**
* statusType's values, shared by access keys, signing certificates, SSH public keys and
* service-specific credentials: Active, Inactive and Expired. Each operation's prose explains
* only the first two, so the third is easy to reject by mistake, while the API Reference lists
* all three as valid on each of them.
*/
private static final Set<String> CREDENTIAL_STATUSES =
Set.of(CREDENTIAL_STATUS_ACTIVE, "Inactive", CREDENTIAL_STATUS_EXPIRED);
/** {@code certificateBodyType} and {@code privateKeyType} are both 1 to 16384 characters. */
private static final int MAX_CERTIFICATE_BODY_LENGTH = 16384;
/** {@code certificateChainType} is far larger, at 1 to 2097152. */
@@ -1274,7 +1265,8 @@ 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 keeps the refused description out of the error body, where a control
* <p>The rendering names the member and not the offending value, which is IAM's form
* throughout. 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) {
@@ -1308,7 +1300,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
return;
}
if (roleName == null) {
throw SmithyValidationErrors.validationError(SmithyValidationErrors.notNull("roleName"));
throw IamValidationErrors.notNull("roleName");
}
throw IamValidationErrors.validationError("roleName", roleName, constraint);
}
@@ -1423,22 +1415,6 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
* {@code _}, and that attribute forces replacement, so a name without one never converges.
*/
public IamRole createServiceLinkedRole(String awsServiceName, String customSuffix, String description) {
if (awsServiceName == null) {
throw SmithyValidationErrors.validationError(SmithyValidationErrors.notNull("aWSServiceName"));
}
String constraint;
if (awsServiceName.isEmpty()) {
constraint = "Member must have length greater than or equal to 1";
} else if (awsServiceName.length() > 128) {
constraint = "Member must have length less than or equal to 128";
} else if (!SERVICE_PRINCIPAL_PATTERN.matcher(awsServiceName).matches()) {
constraint = "Member must satisfy regular expression pattern: [\\w+=.@-]*";
} else {
constraint = null;
}
if (constraint != null) {
throw IamValidationErrors.validationError("aWSServiceName", awsServiceName, constraint);
}
if (customSuffix != null && !customSuffix.isEmpty()
&& !CUSTOM_SUFFIX_PATTERN.matcher(customSuffix).matches()) {
throw new AwsException("InvalidInput",
@@ -2446,12 +2422,12 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
}
/**
* Sets an access key's status, validated before the key is looked up the way the other three
* {@code statusType} operations validate theirs: a status outside the enum is answered for the
* status whether or not the key exists.
* Sets an access key's status. The status is held to {@code statusType} ahead of this, by the
* model the Query front door reads, so a value outside the set and an omitted one are both
* answered before any key is looked up. The CloudFormation provisioner validates the status it
* resolves from a template before it calls here, that path having no front door of its own.
*/
public void updateAccessKey(String userName, String accessKeyId, String status) {
requireStatusFromEnum(status);
synchronized (accessKeyLock) {
AccessKey key = userAccessKey(userName, accessKeyId);
key.setStatus(status);
@@ -2920,8 +2896,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
*/
private static void validatePassword(String password, String member) {
if (password == null) {
throw SmithyValidationErrors.validationError(
SmithyValidationErrors.notNull(member));
throw IamValidationErrors.notNull(member);
}
if (!LOGIN_PROFILE_PASSWORD_PATTERN.matcher(password).matches()) {
throw SmithyValidationErrors.validationError(
@@ -2963,8 +2938,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
*/
private void validateIamResourceName(String value, String paramName) {
if (value == null) {
throw SmithyValidationErrors.validationError(
SmithyValidationErrors.notNull(memberPath(paramName)));
throw IamValidationErrors.notNull(memberPath(paramName));
}
if (!IAM_RESOURCE_NAME_PATTERN.matcher(value).matches()) {
throw IamValidationErrors.validationError(memberPath(paramName), value,
@@ -3013,8 +2987,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
*/
public void putAccountProperties(Map<String, String> properties) {
if (properties == null || properties.isEmpty()) {
throw SmithyValidationErrors.validationError(
SmithyValidationErrors.notNull("properties"));
throw IamValidationErrors.notNull("properties");
}
String namespace = null;
for (Map.Entry<String, String> entry : properties.entrySet()) {
@@ -3458,25 +3431,6 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
return getServerCertificate(name).getTags();
}
// Credential status, shared by the four operations that take statusType
// =========================================================================
/**
* {@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) {
throw SmithyValidationErrors.validationError(
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")));
}
}
// Signing certificates
// =========================================================================
@@ -3532,7 +3486,6 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
}
public void updateSigningCertificate(String userName, String certificateId, String status) {
requireStatusFromEnum(status);
synchronized (signingCertificateLock) {
SigningCertificate certificate = userSigningCertificate(userName, certificateId);
certificate.setStatus(status);
@@ -3696,7 +3649,6 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
}
public void updateSshPublicKey(String userName, String keyId, String status) {
requireStatusFromEnum(status);
synchronized (sshPublicKeyLock) {
SshPublicKey stored = userSshPublicKey(userName, keyId);
stored.setStatus(status);
@@ -3970,7 +3922,6 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
public void updateServiceSpecificCredential(String userName, String credentialId,
String status) {
requireCredentialIdFormat(credentialId);
requireStatusFromEnum(status);
synchronized (serviceCredentialLock) {
ServiceSpecificCredential credential = userServiceCredential(userName, credentialId);
credential.setStatus(status);
@@ -10,9 +10,12 @@ 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 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}.
* <p>A message AWS itself writes with the value is not forced through here: a list checked as a
* whole carries the list. A required member the request leaves out used to read
* {@code Value null at '<member>'} for want of a capture either way; one arrived on 2026-10-31,
* answering an omitted {@code Status} as {@code Value at 'status' failed to satisfy constraint:
* Member must not be null}, so the word {@code null} comes out with every other value this service
* leaves out and {@link #notNull} is where that is decided.
*/
final class IamValidationErrors {
@@ -23,6 +26,15 @@ final class IamValidationErrors {
private IamValidationErrors() {
}
/**
* The 400 {@code ValidationError} for a required member the request leaves out, named with no
* value and no {@code null} beside it. Captured from a real account on 2026-10-31 against the
* {@code Status} the four credential operations share.
*/
static AwsException notNull(String path) {
return SmithyValidationErrors.validationError(MESSAGES.notNull(path));
}
/**
* The 400 {@code ValidationError} for one violation of {@code constraint} by {@code value} at
* {@code path}. The value is taken even though IAM's form leaves it out, so that the one place
@@ -2,7 +2,6 @@ package io.github.hectorvent.floci.services.iam;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.iam.model.OrganizationsAccessReportJob;
@@ -282,7 +281,7 @@ public class OrganizationsAccessReportService {
*/
private static AwsException validationError(String value, String at, String constraint) {
if (value == null) {
return SmithyValidationErrors.validationError(SmithyValidationErrors.notNull(at));
return IamValidationErrors.notNull(at);
}
return IamValidationErrors.validationError(at, value, constraint);
}