Skip to content

Commit fc63965

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

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

pkg/operator/controller/ingress/controller.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,13 +1230,25 @@ func IsProxyProtocolNeeded(ic *operatorv1.IngressController, platform *configv1.
12301230
// This can really be done for for any external [cloud] LBs that support the proxy protocol.
12311231
switch platform.Type {
12321232
case configv1.AWSPlatformType:
1233+
// Handle nil cases - default to Classic Load Balancer behavior (uses PROXY)
1234+
// TODO: validate if this won't generate false positives
12331235
if ic.Status.EndpointPublishingStrategy.LoadBalancer == nil ||
12341236
ic.Status.EndpointPublishingStrategy.LoadBalancer.ProviderParameters == nil ||
1235-
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 {
1237+
ic.Status.EndpointPublishingStrategy.LoadBalancer.ProviderParameters.AWS == nil {
12381238
return true, nil
12391239
}
1240+
1241+
// Only check specific AWS provider configurations if everything is properly set
1242+
if ic.Status.EndpointPublishingStrategy.LoadBalancer.ProviderParameters.Type == operatorv1.AWSLoadBalancerProvider {
1243+
// Classic Load Balancer uses PROXY protocol
1244+
if ic.Status.EndpointPublishingStrategy.LoadBalancer.ProviderParameters.AWS.Type == operatorv1.AWSClassicLoadBalancer {
1245+
return true, nil
1246+
}
1247+
// Network Load Balancer uses PROXY protocol only when internal
1248+
if ic.Status.EndpointPublishingStrategy.LoadBalancer.ProviderParameters.AWS.Type == operatorv1.AWSNetworkLoadBalancer {
1249+
return ic.Status.EndpointPublishingStrategy.LoadBalancer.Scope == operatorv1.InternalLoadBalancer, nil
1250+
}
1251+
}
12401252
case configv1.IBMCloudPlatformType:
12411253
if ic.Status.EndpointPublishingStrategy.LoadBalancer != nil &&
12421254
ic.Status.EndpointPublishingStrategy.LoadBalancer.ProviderParameters != 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)