Seven writes take an IAM policy document and every one of them models
MalformedPolicyDocument, "the request was rejected because the policy document was
malformed". None of them answered it, so a document that was no policy at all was
stored and told apart only later, when something tried to decide with it. A role's
trust policy was the sharpest case: the trust evaluator reads a document it cannot
parse as matching nothing, so a role written that way could no longer be assumed.
The reading goes in IamService rather than at the Query front door, for two reasons.
Three CloudFormation provisioners write these documents straight through the service
and would otherwise be held to nothing. And the order AWS answers in differs per
operation, which only the service can express: CreateRole, CreatePolicy,
CreatePolicyVersion and UpdateAssumeRolePolicy read the document before the name
clash or the entity lookup, where PutUserPolicy, PutGroupPolicy and PutRolePolicy
answer NoSuchEntity for a holder that is not there whatever document the request
carried.
Which reading an operation asks for follows what the document is. A trust policy is
held to the grammar alone and under its own validator's wording, "This policy
contains invalid Json" for a text that does not parse as a JSON object and "Policy
has no statements" for an object carrying no Statement, the element the grammar
requires; its statements name a principal rather than resources, so an identity
statement's elements are not asked of it. An inline policy is held to that grammar
under the identity validator's one sentence for both, "Syntax errors in policy.",
and to the values the language defines: a Version outside 2012-10-17 and 2008-10-17,
an Effect that is not literally Allow or Deny, and a resource named neither by ARN
nor by the wildcard. A managed policy is held to those and to each statement's own
elements, "Policy statement must contain actions." and "Policy statement must
contain resources.".
None of those sentences is published and none is captured. They are the ones AWS's
own emulator answers, a first-party implementation rather than a recording, and the
split between the two validators' wordings is its reading too, which
docs/services/iam.md records.
The grammar is read in one place, not two. #8164 landed
IamPolicyEvaluator.readsAsPolicyDocument for a document a request supplies to the two
simulators or the two context-key readers, which asks exactly what the writes ask of
the top level: parses as a JSON object, and carries Statement. The writes need to know
which of the two failed in order to word their refusal, so the reading lives here and
that method is now its boolean face rather than a second copy of it.
Putting a document back is not a new write. A failed CloudFormation update restores
the trust policy, the inline policy or the policy version it captured before the
attempt, and a document an earlier release accepted must not be refused on the way
back: that would leave the role or the policy without what the rollback had just
removed, and the stack unable to roll back at all. So those three writes keep the
reading on their public entry point and the provisioners restore through
restoreAssumeRolePolicy, restoreRolePolicy and restorePolicyVersion, which apply the
same write without it. The inline-policy provisioner already restored by writing the
captured document straight back, so it needed nothing. This is the same rule as
reading a stored document exactly as it was, applied to the one path that writes one.
The whole text has to be the document. A member taking one takes "the complete, valid
JSON text of an IAM policy", and Jackson reads the first value and stops unless it is
told otherwise, so an object with anything after it parsed as a policy. The reader
enables FAIL_ON_TRAILING_TOKENS, which is what the reference implementation's parser
does by construction.
A null document is nothing to judge: a required member the request leaves out is
answered as absent by the constraints ahead of the operation. What is already stored
is read exactly as it was, so a document an earlier version accepted still decides
what it decided.
Holding every caller means holding the fixtures too, the compatibility suites
included: a Python and a Java SDK test each wrote an inline policy carrying only
Version, and two roles in the EKS access-entry test were created with a trust policy
of {}. All three are documents IAM refuses, the first two being the case recorded for
a document that is valid JSON carrying only Version.
Holding every caller means holding the fixtures too. Filler documents across the test
tree, "{}" as a trust policy chief among them, were documents real AWS refuses; they
now come from one place, io.floci.aws.testing.IamTestPolicies, which also answers a
distinct document per marker for a test that needs several. Two fixtures changed in
substance rather than in spelling: a Step Functions policy meant to name another
event bus named it by bare name, which an identity policy may not, and a managed
policy version's statements named no action.
* test: move compatibility tests into this repo
* fix: add StatisticValues parsing to CloudWatchMetricsJsonHandler
* fix: add missing required abstract methods to EmulatorConfig in EventBridgeSchedulerIntegrationTest
* test: add sdk tests for multipart S3 copy coverage
* fix: cover and fix smithy cbor and multipart s3 copy regressions
* test: migrate more test coverage to new folder
* test: add missing ec2 expectation in healthcheck test
* docs: update READMEs in `./compatibility-tests`