Skip to content

Commit f4f5387

Browse files
authored
Add wafv2AclArn field to IngressClassParams (#3961)
* Add WAFv2ACLArn field to IngressClassParams * Add a test
1 parent 3174f96 commit f4f5387

File tree

6 files changed

+128
-4
lines changed

6 files changed

+128
-4
lines changed

apis/elbv2/v1beta1/ingressclassparams_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ type IngressClassParamsSpec struct {
185185
// PrefixListsIDs defines the security group prefix lists for all Ingresses that belong to IngressClass with this IngressClassParams.
186186
// +optional
187187
PrefixListsIDs []string `json:"prefixListsIDs,omitempty"`
188+
189+
// WAFv2ACLArn specifies ARN for the Amazon WAFv2 web ACL.
190+
// +optional
191+
WAFv2ACLArn string `json:"wafv2AclArn"`
188192
}
189193

190194
// +kubebuilder:object:root=true

config/crd/bases/elbv2.k8s.aws_ingressclassparams.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ spec:
279279
- instance
280280
- ip
281281
type: string
282+
wafv2AclArn:
283+
description: WAFv2ACLArn specifies ARN for the Amazon WAFv2 web ACL.
284+
type: string
282285
type: object
283286
x-kubernetes-validations:
284287
- message: cannot specify both 'prefixListsIDs' and 'PrefixListsIDs' fields

docs/guide/ingress/ingress_class.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ You can use IngressClassParams to enforce settings for a set of Ingresses.
181181
metadata:
182182
name: class2048-config
183183
spec:
184-
ipamConfiguration:
184+
ipamConfiguration:
185185
ipv4IPAMPoolId: ipam-pool-000000000
186186
```
187187
- with PrefixListsIDs (not recommended, use prefixListsIDs instead)
@@ -265,6 +265,7 @@ Cluster administrators can use the optional `inboundCIDRs` field to specify the
265265
If the field is specified, LBC will ignore the `alb.ingress.kubernetes.io/inbound-cidrs` annotation.
266266

267267
#### spec.certificateArn
268+
268269
Cluster administrators can use the optional `certificateARN` field to specify the ARN of the certificates for all Ingresses that belong to IngressClass with this IngressClassParams.
269270

270271
If the field is specified, LBC will ignore the `alb.ingress.kubernetes.io/certificate-arn` annotation.
@@ -349,7 +350,7 @@ Cluster administrators can use `ipamConfiguration` field to specify the IPv4 IPA
349350

350351
#### spec.PrefixListsIDs
351352

352-
We accept either `spec.prefixListsIDs` or `spec.PrefixListsIDs`. Specify both is not allowed. But `spec.PrefixListsIDs` is not recommended, use `spec.prefixListsIDs` instead.
353+
We accept either `spec.prefixListsIDs` or `spec.PrefixListsIDs`. Specify both is not allowed. But `spec.PrefixListsIDs` is not recommended, use `spec.prefixListsIDs` instead.
353354

354355
`PrefixListsIDs` is an optional setting.
355356

@@ -358,7 +359,6 @@ Cluster administrators can use `PrefixListsIDs` field to specify the managed pre
358359
1. If `PrefixListsIDs` is set, the prefix lists defined will be applied to the load balancer that belong to this IngressClass. If you specify invalid prefix list IDs, the controller will fail to reconcile ingresses belonging to the particular ingress class.
359360
2. If `PrefixListsIDs` un-specified, Ingresses with this IngressClass can continue to use `alb.ingress.kubernetes.io/security-group-prefix-lists` annotation to specify the load balancer prefix lists.
360361

361-
362362
#### spec.prefixListsIDs
363363

364364
`prefixListsIDs` is an optional setting.
@@ -372,10 +372,16 @@ Cluster administrators can use `prefixListsIDs` field to specify the managed pre
372372

373373
`listeners` is an optional setting.
374374

375-
!!!note
375+
!!!note
376376
Adding listeners in the classparam specification does not automatically create listeners on your load balancers. To create listeners, you must explicitly define the listen ports in your ingress configurations. The classparam `spec.listeners` are only used to set attributes for the listeners that you define in your ingresses.
377377

378378
Cluster administrators can use `Listeners` field to specify the [Listener Attributes](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html#listener-attributes) for multiple load balancer listeners associated with this IngressClass. For each listener entry in the list, the desired attributes and their values are specified in the `listenerAttributes` field. Each listener is uniquely identified by its `port` and `protocol` fields, which determine which listener the attributes should be applied to.
379379

380380
1. If `listeners` is set, the defined attributes will be applied to the corresponding load balancer listeners based on port and protocol matching. Note that using invalid keys or values will cause the controller to fail when reconciling ingresses in this IngressClass.
381381
2. If `Listeners` un-specified, Ingresses with this IngressClass can continue to use `alb.ingress.kubernetes.io/listener-attributes.${Protocol}-{Port}` annotation to specify the listener attributes.
382+
383+
#### spec.wafv2AclArn
384+
385+
Cluster administrators can use the optional `wafv2AclArn` field to specify ARN for the Amazon WAFv2 web ACL.
386+
Only Regional WAFv2 is supported.
387+
When this annotation is absent or empty, the controller will keep LoadBalancer WAFv2 settings unchanged. To disable WAFv2, explicitly set the annotation value to 'none'.

helm/aws-load-balancer-controller/crds/crds.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ spec:
278278
- instance
279279
- ip
280280
type: string
281+
wafv2AclArn:
282+
description: WAFv2ACLArn specifies ARN for the Amazon WAFv2 web ACL.
283+
type: string
281284
type: object
282285
x-kubernetes-validations:
283286
- message: cannot specify both 'prefixListsIDs' and 'PrefixListsIDs' fields

pkg/ingress/model_build_load_balancer_addons.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ingress
22

33
import (
44
"context"
5+
56
"github.com/pkg/errors"
67
"k8s.io/apimachinery/pkg/util/sets"
78
"sigs.k8s.io/aws-load-balancer-controller/pkg/annotations"
@@ -39,6 +40,10 @@ func (t *defaultModelBuildTask) buildWAFv2WebACLAssociation(_ context.Context, l
3940
if rawWebACLARN != "" {
4041
explicitWebACLARNs.Insert(rawWebACLARN)
4142
}
43+
params := member.IngClassConfig.IngClassParams
44+
if params != nil && params.Spec.WAFv2ACLArn != "" {
45+
explicitWebACLARNs.Insert(params.Spec.WAFv2ACLArn)
46+
}
4247
}
4348
if len(explicitWebACLARNs) == 0 {
4449
return nil, nil

pkg/ingress/model_builder_test.go

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,6 +2750,109 @@ func Test_defaultModelBuilder_Build(t *testing.T) {
27502750
}
27512751
}
27522752
}
2753+
}`,
2754+
},
2755+
{
2756+
name: "Ingress - wafv2AclArn in IngressClassParams",
2757+
env: env{
2758+
svcs: []*corev1.Service{ns_1_svc_1, ns_1_svc_2, ns_1_svc_3},
2759+
},
2760+
fields: fields{
2761+
resolveViaDiscoveryCalls: []resolveViaDiscoveryCall{resolveViaDiscoveryCallForInternalLB},
2762+
listLoadBalancersCalls: []listLoadBalancersCall{listLoadBalancerCallForEmptyLB},
2763+
enableBackendSG: true,
2764+
},
2765+
args: args{
2766+
ingGroup: Group{
2767+
ID: GroupID{Namespace: "ns-1", Name: "ing-1"},
2768+
Members: []ClassifiedIngress{
2769+
{
2770+
IngClassConfig: ClassConfiguration{
2771+
IngClassParams: &v1beta1.IngressClassParams{
2772+
Spec: v1beta1.IngressClassParamsSpec{
2773+
WAFv2ACLArn: "alb.ingress.kubernetes.io/wafv2-acl-arn: arn:aws:wafv2:us-west-2:xxxxx:regional/webacl/xxxxxxx/3ab78708-85b0-49d3-b4e1-7a9615a6613b",
2774+
},
2775+
},
2776+
},
2777+
Ing: &networking.Ingress{ObjectMeta: metav1.ObjectMeta{
2778+
Namespace: "ns-1",
2779+
Name: "ing-1",
2780+
},
2781+
Spec: networking.IngressSpec{
2782+
Rules: []networking.IngressRule{
2783+
{
2784+
Host: "app-1.example.com",
2785+
IngressRuleValue: networking.IngressRuleValue{
2786+
HTTP: &networking.HTTPIngressRuleValue{
2787+
Paths: []networking.HTTPIngressPath{
2788+
{
2789+
Path: "/svc-1",
2790+
Backend: networking.IngressBackend{
2791+
Service: &networking.IngressServiceBackend{
2792+
Name: ns_1_svc_1.Name,
2793+
Port: networking.ServiceBackendPort{
2794+
Name: "http",
2795+
},
2796+
},
2797+
},
2798+
},
2799+
{
2800+
Path: "/svc-2",
2801+
Backend: networking.IngressBackend{
2802+
Service: &networking.IngressServiceBackend{
2803+
Name: ns_1_svc_2.Name,
2804+
Port: networking.ServiceBackendPort{
2805+
Name: "http",
2806+
},
2807+
},
2808+
},
2809+
},
2810+
},
2811+
},
2812+
},
2813+
},
2814+
{
2815+
Host: "app-2.example.com",
2816+
IngressRuleValue: networking.IngressRuleValue{
2817+
HTTP: &networking.HTTPIngressRuleValue{
2818+
Paths: []networking.HTTPIngressPath{
2819+
{
2820+
Path: "/svc-3",
2821+
Backend: networking.IngressBackend{
2822+
Service: &networking.IngressServiceBackend{
2823+
Name: ns_1_svc_3.Name,
2824+
Port: networking.ServiceBackendPort{
2825+
Name: "https",
2826+
},
2827+
},
2828+
},
2829+
},
2830+
},
2831+
},
2832+
},
2833+
},
2834+
},
2835+
},
2836+
},
2837+
},
2838+
},
2839+
},
2840+
},
2841+
wantStackPatch: `
2842+
{
2843+
"id":"ns-1/ing-1",
2844+
"resources":{
2845+
"AWS::WAFv2::WebACLAssociation":{
2846+
"LoadBalancer":{
2847+
"spec":{
2848+
"resourceARN":{
2849+
"$ref":"#/resources/AWS::ElasticLoadBalancingV2::LoadBalancer/LoadBalancer/status/loadBalancerARN"
2850+
},
2851+
"webACLARN":"alb.ingress.kubernetes.io/wafv2-acl-arn: arn:aws:wafv2:us-west-2:xxxxx:regional/webacl/xxxxxxx/3ab78708-85b0-49d3-b4e1-7a9615a6613b"
2852+
}
2853+
}
2854+
}
2855+
}
27532856
}`,
27542857
},
27552858
{

0 commit comments

Comments
 (0)