Skip to content

Commit acad64b

Browse files
authored
Allow using TLS 1.3 policies with NLBs (#2934)
Fixes: #2928 Signed-off-by: Andreas Kohn (Framer) <andreas.kohn@framer.com>
1 parent dd12101 commit acad64b

File tree

4 files changed

+140
-37
lines changed

4 files changed

+140
-37
lines changed

checkov/cloudformation/checks/resource/aws/ALBListenerTLS12.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,38 @@
33
from checkov.common.util.type_forcers import force_list
44
from checkov.cloudformation.parser.cfn_keywords import ConditionFunctions, IntrinsicFunctions
55

6+
supported_policy_prefixes = {
7+
# ALBs support TLS v1.2
8+
'HTTPS': ("ELBSecurityPolicy-FS-1-2", "ELBSecurityPolicy-TLS-1-2"),
9+
# NLBs support TLS v1.2 and 1.3
10+
'TLS': ("ELBSecurityPolicy-TLS13-1-3-2021-06", "ELBSecurityPolicy-TLS13-1-2", "ELBSecurityPolicy-FS-1-2", "ELBSecurityPolicy-TLS-1-2")
11+
}
612

713
class ALBListenerTLS12(BaseResourceCheck):
814

915
def __init__(self):
10-
name = "Ensure that Application Load Balancer Listener is using TLS v1.2"
16+
name = "Ensure that Load Balancer Listener is using at least TLS v1.2"
1117
id = "CKV_AWS_103"
1218
supported_resources = ['AWS::ElasticLoadBalancingV2::Listener']
1319
categories = [CheckCategories.GENERAL_SECURITY]
1420
super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources)
1521

1622
def scan_resource_conf(self, conf):
1723
"""
18-
validates that ALB Listener is using TLS v1.2
24+
validates that ElasticLoadBalancing V2 Listener is using at least TLS v1.2
1925
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticloadbalancingv2-listener.html
2026
:param conf: aws_alb_listener configuration
2127
:return: <CheckResult>
2228
"""
2329

2430
if 'Properties' in conf.keys():
2531
if 'Protocol' in conf['Properties'].keys():
26-
# Check SslPolicy only if protocol is HTTPS or TLS.
27-
# Other protocols are not intresting within the context of this check.
28-
if conf['Properties']['Protocol'] in ('HTTPS', 'TLS'):
32+
# Check SslPolicy only if protocol is HTTPS (ALB) or TLS (NLB).
33+
# Other protocols are not interesting within the context of this check.
34+
protocol = conf['Properties']['Protocol']
35+
if protocol in ('HTTPS', 'TLS'):
2936
if 'SslPolicy' in conf['Properties'].keys():
30-
if conf['Properties']['SslPolicy'].startswith(("ELBSecurityPolicy-FS-1-2", "ELBSecurityPolicy-TLS-1-2")):
37+
if conf['Properties']['SslPolicy'].startswith(supported_policy_prefixes[protocol]):
3138
return CheckResult.PASSED
3239
return CheckResult.FAILED
3340
elif conf['Properties']['Protocol'] in ('TCP', 'UDP', 'TCP_UDP'):

tests/cloudformation/checks/resource/aws/example_ALBListenerTLS12/ALBListenerTLS1.2-FAILED.yaml

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@ Parameters:
77
Type: List<AWS::EC2::Subnet::Id>
88

99
Resources:
10-
LoadBalancer:
10+
ApplicationLoadBalancer:
1111
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
1212
Properties:
1313
Name: CheckovTest
14+
Type: application
1415
Subnets: !Ref Subnets
1516
SecurityGroups:
1617
- sg-1234567
1718

1819
ListenerHTTPSFAILED1:
1920
Type: AWS::ElasticLoadBalancingV2::Listener
2021
Properties:
21-
LoadBalancerArn: !Ref LoadBalancer
22+
LoadBalancerArn: !Ref ApplicationLoadBalancer
2223
Port: 443
2324
Protocol: HTTPS
24-
Certificates:
25+
Certificates:
2526
- CertificateArn: test-cert
2627
SslPolicy: ELBSecurityPolicy-2016-08
2728
DefaultActions:
@@ -31,11 +32,56 @@ Resources:
3132
ListenerHTTPSFAILED2:
3233
Type: AWS::ElasticLoadBalancingV2::Listener
3334
Properties:
34-
LoadBalancerArn: !Ref LoadBalancer
35+
LoadBalancerArn: !Ref ApplicationLoadBalancer
3536
Port: 443
3637
Protocol: HTTPS
37-
Certificates:
38+
Certificates:
3839
- CertificateArn: test-cert
3940
DefaultActions:
4041
- Type: forward
41-
TargetGroupArn: default-target-group
42+
TargetGroupArn: default-target-group
43+
44+
NetworkLoadBalancer:
45+
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
46+
Properties:
47+
Name: CheckovTest
48+
Type: network
49+
Subnets: !Ref Subnets
50+
51+
ListenerTLSFAILED1:
52+
Type: AWS::ElasticLoadBalancingV2::Listener
53+
Properties:
54+
LoadBalancerArn: !Ref NetworkLoadBalancer
55+
Port: 443
56+
Protocol: TLS
57+
Certificates:
58+
- CertificateArn: test-cert
59+
SslPolicy: ELBSecurityPolicy-2016-08
60+
DefaultActions:
61+
- Type: forward
62+
TargetGroupArn: default-target-group
63+
64+
ListenerTLSFAILED2:
65+
Type: AWS::ElasticLoadBalancingV2::Listener
66+
Properties:
67+
LoadBalancerArn: !Ref NetworkLoadBalancer
68+
Port: 443
69+
Protocol: TLS
70+
SslPolicy: ELBSecurityPolicy-TLS13-1-1-2021-06
71+
Certificates:
72+
- CertificateArn: test-cert
73+
DefaultActions:
74+
- Type: forward
75+
TargetGroupArn: default-target-group
76+
77+
ListenerTLSFAILED3:
78+
Type: AWS::ElasticLoadBalancingV2::Listener
79+
Properties:
80+
LoadBalancerArn: !Ref NetworkLoadBalancer
81+
Port: 443
82+
Protocol: TLS
83+
Certificates:
84+
- CertificateArn: test-cert
85+
DefaultActions:
86+
- Type: forward
87+
TargetGroupArn: default-target-group

tests/cloudformation/checks/resource/aws/example_ALBListenerTLS12/ALBListenerTLS1.2-PASSED.yaml

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ Conditions:
1515
- !Ref UseHttps
1616
- 'true'
1717
Resources:
18-
LoadBalancer:
18+
ApplicationLoadBalancer:
1919
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
2020
Properties:
2121
Name: CheckovTest
22+
Type: application
2223
Subnets: !Ref Subnets
2324
SecurityGroups:
2425
- sg-1234567
2526

2627
ListenerHTTPSPASSED1:
2728
Type: AWS::ElasticLoadBalancingV2::Listener
2829
Properties:
29-
LoadBalancerArn: !Ref LoadBalancer
30+
LoadBalancerArn: !Ref ApplicationLoadBalancer
3031
Port: 443
3132
Protocol: HTTPS
3233
Certificates:
@@ -36,23 +37,10 @@ Resources:
3637
- Type: forward
3738
TargetGroupArn: default-target-group
3839

39-
ListenerHTTPSPASSED2:
40+
ListenerHTTPPASSED2:
4041
Type: AWS::ElasticLoadBalancingV2::Listener
4142
Properties:
42-
LoadBalancerArn: !Ref LoadBalancer
43-
Port: 443
44-
Protocol: TLS
45-
Certificates:
46-
- CertificateArn: test-cert
47-
SslPolicy: ELBSecurityPolicy-TLS-1-2-Ext-2018-06
48-
DefaultActions:
49-
- Type: forward
50-
TargetGroupArn: default-target-group
51-
52-
ListenerHTTPPASSED3:
53-
Type: AWS::ElasticLoadBalancingV2::Listener
54-
Properties:
55-
LoadBalancerArn: !Ref LoadBalancer
43+
LoadBalancerArn: !Ref ApplicationLoadBalancer
5644
Port: 80
5745
Protocol: HTTP
5846
DefaultActions:
@@ -68,6 +56,9 @@ Resources:
6856
ListenerHTTPUnknown:
6957
Type: AWS::ElasticLoadBalancingV2::Listener
7058
Properties:
59+
LoadBalancerArn: !Ref ApplicationLoadBalancer
60+
Port: 80
61+
Protocol: HTTP
7162
DefaultActions: !If
7263
- IsHttps
7364
-
@@ -80,6 +71,59 @@ Resources:
8071
-
8172
- TargetGroupArn: default-target-group
8273
Type: forward
83-
LoadBalancerArn: !Ref LoadBalancer
84-
Port: 80
85-
Protocol: HTTP
74+
75+
NetworkLoadBalancer:
76+
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
77+
Properties:
78+
Name: CheckovTest
79+
Type: network
80+
Subnets: !Ref Subnets
81+
82+
ListenerTLSPASSED1:
83+
Type: AWS::ElasticLoadBalancingV2::Listener
84+
Properties:
85+
LoadBalancerArn: !Ref NetworkLoadBalancer
86+
Port: 443
87+
Protocol: TLS
88+
Certificates:
89+
- CertificateArn: test-cert
90+
SslPolicy: ELBSecurityPolicy-TLS-1-2-Ext-2018-06
91+
DefaultActions:
92+
- Type: forward
93+
TargetGroupArn: default-target-group
94+
95+
ListenerTLSPASSED2:
96+
Type: AWS::ElasticLoadBalancingV2::Listener
97+
Properties:
98+
LoadBalancerArn: !Ref NetworkLoadBalancer
99+
Port: 443
100+
Protocol: TLS
101+
Certificates:
102+
- CertificateArn: test-cert
103+
SslPolicy: ELBSecurityPolicy-TLS13-1-2-Ext2-2021-06
104+
DefaultActions:
105+
- Type: forward
106+
TargetGroupArn: default-target-group
107+
108+
ListenerTLSPASSED3:
109+
Type: AWS::ElasticLoadBalancingV2::Listener
110+
Properties:
111+
LoadBalancerArn: !Ref NetworkLoadBalancer
112+
Port: 443
113+
Protocol: TLS
114+
Certificates:
115+
- CertificateArn: test-cert
116+
SslPolicy: ELBSecurityPolicy-TLS13-1-3-2021-06
117+
DefaultActions:
118+
- Type: forward
119+
TargetGroupArn: default-target-group
120+
121+
ListenerTCPPASSED4:
122+
Type: AWS::ElasticLoadBalancingV2::Listener
123+
Properties:
124+
LoadBalancerArn: !Ref NetworkLoadBalancer
125+
Port: 443
126+
Protocol: TCP
127+
DefaultActions:
128+
- Type: forward
129+
TargetGroupArn: default-target-group

tests/cloudformation/checks/resource/aws/test_ALBListenerTLS12.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,27 @@ def test_summary(self):
1818

1919
passing_resources = {
2020
'AWS::ElasticLoadBalancingV2::Listener.ListenerHTTPSPASSED1',
21-
'AWS::ElasticLoadBalancingV2::Listener.ListenerHTTPSPASSED2',
22-
'AWS::ElasticLoadBalancingV2::Listener.ListenerHTTPPASSED3'
21+
'AWS::ElasticLoadBalancingV2::Listener.ListenerHTTPPASSED2',
22+
'AWS::ElasticLoadBalancingV2::Listener.ListenerTLSPASSED1',
23+
'AWS::ElasticLoadBalancingV2::Listener.ListenerTLSPASSED2',
24+
'AWS::ElasticLoadBalancingV2::Listener.ListenerTLSPASSED3',
25+
'AWS::ElasticLoadBalancingV2::Listener.ListenerTCPPASSED4'
2326
}
2427

2528
failing_resources = {
2629
'AWS::ElasticLoadBalancingV2::Listener.ListenerHTTPSFAILED1',
27-
'AWS::ElasticLoadBalancingV2::Listener.ListenerHTTPSFAILED2'
30+
'AWS::ElasticLoadBalancingV2::Listener.ListenerHTTPSFAILED2',
31+
'AWS::ElasticLoadBalancingV2::Listener.ListenerTLSFAILED1',
32+
'AWS::ElasticLoadBalancingV2::Listener.ListenerTLSFAILED2',
33+
'AWS::ElasticLoadBalancingV2::Listener.ListenerTLSFAILED3'
2834
}
2935

3036
unknown_resource = 'AWS::ElasticLoadBalancingV2::Listener.ListenerHTTPUnknown'
3137
passed_check_resources = set([c.resource for c in report.passed_checks])
3238
failed_check_resources = set([c.resource for c in report.failed_checks])
3339

34-
self.assertEqual(summary['passed'], 3)
35-
self.assertEqual(summary['failed'], 2)
40+
self.assertEqual(summary['passed'], passing_resources.__len__())
41+
self.assertEqual(summary['failed'], failing_resources.__len__())
3642
self.assertEqual(summary['skipped'], 0)
3743
self.assertEqual(summary['parsing_errors'], 0)
3844
self.assertNotIn(unknown_resource, passed_check_resources)

0 commit comments

Comments
 (0)