Skip to content

Commit 06e57df

Browse files
authoredJan 22, 2025··
Merge pull request #3939 from chriswachira/introduce-annotation-to-enable-icmp-rule-for-path-mtu-discovery
feat(NLB): Introduce Service annotation to allow ICMP for Path MTU Discovery
2 parents 6967226 + 64e498f commit 06e57df

File tree

5 files changed

+55
-6
lines changed

5 files changed

+55
-6
lines changed
 

‎docs/guide/service/annotations.md

+8
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
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 |
5959
| [service.beta.kubernetes.io/aws-load-balancer-minimum-load-balancer-capacity](#load-balancer-capacity-reservation) | stringMap | |
60+
| [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. |
6061

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

196+
- <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.
197+
198+
!!!example
199+
```
200+
service.beta.kubernetes.io/aws-load-balancer-enable-icmp-for-path-mtu-discovery: "on"
201+
```
202+
195203
## Traffic Listening
196204
Traffic Listening can be controlled with following annotations:
197205

‎pkg/annotations/constants.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ const (
100100
SvcLBSuffixSecurityGroupPrefixLists = "aws-load-balancer-security-group-prefix-lists"
101101
SvcLBSuffixlsAttsAnnotationPrefix = "aws-load-balancer-listener-attributes"
102102
SvcLBSuffixMultiClusterTargetGroup = "aws-load-balancer-multi-cluster-target-group"
103-
ScvLBSuffixEnablePrefixForIpv6SourceNat = "aws-load-balancer-enable-prefix-for-ipv6-source-nat"
104-
ScvLBSuffixSourceNatIpv6Prefixes = "aws-load-balancer-source-nat-ipv6-prefixes"
103+
SvcLBSuffixEnablePrefixForIpv6SourceNat = "aws-load-balancer-enable-prefix-for-ipv6-source-nat"
104+
SvcLBSuffixSourceNatIpv6Prefixes = "aws-load-balancer-source-nat-ipv6-prefixes"
105105
SvcLBSuffixLoadBalancerCapacityReservation = "aws-load-balancer-minimum-load-balancer-capacity"
106+
SvcLBSuffixEnableIcmpForPathMtuDiscovery = "aws-load-balancer-enable-icmp-for-path-mtu-discovery"
106107
)

‎pkg/service/model_build_load_balancer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func (t *defaultModelBuildTask) buildLoadBalancerIPAddressType(_ context.Context
199199

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

@@ -382,7 +382,7 @@ func (t *defaultModelBuildTask) buildLoadBalancerSubnetMappings(_ context.Contex
382382
var isPrefixForIpv6SourceNatEnabled = enablePrefixForIpv6SourceNat == elbv2model.EnablePrefixForIpv6SourceNatOn
383383

384384
var sourceNatIpv6Prefixes []string
385-
sourceNatIpv6PrefixesConfigured := t.annotationParser.ParseStringSliceAnnotation(annotations.ScvLBSuffixSourceNatIpv6Prefixes, &sourceNatIpv6Prefixes, t.service.Annotations)
385+
sourceNatIpv6PrefixesConfigured := t.annotationParser.ParseStringSliceAnnotation(annotations.SvcLBSuffixSourceNatIpv6Prefixes, &sourceNatIpv6Prefixes, t.service.Annotations)
386386
if sourceNatIpv6PrefixesConfigured {
387387
sourceNatIpv6PrefixesError := networking.ValidateSourceNatPrefixes(sourceNatIpv6Prefixes, ipAddressType, isPrefixForIpv6SourceNatEnabled, ec2Subnets)
388388
if sourceNatIpv6PrefixesError != nil {

‎pkg/service/model_build_managed_sg.go

+38
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 icmpForPathMtuConfiguredFlag string
78+
79+
icmpForPathMtuConfigured := t.annotationParser.ParseStringAnnotation(annotations.SvcLBSuffixEnableIcmpForPathMtuDiscovery, &icmpForPathMtuConfiguredFlag, 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 && icmpForPathMtuConfiguredFlag == "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 && icmpForPathMtuConfiguredFlag == "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

‎pkg/service/model_builder_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package service
22

33
import (
44
"context"
5-
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
6-
elbv2types "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types"
75
"testing"
86
"time"
97

8+
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
9+
elbv2types "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types"
10+
1011
awssdk "github.com/aws/aws-sdk-go-v2/aws"
1112
"github.com/go-logr/logr"
1213
"github.com/golang/mock/gomock"
@@ -6503,6 +6504,7 @@ func Test_defaultModelBuilderTask_Build(t *testing.T) {
65036504
"securityGroupsInboundRulesOnPrivateLink":"on",
65046505
"enablePrefixForIpv6SourceNat": "off",
65056506
"ipAddressType":"ipv4",
6507+
"enablePrefixForIpv6SourceNat": "off",
65066508
"subnetMapping":[
65076509
{
65086510
"subnetID":"subnet-1"

0 commit comments

Comments
 (0)
Please sign in to comment.