-
Notifications
You must be signed in to change notification settings - Fork 34
/
aws_clb_encryption.pt
360 lines (328 loc) · 12 KB
/
aws_clb_encryption.pt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
name "AWS Unencrypted ELB Listeners (CLB)"
rs_pt_ver 20180301
type "policy"
short_description "**Deprecated: This policy is no longer being updated. Please see [README](https://github.com/flexera-public/policy_templates/tree/master/security/aws/clb_unencrypted/) for more details.** Report any AWS Classic Load Balancers w/Internet-facing Unencrypted Listeners. \n See the [README](https://github.com/flexera-public/policy_templates/tree/master/security/aws/clb_unencrypted/) and [docs.flexera.com/flexera/EN/Automation](https://docs.flexera.com/flexera/EN/Automation/AutomationGS.htm) to learn more."
long_description ""
category "Security"
severity "medium"
info(
version: "3.1.3",
provider: "AWS",
service: "ELB",
policy_set: "",
deprecated: "true",
hide_skip_approvals: "true"
)
###############################################################################
# Parameters
###############################################################################
parameter "param_allowed_regions_allow_or_deny" do
type "string"
label "Allow/Deny Regions"
description "Allow or Deny entered regions. See the README for more details"
allowed_values "Allow", "Deny"
default "Allow"
end
parameter "param_allowed_regions" do
type "list"
label "Regions"
allowed_pattern /^([a-zA-Z-_]+-[a-zA-Z0-9-_]+-[0-9-_]+,*|)+$/
description "A list of allowed or denied regions. See the README for more details"
end
parameter "param_email" do
type "list"
label "Email Address"
description "Email addresses of the recipients you wish to notify"
end
parameter "param_aws_account_number" do
type "string"
category "Policy Settings"
label "Account Number"
description "Leave blank; this is for automated use with Meta Policies. See README for more details."
default ""
end
parameter "param_exclude_tags" do
type "list"
label "Ignore Tags"
description "List of one or more Tags that will exclude Classic Load Balancer from actions being taken. Format: Key=Value"
end
###############################################################################
# Authentication
###############################################################################
credentials "auth_aws" do
schemes "aws","aws_sts"
label "AWS"
description "Select the AWS Credential from the list"
tags "provider=aws"
aws_account_number $param_aws_account_number
end
###############################################################################
# Pagination
###############################################################################
pagination "elb_pagination" do
get_page_marker do
body_path "DescribeLoadBalancersResult.NextMarker"
end
set_page_marker do
query "Marker"
end
end
###############################################################################
# Datasources
###############################################################################
# ds_region_list is a list of regions that are opted-in or opt-in-not-required
datasource "ds_regions_list" do
# https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeRegions.html
request do
auth $auth_aws
host "ec2.amazonaws.com"
path "/"
query "Action", "DescribeRegions"
query "Version", "2016-11-15"
query "Filter.1.Name", "opt-in-status"
query "Filter.1.Value.1", "opt-in-not-required"
query "Filter.1.Value.2", "opted-in"
end
result do
encoding "xml"
collect xpath(response, "//DescribeRegionsResponse/regionInfo/item", "array") do
field "region", xpath(col_item, "regionName")
end
end
end
# Get only SCP enabled regions
datasource "ds_regions" do
run_script $js_regions, $param_allowed_regions, $ds_regions_list, $param_allowed_regions_allow_or_deny
end
#Get the list of all Classic load Balancers
datasource "ds_elb_list" do
iterate $ds_regions
request do
run_script $js_elb_list, val(iter_item,"region")
end
result do
encoding "json"
collect jmes_path(response, "DescribeLoadBalancersResponse.DescribeLoadBalancersResult.*[*][]") do
field "loadBalancerName", jmes_path(col_item, "LoadBalancerName")
field "region", val(iter_item,"region")
field "availabilityZones", jmes_path(col_item, "AvailabilityZones")
field "scheme", jmes_path(col_item, "Scheme")
field "listenerDescriptions", jmes_path(col_item, "ListenerDescriptions")
end
end
end
#Get respective tags for all Classic load Balancers
datasource "ds_elb_list_with_tags" do
iterate $ds_elb_list
request do
run_script $js_elb_list_with_tags, val(iter_item,"region"), val(iter_item, "loadBalancerName")
end
result do
encoding "json"
collect jmes_path(response, "DescribeTagsResponse.DescribeTagsResult.TagDescriptions[*]") do
field "loadBalancerName", val(iter_item, "loadBalancerName")
field "region", val(iter_item,"region")
field "availabilityZones", val(iter_item, "availabilityZones")
field "scheme", val(iter_item,"scheme")
field "listenerDescriptions", val(iter_item,"listenerDescriptions")
field "tags" do
collect jmes_path(col_item,"Tags") do
field "tagKey", jmes_path(col_item,"Key")
field "tagValue", jmes_path(col_item,"Value")
end
end
end
end
end
datasource "ds_unencrypted_elb_map" do
run_script $js_elb_filter_map, $ds_elb_list_with_tags, $param_exclude_tags
end
###############################################################################
# Script
###############################################################################
script "js_regions", type:"javascript" do
parameters "user_entered_regions", "all_regions", "regions_allow_or_deny"
result "regions"
code <<-EOS
if(_.isEmpty(user_entered_regions)){
regions = all_regions;
}else{
//Filter unique regions
var uniqueRegions = _.uniq(user_entered_regions);
var all_regions_list = [];
//Filter and remove denied regions from all_regions
if (regions_allow_or_deny == "Deny"){
var all_regions = all_regions.filter(function(obj){
return user_entered_regions.indexOf(obj.region) === -1;
});
}
all_regions.forEach(function(all_region){
all_regions_list.push(all_region.region)
})
//Filter valid regions
var valid_regions = [];
_.map(uniqueRegions, function(uniqueRegion){
if(all_regions_list.indexOf(uniqueRegion) > -1){
valid_regions.push({"region": uniqueRegion})
}
})
//Throw an error if no valid regions found
if (_.isEmpty(valid_regions)) {
regions = all_regions;
}else{
regions = valid_regions
}
}
EOS
end
#https://docs.aws.amazon.com/elasticloadbalancing/2012-06-01/APIReference/API_DescribeLoadBalancers.html (Classic Load Balancer)
script "js_elb_list", type: "javascript" do
parameters "region"
result "request"
code <<-EOS
request = {
auth: 'auth_aws',
pagination: 'elb_pagination',
host: 'elasticloadbalancing.'+region+'.amazonaws.com',
path: '/',
verb: 'GET',
query_params: {
"Action": "DescribeLoadBalancers",
"Version": "2012-06-01"
},
headers: {
"Accept": "application/json"
}
}
EOS
end
#https://docs.aws.amazon.com/elasticloadbalancing/2012-06-01/APIReference/API_DescribeTags.html (Classic Load Balancer)
script "js_elb_list_with_tags", type: "javascript" do
parameters "region", "loadBalancerName"
result "request"
code <<-EOS
request = {
auth: 'auth_aws',
host: 'elasticloadbalancing.'+region+'.amazonaws.com',
path: '/',
verb: 'GET',
query_params: {
"Action": "DescribeTags",
"Version": "2012-06-01",
"LoadBalancerNames.member.1": loadBalancerName
},
headers: {
"Accept": "application/json"
}
}
EOS
end
#Process the response data, check for the tags and generate a list of internetfacing listeners
script "js_elb_filter_map", type: "javascript" do
parameters "ds_elb_list_with_tags", "param_exclude_tags"
result "content"
code <<-EOS
var param_exclude_tags_lower=[];
for(var j=0; j < param_exclude_tags.length; j++){
param_exclude_tags_lower[j]=param_exclude_tags[j].toString().toLowerCase();
}
var content=[]
for(var i=0; i<ds_elb_list_with_tags.length; i++){
elb=ds_elb_list_with_tags[i]
// Constructing availabilityZones with comma separated to display in detail_template
var availabilityZones=elb['availabilityZones']
var s_availabilityZones=""
for(var j=0; j < availabilityZones.length; j++){
availabilityZone = availabilityZones[j]
s_availabilityZones = s_availabilityZones + ', '+ availabilityZone
}
//Constructing Tags of individual ELB into key=value format. Check, if the tag present in entered param_exclude_tags. Ignore the Load Balancer if the tag matches/present.
var tags = elb['tags']
var isTagMatched=false
var tagKeyValue=""
for(var j=0; j < tags.length; j++){
tag = tags[j]
if((param_exclude_tags_lower.indexOf((tag['tagKey']).toLowerCase()) !== -1) || (param_exclude_tags_lower.indexOf((tag['tagKey']+'='+tag['tagValue']).toLowerCase()) !== -1)){
isTagMatched = true;
}
// Constructing tags with comma separated to display in detail_template
if((tag['tagValue']).length > 0){
tagKeyValue = tagKeyValue + ', '+ tag['tagKey']+'='+tag['tagValue']
}else{
tagKeyValue = tagKeyValue + ', '+ tag['tagKey']
}
}
//If the Load Balancer tag does not match with entered param_exclude_tags, then check if Load Balancer is internet-facing and has HTTPS/SSL in use.
if(!(isTagMatched) && (elb['scheme']) === 'internet-facing') {
// check for HTTPS or SSL listeners
var protocols = _.pluck(_.pluck(elb['listenerDescriptions'],'Listener'),'Protocol')
var ports = _.pluck(_.pluck(elb['listenerDescriptions'],'Listener'),'LoadBalancerPort')
for (var x = 0; x < protocols.length; x++) {
switch (protocols[x]) {
case "HTTPS":
break
case "SSL":
break
default:
content.push ({
id: elb['loadBalancerName'],
loadBalancerType: "classic",
loadBalancerProtocol: protocols[x],
loadBalancerPort: ports[x],
region: elb['region'],
availabilityZones:(s_availabilityZones.slice(2)),
tagKeyValue:(tagKeyValue.slice(2)),
loadBalancerProtocolAndPort: protocols[x]+" "+ports[x]
})
}
}
}
}
content = _.sortBy(content,'id')
content = _.sortBy(content,'loadBalancerType')
content = _.sortBy(content,'region')
EOS
end
###############################################################################
# Policy
###############################################################################
policy "policy_unencrypted_CLB" do
validate $ds_unencrypted_elb_map do
summary_template "{{ rs_project_name }} (Account ID: {{ rs_project_id }}): {{ len data }} AWS Unencrypted ELB Listeners (CLB)"
escalate $esc_unencrypted_lbs
check eq(size(data),0)
export do
resource_level true
field "id" do
label "LoadBalancer Name"
end
field "loadBalancerType" do
label "LoadBalancer Type"
end
field "loadBalancerProtocolAndPort" do
label "Listener Protocol (Port)"
end
field "region" do
label "Region"
end
field "availabilityZones" do
label "Availability Zones"
end
field "tagKeyValue" do
label "TAGs"
end
end
end
end
###############################################################################
# Escalations
###############################################################################
escalation "esc_unencrypted_lbs" do
automatic true
label "Send Email"
description "Send incident email"
email $param_email
end
###############################################################################
# Cloud Workflow
###############################################################################