fix(ec2): persist default egress as SecurityGroupRule and fix DescribeSecurityGroupRules filter parsing (#1525)

This commit is contained in:
Prakhar Kapoor authored and GitHub committed 2026-06-25 01:16:18 -05:00
1 parent 28a1427ea8
commit 0b28554626
3 files changed
+78 -5

No files matched your search

@@ -913,10 +913,15 @@ public class Ec2QueryHandler {
}
private Response handleDescribeSecurityGroupRules(MultivaluedMap<String, String> p, String region) {
String groupId = p.getFirst("Filter.1.Value.1");
Map<String, List<String>> filters = getFilters(p);
// The AWS SDK sends the security group id as a filter with name "group-id"
String groupId = "";
List<String> groupIdFilter = filters.get("group-id");
if (groupIdFilter != null && !groupIdFilter.isEmpty()) {
groupId = groupIdFilter.get(0);
}
List<String> ruleIds = getList(p, "SecurityGroupRuleId");
List<SecurityGroupRule> rules = service.describeSecurityGroupRules(region,
groupId != null ? groupId : "", ruleIds);
List<SecurityGroupRule> rules = service.describeSecurityGroupRules(region, groupId, ruleIds);
XmlBuilder xml = new XmlBuilder()
.start("DescribeSecurityGroupRulesResponse", AwsNamespaces.EC2)
.elem("requestId", UUID.randomUUID().toString())
@@ -299,6 +299,9 @@ public class Ec2Service {
egressAll.getIpRanges().add(new IpRange("0.0.0.0/0"));
defaultSg.getIpPermissionsEgress().add(egressAll);
securityGroups.put(key(region, securityGroupId), defaultSg);
// Persist the default egress rule as a SecurityGroupRule so that
// DescribeSecurityGroupRules can find it immediately (#1093).
createRules(region, securityGroupId, egressAll, true);
}
private String createMainRouteTable(String region, Vpc vpc, String routeTableId, String associationId) {
@@ -1110,6 +1113,9 @@ public class Ec2Service {
egressAll.getIpRanges().add(new IpRange("0.0.0.0/0"));
sg.getIpPermissionsEgress().add(egressAll);
securityGroups.put(key(region, sgId), sg);
// Persist the default egress rule as a SecurityGroupRule so that
// DescribeSecurityGroupRules can find it immediately (#1093).
createRules(region, sgId, egressAll, true);
return sg;
}
@@ -1228,8 +1234,9 @@ public class Ec2Service {
public List<SecurityGroupRule> describeSecurityGroupRules(String region, String groupId, List<String> ruleIds) {
ensureDefaultResources(region);
return securityGroupRules.scan(k -> true).stream()
.filter(r -> r.getGroupId().equals(groupId))
String regionPrefix = region + "::";
return securityGroupRules.scan(k -> k.startsWith(regionPrefix)).stream()
.filter(r -> groupId.isEmpty() || groupId.equals(r.getGroupId()))
.filter(r -> ruleIds.isEmpty() || ruleIds.contains(r.getSecurityGroupRuleId()))
.collect(Collectors.toList());
}