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
@@ -28,8 +28,9 @@ import java.util.List;
|
||||
* required.";</li>
|
||||
* <li>the <em>values</em> the elements declare, which an identity-based document is held to: the
|
||||
* version it declares has to be one the language defines, a statement's {@code Effect} has to
|
||||
* be {@code Allow} or {@code Deny} compared literally, and a resource it names has to be
|
||||
* named by ARN or by the wildcard.</li>
|
||||
* be {@code Allow} or {@code Deny} compared literally, an action it names has to be prefaced
|
||||
* by a vendor or be the bare wildcard, and a resource it names has to be named by ARN or by
|
||||
* the wildcard.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>A managed policy's document is held to its statements' own elements as well, each statement
|
||||
@@ -80,6 +81,16 @@ final class IamPolicyDocuments {
|
||||
*/
|
||||
private static final String POLICY_PARSE_FAILED = "The policy failed legacy parsing";
|
||||
|
||||
/**
|
||||
* What a statement naming an action that no vendor prefaces is refused with. 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.
|
||||
*/
|
||||
private static final String ACTION_WITHOUT_VENDOR =
|
||||
"Actions/Conditions must be prefaced by a vendor, e.g., iam, sdb, ec2, etc.";
|
||||
|
||||
private static final String ANY_ACTION = "*";
|
||||
|
||||
private static final String ANY_RESOURCE = "*";
|
||||
|
||||
private static final String ARN_PREFIX = "arn:";
|
||||
@@ -187,7 +198,12 @@ final class IamPolicyDocuments {
|
||||
if (effect != null && !EFFECTS.contains(effect.asText())) {
|
||||
throw malformed(unreadableEffect);
|
||||
}
|
||||
for (String resource : resourceValues(statement)) {
|
||||
for (String action : elementValues(statement, "Action", "NotAction")) {
|
||||
if (!prefacedByVendor(action)) {
|
||||
throw malformed(ACTION_WITHOUT_VENDOR);
|
||||
}
|
||||
}
|
||||
for (String resource : elementValues(statement, "Resource", "NotResource")) {
|
||||
if (!resource.startsWith(ARN_PREFIX) && !ANY_RESOURCE.equals(resource)) {
|
||||
throw malformed("Resource " + resource + " must be in ARN format or \""
|
||||
+ ANY_RESOURCE + "\".");
|
||||
@@ -267,16 +283,17 @@ final class IamPolicyDocuments {
|
||||
}
|
||||
|
||||
/**
|
||||
* Every value a statement's resource elements name, in the order the document carries them. A
|
||||
* value that is no string names the text of that value, which is how the {@code Version} and
|
||||
* the {@code Effect} above are already read: a number or a boolean is held to naming a resource
|
||||
* rather than passed over, so {@code 123} and {@code "123"} are refused alike. A null names
|
||||
* nothing, as {@link #namesSomething} reads it, and a list or an object is no value of this
|
||||
* element at all.
|
||||
* Every value a statement names under {@code spellings}, in the order the document carries
|
||||
* them, which is how both pattern elements are read: the actions a statement is about and the
|
||||
* resources they apply to. A value that is no string names the text of that value, which is
|
||||
* how the {@code Version} and the {@code Effect} above are already read: a number or a boolean
|
||||
* is held to naming a value of its element rather than passed over, so {@code 123} and
|
||||
* {@code "123"} are refused alike. A null names nothing, as {@link #namesSomething} reads it,
|
||||
* and a list or an object is no value of these elements at all.
|
||||
*/
|
||||
private static List<String> resourceValues(JsonNode statement) {
|
||||
private static List<String> elementValues(JsonNode statement, String... spellings) {
|
||||
List<String> values = new ArrayList<>();
|
||||
for (String spelling : new String[] {"Resource", "NotResource"}) {
|
||||
for (String spelling : spellings) {
|
||||
JsonNode element = statement.get(spelling);
|
||||
if (element == null) {
|
||||
continue;
|
||||
@@ -290,6 +307,20 @@ final class IamPolicyDocuments {
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether an action value names the vendor the language asks for. The 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 is prefaced
|
||||
* when it carries a namespace before a colon, whatever the name after it spells, the wildcards
|
||||
* the reference admits in an action name included ({@code s3:*} and {@code iam:*AccessKey*} are
|
||||
* its own examples). The namespace is asked for rather than looked up: no sentence says AWS
|
||||
* refuses an action whose vendor it does not publish, and refusing one here would turn a
|
||||
* service this emulator has yet to model into a document nobody can store.
|
||||
*/
|
||||
private static boolean prefacedByVendor(String action) {
|
||||
return ANY_ACTION.equals(action) || action.indexOf(':') > 0;
|
||||
}
|
||||
|
||||
private static JsonNode parse(String document) {
|
||||
if (document == null) {
|
||||
return null;
|
||||
|
||||
Reference in new issue
Block a user