mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(iam): check lambda:PassNetworkConnector from a table generated from the Service Reference (#6699)
* feat(lambdaweb): check lambda:PassNetworkConnector as AWS does A revision that sets egressNetworkConnectorArn needs lambda:PassNetworkConnector on the connector version ARN as given. Lambda checks it after the connector ARN checks and before it looks the connector up. A refusal names the first policy type that refuses, in the order identity policies, permissions boundary, session policy. An explicit deny in a managed policy or a boundary also names that policy's ARN. * fix(lambdaweb): apply service control policies to the account root when passing a connector * fix(lambdaweb): name the managed policy that denies a session token caller * feat(iam): check lambda:PassNetworkConnector from a generated table Move the check out of Lambda Web into the IAM enforcement filter, where iam:PassRole is checked. tools/aws/regen_iam_passed_network_connectors.py joins AWS's Service Reference and botocore's models into src/main/resources/aws/iam-passed-network-connectors.json, and the filter reads it for Web Functions, MicroVM images and MicroVMs. A MicroVM request that names no egress connector, or an empty list, passes the Lambda-managed INTERNET_EGRESS connector, and RunMicrovm with no ingress connector passes HTTP_INGRESS, as AWS checks them. AppSync's data source operations are listed too, but botocore's model has no member for their connector, so they are not read. The refusal text now comes from AccessDeniedMessages, which LambdaTaskAuthorizer and GetStackOutputRoleAuthorizer use as well.
This commit is contained in:
1 parent
8a3d769c70
commit
b0cd70401b
20 files changed
+1405
-85
No files matched your search
+176
@@ -0,0 +1,176 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import io.github.hectorvent.floci.services.iam.IamService;
|
||||
import io.github.hectorvent.floci.services.lambdaweb.LambdaWebRoles;
|
||||
import io.github.hectorvent.floci.testing.EnforcementFixtures;
|
||||
import io.github.hectorvent.floci.testing.EnforcementFixtures.Session;
|
||||
import io.github.hectorvent.floci.testing.EnforcementFixtures.UserCredentials;
|
||||
import io.github.hectorvent.floci.testing.IamEnforcementProfile;
|
||||
import io.github.hectorvent.floci.testing.PartitionCleanup;
|
||||
import io.quarkus.test.common.http.TestHTTPResource;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import io.restassured.path.xml.XmlPath;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import static io.github.hectorvent.floci.testing.EnforcementFixtures.auth;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/** Under IAM enforcement a request needs lambda:PassNetworkConnector on each network connector it passes. */
|
||||
@QuarkusTest
|
||||
@TestProfile(IamEnforcementProfile.class)
|
||||
class PassedNetworkConnectorsIntegrationTest {
|
||||
|
||||
private static final String ACCOUNT = "000000000000";
|
||||
private static final String ROLE = "arn:aws:iam::000000000000:role/web";
|
||||
private static final String CONNECTOR =
|
||||
"arn:aws:lambda:us-east-1:000000000000:network-connector:nc-0123456789abcdef0";
|
||||
private static final String MANAGED = "arn:aws:lambda:us-east-1:aws:network-connector:aws-network-connector:";
|
||||
private static final String DENY = """
|
||||
{"Version":"2012-10-17","Statement":[
|
||||
{"Effect":"Deny","Action":"lambda:PassNetworkConnector","Resource":"*"}]}""";
|
||||
|
||||
@TestHTTPResource("/")
|
||||
static URI baseUri;
|
||||
|
||||
@RegisterExtension
|
||||
final PartitionCleanup cleanup = new PartitionCleanup();
|
||||
|
||||
@Inject
|
||||
IamService iamService;
|
||||
|
||||
@Test
|
||||
void aRevisionNeedsPassNetworkConnectorOnTheVersionItNames() {
|
||||
int port = baseUri.getPort();
|
||||
String name = "connector-pass-" + Long.toString(System.nanoTime(), 36);
|
||||
String denyArn = "arn:aws:iam::" + ACCOUNT + ":policy/" + name;
|
||||
cleanup.register(() -> EnforcementFixtures.removePolicy(port, auth(ACCOUNT, "iam"), denyArn));
|
||||
LambdaWebRoles.trustLambda(iamService, ROLE);
|
||||
String roleArn = EnforcementFixtures.createRole(cleanup, port, ACCOUNT, "/", name,
|
||||
policy("lambda:CreateWebFunctionRevision", ""));
|
||||
Session session = EnforcementFixtures.assumeRole(port, ACCOUNT, roleArn);
|
||||
String denied = "User: arn:aws:sts::" + ACCOUNT + ":assumed-role/" + name + "/s is not authorized to perform:"
|
||||
+ " lambda:PassNetworkConnector on resource: " + CONNECTOR + ":1 ";
|
||||
|
||||
revision(session, CONNECTOR + ":1").statusCode(403)
|
||||
.header("X-Amzn-Errortype", "AccessDeniedException")
|
||||
.body("Message", equalTo(denied
|
||||
+ "because no identity-based policy allows the lambda:PassNetworkConnector action"));
|
||||
|
||||
iamService.putRolePolicy(name, "p", policy("lambda:CreateWebFunctionRevision", allow(CONNECTOR + ":1")));
|
||||
revision(session, CONNECTOR + ":1").statusCode(404)
|
||||
.body("message", equalTo("The function arn:aws:lambda:us-east-1:" + ACCOUNT
|
||||
+ ":web-function/missing does not exist."));
|
||||
revision(session, CONNECTOR + ":2").statusCode(403);
|
||||
|
||||
iamService.createPolicy(name, "/", null, DENY, null);
|
||||
iamService.attachRolePolicy(name, denyArn);
|
||||
revision(session, CONNECTOR + ":1").statusCode(403)
|
||||
.body("Message", equalTo(denied + "with an explicit deny in an identity-based policy: " + denyArn));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aUserAndItsSessionTokenNameTheManagedPolicyThatDenies() {
|
||||
int port = baseUri.getPort();
|
||||
String name = "connector-pass-" + Long.toString(System.nanoTime(), 36);
|
||||
String denyArn = "arn:aws:iam::" + ACCOUNT + ":policy/" + name;
|
||||
cleanup.register(() -> EnforcementFixtures.removePolicy(port, auth(ACCOUNT, "iam"), denyArn));
|
||||
LambdaWebRoles.trustLambda(iamService, ROLE);
|
||||
UserCredentials user = EnforcementFixtures.createUser(cleanup, port, auth(ACCOUNT, "iam"), name);
|
||||
EnforcementFixtures.putUserPolicy(port, auth(ACCOUNT, "iam"), name, "p",
|
||||
policy("lambda:CreateWebFunctionRevision", allow("*")));
|
||||
iamService.createPolicy(name, "/", null, DENY, null);
|
||||
iamService.attachUserPolicy(name, denyArn);
|
||||
Session token = sessionToken(user.accessKeyId());
|
||||
String denied = "User: arn:aws:iam::" + ACCOUNT + ":user/" + name + " is not authorized to perform:"
|
||||
+ " lambda:PassNetworkConnector on resource: " + CONNECTOR + ":1"
|
||||
+ " with an explicit deny in an identity-based policy: " + denyArn;
|
||||
|
||||
revision(new Session(user.accessKeyId(), null), CONNECTOR + ":1").statusCode(403)
|
||||
.body("Message", equalTo(denied));
|
||||
revision(token, CONNECTOR + ":1").statusCode(403).body("Message", equalTo(denied));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMicrovmPassesTheManagedConnectorsWhenItNamesNone() {
|
||||
int port = baseUri.getPort();
|
||||
String name = "connector-pass-" + Long.toString(System.nanoTime(), 36);
|
||||
String roleArn = EnforcementFixtures.createRole(cleanup, port, ACCOUNT, "/", name,
|
||||
policy("lambda:RunMicrovm", ""));
|
||||
Session session = EnforcementFixtures.assumeRole(port, ACCOUNT, roleArn);
|
||||
String denied = "User: arn:aws:sts::" + ACCOUNT + ":assumed-role/" + name + "/s is not authorized to perform:"
|
||||
+ " lambda:PassNetworkConnector on resource: ";
|
||||
String noAllow = " because no identity-based policy allows the lambda:PassNetworkConnector action";
|
||||
|
||||
microvm(session, "").statusCode(403).body("Message", equalTo(denied + MANAGED + "INTERNET_EGRESS" + noAllow));
|
||||
microvm(session, ", \"egressNetworkConnectors\": []").statusCode(403)
|
||||
.body("Message", equalTo(denied + MANAGED + "INTERNET_EGRESS" + noAllow));
|
||||
|
||||
iamService.putRolePolicy(name, "p", policy("lambda:RunMicrovm",
|
||||
allow(MANAGED + "INTERNET_EGRESS") + allow(CONNECTOR + ":1")));
|
||||
microvm(session, "").statusCode(403).body("Message", equalTo(denied + MANAGED + "HTTP_INGRESS" + noAllow));
|
||||
microvm(session, ", \"ingressNetworkConnectors\": [\"" + CONNECTOR + ":2\"]").statusCode(403)
|
||||
.body("Message", equalTo(denied + CONNECTOR + ":2" + noAllow));
|
||||
microvm(session, ", \"egressNetworkConnectors\": [\"" + CONNECTOR + ":1\", \"" + CONNECTOR + ":3\"],"
|
||||
+ " \"ingressNetworkConnectors\": [\"" + CONNECTOR + ":2\"]").statusCode(403)
|
||||
.body("Message", equalTo(denied + CONNECTOR + ":3" + noAllow));
|
||||
|
||||
iamService.putRolePolicy(name, "p", policy("lambda:RunMicrovm", allow("*")));
|
||||
microvm(session, "").statusCode(404);
|
||||
}
|
||||
|
||||
private static Session sessionToken(String accessKeyId) {
|
||||
XmlPath credentials = given().header("Authorization", auth(accessKeyId, "sts"))
|
||||
.formParam("Action", "GetSessionToken")
|
||||
.when().post("/")
|
||||
.then().statusCode(200).extract().xmlPath();
|
||||
return new Session(
|
||||
credentials.getString("GetSessionTokenResponse.GetSessionTokenResult.Credentials.AccessKeyId"),
|
||||
credentials.getString("GetSessionTokenResponse.GetSessionTokenResult.Credentials.SessionToken"));
|
||||
}
|
||||
|
||||
private static ValidatableResponse revision(Session session, String connectorArn) {
|
||||
return signed(session).contentType("application/json")
|
||||
.body("""
|
||||
{"buildConfig": {"codeConfig": {"s3Object": {"bucket": "web-code", "key": "app.zip"}},
|
||||
"runtimeConfig": {"runtime": "nodejs24.x"}},
|
||||
"serviceConfig": {"executionRoleArn": "%s", "egressNetworkConnectorArn": "%s"}}
|
||||
""".formatted(ROLE, connectorArn))
|
||||
.when().post("/2025-03-07/web-functions/missing/revisions")
|
||||
.then();
|
||||
}
|
||||
|
||||
private static ValidatableResponse microvm(Session session, String connectors) {
|
||||
return signed(session).contentType("application/json")
|
||||
.body("{\"imageIdentifier\": \"arn:aws:lambda:us-east-1:" + ACCOUNT + ":microvm-image:missing\""
|
||||
+ connectors + "}")
|
||||
.when().post("/2025-09-09/microvms")
|
||||
.then();
|
||||
}
|
||||
|
||||
private static RequestSpecification signed(Session session) {
|
||||
RequestSpecification request = given().header("Authorization", auth(session.accessKeyId(), "lambda"));
|
||||
if (session.sessionToken() != null) {
|
||||
request.header("X-Amz-Security-Token", session.sessionToken());
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
private static String allow(String resource) {
|
||||
return ",{\"Effect\":\"Allow\",\"Action\":\"lambda:PassNetworkConnector\",\"Resource\":\"" + resource + "\"}";
|
||||
}
|
||||
|
||||
private static String policy(String action, String more) {
|
||||
return """
|
||||
{"Version":"2012-10-17","Statement":[
|
||||
{"Effect":"Allow","Action":"%s","Resource":"*"},
|
||||
{"Effect":"Allow","Action":"iam:PassRole","Resource":"*"}%s]}""".formatted(action, more);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import jakarta.ws.rs.container.ContainerRequestContext;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** The vendored table of where each operation's request names the network connectors it passes. */
|
||||
class PassedNetworkConnectorsTest {
|
||||
|
||||
private static final String CONNECTOR = "arn:aws:lambda:us-east-1:111122223333:network-connector:nc-1";
|
||||
private static final String MANAGED = "arn:aws:lambda:us-west-2:aws:network-connector:aws-network-connector:";
|
||||
|
||||
@Test
|
||||
void theTableReadsTheLambdaOperationsAndLeavesOutTheUnreadOnes() {
|
||||
assertEquals(Set.of("lambda:CreateMicrovmImage", "lambda:CreateWebFunction", "lambda:CreateWebFunctionRevision",
|
||||
"lambda:RunMicrovm", "lambda:UpdateMicrovmImage"), PassedNetworkConnectors.table().keySet());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aWebFunctionPassesTheConnectorItsRevisionNames() {
|
||||
assertEquals(List.of(CONNECTOR + ":1"), PassedNetworkConnectors.of("lambda:CreateWebFunctionRevision",
|
||||
json("{\"serviceConfig\":{\"egressNetworkConnectorArn\":\"" + CONNECTOR + ":1\"}}"), "us-west-2"));
|
||||
assertEquals(List.of(CONNECTOR + ":2"), PassedNetworkConnectors.of("lambda:CreateWebFunction",
|
||||
json("{\"revisionConfig\":{\"serviceConfig\":{\"egressNetworkConnectorArn\":\"" + CONNECTOR + ":2\"}}}"),
|
||||
"us-west-2"));
|
||||
assertEquals(List.of(), PassedNetworkConnectors.of("lambda:CreateWebFunctionRevision",
|
||||
json("{\"serviceConfig\":{\"executionRoleArn\":\"arn:aws:iam::111122223333:role/r\"}}"), "us-west-2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMicrovmPassesItsEgressConnectorsThenItsIngressOnes() {
|
||||
assertEquals(List.of(CONNECTOR + ":1", CONNECTOR + ":3", CONNECTOR + ":2"), PassedNetworkConnectors.of(
|
||||
"lambda:RunMicrovm", json("{\"ingressNetworkConnectors\":[\"" + CONNECTOR + ":2\"],"
|
||||
+ "\"egressNetworkConnectors\":[\"" + CONNECTOR + ":1\",\"" + CONNECTOR + ":3\"]}"), "us-west-2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMicrovmThatNamesNoConnectorPassesTheManagedOnes() {
|
||||
assertEquals(List.of(MANAGED + "INTERNET_EGRESS", MANAGED + "HTTP_INGRESS"),
|
||||
PassedNetworkConnectors.of("lambda:RunMicrovm", json("{\"imageIdentifier\":\"i\"}"), "us-west-2"));
|
||||
assertEquals(List.of(MANAGED + "INTERNET_EGRESS", CONNECTOR + ":2"), PassedNetworkConnectors.of(
|
||||
"lambda:RunMicrovm", json("{\"egressNetworkConnectors\":[],\"ingressNetworkConnectors\":[\""
|
||||
+ CONNECTOR + ":2\"]}"), "us-west-2"));
|
||||
assertEquals(List.of(MANAGED + "INTERNET_EGRESS"),
|
||||
PassedNetworkConnectors.of("lambda:CreateMicrovmImage", json("{\"name\":\"n\"}"), "us-west-2"));
|
||||
assertEquals(List.of("arn:aws-cn:lambda:cn-north-1:aws:network-connector:aws-network-connector:INTERNET_EGRESS"),
|
||||
PassedNetworkConnectors.of("lambda:UpdateMicrovmImage", json("{}"), "cn-north-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anOperationTheTableDoesNotReadPassesNothing() {
|
||||
assertEquals(List.of(), PassedNetworkConnectors.of("appsync:CreateDataSource", json("{}"), "us-west-2"));
|
||||
assertEquals(List.of(), PassedNetworkConnectors.of("lambda:CreateFunction", json("{}"), "us-west-2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMalformedTableFailsToLoad() {
|
||||
assertThrows(IllegalStateException.class, () -> PassedNetworkConnectors.parse(stream("{\"operations\":{}}")));
|
||||
assertThrows(IllegalStateException.class, () -> PassedNetworkConnectors.parse(stream(
|
||||
"{\"operations\":{\"lambda:RunMicrovm\":{\"connectors\":[{\"member\":\"a..b\"}]}}}")));
|
||||
}
|
||||
|
||||
private static ByteArrayInputStream stream(String text) {
|
||||
return new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
private static ContainerRequestContext json(String body) {
|
||||
byte[] bytes = body.getBytes(StandardCharsets.UTF_8);
|
||||
ContainerRequestContext request = mock(ContainerRequestContext.class);
|
||||
when(request.getMediaType()).thenReturn(MediaType.APPLICATION_JSON_TYPE);
|
||||
when(request.getEntityStream()).thenAnswer(invocation -> new ByteArrayInputStream(bytes));
|
||||
return request;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package io.github.hectorvent.floci.services.iam;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.services.iam.AccessDeniedMessages.PolicyType;
|
||||
import io.github.hectorvent.floci.services.iam.IamPolicyEvaluator.SimulationDecision;
|
||||
import io.github.hectorvent.floci.services.iam.IamService.HeldPolicies;
|
||||
import io.github.hectorvent.floci.services.iam.IamService.HeldPolicy;
|
||||
import io.github.hectorvent.floci.services.iam.model.CallerContext;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
class AccessDeniedMessagesTest {
|
||||
|
||||
private static final String ACTION = "lambda:PassNetworkConnector";
|
||||
private static final String CONNECTOR = "arn:aws:lambda:us-east-1:111111111111:network-connector:nc-1";
|
||||
private static final String MANAGED = "arn:aws:iam::111111111111:policy/deny";
|
||||
private static final String BOUNDARY = "arn:aws:iam::111111111111:policy/boundary";
|
||||
private static final String NO_IDENTITY_ALLOW =
|
||||
"because no identity-based policy allows the lambda:PassNetworkConnector action";
|
||||
|
||||
private final IamPolicyEvaluator evaluator = new IamPolicyEvaluator(new ObjectMapper());
|
||||
|
||||
@Test
|
||||
void eachPolicyTypeIsWordedAsAwsWordsIt() {
|
||||
assertEquals("with an explicit deny in a service control policy", PolicyType.SERVICE_CONTROL_POLICY.explicitDeny());
|
||||
assertEquals("with an explicit deny in the role trust policy", PolicyType.ROLE_TRUST_POLICY.explicitDeny());
|
||||
assertEquals("with an explicit deny in an identity-based policy: " + MANAGED,
|
||||
PolicyType.IDENTITY_BASED_POLICY.explicitDeny(MANAGED));
|
||||
assertEquals("because no resource-based policy allows the s3:GetObject action",
|
||||
PolicyType.RESOURCE_BASED_POLICY.noAllow("s3:GetObject"));
|
||||
assertEquals("because no session policy allows the s3:GetObject action",
|
||||
PolicyType.SESSION_POLICY.refusal(SimulationDecision.IMPLICIT_DENY, "s3:GetObject", MANAGED));
|
||||
assertEquals("User: arn:aws:iam::111111111111:root is not authorized to perform: sts:AssumeRole on resource: r",
|
||||
AccessDeniedMessages.notAuthorized("arn:aws:iam::111111111111:root", "sts:AssumeRole", "r", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theVersionArnAsGivenHasToBeAllowed() {
|
||||
assertNull(refusal(policy(allow(CONNECTOR + ":1")), CONNECTOR + ":1"));
|
||||
assertEquals(NO_IDENTITY_ALLOW, refusal(policy(allow(CONNECTOR + ":1")), CONNECTOR + ":2"));
|
||||
assertEquals(NO_IDENTITY_ALLOW, refusal(policy(allow(CONNECTOR)), CONNECTOR + ":1"));
|
||||
assertNull(refusal(policy(allow(CONNECTOR + ":*")), CONNECTOR + ":1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anExplicitDenyNamesTheManagedPolicyThatHoldsIt() {
|
||||
HeldPolicies held = new HeldPolicies(List.of(new HeldPolicy(null, policy(allow("*"))),
|
||||
new HeldPolicy(MANAGED, policy(deny("*")))), null);
|
||||
assertEquals("with an explicit deny in an identity-based policy: " + MANAGED,
|
||||
AccessDeniedMessages.firstRefusal(evaluator, caller(held, null, null), held, ACTION, CONNECTOR, Map.of()));
|
||||
|
||||
HeldPolicies inlineFirst = new HeldPolicies(List.of(new HeldPolicy(null, policy(allow("*"), deny("*"))),
|
||||
new HeldPolicy(MANAGED, policy(deny("*")))), null);
|
||||
assertEquals("with an explicit deny in an identity-based policy", AccessDeniedMessages.firstRefusal(
|
||||
evaluator, caller(inlineFirst, null, null), inlineFirst, ACTION, CONNECTOR, Map.of()));
|
||||
assertEquals("with an explicit deny in an identity-based policy", AccessDeniedMessages.firstRefusal(
|
||||
evaluator, caller(held, null, null), null, ACTION, CONNECTOR, Map.of()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theIdentityPoliciesThenTheBoundaryThenTheSessionPolicyNameTheReason() {
|
||||
String allowAll = policy(allow("*"));
|
||||
String denyAll = policy(allow("*"), deny("*"));
|
||||
String allowNothing = policy(allowCreate());
|
||||
|
||||
assertEquals(NO_IDENTITY_ALLOW, refusal(allowNothing, denyAll, denyAll));
|
||||
assertEquals("because no permissions boundary allows the lambda:PassNetworkConnector action",
|
||||
refusal(allowAll, allowNothing, denyAll));
|
||||
assertEquals("with an explicit deny in a permissions boundary: " + BOUNDARY, refusal(allowAll, denyAll, allowNothing));
|
||||
assertEquals("because no session policy allows the lambda:PassNetworkConnector action",
|
||||
refusal(allowAll, allowAll, allowNothing));
|
||||
assertEquals("with an explicit deny in a session policy", refusal(allowAll, null, denyAll));
|
||||
assertNull(refusal(allowAll, allowAll, allowAll));
|
||||
}
|
||||
|
||||
@Test
|
||||
void serviceControlPoliciesComeFirstAndAnEmptyLevelIsSkipped() {
|
||||
CallerContext caller = CallerContext.of(List.of(policy(allowCreate())));
|
||||
assertEquals("with an explicit deny in a service control policy", AccessDeniedMessages.firstRefusal(evaluator,
|
||||
caller.withScpLevels(List.of(List.of(), List.of(policy(allow("*"), deny("*"))))), null, ACTION,
|
||||
CONNECTOR, Map.of()));
|
||||
assertEquals("because no service control policy allows the lambda:PassNetworkConnector action",
|
||||
AccessDeniedMessages.firstRefusal(evaluator, caller.withScpLevels(List.of(List.of(policy(allowCreate())))),
|
||||
null, ACTION, CONNECTOR, Map.of()));
|
||||
}
|
||||
|
||||
private String refusal(String identity, String resource) {
|
||||
return AccessDeniedMessages.firstRefusal(evaluator, CallerContext.of(List.of(identity)), null, ACTION, resource,
|
||||
Map.of());
|
||||
}
|
||||
|
||||
private String refusal(String identity, String boundary, String session) {
|
||||
HeldPolicies held = new HeldPolicies(List.of(new HeldPolicy(null, identity)), boundary == null ? null : BOUNDARY);
|
||||
return AccessDeniedMessages.firstRefusal(evaluator, caller(held, boundary, session), held, ACTION, CONNECTOR,
|
||||
Map.of());
|
||||
}
|
||||
|
||||
private static CallerContext caller(HeldPolicies held, String boundary, String session) {
|
||||
return new CallerContext(held.identity().stream().map(HeldPolicy::document).toList(), session, boundary);
|
||||
}
|
||||
|
||||
private static String policy(String... statements) {
|
||||
return "{\"Version\":\"2012-10-17\",\"Statement\":[" + String.join(",", statements) + "]}";
|
||||
}
|
||||
|
||||
private static String allow(String resource) {
|
||||
return "{\"Effect\":\"Allow\",\"Action\":\"" + ACTION + "\",\"Resource\":\"" + resource + "\"}";
|
||||
}
|
||||
|
||||
private static String deny(String resource) {
|
||||
return "{\"Effect\":\"Deny\",\"Action\":\"" + ACTION + "\",\"Resource\":\"" + resource + "\"}";
|
||||
}
|
||||
|
||||
private static String allowCreate() {
|
||||
return "{\"Effect\":\"Allow\",\"Action\":\"lambda:CreateWebFunctionRevision\",\"Resource\":\"*\"}";
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -567,7 +567,9 @@ class IamPassRoleEnforcementIntegrationTest {
|
||||
|
||||
user.policy(allow("lambda:CreateMicrovmImage", "*"));
|
||||
denied(user.rest("lambda").body(createImage).post("/2025-09-09/microvm-images").then());
|
||||
user.policy(allow("lambda:CreateMicrovmImage", "*") + "," + passRole(build, LAMBDA));
|
||||
// It also passes the managed egress connector an image gets when it names none.
|
||||
user.policy(allow("lambda:CreateMicrovmImage", "*") + "," + passRole(build, LAMBDA) + ","
|
||||
+ allow("lambda:PassNetworkConnector", "*"));
|
||||
user.rest("lambda").body(createImage).post("/2025-09-09/microvm-images").then().statusCode(201);
|
||||
cleanup.register(() -> admin("lambda").delete("/2025-09-09/microvm-images/" + image));
|
||||
// Reading it is checked against the image's ARN.
|
||||
|
||||
+2
-1
@@ -430,7 +430,8 @@ class IamRestRouteEnforcementIntegrationTest {
|
||||
|
||||
policy(user, allow("lambda:RunMicrovm", "*") + "," + deny("lambda:RunMicrovm", image));
|
||||
refused(as(user, "lambda").body(run).post("/2025-09-09/microvms").then(), "lambda:RunMicrovm");
|
||||
policy(user, allow("lambda:RunMicrovm", image));
|
||||
// It also passes the managed connectors a MicroVM gets when it names none.
|
||||
policy(user, allow("lambda:RunMicrovm", image) + "," + allow("lambda:PassNetworkConnector", "*"));
|
||||
String microvm = as(user, "lambda").body(run).post("/2025-09-09/microvms").then().statusCode(200)
|
||||
.extract().path("microvmId");
|
||||
cleanup.register(() -> admin().delete("/2025-09-09/microvms/" + microvm));
|
||||
|
||||
Reference in new issue
Block a user