Skip to content

Commit 7cd06f1

Browse files
authored
keep LB addons' settings unchanged unless explicitly specified (kubernetes-sigs#3800)
add UTs for related components
1 parent 2556198 commit 7cd06f1

14 files changed

+1934
-112
lines changed

docs/guide/ingress/annotations.md

+33-15
Original file line numberDiff line numberDiff line change
@@ -907,35 +907,53 @@ In addition, you can use annotations to specify additional tags
907907

908908
## Addons
909909

910-
!!!note
911-
If waf-acl-arn is specified via the ingress annotations, the controller will make sure the waf-acl is associated to the provisioned ALB with the ingress.
912-
If there is not such annotation, the controller will make sure no waf-acl is associated, so it may remove the existing waf-acl on the ALB provisioned.
913-
If users do not want the controller to manage the waf-acl on the ALBs, they can disable the feature by setting controller command line flags `--enable-waf=false` or `--enable-wafv2=false`
914-
915-
- <a name="waf-acl-id">`alb.ingress.kubernetes.io/waf-acl-id`</a> specifies the identifier for the Amazon WAF web ACL.
910+
- <a name="waf-acl-id">`alb.ingress.kubernetes.io/waf-acl-id`</a> specifies the identifier for the Amazon WAF Classic web ACL.
916911

917912
!!!warning ""
918-
Only Regional WAF is supported.
913+
Only Regional WAF Classic is supported.
914+
915+
!!!note ""
916+
When this annotation is absent or empty, the controller will keep LoadBalancer WAF Classic settings unchanged.
917+
To disable WAF Classic, explicitly set the annotation value to 'none'.
919918

920919
!!!example
921-
```alb.ingress.kubernetes.io/waf-acl-id: 499e8b99-6671-4614-a86d-adb1810b7fbe
922-
```
920+
- enable WAF Classic
921+
```alb.ingress.kubernetes.io/waf-acl-id: 499e8b99-6671-4614-a86d-adb1810b7fbe
922+
```
923+
- disable WAF Classic
924+
```alb.ingress.kubernetes.io/waf-acl-id: none
925+
```
923926

924927
- <a name="wafv2-acl-arn">`alb.ingress.kubernetes.io/wafv2-acl-arn`</a> specifies ARN for the Amazon WAFv2 web ACL.
925928

926929
!!!warning ""
927930
Only Regional WAFv2 is supported.
928931

932+
!!!note ""
933+
When this annotation is absent or empty, the controller will keep LoadBalancer WAFv2 settings unchanged.
934+
To disable WAFv2, explicitly set the annotation value to 'none'.
935+
929936
!!!tip ""
930937
To get the WAFv2 Web ACL ARN from the Console, click the gear icon in the upper right and enable the ARN column.
931938

932939
!!!example
933-
```alb.ingress.kubernetes.io/wafv2-acl-arn: arn:aws:wafv2:us-west-2:xxxxx:regional/webacl/xxxxxxx/3ab78708-85b0-49d3-b4e1-7a9615a6613b
934-
```
935-
940+
- enable WAFv2
941+
```alb.ingress.kubernetes.io/wafv2-acl-arn: arn:aws:wafv2:us-west-2:xxxxx:regional/webacl/xxxxxxx/3ab78708-85b0-49d3-b4e1-7a9615a6613b
942+
```
943+
- disable WAFV2
944+
```alb.ingress.kubernetes.io/wafv2-acl-arn: none
945+
```
946+
936947
- <a name="shield-advanced-protection">`alb.ingress.kubernetes.io/shield-advanced-protection`</a> turns on / off the AWS Shield Advanced protection for the load balancer.
937948

938-
!!!example
939-
```alb.ingress.kubernetes.io/shield-advanced-protection: 'true'
940-
```
949+
!!!note ""
950+
When this annotation is absent, the controller will keep LoadBalancer shield protection settings unchanged.
951+
To disable shield protection, explicitly set the annotation value to 'false'.
941952

953+
!!!example
954+
- enable shield protection
955+
```alb.ingress.kubernetes.io/shield-advanced-protection: 'true'
956+
```
957+
- disable shield protection
958+
```alb.ingress.kubernetes.io/shield-advanced-protection: 'false'
959+
```

pkg/deploy/shield/protection_manager_mocks.go

+94
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/deploy/shield/protection_synthesizer.go

+13-25
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package shield
22

33
import (
44
"context"
5+
"fmt"
56
"github.com/go-logr/logr"
67
"github.com/pkg/errors"
78
"k8s.io/apimachinery/pkg/util/sets"
89
"sigs.k8s.io/aws-load-balancer-controller/pkg/model/core"
9-
elbv2model "sigs.k8s.io/aws-load-balancer-controller/pkg/model/elbv2"
1010
shieldmodel "sigs.k8s.io/aws-load-balancer-controller/pkg/model/shield"
1111
)
1212

@@ -32,25 +32,18 @@ type protectionSynthesizer struct {
3232

3333
func (s *protectionSynthesizer) Synthesize(ctx context.Context) error {
3434
var resProtections []*shieldmodel.Protection
35-
s.stack.ListResources(&resProtections)
35+
if err := s.stack.ListResources(&resProtections); err != nil {
36+
return fmt.Errorf("[should never happen] failed to list resources: %w", err)
37+
}
38+
if len(resProtections) == 0 {
39+
return nil
40+
}
3641
resProtectionsByResARN, err := mapResProtectionByResourceARN(resProtections)
3742
if err != nil {
3843
return err
3944
}
40-
41-
var resLBs []*elbv2model.LoadBalancer
42-
s.stack.ListResources(&resLBs)
43-
for _, resLB := range resLBs {
44-
// shield protection can only be associated with ALB for now.
45-
if resLB.Spec.Type != elbv2model.LoadBalancerTypeApplication {
46-
continue
47-
}
48-
lbARN, err := resLB.LoadBalancerARN().Resolve(ctx)
49-
if err != nil {
50-
return err
51-
}
52-
resProtections := resProtectionsByResARN[lbARN]
53-
if err := s.synthesizeProtectionsOnLB(ctx, lbARN, resProtections); err != nil {
45+
for resARN, protections := range resProtectionsByResARN {
46+
if err := s.synthesizeProtectionsOnLB(ctx, resARN, protections); err != nil {
5447
return err
5548
}
5649
}
@@ -63,18 +56,13 @@ func (s *protectionSynthesizer) PostSynthesize(ctx context.Context) error {
6356
}
6457

6558
func (s *protectionSynthesizer) synthesizeProtectionsOnLB(ctx context.Context, lbARN string, resProtections []*shieldmodel.Protection) error {
66-
if len(resProtections) > 1 {
67-
return errors.Errorf("[should never happen] multiple shield protection desired on LoadBalancer: %v", lbARN)
68-
}
69-
70-
enableProtection := false
71-
if len(resProtections) == 1 {
72-
enableProtection = true
59+
if len(resProtections) != 1 {
60+
return errors.Errorf("[should never happen] should be exactly one shield protection desired on LoadBalancer: %v", lbARN)
7361
}
74-
62+
enableProtection := resProtections[0].Spec.Enabled
7563
protectionInfo, err := s.protectionManager.GetProtection(ctx, lbARN)
7664
if err != nil {
77-
return err
65+
return errors.Wrap(err, "failed to get shield protection on LoadBalancer")
7866
}
7967
switch {
8068
case !enableProtection && protectionInfo != nil:

0 commit comments

Comments
 (0)