/
storage_account_dashboard.sp
402 lines (352 loc) · 7.89 KB
/
storage_account_dashboard.sp
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
dashboard "storage_account_dashboard" {
title = "Azure Storage Account Dashboard"
documentation = file("./dashboards/storage/docs/storage_account_dashboard.md")
tags = merge(local.storage_common_tags, {
type = "Dashboard"
})
container {
# Analysis
card {
query = query.storage_account_count
width = 2
}
# Assessments
card {
query = query.storage_account_blob_soft_delete_disabled_count
width = 2
}
card {
query = query.storage_account_blob_public_access_enabled_count
width = 2
}
card {
query = query.storage_account_https_traffic_disabled_count
width = 2
}
card {
query = query.storage_account_unrestricted_network_access_count
width = 2
}
card {
query = query.storage_account_infrastructure_encryption_disabled_count
width = 2
}
}
container {
title = "Assessments"
chart {
title = "Blob Soft Delete Status"
query = query.storage_account_blob_soft_delete_status
type = "donut"
width = 2
series "count" {
point "enabled" {
color = "ok"
}
point "disabled" {
color = "alert"
}
}
}
chart {
title = "Blob Public Access Status"
query = query.storage_account_blob_public_access_status
type = "donut"
width = 2
series "count" {
point "private" {
color = "ok"
}
point "public" {
color = "alert"
}
}
}
chart {
title = "HTTPS Status"
query = query.storage_account_https_traffic_status
type = "donut"
width = 2
series "count" {
point "enabled" {
color = "ok"
}
point "disabled" {
color = "alert"
}
}
}
chart {
title = "Network Access Status"
query = query.storage_account_network_access_status
type = "donut"
width = 2
series "count" {
point "restricted" {
color = "ok"
}
point "unrestricted" {
color = "alert"
}
}
}
chart {
title = "Infrastructure Encryption Status"
query = query.storage_account_infrastructure_encryption_status
type = "donut"
width = 2
series "count" {
point "enabled" {
color = "ok"
}
point "disabled" {
color = "alert"
}
}
}
}
container {
title = "Analysis"
chart {
title = "Storage Accounts by Subscription"
query = query.torage_account_by_subscription
type = "column"
width = 3
}
chart {
title = "Storage Accounts by Resource Group"
query = query.storage_account_by_resource_group
type = "column"
width = 3
}
chart {
title = "Storage Accounts by Region"
query = query.storage_account_by_region
type = "column"
width = 3
}
chart {
title = "Storage Accounts by Access Tier"
query = query.storage_account_by_access_tier
type = "column"
width = 3
}
}
}
# Card Queries
query "storage_account_count" {
sql = <<-EOQ
select count(*) as "Storage Accounts" from azure_storage_account;
EOQ
}
query "storage_account_blob_soft_delete_disabled_count" {
sql = <<-EOQ
select
count(*) as value,
'Blob Soft Delete Disabled' as label,
case when count(*) = 0 then 'ok' else 'alert' end as type
from
azure_storage_account
where
blob_soft_delete_enabled is not true;
EOQ
}
query "storage_account_blob_public_access_enabled_count" {
sql = <<-EOQ
select
count(*) as value,
'Blob Public Access Enabled' as label,
case when count(*) = 0 then 'ok' else 'alert' end as type
from
azure_storage_account
where
allow_blob_public_access;
EOQ
}
query "storage_account_https_traffic_disabled_count" {
sql = <<-EOQ
select
count(*) as value,
'HTTPS Disabled' as label,
case when count(*) = 0 then 'ok' else 'alert' end as type
from
azure_storage_account
where
enable_https_traffic_only is not true;
EOQ
}
query "storage_account_unrestricted_network_access_count" {
sql = <<-EOQ
select
count(*) as value,
'Unrestricted Network Access' as label,
case when count(*) = 0 then 'ok' else 'alert' end as type
from
azure_storage_account
where
network_rule_default_action <> 'Deny'
EOQ
}
query "storage_account_infrastructure_encryption_disabled_count" {
sql = <<-EOQ
select
count(*) as value,
'Infrastructure Unencrypted' as label,
case when count(*) = 0 then 'ok' else 'alert' end as type
from
azure_storage_account
where
require_infrastructure_encryption is not true;
EOQ
}
query "storage_account_blob_soft_delete_status" {
sql = <<-EOQ
select
blob_soft_delete,
count(*)
from (
select
case when blob_soft_delete_enabled then
'enabled'
else
'disabled'
end blob_soft_delete
from
azure_storage_account) as cd
group by
blob_soft_delete
order by
blob_soft_delete;
EOQ
}
query "storage_account_blob_public_access_status" {
sql = <<-EOQ
select
public_access,
count(*)
from (
select
case when allow_blob_public_access then 'public'
else 'private'
end public_access
from
azure_storage_account) as cd
group by
public_access
order by
public_access;
EOQ
}
query "storage_account_https_traffic_status" {
sql = <<-EOQ
select
https_traffic,
count(*)
from (
select
case when enable_https_traffic_only then 'enabled'
else 'disabled'
end https_traffic
from
azure_storage_account) as cd
group by
https_traffic
order by
https_traffic;
EOQ
}
query "storage_account_network_access_status" {
sql = <<-EOQ
select
network_rule,
count(*)
from (
select
case when network_rule_default_action = 'Deny' then 'restricted'
else 'unrestricted'
end network_rule
from
azure_storage_account) as cd
group by
network_rule
order by
network_rule;
EOQ
}
query "storage_account_infrastructure_encryption_status" {
sql = <<-EOQ
select
infrastructure_encryption,
count(*)
from (
select
case when require_infrastructure_encryption then 'enabled'
else 'disabled'
end infrastructure_encryption
from
azure_storage_account) as cd
group by
infrastructure_encryption
order by
infrastructure_encryption;
EOQ
}
# Analysis Queries
query "torage_account_by_subscription" {
sql = <<-EOQ
select
a.title as "Subscription",
count(v.*) as "Storage Accounts"
from
azure_storage_account as v,
azure_subscription as a
where
a.subscription_id = v.subscription_id
group by
a.title
order by
a.title;
EOQ
}
query "storage_account_by_resource_group" {
sql = <<-EOQ
select
resource_group || ' [' || sub.title || ']' as "Resource Group",
count(a.*) as "Storage Accounts"
from
azure_storage_account as a,
azure_subscription as sub
where
a.subscription_id = sub.subscription_id
group by
resource_group, sub.title
order by
resource_group;
EOQ
}
query "storage_account_by_region" {
sql = <<-EOQ
select
region as "Region",
count(*) as "Storage Accounts"
from
azure_storage_account
group by
region
order by
region;
EOQ
}
query "storage_account_by_access_tier" {
sql = <<-EOQ
select
access_tier as "Access Tier",
count(*) as "Storage Accounts"
from
azure_storage_account
group by
access_tier
order by
access_tier;
EOQ
}