-
Notifications
You must be signed in to change notification settings - Fork 0
/
ram_group_detail.sp
261 lines (216 loc) · 5.07 KB
/
ram_group_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
dashboard "ram_group_detail" {
title = "AliCloud RAM Group Detail"
documentation = file("./dashboards/ram/docs/ram_group_detail.md")
tags = merge(local.ram_common_tags, {
type = "Detail"
})
input "group_arn" {
title = "Select a group:"
query = query.ram_group_input
width = 4
}
container {
card {
width = 3
query = query.ram_groups_users_count
args = [self.input.group_arn.value]
}
card {
width = 3
query = query.ram_groups_policies_count
args = [self.input.group_arn.value]
}
}
with "ram_policies_for_ram_group" {
query = query.ram_policies_for_ram_group
args = [self.input.group_arn.value]
}
with "ram_users_for_ram_group" {
query = query.ram_users_for_ram_group
args = [self.input.group_arn.value]
}
container {
graph {
title = "Relationships"
type = "graph"
node {
base = node.ram_group
args = {
ram_group_arns = [self.input.group_arn.value]
}
}
node {
base = node.ram_policy
args = {
ram_policy_names = with.ram_policies_for_ram_group.rows[*].policy_name
}
}
node {
base = node.ram_user
args = {
ram_user_arns = with.ram_users_for_ram_group.rows[*].user_arn
}
}
edge {
base = edge.ram_group_to_ram_policy
args = {
ram_group_arns = [self.input.group_arn.value]
}
}
edge {
base = edge.ram_group_to_ram_user
args = {
ram_group_arns = [self.input.group_arn.value]
}
}
}
}
container {
container {
title = "Overview"
table {
type = "line"
width = 6
query = query.ram_group_overview
args = [self.input.group_arn.value]
}
}
}
container {
title = "AliCloud RAM Group Analysis"
table {
title = "Users"
width = 6
column "User Name" {
href = "${dashboard.ram_user_detail.url_path}?input.user_arn={{.'User ARN' | @uri}}"
}
query = query.ram_users_for_group
args = [self.input.group_arn.value]
column "User ARN" {
display = "none"
}
}
table {
title = "Policies"
width = 6
query = query.ram_all_policies_for_group
args = [self.input.group_arn.value]
}
}
}
# Input queries
query "ram_group_input" {
sql = <<-EOQ
select
title as label,
arn as value,
json_build_object(
'account_id', account_id
) as tags
from
alicloud_ram_group
order by
title;
EOQ
}
# With queries
query "ram_policies_for_ram_group" {
sql = <<-EOQ
select
p.policy_name
from
alicloud_ram_group as g,
alicloud_ram_policy as p,
jsonb_array_elements(g.attached_policy) as policy
where
g.arn = $1
and p.account_id = g.account_id
and policy ->> 'PolicyName' = p.policy_name;
EOQ
}
query "ram_users_for_ram_group" {
sql = <<-EOQ
select
u.arn as user_arn
from
alicloud_ram_user as u,
alicloud_ram_group as g,
jsonb_array_elements(users) as member
where
g.arn = $1
and member ->> 'UserName' = u.name
and u.account_id = g.account_id;
EOQ
}
# Card queries
query "ram_groups_users_count" {
sql = <<-EOQ
select
jsonb_array_length(users) as value,
'Users' as label,
case when jsonb_array_length(users) > 0 then 'ok' else 'alert' end as type
from
alicloud_ram_group
where
arn = $1
and account_id = split_part($1,':',4);
EOQ
}
query "ram_groups_policies_count" {
sql = <<-EOQ
select
jsonb_array_length(attached_policy) as value,
'Policies' as label,
case when jsonb_array_length(attached_policy) > 0 then 'ok' else 'alert' end as type
from
alicloud_ram_group
where
arn = $1
and account_id = split_part($1,':',4);
EOQ
}
# Other detail page queries
query "ram_group_overview" {
sql = <<-EOQ
select
name as "Name",
title as "Title",
create_date as "Create Date",
account_id as "Account ID"
from
alicloud_ram_group
where
arn = $1
and account_id = split_part($1,':',4);
EOQ
}
query "ram_users_for_group" {
sql = <<-EOQ
select
u ->> 'UserName' as "User Name",
'acs:ram::' || account_id || ':user/' || (u ->> 'UserName') as "User ARN",
u ->> 'DisplayName' as "Display Name",
u ->> 'JoinDate' as "Join Date"
from
alicloud_ram_group as g,
jsonb_array_elements(users) as u
where
arn = $1
and account_id = split_part($1,':',4);
EOQ
}
query "ram_all_policies_for_group" {
sql = <<-EOQ
select
policies ->> 'PolicyName' as "Name",
policies ->> 'PolicyType' as "Type",
policies ->> 'DefaultVersion' as "Default Version",
policies ->> 'AttachDate' as "Attachment Date"
from
alicloud_ram_group,
jsonb_array_elements(attached_policy) as policies
where
arn = $1
and account_id = split_part($1,':',4);
EOQ
}