Skip to content

Commit 6ed4baf

Browse files
committed
feat(NLB): Introduce annotation to allow ICMP for Path MTU Discovery
1 parent 8def727 commit 6ed4baf

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

docs/guide/service/annotations.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
| [service.beta.kubernetes.io/aws-load-balancer-multi-cluster-target-group](#multi-cluster-target-group) | boolean | false | If specified, the controller will only operate on targets that exist within the cluster, ignoring targets from other sources. |
5757
| [service.beta.kubernetes.io/aws-load-balancer-enable-prefix-for-ipv6-source-nat](#enable-prefix-for-ipv6-source-nat) | string | off | Optional annotation. dualstack lb only. Allowed values - on and off |
5858
| [service.beta.kubernetes.io/aws-load-balancer-source-nat-ipv6-prefixes](#source-nat-ipv6-prefixes) | stringList | | Optional annotation. dualstack lb only. This annotation is only applicable when user has to set the service.beta.kubernetes.io/aws-load-balancer-enable-prefix-for-ipv6-source-nat to "on". Length must match the number of subnets |
59+
| [service.beta.kubernetes.io/aws-load-balancer-enable-icmp-for-path-mtu-discovery](#icmp-path-mtu-discovery) | string | | If specified, a security group rule is added to the managed security group to allow explicit ICMP traffic for [Path MTU discovery](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/network_mtu.html#path_mtu_discovery) for IPv4 and dual-stack VPCs. Creates a rule for each source range if `service.beta.kubernetes.io/load-balancer-source-ranges` is present. |
5960

6061
## Traffic Routing
6162
Traffic Routing can be controlled with following annotations:
@@ -191,6 +192,13 @@ on the load balancer.
191192
service.beta.kubernetes.io/aws-load-balancer-ipv6-addresses: 2600:1f13:837:8501::1, 2600:1f13:837:8504::1
192193
```
193194

195+
- <a name="icmp-path-mtu-discovery">`service.beta.kubernetes.io/aws-load-balancer-enable-icmp-for-path-mtu-discovery`</a> enables the creation of security group rules to the managed security group to allow explicit ICMP traffic for [Path MTU discovery](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/network_mtu.html#path_mtu_discovery) for IPv4 and dual-stack VPCs. Creates a rule for each source range if `service.beta.kubernetes.io/load-balancer-source-ranges` is present.
196+
197+
!!!example
198+
```
199+
service.beta.kubernetes.io/aws-load-balancer-enable-icmp-for-path-mtu-discovery: "on"
200+
```
201+
194202
## Traffic Listening
195203
Traffic Listening can be controlled with following annotations:
196204

pkg/annotations/constants.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ const (
9999
SvcLBSuffixSecurityGroupPrefixLists = "aws-load-balancer-security-group-prefix-lists"
100100
SvcLBSuffixlsAttsAnnotationPrefix = "aws-load-balancer-listener-attributes"
101101
SvcLBSuffixMultiClusterTargetGroup = "aws-load-balancer-multi-cluster-target-group"
102-
ScvLBSuffixEnablePrefixForIpv6SourceNat = "aws-load-balancer-enable-prefix-for-ipv6-source-nat"
103-
ScvLBSuffixSourceNatIpv6Prefixes = "aws-load-balancer-source-nat-ipv6-prefixes"
102+
SvcLBSuffixEnablePrefixForIpv6SourceNat = "aws-load-balancer-enable-prefix-for-ipv6-source-nat"
103+
SvcLBSuffixSourceNatIpv6Prefixes = "aws-load-balancer-source-nat-ipv6-prefixes"
104+
SvcLBSuffixEnableIcmpForPathMtuDiscovery = "aws-load-balancer-enable-icmp-for-path-mtu-discovery"
104105
)

pkg/service/model_build_load_balancer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (t *defaultModelBuildTask) buildLoadBalancerIPAddressType(_ context.Context
194194

195195
func (t *defaultModelBuildTask) buildLoadBalancerEnablePrefixForIpv6SourceNat(_ context.Context, ipAddressType elbv2model.IPAddressType, ec2Subnets []ec2types.Subnet) (elbv2model.EnablePrefixForIpv6SourceNat, error) {
196196
rawEnablePrefixForIpv6SourceNat := ""
197-
if exists := t.annotationParser.ParseStringAnnotation(annotations.ScvLBSuffixEnablePrefixForIpv6SourceNat, &rawEnablePrefixForIpv6SourceNat, t.service.Annotations); !exists {
197+
if exists := t.annotationParser.ParseStringAnnotation(annotations.SvcLBSuffixEnablePrefixForIpv6SourceNat, &rawEnablePrefixForIpv6SourceNat, t.service.Annotations); !exists {
198198
return elbv2model.EnablePrefixForIpv6SourceNatOff, nil
199199
}
200200

@@ -377,7 +377,7 @@ func (t *defaultModelBuildTask) buildLoadBalancerSubnetMappings(_ context.Contex
377377
var isPrefixForIpv6SourceNatEnabled = enablePrefixForIpv6SourceNat == elbv2model.EnablePrefixForIpv6SourceNatOn
378378

379379
var sourceNatIpv6Prefixes []string
380-
sourceNatIpv6PrefixesConfigured := t.annotationParser.ParseStringSliceAnnotation(annotations.ScvLBSuffixSourceNatIpv6Prefixes, &sourceNatIpv6Prefixes, t.service.Annotations)
380+
sourceNatIpv6PrefixesConfigured := t.annotationParser.ParseStringSliceAnnotation(annotations.SvcLBSuffixSourceNatIpv6Prefixes, &sourceNatIpv6Prefixes, t.service.Annotations)
381381
if sourceNatIpv6PrefixesConfigured {
382382
sourceNatIpv6PrefixesError := networking.ValidateSourceNatPrefixes(sourceNatIpv6Prefixes, ipAddressType, isPrefixForIpv6SourceNatEnabled, ec2Subnets)
383383
if sourceNatIpv6PrefixesError != nil {

pkg/service/model_build_managed_sg.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ import (
1717
)
1818

1919
const (
20+
icmpv4Protocol = "icmp"
21+
icmpv6Protocol = "icmpv6"
22+
23+
icmpv4TypeForPathMtu = 3 // https://www.iana.org/assignments/icmp-parameters/icmp-parameters.xhtml#icmp-parameters-codes-3
24+
icmpv4CodeForPathMtu = 4
25+
26+
icmpv6TypeForPathMtu = 2 // https://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml#icmpv6-parameters-codes-2
27+
icmpv6CodeForPathMtu = 0
28+
2029
resourceIDManagedSecurityGroup = "ManagedLBSecurityGroup"
2130
)
2231

@@ -65,7 +74,11 @@ func (t *defaultModelBuildTask) buildManagedSecurityGroupName(_ context.Context)
6574
func (t *defaultModelBuildTask) buildManagedSecurityGroupIngressPermissions(ctx context.Context, ipAddressType elbv2model.IPAddressType) ([]ec2model.IPPermission, error) {
6675
var permissions []ec2model.IPPermission
6776
var prefixListIDs []string
77+
var icmpForPathMtuEnabledFlag string
78+
79+
icmpForPathMtuConfigured := t.annotationParser.ParseStringAnnotation(annotations.SvcLBSuffixEnableIcmpForPathMtuDiscovery, &icmpForPathMtuEnabledFlag, t.service.Annotations)
6880
prefixListsConfigured := t.annotationParser.ParseStringSliceAnnotation(annotations.SvcLBSuffixSecurityGroupPrefixLists, &prefixListIDs, t.service.Annotations)
81+
6982
cidrs, err := t.buildCIDRsFromSourceRanges(ctx, ipAddressType, prefixListsConfigured)
7083
if err != nil {
7184
return nil, err
@@ -84,6 +97,18 @@ func (t *defaultModelBuildTask) buildManagedSecurityGroupIngressPermissions(ctx
8497
},
8598
},
8699
})
100+
if icmpForPathMtuConfigured && icmpForPathMtuEnabledFlag == "on" {
101+
permissions = append(permissions, ec2model.IPPermission{
102+
IPProtocol: string(icmpv4Protocol),
103+
FromPort: awssdk.Int32(icmpv4TypeForPathMtu),
104+
ToPort: awssdk.Int32(icmpv4CodeForPathMtu),
105+
IPRanges: []ec2model.IPRange{
106+
{
107+
CIDRIP: cidr,
108+
},
109+
},
110+
})
111+
}
87112
} else {
88113
permissions = append(permissions, ec2model.IPPermission{
89114
IPProtocol: strings.ToLower(string(port.Protocol)),
@@ -95,6 +120,18 @@ func (t *defaultModelBuildTask) buildManagedSecurityGroupIngressPermissions(ctx
95120
},
96121
},
97122
})
123+
if icmpForPathMtuConfigured && icmpForPathMtuEnabledFlag == "on" {
124+
permissions = append(permissions, ec2model.IPPermission{
125+
IPProtocol: string(icmpv6Protocol),
126+
FromPort: awssdk.Int32(icmpv6TypeForPathMtu),
127+
ToPort: awssdk.Int32(icmpv6CodeForPathMtu),
128+
IPv6Range: []ec2model.IPv6Range{
129+
{
130+
CIDRIPv6: cidr,
131+
},
132+
},
133+
})
134+
}
98135
}
99136
}
100137
if prefixListsConfigured {
@@ -112,6 +149,7 @@ func (t *defaultModelBuildTask) buildManagedSecurityGroupIngressPermissions(ctx
112149
}
113150
}
114151
}
152+
115153
return permissions, nil
116154
}
117155

0 commit comments

Comments
 (0)