mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(iam): refuse an action no vendor prefaces on the way in (#8428)
No write read the values a statement's action elements name, so a document naming a bare verb was stored and only told apart later, by whatever tried to decide with it. AWS refuses that document before it stores anything, with MalformedPolicyDocument at 400 and the clause's own sentence, "Actions/Conditions must be prefaced by a vendor, e.g., iam, sdb, ec2, etc.", fixed text with no request value in it. The resource elements beside them have been read value by value for a while, so this is the action half of the same clause check. The policy grammar writes an action as a service namespace, a colon and the name of an action, and an action element may name the bare wildcard instead, which stands for every action there is. So a value passes when it is "*" or carries a namespace before a colon, whatever the name after it spells: "s3:*" and "iam:*AccessKey*" are the reference's own examples of a wildcard inside the name. A value that is no string is held to the text it spells, as the Version, the Effect and the resource values already are, so "Action": 123 is refused where "Action": "123" was; an element carrying null still names nothing, which is the element's own sentence rather than a value to read. The namespace is asked for rather than looked up. No sentence anywhere says AWS refuses an action whose vendor it does not publish, so reading these values against a catalog of services would refuse documents AWS stores and would make an action of a service this emulator has yet to model impossible to write. What is read is the shape the grammar gives, nothing more. Both identity validators word this clause alike, the effect being the one clause of an identity document whose sentence follows the validator that read it. The actions are read before the resources, which is the order the elements a statement must carry are already read in, so a document missing both answers the action sentence first. No code and no status moves: the refusal is MalformedPolicyDocument at 400, as every other sentence of this reader is. AWS words the clause for actions and condition keys together and only the actions are read here, a condition key being a value neither validator reads yet.
This commit is contained in:
1 parent
31c86c05e9
commit
a8c34f6326
4 files changed
+133
-14
No files matched your search
@@ -34,6 +34,9 @@ class IamPolicyDocumentWriteIntegrationTest {
|
||||
|
||||
private static final String MALFORMED = "MalformedPolicyDocument";
|
||||
|
||||
private static final String ACTIONS_WANT_A_VENDOR =
|
||||
"Actions/Conditions must be prefaced by a vendor, e.g., iam, sdb, ec2, etc.";
|
||||
|
||||
/** Everything these tests create outlives the class otherwise: the emulator is shared. */
|
||||
@RegisterExtension
|
||||
final PartitionCleanup cleanup = new PartitionCleanup();
|
||||
@@ -383,4 +386,70 @@ class IamPolicyDocumentWriteIntegrationTest {
|
||||
"The policy failed legacy parsing");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An action is written as a service namespace, a colon and the name of an action, so one that
|
||||
* no vendor prefaces is refused with the clause's own sentence, which both identity validators
|
||||
* word alike. A value that is no string is held to the rule its text would be, as the resource
|
||||
* values beside it are.
|
||||
*/
|
||||
@Test
|
||||
void anActionNoVendorPrefacesIsRefusedByBothValidators() {
|
||||
String userName = createUser("write-action-vendor");
|
||||
String arn = createManagedPolicy("write-action-vendor");
|
||||
String bare = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","
|
||||
+ "\"Action\":\"GetObject\",\"Resource\":\"*\"}]}";
|
||||
String inAList = "{\"Statement\":[{\"Effect\":\"Allow\","
|
||||
+ "\"Action\":[\"s3:GetObject\",\"ListAllMyBuckets\"],\"Resource\":\"*\"}]}";
|
||||
String notAction = "{\"Statement\":[{\"Effect\":\"Allow\",\"NotAction\":\"ChangePassword\","
|
||||
+ "\"Resource\":\"*\"}]}";
|
||||
String noString = "{\"Statement\":[{\"Effect\":\"Allow\",\"Action\":123,\"Resource\":\"*\"}]}";
|
||||
|
||||
for (String document : new String[] {bare, inAList, notAction, noString}) {
|
||||
expectMalformed(inlinePolicyWrite(userName, "write-action-vendor", document),
|
||||
ACTIONS_WANT_A_VENDOR);
|
||||
expectMalformed(managedPolicyWrite("write-action-vendor-managed", document),
|
||||
ACTIONS_WANT_A_VENDOR);
|
||||
expectMalformed(iam("CreatePolicyVersion")
|
||||
.formParam("PolicyArn", arn)
|
||||
.formParam("PolicyDocument", document),
|
||||
ACTIONS_WANT_A_VENDOR);
|
||||
}
|
||||
|
||||
// An action element naming nothing is the element's own sentence rather than this one.
|
||||
expectMalformed(managedPolicyWrite("write-action-none",
|
||||
"{\"Statement\":[{\"Effect\":\"Allow\",\"Action\":null,\"Resource\":\"*\"}]}"),
|
||||
"Policy statement must contain actions.");
|
||||
}
|
||||
|
||||
/**
|
||||
* What the rule admits: the bare wildcard, which stands for every action there is, and a
|
||||
* namespace before a colon whatever the name after it spells, the wildcards the reference
|
||||
* writes into an action name included. The vendor is asked for rather than looked up, so an
|
||||
* action of a service this emulator does not model is stored as written.
|
||||
*/
|
||||
@Test
|
||||
void anActionThatNamesAVendorIsStoredWhateverTheNameSpells() {
|
||||
String userName = createUser("write-action-admitted");
|
||||
|
||||
for (String action : new String[] {"\"*\"", "[\"*\"]", "\"s3:*\"", "\"iam:*AccessKey\"",
|
||||
"\"*:GetObject\"", "\"nosuchservice:DoThing\"", "[\"s3:Get*\",\"s3:List*\"]"}) {
|
||||
String document = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","
|
||||
+ "\"Action\":" + action + ",\"Resource\":\"*\"}]}";
|
||||
String policyName = unique("write-action-admitted");
|
||||
|
||||
inlinePolicyWrite(userName, policyName, document)
|
||||
.when().post("/").then().statusCode(200);
|
||||
iam("GetUserPolicy")
|
||||
.formParam("UserName", userName)
|
||||
.formParam("PolicyName", policyName)
|
||||
.when().post("/").then().statusCode(200);
|
||||
// The holder has to be deletable afterwards, and a user keeping an inline policy is
|
||||
// not, so each case takes its own back out.
|
||||
iam("DeleteUserPolicy")
|
||||
.formParam("UserName", userName)
|
||||
.formParam("PolicyName", policyName)
|
||||
.when().post("/").then().statusCode(200);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user