mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(ec2): ignore ports when revoking an all-traffic rule (#6895)
* fix(ec2): ignore ports when revoking an all-traffic rule Revoking an "all traffic" (-1) rule compared ports literally. Terraform's aws_security_group revokes AWS's default egress rule as -1 with FromPort=0 and ToPort=0, which never matched the stored rule (it has no ports), so every new group kept allowing all egress and the next plan wanted to remove it again. AWS ignores ports for -1. Protocols are now compared after the same normalization the security-group evaluation uses, so a revoke naming protocol 6 also matches a tcp rule, as on AWS. * test(ec2): name the all-traffic revoke test a service test * test(ec2): move the all-traffic revoke tests into Ec2ServiceTest Use Ec2ServiceTest's existing mockModeService() instead of a copied mock-mode harness, as requested in review.
This commit is contained in:
1 parent
1356cbbc84
commit
d68876edcc
4 files changed
+52
-5
No files matched your search
@@ -8155,9 +8155,14 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
}
|
||||
|
||||
private boolean sameProtocolAndPorts(IpPermission a, IpPermission b) {
|
||||
return Objects.equals(a.getIpProtocol(), b.getIpProtocol())
|
||||
&& Objects.equals(a.getFromPort(), b.getFromPort())
|
||||
&& Objects.equals(a.getToPort(), b.getToPort());
|
||||
String protocol = SecurityGroupPolicy.normalizeProtocol(a.getIpProtocol());
|
||||
if (!Objects.equals(protocol, SecurityGroupPolicy.normalizeProtocol(b.getIpProtocol()))) {
|
||||
return false;
|
||||
}
|
||||
// "All traffic" has no ports, and AWS ignores any a request names: Terraform's
|
||||
// aws_security_group revokes the default egress rule as -1 with FromPort=0, ToPort=0.
|
||||
return "-1".equals(protocol)
|
||||
|| (Objects.equals(a.getFromPort(), b.getFromPort()) && Objects.equals(a.getToPort(), b.getToPort()));
|
||||
}
|
||||
|
||||
private boolean hasSources(IpPermission perm) {
|
||||
|
||||
@@ -63,7 +63,7 @@ public final class SecurityGroupPolicy {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static String normalizeProtocol(String protocol) {
|
||||
static String normalizeProtocol(String protocol) {
|
||||
if (protocol == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user