mirror of
https://github.com/floci-io/floci.git
synced 2026-12-02 17:58:05 -05:00
fix(lambdaweb): accept a policy Resource in any partition, region or account (#6863)
This commit is contained in:
1 parent
096d336fab
commit
fc1388da6f
4 files changed
+49
-2
No files matched your search
+6
@@ -527,6 +527,12 @@ class LambdaWebIntegrationTest {
|
||||
.then().statusCode(400)
|
||||
.body("message", equalTo("Lambda blocked the creation of this policy because it would grant public"
|
||||
+ " access to your function."));
|
||||
given().contentType("application/json")
|
||||
.body(Map.of("Policy", publicPolicy.replace(ARN, "arn:aws:lambda:*:*:web-function/" + FN)))
|
||||
.when().put(policyPath)
|
||||
.then().statusCode(400)
|
||||
.body("message", equalTo("Lambda blocked the creation of this policy because it would grant public"
|
||||
+ " access to your function."));
|
||||
given().contentType("application/json").body(Map.of("Policy", publicPolicy.replace("\"Allow\"", "\"Maybe\"")))
|
||||
.when().put(policyPath)
|
||||
.then().statusCode(400)
|
||||
|
||||
@@ -915,6 +915,39 @@ class LambdaWebServiceTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void aPolicyResourceIsReadByItsServiceAndResourceOnly() {
|
||||
LambdaWebService service = service();
|
||||
String missing = "arn:aws:lambda:us-east-1:000000000000:web-function/missing";
|
||||
String function = "web-function/missing";
|
||||
for (String accepted : List.of("arn:aws-cn:lambda:us-east-1:000000000000:" + function,
|
||||
"arn::lambda:us-east-1:000000000000:" + function, "xyz:aws:lambda:us-east-1:000000000000:" + function,
|
||||
"ARN:aws:lambda:us-east-1:000000000000:" + function, "arn:aws:lambda:*:*:" + function,
|
||||
"arn:aws:lambda:foo:000000000000:" + function, "arn:aws:lambda:us-west-2:111122223333:" + function,
|
||||
"arn:aws:lambda:us-east-1::" + function, missing + "*", missing + "/", missing + "/endpoint/x:y",
|
||||
missing + "//x")) {
|
||||
assertEquals("ResourceNotFoundException", error(() -> service.putResourcePolicy(REGION, missing,
|
||||
policy(resourcePolicy("\"" + accepted + "\"")))).getErrorCode(), accepted);
|
||||
}
|
||||
for (String refused : List.of("arn:aws:lambda*:us-east-1:000000000000:" + function,
|
||||
"arn:aws:LAMBDA:us-east-1:000000000000:" + function, "arn:aws:lambda:us-east-1:" + function,
|
||||
"arn:aws:lambda:us-east-1:000000000000:Web-Function/missing", missing + ":1", missing + "**",
|
||||
missing + "x", missing + "x*", missing + "*/endpoint/x", missing + "?",
|
||||
"arn:aws:lambda:us-east-1:000000000000:web-function/miss*", "arn:aws:lambda:us-east-1:000000000000:*",
|
||||
"*")) {
|
||||
assertEquals("Policy has syntax errors.", message(() -> service.putResourcePolicy(REGION, missing,
|
||||
policy(resourcePolicy("\"" + refused + "\"")))), refused);
|
||||
}
|
||||
String other = "arn:aws:lambda:us-east-1:000000000000:web-function/other";
|
||||
assertEquals("Policy has syntax errors.", message(() -> service.putResourcePolicy(REGION, missing,
|
||||
policy(resourcePolicy("[\"" + missing + "\",\"" + other + "\"]")))));
|
||||
}
|
||||
|
||||
private static String resourcePolicy(String resource) {
|
||||
return "{\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"000000000000\"},"
|
||||
+ "\"Action\":\"lambda:GetWebFunction\",\"Resource\":" + resource + "}]}";
|
||||
}
|
||||
|
||||
private static String principalPolicy(String effect, String principal, String functionArn) {
|
||||
return "{\"Statement\":[" + statement(effect, principal, functionArn) + "]}";
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user