Skip to content

Commit a5679af

Browse files
committed
spike/aws-nlb/internal/proxy: enforce proxy proto on internal NLB IC
1 parent 2371120 commit a5679af

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

pkg/operator/controller/ingress/controller.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,9 +1233,14 @@ func IsProxyProtocolNeeded(ic *operatorv1.IngressController, platform *configv1.
12331233
if ic.Status.EndpointPublishingStrategy.LoadBalancer == nil ||
12341234
ic.Status.EndpointPublishingStrategy.LoadBalancer.ProviderParameters == nil ||
12351235
ic.Status.EndpointPublishingStrategy.LoadBalancer.ProviderParameters.AWS == nil ||
1236-
ic.Status.EndpointPublishingStrategy.LoadBalancer.ProviderParameters.Type == operatorv1.AWSLoadBalancerProvider &&
1237-
ic.Status.EndpointPublishingStrategy.LoadBalancer.ProviderParameters.AWS.Type == operatorv1.AWSClassicLoadBalancer {
1238-
return true, nil
1236+
ic.Status.EndpointPublishingStrategy.LoadBalancer.ProviderParameters.Type == operatorv1.AWSLoadBalancerProvider {
1237+
if ic.Status.EndpointPublishingStrategy.LoadBalancer.ProviderParameters.AWS.Type == operatorv1.AWSClassicLoadBalancer {
1238+
return true, nil
1239+
}
1240+
if ic.Status.EndpointPublishingStrategy.LoadBalancer.Scope == operatorv1.InternalLoadBalancer &&
1241+
ic.Status.EndpointPublishingStrategy.LoadBalancer.ProviderParameters.AWS.Type == operatorv1.AWSNetworkLoadBalancer {
1242+
return true, nil
1243+
}
12391244
}
12401245
case configv1.IBMCloudPlatformType:
12411246
if ic.Status.EndpointPublishingStrategy.LoadBalancer != nil &&

pkg/operator/controller/ingress/load_balancer_service.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ const (
6464
// See https://docs.aws.amazon.com/elasticloadbalancing/latest/network/target-group-health-checks.html
6565
awsLBHealthCheckIntervalNLB = "10"
6666

67+
// awsTargetGroupAttributesInternalProxyProtocolEnabled is the value of the awsTargetGroupAttributesAnnotation for internal load balancers that need to enable proxy protocol.
68+
awsTargetGroupAttributesInternalProxyProtocolEnabled = "preserve_client_ip.enabled=false,proxy_protocol_v2.enabled=true"
69+
6770
// awsLBHealthCheckTimeoutAnnotation is the amount of time, in seconds, during which no response
6871
// means a failed AWS load balancer health check. The value must be less than the value of
6972
// awsLBHealthCheckIntervalAnnotation. Defaults to 4, must be between 2 and 60.
@@ -92,6 +95,9 @@ const (
9295
// awsEIPAllocationsAnnotation specifies a list of eips for NLBs.
9396
awsEIPAllocationsAnnotation = "service.beta.kubernetes.io/aws-load-balancer-eip-allocations"
9497

98+
// awsTargetGroupAttributesAnnotation is the annotation used on a service to specify target group attributes for an AWS load balancer.
99+
awsTargetGroupAttributesAnnotation = "service.beta.kubernetes.io/aws-load-balancer-target-group-attributes"
100+
95101
// iksLBScopeAnnotation is the annotation used on a service to specify an IBM
96102
// load balancer IP type.
97103
iksLBScopeAnnotation = "service.kubernetes.io/ibm-load-balancer-cloud-provider-ip-type"
@@ -422,6 +428,11 @@ func desiredLoadBalancerService(ci *operatorv1.IngressController, deploymentRef
422428
}
423429
}
424430

431+
// Configure the target group attributes for internal load balancers that need to enable proxy protocol and support hairpinning traffic.
432+
if proxyNeeded && isInternal {
433+
service.Annotations[awsTargetGroupAttributesAnnotation] = awsTargetGroupAttributesInternalProxyProtocolEnabled
434+
}
435+
425436
case operatorv1.AWSClassicLoadBalancer:
426437
if aws.ClassicLoadBalancerParameters != nil {
427438
if v := aws.ClassicLoadBalancerParameters.ConnectionIdleTimeout; v.Duration > 0 {

0 commit comments

Comments
 (0)