-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage_bucket_detail.sp
487 lines (432 loc) · 10.9 KB
/
storage_bucket_detail.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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
dashboard "storage_bucket_detail" {
title = "GCP Storage Bucket Detail"
documentation = file("./dashboards/storage/docs/storage_bucket_detail.md")
tags = merge(local.storage_common_tags, {
type = "Detail"
})
input "bucket_id" {
title = "Select a bucket:"
query = query.storage_bucket_input
width = 4
}
container {
card {
width = 2
query = query.storage_bucket_class
args = [self.input.bucket_id.value]
}
card {
width = 2
query = query.storage_bucket_public_access
args = [self.input.bucket_id.value]
}
card {
width = 2
query = query.storage_bucket_versioning_disabled
args = [self.input.bucket_id.value]
}
card {
width = 2
query = query.storage_bucket_retention_policy
args = [self.input.bucket_id.value]
}
card {
width = 2
query = query.storage_bucket_logging
args = [self.input.bucket_id.value]
}
card {
width = 2
query = query.storage_bucket_uniform_bucket_level_access
args = [self.input.bucket_id.value]
}
}
with "compute_backend_buckets_for_storage_bucket" {
query = query.compute_backend_buckets_for_storage_bucket
args = [self.input.bucket_id.value]
}
with "kms_keys_for_storage_bucket" {
query = query.kms_keys_for_storage_bucket
args = [self.input.bucket_id.value]
}
with "logging_buckets_for_storage_bucket" {
query = query.logging_buckets_for_storage_bucket
args = [self.input.bucket_id.value]
}
container {
graph {
title = "Relationships"
type = "graph"
node {
base = node.compute_backend_bucket
args = {
compute_backend_bucket_ids = with.compute_backend_buckets_for_storage_bucket.rows[*].bucket_id
}
}
node {
base = node.kms_key
args = {
kms_key_self_links = with.kms_keys_for_storage_bucket.rows[*].self_link
}
}
node {
base = node.logging_bucket
args = {
logging_bucket_names = with.logging_buckets_for_storage_bucket.rows[*].bucket_name
}
}
node {
base = node.storage_bucket
args = {
storage_bucket_ids = [self.input.bucket_id.value]
}
}
edge {
base = edge.compute_backend_bucket_to_storage_bucket
args = {
compute_backend_bucket_ids = with.compute_backend_buckets_for_storage_bucket.rows[*].bucket_id
}
}
edge {
base = edge.storage_bucket_to_kms_key
args = {
storage_bucket_ids = [self.input.bucket_id.value]
}
}
edge {
base = edge.storage_bucket_to_logging_bucket
args = {
storage_bucket_ids = [self.input.bucket_id.value]
}
}
}
}
container {
container {
width = 6
table {
title = "Overview"
type = "line"
width = 6
query = query.storage_bucket_overview
args = [self.input.bucket_id.value]
}
table {
title = "Tags"
width = 6
query = query.storage_bucket_tags_detail
args = [self.input.bucket_id.value]
}
}
container {
width = 6
table {
title = "Logging Details"
query = query.storage_bucket_logging_detail
args = [self.input.bucket_id.value]
}
table {
title = "Compute Backend Bucket"
query = query.storage_bucket_compute_backend_bucket_detail
args = [self.input.bucket_id.value]
}
table {
title = "Encryption Details"
column "Self Link" {
display = "none"
}
column "Key Name" {
href = "${dashboard.kms_key_detail.url_path}?input.key_self_link={{.'Self Link' | @uri}}"
}
query = query.storage_bucket_encryption_detail
args = [self.input.bucket_id.value]
}
}
}
}
# Input queries
query "storage_bucket_input" {
sql = <<-EOQ
select
title as label,
id || '/' || project as value,
json_build_object(
'project', project
) as tags
from
gcp_storage_bucket
order by
title;
EOQ
}
# Card Queries
query "storage_bucket_class" {
sql = <<-EOQ
select
'Storage Class' as label,
initcap(storage_class) as value
from
gcp_storage_bucket
where
id = split_part($1, '/', 1)
and project = split_part($1, '/', 2);
EOQ
}
query "storage_bucket_public_access" {
sql = <<-EOQ
select
'Public Access' as label,
case when iam_policy ->> 'bindings' like any (array ['%allAuthenticatedUsers%','%allUsers%']) then 'Enabled' else 'Disabled' end as value,
case when iam_policy ->> 'bindings' like any (array ['%allAuthenticatedUsers%','%allUsers%']) then 'alert' else 'ok' end as type
from
gcp_storage_bucket
where
id = split_part($1, '/', 1)
and project = split_part($1, '/', 2);
EOQ
}
query "storage_bucket_versioning_disabled" {
sql = <<-EOQ
select
'Versioning' as label,
case when versioning_enabled then 'Enabled' else 'Disabled' end as value,
case when versioning_enabled then 'ok' else 'alert' end as type
from
gcp_storage_bucket
where
id = split_part($1, '/', 1)
and project = split_part($1, '/', 2);
EOQ
}
query "storage_bucket_retention_policy" {
sql = <<-EOQ
select
'Retention Policy' as label,
case when retention_policy is not null then 'Enabled' else 'Disabled' end as value,
case when retention_policy is not null then 'ok' else 'alert' end as type
from
gcp_storage_bucket
where
id = split_part($1, '/', 1)
and project = split_part($1, '/', 2);
EOQ
}
query "storage_bucket_logging" {
sql = <<-EOQ
select
'Logging' as label,
case when log_bucket is not null then 'Enabled' else 'Disabled' end as value,
case when log_bucket is not null then 'ok' else 'alert' end as type
from
gcp_storage_bucket
where
id = split_part($1, '/', 1)
and project = split_part($1, '/', 2);
EOQ
}
query "storage_bucket_uniform_bucket_level_access" {
sql = <<-EOQ
select
'Uniform Bucket Level Access' as label,
case when iam_configuration_uniform_bucket_level_access_enabled then 'Enabled' else 'Disabled' end as value,
case when iam_configuration_uniform_bucket_level_access_enabled then 'ok' else 'alert' end as type
from
gcp_storage_bucket
where
id = split_part($1, '/', 1)
and project = split_part($1, '/', 2);
EOQ
}
# With queries
query "compute_backend_buckets_for_storage_bucket" {
sql = <<-EOQ
with compute_backend_bucket as (
select
id,
bucket_name
from
gcp_compute_backend_bucket
), storage_bucket as (
select
id,
name
from
gcp_storage_bucket
where
id = split_part($1, '/', 1)
and project = split_part($1, '/', 2)
)
select
c.id::text as bucket_id
from
storage_bucket b,
compute_backend_bucket c
where
b.name = c.bucket_name;
EOQ
}
query "kms_keys_for_storage_bucket" {
sql = <<-EOQ
select
k.self_link
from
gcp_storage_bucket b,
gcp_kms_key k
where
b.id = split_part($1, '/', 1)
and b.project = split_part($1, '/', 2)
and b.default_kms_key_name is not null
and k.self_link like '%' || b.default_kms_key_name;
EOQ
}
query "logging_buckets_for_storage_bucket" {
sql = <<-EOQ
with logging_bucket as (
select
name
from
gcp_logging_bucket
), storage_bucket as (
select
id,
log_bucket
from
gcp_storage_bucket
where
id = split_part($1, '/', 1)
and project = split_part($1, '/', 2)
and log_bucket is not null
)
select
l.name as bucket_name
from
storage_bucket b,
logging_bucket l
where
b.log_bucket = l.name;
EOQ
}
# Other queries
query "storage_bucket_overview" {
sql = <<-EOQ
select
name as "Name",
versioning_enabled as "Versioning Enabled",
storage_class as "Storage Class",
time_created as "Create Time",
title as "Title",
location as "Location",
project as "Project ID"
from
gcp_storage_bucket
where
id = split_part($1, '/', 1)
and project = split_part($1, '/', 2);
EOQ
}
query "storage_bucket_tags_detail" {
sql = <<-EOQ
with jsondata as (
select
tags::json as tags
from
gcp_storage_bucket
where
id = split_part($1, '/', 1)
and project = split_part($1, '/', 2)
)
select
key as "Key",
value as "Value"
from
jsondata,
json_each_text(tags)
order by
key;
EOQ
}
query "storage_bucket_logging_detail" {
sql = <<-EOQ
with logging_bucket as (
select
name,
lifecycle_state,
retention_days,
create_time
from
gcp_logging_bucket
), storage_bucket as (
select
id,
log_bucket,
log_object_prefix
from
gcp_storage_bucket
where
id = split_part($1, '/', 1)
and project = split_part($1, '/', 2)
and log_bucket is not null
)
select
b.log_bucket as "Log Bucket",
b.log_object_prefix as "Log Object Prefix",
l.create_time as "Created Time",
l.retention_days as "Retention Days",
l.lifecycle_state as "Lifecycle State"
from
storage_bucket b,
logging_bucket l
where
b.log_bucket = l.name;
EOQ
}
query "storage_bucket_compute_backend_bucket_detail" {
sql = <<-EOQ
with compute_backend_bucket as (
select
id,
name,
creation_timestamp,
location,
bucket_name
from
gcp_compute_backend_bucket
), storage_bucket as (
select
id,
name
from
gcp_storage_bucket
where
id = split_part($1, '/', 1)
and project = split_part($1, '/', 2)
)
select
c.id as "Backend Bucket ID",
c.name as "Backend Bucket Name",
c.creation_timestamp as "Created Time",
c.location as "Location"
from
storage_bucket b,
compute_backend_bucket c
where
b.name = c.bucket_name;
EOQ
}
query "storage_bucket_encryption_detail" {
sql = <<-EOQ
select
case when k.name is not null then 'Customer-managed encryption key (CMEK)' else 'Google-managed encryption key' end as "Encryption Type",
k.name as "Key Name",
k.key_ring_name as "Key Ring Name",
k.create_time as "Created Time",
k.location as "Location",
k.self_link as "Self Link"
from
gcp_storage_bucket b
left join gcp_kms_key k on split_part(b.default_kms_key_name, 'cryptoKeys/', 2) = k.name
where
b.id = split_part($1, '/', 1)
and b.project = split_part($1, '/', 2)
EOQ
}