mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(ec2): add Network ACL support (#1473)
Implements CreateNetworkAcl, DescribeNetworkAcls (with vpc-id / default / association.subnet-id filters), CreateNetworkAclEntry, ReplaceNetworkAclEntry, DeleteNetworkAclEntry, ReplaceNetworkAclAssociation, and DeleteNetworkAcl. Every VPC is provisioned with a default NACL and each subnet is associated with it, so aws_network_acl and aws_default_network_acl work via Terraform. Adds Ec2IntegrationTest coverage and documents the new actions.
This commit is contained in:
1 parent
7b3c5b230d
commit
2301db53c7
9 files changed
+604
-1
No files matched your search
@@ -2390,4 +2390,194 @@ class Ec2IntegrationTest {
|
||||
.statusCode(200)
|
||||
.body("DescribeSpotInstanceRequestsResponse.spotInstanceRequestSet.item[0].state", equalTo("cancelled"));
|
||||
}
|
||||
|
||||
private String newVpc(String cidr) {
|
||||
return given()
|
||||
.formParam("Action", "CreateVpc")
|
||||
.formParam("CidrBlock", cidr)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.extract().path("CreateVpcResponse.vpc.vpcId");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(310)
|
||||
void defaultNetworkAclCreatedWithVpc() {
|
||||
String vpc = newVpc("10.30.0.0/16");
|
||||
given()
|
||||
.formParam("Action", "DescribeNetworkAcls")
|
||||
.formParam("Filter.1.Name", "vpc-id")
|
||||
.formParam("Filter.1.Value.1", vpc)
|
||||
.formParam("Filter.2.Name", "default")
|
||||
.formParam("Filter.2.Value.1", "true")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeNetworkAclsResponse.networkAclSet.item.networkAclId", startsWith("acl-"))
|
||||
.body("DescribeNetworkAclsResponse.networkAclSet.item.vpcId", equalTo(vpc));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(311)
|
||||
void networkAclCreateEntryAndDelete() {
|
||||
String vpc = newVpc("10.31.0.0/16");
|
||||
String aclId = given()
|
||||
.formParam("Action", "CreateNetworkAcl")
|
||||
.formParam("VpcId", vpc)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CreateNetworkAclResponse.networkAcl.networkAclId", startsWith("acl-"))
|
||||
.body("CreateNetworkAclResponse.networkAcl.vpcId", equalTo(vpc))
|
||||
.extract().path("CreateNetworkAclResponse.networkAcl.networkAclId");
|
||||
|
||||
given()
|
||||
.formParam("Action", "CreateNetworkAclEntry")
|
||||
.formParam("NetworkAclId", aclId)
|
||||
.formParam("RuleNumber", "100")
|
||||
.formParam("Protocol", "6")
|
||||
.formParam("RuleAction", "allow")
|
||||
.formParam("Egress", "false")
|
||||
.formParam("CidrBlock", "0.0.0.0/0")
|
||||
.formParam("PortRange.From", "443")
|
||||
.formParam("PortRange.To", "443")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("CreateNetworkAclEntryResponse.return", equalTo("true"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "DescribeNetworkAcls")
|
||||
.formParam("NetworkAclId.1", aclId)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeNetworkAclsResponse.networkAclSet.item.networkAclId", equalTo(aclId));
|
||||
|
||||
given()
|
||||
.formParam("Action", "DeleteNetworkAcl")
|
||||
.formParam("NetworkAclId", aclId)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("DeleteNetworkAclResponse.return", equalTo("true"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(312)
|
||||
void createNetworkAclEntryRejectsDuplicateButReplaceOverwrites() {
|
||||
String vpc = newVpc("10.32.0.0/16");
|
||||
String aclId = given()
|
||||
.formParam("Action", "CreateNetworkAcl")
|
||||
.formParam("VpcId", vpc)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.extract().path("CreateNetworkAclResponse.networkAcl.networkAclId");
|
||||
|
||||
given()
|
||||
.formParam("Action", "CreateNetworkAclEntry")
|
||||
.formParam("NetworkAclId", aclId)
|
||||
.formParam("RuleNumber", "100")
|
||||
.formParam("Protocol", "6")
|
||||
.formParam("RuleAction", "allow")
|
||||
.formParam("Egress", "false")
|
||||
.formParam("CidrBlock", "0.0.0.0/0")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("CreateNetworkAclEntryResponse.return", equalTo("true"));
|
||||
|
||||
// Re-creating the same rule number/direction must fail — only Replace may overwrite.
|
||||
given()
|
||||
.formParam("Action", "CreateNetworkAclEntry")
|
||||
.formParam("NetworkAclId", aclId)
|
||||
.formParam("RuleNumber", "100")
|
||||
.formParam("Protocol", "6")
|
||||
.formParam("RuleAction", "deny")
|
||||
.formParam("Egress", "false")
|
||||
.formParam("CidrBlock", "0.0.0.0/0")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("NetworkAclEntryAlreadyExists"));
|
||||
|
||||
// Replace on the same rule number succeeds and overwrites the existing entry.
|
||||
given()
|
||||
.formParam("Action", "ReplaceNetworkAclEntry")
|
||||
.formParam("NetworkAclId", aclId)
|
||||
.formParam("RuleNumber", "100")
|
||||
.formParam("Protocol", "6")
|
||||
.formParam("RuleAction", "deny")
|
||||
.formParam("Egress", "false")
|
||||
.formParam("CidrBlock", "0.0.0.0/0")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("ReplaceNetworkAclEntryResponse.return", equalTo("true"));
|
||||
|
||||
// Confirm the rule was actually overwritten (allow -> deny), not just that the call succeeded.
|
||||
given()
|
||||
.formParam("Action", "DescribeNetworkAcls")
|
||||
.formParam("NetworkAclId.1", aclId)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("DescribeNetworkAclsResponse.networkAclSet.item.entrySet.item.find { it.ruleNumber == '100' }.ruleAction",
|
||||
equalTo("deny"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(313)
|
||||
void deleteNetworkAclWithAssociationFails() {
|
||||
String vpc = newVpc("10.33.0.0/16");
|
||||
given()
|
||||
.formParam("Action", "CreateSubnet")
|
||||
.formParam("VpcId", vpc)
|
||||
.formParam("CidrBlock", "10.33.1.0/24")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
|
||||
// The subnet starts on the VPC's default NACL — grab that association ID.
|
||||
String associationId = given()
|
||||
.formParam("Action", "DescribeNetworkAcls")
|
||||
.formParam("Filter.1.Name", "vpc-id")
|
||||
.formParam("Filter.1.Value.1", vpc)
|
||||
.formParam("Filter.2.Name", "default")
|
||||
.formParam("Filter.2.Value.1", "true")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.extract().path("DescribeNetworkAclsResponse.networkAclSet.item.associationSet.item.networkAclAssociationId");
|
||||
|
||||
String aclId = given()
|
||||
.formParam("Action", "CreateNetworkAcl")
|
||||
.formParam("VpcId", vpc)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.extract().path("CreateNetworkAclResponse.networkAcl.networkAclId");
|
||||
|
||||
// Move the subnet onto the custom NACL so it now has a live association.
|
||||
given()
|
||||
.formParam("Action", "ReplaceNetworkAclAssociation")
|
||||
.formParam("AssociationId", associationId)
|
||||
.formParam("NetworkAclId", aclId)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
|
||||
given()
|
||||
.formParam("Action", "DeleteNetworkAcl")
|
||||
.formParam("NetworkAclId", aclId)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("DependencyViolation"));
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Address;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Instance;
|
||||
import io.github.hectorvent.floci.services.ec2.model.InternetGateway;
|
||||
import io.github.hectorvent.floci.services.ec2.model.NetworkAcl;
|
||||
import io.github.hectorvent.floci.services.ec2.model.KeyPair;
|
||||
import io.github.hectorvent.floci.services.ec2.model.LaunchTemplate;
|
||||
import io.github.hectorvent.floci.services.ec2.model.NatGateway;
|
||||
@@ -82,6 +83,7 @@ class Ec2ServicePersistenceTest {
|
||||
load(dir, "ec2-vpc-endpoints.json", new TypeReference<Map<String, VpcEndpoint>>() {}),
|
||||
load(dir, "ec2-nat-gateways.json", new TypeReference<Map<String, NatGateway>>() {}),
|
||||
load(dir, "ec2-spot-instance-requests.json", new TypeReference<Map<String, SpotInstanceRequest>>() {}),
|
||||
load(dir, "ec2-network-acls.json", new TypeReference<Map<String, NetworkAcl>>() {}),
|
||||
load(dir, "ec2-tags.json", new TypeReference<Map<String, List<Tag>>>() {}));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user