mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(iam): check ARNs inside structures and EventBridge's resources (#6561)
The table of request resources read only top-level members, so an
operation naming its resource inside a structure was checked on *:
SetRulePriorities' RulePriorities[].RuleArn and a state machine alias's
routingConfiguration[].stateMachineVersionArn. A member ending in Arn or
Arns one level inside a structure, or inside each of a list's
structures, now names a resource as a top-level one does, the value's
format deciding which of the action's types it is. Such a member never
fills a variable, holds a type or names a create's parent. A form's list
is read to the first element without the field, as the ELB handler
loops.
EventBridge joins the table (71 operations). Its rules are named by the
rule's name on the event bus EventBusName names, by name or by ARN, and
on the default bus when it names none ("If you omit this, the default
event bus is used"), whose rules are rule/<name>, with no bus.
Corrections give the eight rule operations the default bus's rule when
EventBusName is default or absent, and the custom bus's otherwise, with
two new keys: unless, the complement of when, and absent, the value a
missing member is read as. DescribeEventBus naming no bus is checked on
event-bus/default ("If you omit this, the default event bus is
displayed"). A member whose botocore pattern takes an ARN before a name,
(arn:...:event-bus/)?<name>, is recorded as arnOf: an ARN given for it
is read as that type's one variable, and the resource is in the ARN's
account and Region, so a bus of another account, its default bus
included, names that account's rule, as DescribeRule's CreatedBy says,
checked as given and as the caller's own, which Floci acts on. An ARN
leaving its account and Region empty, which EventBridge's handler takes
as the caller's bus of that name, names the caller's, and a JSON null
for a member read as a value when absent is absent too, as the handler's
asText(null) reads it, so a null EventBusName is the default bus.
EventBridge V2's client, AWSEventsV2 over Smithy RPC v2 CBOR, which
Floci does not serve, shares the operations' names and is left out
(clientsNotRead), and verify ignores it.
EventBridge mints a connection's ARN as connection/<name>/<id> and an
API destination's as api-destination/<name>/<id>, as botocore's ARN
patterns give them, and checks a connection on it (the user guide grants
events:RetrieveConnectionCredentials on connection/<name>/*), while the
Service Reference's formats stop at the name. MINTED_IDS records those
types (mintedIds), and a request naming one by its name is checked on
the ARN its service stores it under, which a StoredResourceArns the
service registers finds for the caller in the request's Region
(EventBridgeService does), or on <name>/* when there is none yet, a
create's included.
Not in this change: PutEvents, whose entries each name their bus, stays
on *, and UpdateEventBus with no Name, which no document says is the
default bus, stays on * too.
This commit is contained in:
1 parent
8d5c135f0a
commit
c5e873ff84
12 files changed
+1100
-134
No files matched your search
+62
-10
@@ -71,6 +71,14 @@ class RequestResourceMembersTest {
|
||||
assertFalse(RequestResourceMembers.table().formats().get("states").get("execution").unqualified());
|
||||
}
|
||||
|
||||
@Test
|
||||
void connectionsAndApiDestinationsAreOfTypesWhoseServiceMintsAnIdAfterTheirName() {
|
||||
Map<String, ArnFormat> events = RequestResourceMembers.table().formats().get("events");
|
||||
assertTrue(events.get("connection").minted());
|
||||
assertTrue(events.get("api-destination").minted());
|
||||
assertFalse(events.get("event-bus").minted());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMalformedTableFailsToLoad() {
|
||||
assertThrows(IllegalStateException.class, () -> parse("{\"operations\":{}}"));
|
||||
@@ -81,7 +89,7 @@ class RequestResourceMembersTest {
|
||||
String formats = "\"arnFormats\":{\"a\":{\"thing\":\"arn:${Partition}:a:${Region}:${Account}:thing/${ThingName}\"}}";
|
||||
assertThrows(IllegalStateException.class, () -> parse(document(formats, "{\"types\":[\"other\"],\"arn\":\"Arn\"}")));
|
||||
assertThrows(IllegalStateException.class, () -> parse(document(formats, "{\"type\":\"thing\",\"fill\":{\"Other\":\"Name\"}}")));
|
||||
assertThrows(IllegalStateException.class, () -> parse(document(formats, "{\"types\":[\"thing\"],\"arn\":\"a.b\"}")));
|
||||
assertThrows(IllegalStateException.class, () -> parse(document(formats, "{\"types\":[\"thing\"],\"arn\":\"a.b.c\"}")));
|
||||
assertThrows(IllegalStateException.class, () -> parse(
|
||||
"{\"namespaces\":{\"a\":[]},\"arnFormats\":{\"a\":{\"thing\":\"*\"}},\"operations\":{\"a:Op\":{\"resources\":[]}}}"));
|
||||
// A type made under a parent whose format it does not extend by one id.
|
||||
@@ -92,6 +100,13 @@ class RequestResourceMembersTest {
|
||||
+ "{\"resources\":[],\"creates\":[{\"type\":\"part\",\"parent\":\"thing\",\"arn\":\"ThingArn\"}]}}}"),
|
||||
part);
|
||||
}
|
||||
// A member past one structure, or a structure's member filling a variable.
|
||||
assertThrows(IllegalStateException.class, () -> parse(document(formats, "{\"types\":[\"thing\"],\"arn\":\"A[].B.ThingArn\"}")));
|
||||
assertThrows(IllegalStateException.class, () -> parse(document(formats,
|
||||
"{\"type\":\"thing\",\"fill\":{\"ThingName\":\"A[].Name\"}}")));
|
||||
assertEquals(List.of(new Resource(List.of("thing"), new Member("A", true, new Member("ThingArns", true)), Map.of(),
|
||||
Map.of(), Map.of(), Map.of(), Map.of(), null, null)), parseUnchecked(document(formats, "{\"types\":[\"thing\"],\"arn\":\"A[].ThingArns[]\"}"))
|
||||
.operations().get("a:Op"));
|
||||
// An ARN read before more than one character.
|
||||
assertThrows(IllegalStateException.class, () -> parse(document(formats,
|
||||
"{\"types\":[\"thing\"],\"arn\":\"ThingArn\",\"before\":\"##\"}")));
|
||||
@@ -106,8 +121,30 @@ class RequestResourceMembersTest {
|
||||
+ ",\"unqualified\":{\"a\":[\"other\"]},\"operations\":{\"a:Op\":{\"resources\":[]}}}"));
|
||||
assertThrows(IllegalStateException.class, () -> parse("{\"namespaces\":{\"a\":[]}," + formats
|
||||
+ ",\"unqualified\":{\"a\":\"thing\"},\"operations\":{\"a:Op\":{\"resources\":[]}}}"));
|
||||
// A type given a minted id that has no format, whose format does not end in its one variable, or not a list.
|
||||
String parts = "\"arnFormats\":{\"a\":{\"thing\":\"arn:${Partition}:a:${Region}:${Account}:thing/${ThingName}\","
|
||||
+ "\"part\":\"arn:${Partition}:a:${Region}:${Account}:part/${ThingName}/${PartId}\"}}";
|
||||
for (String bad : List.of("{\"a\":[\"other\"]}", "{\"a\":[\"part\"]}", "{\"a\":\"thing\"}")) {
|
||||
assertThrows(IllegalStateException.class, () -> parse("{\"namespaces\":{\"a\":[]}," + parts
|
||||
+ ",\"mintedIds\":" + bad + ",\"operations\":{\"a:Op\":{\"resources\":[]}}}"), bad);
|
||||
}
|
||||
assertTrue(parseUnchecked("{\"namespaces\":{\"a\":[]}," + parts + ",\"mintedIds\":{\"a\":[\"thing\"]},"
|
||||
+ "\"operations\":{\"a:Op\":{\"resources\":[]}}}").formats().get("a").get("thing").minted());
|
||||
// A member read when absent as no value, or as an ARN of a type with no format or of more than one variable.
|
||||
for (String bad : List.of("\"absent\":{\"Bus\":\"\"}", "\"absent\":{\"Bus[]\":\"default\"}",
|
||||
"\"arnOf\":{\"Bus\":\"other\"}", "\"arnOf\":{\"Bus\":\"part\"}", "\"unless\":{\"Bus\":[]}")) {
|
||||
assertThrows(IllegalStateException.class, () -> parse(document("\"arnFormats\":{\"a\":{"
|
||||
+ "\"thing\":\"arn:${Partition}:a:${Region}:${Account}:thing/${ThingName}\","
|
||||
+ "\"part\":\"arn:${Partition}:a:${Region}:${Account}:part/${ThingName}/${PartId}\"}}",
|
||||
"{\"type\":\"thing\",\"fill\":{\"ThingName\":\"Name\"}," + bad + "}")), bad);
|
||||
}
|
||||
assertEquals(List.of(new Resource(List.of("thing"), null, Map.of("ThingName", new Member("Name", false)),
|
||||
Map.of(), Map.of("Bus", List.of("default")), Map.of("Bus", "default"), Map.of("Bus", "thing"), null, null)),
|
||||
parseUnchecked(document(formats, "{\"type\":\"thing\",\"fill\":{\"ThingName\":\"Name\"},"
|
||||
+ "\"unless\":{\"Bus\":[\"default\"]},\"absent\":{\"Bus\":\"default\"},"
|
||||
+ "\"arnOf\":{\"Bus\":\"thing\"}}")).operations().get("a:Op"));
|
||||
assertEquals(List.of(new Resource(List.of("thing"), null, Map.of("ThingName", new Member("Names", true)), Map.of(),
|
||||
new Member("registryId", false), null)),
|
||||
Map.of(), Map.of(), Map.of(), new Member("registryId", false), null)),
|
||||
parseUnchecked(document(formats, "{\"type\":\"thing\",\"fill\":{\"ThingName\":\"Names[]\"},"
|
||||
+ "\"account\":\"registryId\"}")).operations().get("a:Op"));
|
||||
}
|
||||
@@ -126,7 +163,8 @@ class RequestResourceMembersTest {
|
||||
ArnFormat format = table.formats().get(namespace).get(resource.types().getFirst());
|
||||
String arn = example(format.format());
|
||||
String account = resource.account() != null ? "111122223333" : "000000000000";
|
||||
String expected = resource.arn() != null ? arn : expected(format.format(), resource, account);
|
||||
String expected = resource.arn() != null ? arn
|
||||
: expected(format.format(), resource, account) + (format.minted() ? "/*" : "");
|
||||
ObjectNode body = MAPPER.createObjectNode();
|
||||
StringBuilder form = new StringBuilder("Action=" + name);
|
||||
Map<Member, String> values = resource.arn() != null ? Map.of(resource.arn(), arn)
|
||||
@@ -141,13 +179,8 @@ class RequestResourceMembersTest {
|
||||
}
|
||||
});
|
||||
given.forEach((member, value) -> {
|
||||
if (member.list()) {
|
||||
body.putArray(member.name()).add(value);
|
||||
form.append('&').append(member.name()).append(".member.1=").append(encoded(value));
|
||||
} else {
|
||||
body.put(member.name(), value);
|
||||
form.append('&').append(member.name()).append('=').append(encoded(value));
|
||||
}
|
||||
put(body, member, value);
|
||||
form.append('&').append(parameter(member)).append('=').append(encoded(value));
|
||||
});
|
||||
assertEquals(List.of(expected), RequestResources.of(operation.getKey(), json(body.toString()),
|
||||
"aws", "us-east-1", "000000000000"), body.toString());
|
||||
@@ -182,6 +215,25 @@ class RequestResourceMembersTest {
|
||||
})));
|
||||
}
|
||||
|
||||
/** The value at the member's path in a body: in its list's first element, and in its field's structure. */
|
||||
private static void put(ObjectNode body, Member member, String value) {
|
||||
if (member.field() == null) {
|
||||
if (member.list()) {
|
||||
body.putArray(member.name()).add(value);
|
||||
} else {
|
||||
body.put(member.name(), value);
|
||||
}
|
||||
} else {
|
||||
put(member.list() ? body.putArray(member.name()).addObject() : body.putObject(member.name()), member.field(), value);
|
||||
}
|
||||
}
|
||||
|
||||
/** The form parameter of the member's path, its lists' first elements. */
|
||||
private static String parameter(Member member) {
|
||||
String name = member.name() + (member.list() ? ".member.1" : "");
|
||||
return member.field() == null ? name : name + "." + parameter(member.field());
|
||||
}
|
||||
|
||||
/** An ARN of the format in the test's partition, Region and account, each other variable {@code x}. */
|
||||
private static String example(String format) {
|
||||
return format.replace("${Partition}", "aws").replace("${Region}", "us-east-1")
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.junit.jupiter.api.Test;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -215,6 +216,114 @@ class RequestResourcesTest {
|
||||
assertEquals(List.of(execution), of("states:DescribeExecution", json("{\"executionArn\":\"" + execution + "\"}")));
|
||||
}
|
||||
|
||||
/**
|
||||
* An ARN inside a structure, or inside each of a list's structures, names its resource as a top-level one does:
|
||||
* {@code SetRulePriorities} acts on the rules its priorities name, read to the first element without one, as
|
||||
* its handler loops, and an alias acts on the state machine its versions are of.
|
||||
*/
|
||||
@Test
|
||||
void anArnInsideAStructureNamesItsResource() {
|
||||
String prefix = "arn:aws:elasticloadbalancing:us-east-1:000000000000:listener-rule/app/web/abc/def/";
|
||||
assertEquals(List.of(prefix + "1", prefix + "2"), of("elasticloadbalancing:SetRulePriorities", form(
|
||||
"Action=SetRulePriorities&RulePriorities.member.1.RuleArn=" + prefix + "1&RulePriorities.member.1.Priority=5"
|
||||
+ "&RulePriorities.member.2.RuleArn=" + prefix + "2&RulePriorities.member.2.Priority=6"
|
||||
+ "&RulePriorities.member.3.Priority=7&RulePriorities.member.4.RuleArn=" + prefix + "4")));
|
||||
assertEquals(List.of(prefix + "1"), of("elasticloadbalancing:SetRulePriorities",
|
||||
json("{\"RulePriorities\":[{\"RuleArn\":\"" + prefix + "1\"},\"" + prefix + "2\",{\"Priority\":1}]}")));
|
||||
assertEquals(List.of(MACHINE), of("states:CreateStateMachineAlias", json("{\"name\":\"PROD\","
|
||||
+ "\"routingConfiguration\":[{\"stateMachineVersionArn\":\"" + MACHINE + ":1\",\"weight\":90},"
|
||||
+ "{\"stateMachineVersionArn\":\"" + MACHINE + ":2\",\"weight\":10}]}")));
|
||||
assertEquals(List.of(MACHINE), of("states:UpdateStateMachineAlias", json("{\"stateMachineAliasArn\":\""
|
||||
+ MACHINE + ":PROD\",\"routingConfiguration\":[{\"stateMachineVersionArn\":\"" + MACHINE + ":2\"}]}")));
|
||||
// An ARN there of a type the action does not act on is not checked: a rule's target group.
|
||||
String listener = "arn:aws:elasticloadbalancing:us-east-1:000000000000:listener/app/web/abc/def";
|
||||
assertEquals(List.of(listener), of("elasticloadbalancing:CreateRule", form("Action=CreateRule&ListenerArn="
|
||||
+ listener + "&Actions.member.1.Type=forward&Actions.member.1.TargetGroupArn="
|
||||
+ "arn:aws:elasticloadbalancing:us-east-1:000000000000:targetgroup/web/1")));
|
||||
}
|
||||
|
||||
/**
|
||||
* An EventBridge rule is on the event bus its request names, by name or ARN, or on the default one when it names
|
||||
* none, whose rules have no bus in their ARN; a bus of another account names that account's rule, as given and
|
||||
* as the caller's own, which Floci acts on.
|
||||
*/
|
||||
@Test
|
||||
void aRuleIsOnTheEventBusItsRequestNames() {
|
||||
String events = "arn:aws:events:us-east-1:000000000000:";
|
||||
assertEquals(List.of(events + "rule/r"), of("events:DescribeRule", json("{\"Name\":\"r\"}")));
|
||||
assertEquals(List.of(events + "rule/r"), of("events:DescribeRule",
|
||||
json("{\"Name\":\"r\",\"EventBusName\":\"default\"}")));
|
||||
assertEquals(List.of(events + "rule/orders/r"), of("events:DescribeRule",
|
||||
json("{\"Name\":\"r\",\"EventBusName\":\"orders\"}")));
|
||||
assertEquals(List.of(events + "rule/orders/r"), of("events:DescribeRule",
|
||||
json("{\"Name\":\"r\",\"EventBusName\":\"" + events + "event-bus/orders\"}")));
|
||||
assertEquals(List.of(events + "rule/r"), of("events:DescribeRule",
|
||||
json("{\"Name\":\"r\",\"EventBusName\":\"" + events + "event-bus/default\"}")));
|
||||
assertEquals(List.of("arn:aws:events:eu-west-1:111122223333:rule/orders/r",
|
||||
"arn:aws:events:us-east-1:111122223333:rule/orders/r", "arn:aws:events:eu-west-1:000000000000:rule/orders/r",
|
||||
events + "rule/orders/r"), of("events:DescribeRule", json("{\"Name\":\"r\",\"EventBusName\":"
|
||||
+ "\"arn:aws:events:eu-west-1:111122223333:event-bus/orders\"}")));
|
||||
// A target's rule is named by Rule.
|
||||
assertEquals(List.of(events + "rule/orders/r"), of("events:PutTargets", json("{\"Rule\":\"r\","
|
||||
+ "\"EventBusName\":\"orders\",\"Targets\":[{\"Id\":\"1\",\"Arn\":\"arn:aws:sqs:us-east-1:000000000000:q\"}]}")));
|
||||
// A request naming no event bus describes the default one.
|
||||
assertEquals(List.of(events + "event-bus/default"), of("events:DescribeEventBus", json("{}")));
|
||||
assertEquals(List.of(events + "event-bus/orders"), of("events:DescribeEventBus", json("{\"Name\":\"orders\"}")));
|
||||
assertEquals(List.of(events + "event-bus/orders"), of("events:DescribeEventBus",
|
||||
json("{\"Name\":\"" + events + "event-bus/orders\"}")));
|
||||
}
|
||||
|
||||
/**
|
||||
* A rule on another account's default event bus is that account's, checked as the caller's too, and a bus ARN
|
||||
* leaving its account and Region empty, or a null bus, names the caller's, which the handler acts on.
|
||||
*/
|
||||
@Test
|
||||
void aRuleIsOnTheEventBusItsHandlerActsOn() {
|
||||
String events = "arn:aws:events:us-east-1:000000000000:";
|
||||
assertEquals(List.of("arn:aws:events:us-east-1:111122223333:rule/r", events + "rule/r"),
|
||||
of("events:DescribeRule", json("{\"Name\":\"r\",\"EventBusName\":"
|
||||
+ "\"arn:aws:events:us-east-1:111122223333:event-bus/default\"}")));
|
||||
assertEquals(List.of(events + "rule/orders/r"), of("events:DescribeRule",
|
||||
json("{\"Name\":\"r\",\"EventBusName\":\"arn:aws:events:::event-bus/orders\"}")));
|
||||
assertEquals(List.of(events + "rule/r"), of("events:DescribeRule",
|
||||
json("{\"Name\":\"r\",\"EventBusName\":null}")));
|
||||
assertEquals(List.of(events + "event-bus/orders"), of("events:DescribeEventBus",
|
||||
json("{\"Name\":\"arn:aws:events:::event-bus/orders\"}")));
|
||||
assertEquals(List.of(events + "event-bus/default"), of("events:DescribeEventBus", json("{\"Name\":null}")));
|
||||
}
|
||||
|
||||
/**
|
||||
* A connection or an API destination, whose ARN EventBridge follows with an id it mints after the name, is the
|
||||
* one stored under the name the request gives, and has that id open when none is or nothing looks it up.
|
||||
*/
|
||||
@Test
|
||||
void aResourceWhoseIdItsServiceMintsIsTheOneStoredUnderItsName() {
|
||||
String events = "arn:aws:events:us-east-1:000000000000:";
|
||||
StoredResourceArns stored = new StoredResourceArns() {
|
||||
@Override
|
||||
public String namespace() {
|
||||
return "events";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> find(String type, String name, String region) {
|
||||
return "web".equals(name) && "us-east-1".equals(region) ? Optional.of(events + type + "/web/1234")
|
||||
: Optional.empty();
|
||||
}
|
||||
};
|
||||
assertEquals(List.of(events + "connection/web/1234"), RequestResources.of("events:DescribeConnection",
|
||||
json("{\"Name\":\"web\"}"), "aws", "us-east-1", "000000000000", stored));
|
||||
assertEquals(List.of(events + "api-destination/web/1234"), RequestResources.of(
|
||||
"events:DescribeApiDestination", json("{\"Name\":\"web\"}"), "aws", "us-east-1", "000000000000", stored));
|
||||
assertEquals(List.of(events + "connection/other/*"), RequestResources.of("events:DescribeConnection",
|
||||
json("{\"Name\":\"other\"}"), "aws", "us-east-1", "000000000000", stored));
|
||||
assertEquals(List.of(events + "connection/web/*"), of("events:DescribeConnection", json("{\"Name\":\"web\"}")));
|
||||
// A create names the connection it uses by its ARN, the id given, and has its own id open.
|
||||
assertEquals(List.of(events + "connection/web/1234", events + "api-destination/new/*"), RequestResources.of(
|
||||
"events:CreateApiDestination", json("{\"Name\":\"new\",\"ConnectionArn\":\"" + events
|
||||
+ "connection/web/1234\"}"), "aws", "us-east-1", "000000000000", stored));
|
||||
}
|
||||
|
||||
/** A request value is a name, so a {@code ${...}} in it is kept, not read as a variable of the format. */
|
||||
@Test
|
||||
void aValueIsTakenLiterally() {
|
||||
|
||||
+173
-7
@@ -40,6 +40,7 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
private static final String ACCOUNT = "000000000000";
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String ELB = "arn:aws:elasticloadbalancing:" + REGION + ":" + ACCOUNT + ":";
|
||||
private static final String EVENTS = "arn:aws:events:" + REGION + ":" + ACCOUNT + ":";
|
||||
/** The AWS Load Balancer Controller's create, tag-on-create and listener statements (its policy v2.14.0). */
|
||||
private static final String CONTROLLER_CREATE = "{\"Effect\":\"Allow\",\"Action\":[\"elasticloadbalancing:CreateLoadBalancer\","
|
||||
+ "\"elasticloadbalancing:CreateTargetGroup\"],\"Resource\":\"*\","
|
||||
@@ -225,13 +226,9 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
@Test
|
||||
void aVersionOrAnAliasIsCheckedOnItsStateMachine() {
|
||||
String arn = createStateMachine("res-alias-" + suffix());
|
||||
String version = admin("states").header("X-Amz-Target", "AWSStepFunctions.PublishStateMachineVersion")
|
||||
.contentType("application/x-amz-json-1.0").body("{\"stateMachineArn\":\"" + arn + "\"}")
|
||||
.post("/").then().statusCode(200).extract().path("stateMachineVersionArn");
|
||||
String alias = admin("states").header("X-Amz-Target", "AWSStepFunctions.CreateStateMachineAlias")
|
||||
.contentType("application/x-amz-json-1.0").body("{\"name\":\"PROD\",\"routingConfiguration\":"
|
||||
+ "[{\"stateMachineVersionArn\":\"" + version + "\",\"weight\":100}]}")
|
||||
.post("/").then().statusCode(200).extract().path("stateMachineAliasArn");
|
||||
String version = publishVersion(arn);
|
||||
String alias = createAlias(ADMIN, version).statusCode(200)
|
||||
.extract().path("stateMachineAliasArn");
|
||||
assertEquals(arn + ":PROD", alias);
|
||||
|
||||
User user = user("res-alias");
|
||||
@@ -247,6 +244,136 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
refusedJson(startExecution(user, version), "states:StartExecution");
|
||||
}
|
||||
|
||||
/**
|
||||
* An alias is created on the state machine its routing configuration's versions are of, so a grant on that
|
||||
* machine allows it and one on another does not.
|
||||
*/
|
||||
@Test
|
||||
void anAliasIsCreatedOnTheStateMachineItsVersionsAreOf() {
|
||||
String arn = createStateMachine("res-new-alias-" + suffix());
|
||||
String version = publishVersion(arn);
|
||||
User user = user("res-new-alias");
|
||||
user.policy(allowOn("states:CreateStateMachineAlias", arn + "-other"));
|
||||
refusedJson(createAlias(user.accessKeyId(), version), "states:CreateStateMachineAlias");
|
||||
user.policy(allowOn("states:CreateStateMachineAlias", arn));
|
||||
createAlias(user.accessKeyId(), version).statusCode(200);
|
||||
}
|
||||
|
||||
/** {@code SetRulePriorities} is checked on the rules its priorities name. */
|
||||
@Test
|
||||
void rulePrioritiesAreCheckedOnTheRulesTheyName() {
|
||||
String rule = ELB + "listener-rule/app/res-none/0123456789abcdef/0123456789abcdef/0123456789abcdef";
|
||||
User user = user("res-priorities");
|
||||
user.policy(allowOn("elasticloadbalancing:SetRulePriorities", rule));
|
||||
setRulePriority(user, rule).statusCode(400).body(containsString("RuleNotFound"));
|
||||
refused(setRulePriority(user, rule.replace("0123456789abcdef/0123456789abcdef/0123456789abcdef",
|
||||
"0123456789abcdef/0123456789abcdef/fedcba9876543210")), "elasticloadbalancing:SetRulePriorities");
|
||||
}
|
||||
|
||||
/**
|
||||
* An EventBridge rule is checked on the rule its request names, on the event bus it names by name or ARN, or on
|
||||
* the default one when it names none, whose rules have no bus in their ARN, as EventBridge mints them.
|
||||
*/
|
||||
@Test
|
||||
void aRuleIsCheckedOnTheEventBusItsRequestNames() {
|
||||
String bus = "res-bus-" + suffix();
|
||||
String name = "res-rule-" + suffix();
|
||||
admin("events").header("X-Amz-Target", "AWSEvents.CreateEventBus").contentType("application/x-amz-json-1.1")
|
||||
.body("{\"Name\":\"" + bus + "\"}").post("/").then().statusCode(200);
|
||||
cleanup.register(() -> admin("events").header("X-Amz-Target", "AWSEvents.DeleteEventBus")
|
||||
.contentType("application/x-amz-json-1.1").body("{\"Name\":\"" + bus + "\"}").post("/"));
|
||||
String custom = putRule(name, ",\"EventBusName\":\"" + bus + "\"");
|
||||
String onDefault = putRule(name, "");
|
||||
assertEquals(EVENTS + "rule/" + bus + "/" + name, custom);
|
||||
assertEquals(EVENTS + "rule/" + name, onDefault);
|
||||
|
||||
User user = user("res-rule");
|
||||
user.policy(allowOn("events:DescribeRule", custom));
|
||||
describeRule(user, name, ",\"EventBusName\":\"" + bus + "\"").statusCode(200);
|
||||
describeRule(user, name, ",\"EventBusName\":\"" + EVENTS + "event-bus/" + bus + "\"").statusCode(200);
|
||||
refusedJson(describeRule(user, name, ""), "events:DescribeRule");
|
||||
|
||||
user.policy(allowOn("events:DescribeRule", onDefault));
|
||||
describeRule(user, name, "").statusCode(200);
|
||||
describeRule(user, name, ",\"EventBusName\":\"default\"").statusCode(200);
|
||||
refusedJson(describeRule(user, name, ",\"EventBusName\":\"" + bus + "\""), "events:DescribeRule");
|
||||
}
|
||||
|
||||
/**
|
||||
* A bus ARN leaving its account and Region empty names the caller's bus, and a null bus the default one, as the
|
||||
* handler reads them, so a deny on the caller's rules holds.
|
||||
*/
|
||||
@Test
|
||||
void aDenyHoldsOnTheRuleOfTheBusTheHandlerActsOn() {
|
||||
String bus = "res-bus-" + suffix();
|
||||
String name = "res-rule-" + suffix();
|
||||
admin("events").header("X-Amz-Target", "AWSEvents.CreateEventBus").contentType("application/x-amz-json-1.1")
|
||||
.body("{\"Name\":\"" + bus + "\"}").post("/").then().statusCode(200);
|
||||
cleanup.register(() -> admin("events").header("X-Amz-Target", "AWSEvents.DeleteEventBus")
|
||||
.contentType("application/x-amz-json-1.1").body("{\"Name\":\"" + bus + "\"}").post("/"));
|
||||
String custom = putRule(name, ",\"EventBusName\":\"" + bus + "\"");
|
||||
String onDefault = putRule(name, "");
|
||||
String noAccount = ",\"EventBusName\":\"arn:aws:events:::event-bus/" + bus + "\"";
|
||||
|
||||
User user = user("res-rule-deny");
|
||||
user.policy(allowOn("events:DescribeRule", "*") + ",{\"Effect\":\"Deny\",\"Action\":\"events:DescribeRule\","
|
||||
+ "\"Resource\":[\"" + custom + "\",\"" + onDefault + "\"]}");
|
||||
refusedJson(describeRule(user, name, noAccount), "events:DescribeRule");
|
||||
refusedJson(describeRule(user, name, ",\"EventBusName\":null"), "events:DescribeRule");
|
||||
describeRule(user, name + "-other", noAccount).statusCode(400)
|
||||
.body(containsString("ResourceNotFoundException"));
|
||||
describeRule(user, name + "-other", ",\"EventBusName\":null").statusCode(400)
|
||||
.body(containsString("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
/**
|
||||
* A connection or an API destination named by its name is checked on the ARN EventBridge stored it under, which
|
||||
* follows the name with the id it minted, so a grant on that ARN or on {@code <name>/*} allows it, one on the
|
||||
* name alone does not, and a deny on that ARN holds.
|
||||
*/
|
||||
@Test
|
||||
void aConnectionNamedByItsNameIsCheckedOnTheArnItWasMintedUnder() {
|
||||
String name = "res-conn-" + suffix();
|
||||
String connection = admin("events").header("X-Amz-Target", "AWSEvents.CreateConnection")
|
||||
.contentType("application/x-amz-json-1.1").body("{\"Name\":\"" + name + "\",\"AuthorizationType\":\"API_KEY\","
|
||||
+ "\"AuthParameters\":{\"ApiKeyAuthParameters\":{\"ApiKeyName\":\"k\",\"ApiKeyValue\":\"v\"}}}")
|
||||
.post("/").then().statusCode(200).extract().path("ConnectionArn");
|
||||
cleanup.register(() -> admin("events").header("X-Amz-Target", "AWSEvents.DeleteConnection")
|
||||
.contentType("application/x-amz-json-1.1").body("{\"Name\":\"" + name + "\"}").post("/"));
|
||||
String destination = admin("events").header("X-Amz-Target", "AWSEvents.CreateApiDestination")
|
||||
.contentType("application/x-amz-json-1.1").body("{\"Name\":\"" + name + "\",\"ConnectionArn\":\""
|
||||
+ connection + "\",\"InvocationEndpoint\":\"https://example.com/hook\",\"HttpMethod\":\"POST\"}")
|
||||
.post("/").then().statusCode(200).extract().path("ApiDestinationArn");
|
||||
cleanup.register(() -> admin("events").header("X-Amz-Target", "AWSEvents.DeleteApiDestination")
|
||||
.contentType("application/x-amz-json-1.1").body("{\"Name\":\"" + name + "\"}").post("/"));
|
||||
assertTrue(connection.startsWith(EVENTS + "connection/" + name + "/"), connection);
|
||||
assertTrue(destination.startsWith(EVENTS + "api-destination/" + name + "/"), destination);
|
||||
|
||||
User user = user("res-conn");
|
||||
user.policy(allowOn("events:DescribeConnection", connection));
|
||||
describeByName(user, "DescribeConnection", name).statusCode(200);
|
||||
user.policy(allowOn("events:DescribeConnection", EVENTS + "connection/" + name + "/*"));
|
||||
describeByName(user, "DescribeConnection", name).statusCode(200);
|
||||
user.policy(allowOn("events:DescribeConnection", EVENTS + "connection/" + name));
|
||||
refusedJson(describeByName(user, "DescribeConnection", name), "events:DescribeConnection");
|
||||
user.policy(allowOn("events:DescribeConnection", "*") + ",{\"Effect\":\"Deny\",\"Action\":"
|
||||
+ "\"events:DescribeConnection\",\"Resource\":\"" + connection + "\"}");
|
||||
refusedJson(describeByName(user, "DescribeConnection", name), "events:DescribeConnection");
|
||||
user.policy(allowOn("events:DescribeApiDestination", destination));
|
||||
describeByName(user, "DescribeApiDestination", name).statusCode(200);
|
||||
refusedJson(describeByName(user, "DescribeApiDestination", name + "-other"), "events:DescribeApiDestination");
|
||||
}
|
||||
|
||||
/** A request naming no event bus describes the default one, so it is checked on that bus. */
|
||||
@Test
|
||||
void anEventBusRequestNamingNoneIsCheckedOnTheDefaultOne() {
|
||||
User user = user("res-default-bus");
|
||||
user.policy(allowOn("events:DescribeEventBus", EVENTS + "event-bus/default"));
|
||||
user.json("events", "AWSEvents.DescribeEventBus", "1.1").body("{}").post("/").then().statusCode(200);
|
||||
refusedJson(user.json("events", "AWSEvents.DescribeEventBus", "1.1").body("{\"Name\":\"res-other\"}").post("/")
|
||||
.then(), "events:DescribeEventBus");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aUserPoolIsCheckedOnTheArnItsIdNames() {
|
||||
String id = admin("cognito-idp").header("X-Amz-Target", "AWSCognitoIdentityProviderService.CreateUserPool")
|
||||
@@ -376,6 +503,45 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
return arn;
|
||||
}
|
||||
|
||||
/** Puts a rule of the name on the bus {@code bus} names, a JSON member or none, and gives its ARN. */
|
||||
private String putRule(String name, String bus) {
|
||||
String arn = admin("events").header("X-Amz-Target", "AWSEvents.PutRule").contentType("application/x-amz-json-1.1")
|
||||
.body("{\"Name\":\"" + name + "\",\"ScheduleExpression\":\"rate(1 hour)\"" + bus + "}")
|
||||
.post("/").then().statusCode(200).extract().path("RuleArn");
|
||||
cleanup.register(() -> admin("events").header("X-Amz-Target", "AWSEvents.DeleteRule")
|
||||
.contentType("application/x-amz-json-1.1").body("{\"Name\":\"" + name + "\"" + bus + "}").post("/"));
|
||||
return arn;
|
||||
}
|
||||
|
||||
private static ValidatableResponse describeByName(User user, String operation, String name) {
|
||||
return user.json("events", "AWSEvents." + operation, "1.1").body("{\"Name\":\"" + name + "\"}").post("/").then();
|
||||
}
|
||||
|
||||
private static ValidatableResponse describeRule(User user, String name, String bus) {
|
||||
return user.json("events", "AWSEvents.DescribeRule", "1.1").body("{\"Name\":\"" + name + "\"" + bus + "}")
|
||||
.post("/").then();
|
||||
}
|
||||
|
||||
private static String publishVersion(String arn) {
|
||||
return admin("states").header("X-Amz-Target", "AWSStepFunctions.PublishStateMachineVersion")
|
||||
.contentType("application/x-amz-json-1.0").body("{\"stateMachineArn\":\"" + arn + "\"}")
|
||||
.post("/").then().statusCode(200).extract().path("stateMachineVersionArn");
|
||||
}
|
||||
|
||||
/** An alias {@code PROD} routing every execution to the version. */
|
||||
private static ValidatableResponse createAlias(String accessKeyId, String version) {
|
||||
return given().header("Authorization", auth(accessKeyId, "states"))
|
||||
.header("X-Amz-Target", "AWSStepFunctions.CreateStateMachineAlias")
|
||||
.contentType("application/x-amz-json-1.0").body("{\"name\":\"PROD\",\"routingConfiguration\":"
|
||||
+ "[{\"stateMachineVersionArn\":\"" + version + "\",\"weight\":100}]}").post("/").then();
|
||||
}
|
||||
|
||||
private static ValidatableResponse setRulePriority(User user, String rule) {
|
||||
return user.query("elasticloadbalancing", "SetRulePriorities").formParam("Version", "2015-12-01")
|
||||
.formParam("RulePriorities.member.1.RuleArn", rule).formParam("RulePriorities.member.1.Priority", "5")
|
||||
.post("/").then();
|
||||
}
|
||||
|
||||
private static ValidatableResponse describeStateMachine(User user, String arn) {
|
||||
return user.json("states", "AWSStepFunctions.DescribeStateMachine", "1.0")
|
||||
.body("{\"stateMachineArn\":\"" + arn + "\"}").post("/").then();
|
||||
|
||||
Reference in new issue
Block a user