-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathpermissions.ts
More file actions
343 lines (330 loc) · 10.9 KB
/
Copy pathpermissions.ts
File metadata and controls
343 lines (330 loc) · 10.9 KB
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
import * as z from "zod";
export const orgPermissions = {
org_rename: {
description: "rename org",
},
org_manage_settings: {
description: "read and update org settings",
},
org_manage_auth_settings: {
description: "read and update authentication settings",
},
org_manage_billing: {
description: "manage billing",
},
org_manage_users: {
description: "add, update, and remove user access",
},
org_manage_user_devices: {
description: "add or remove device access",
},
org_invite_users_to_permitted_apps: {
description: "invite users to permitted apps",
},
org_approve_devices_for_permitted: {
description: "approve device access for permitted apps",
},
org_manage_cli_users: {
description: "add, update, and remove CLI key access",
},
org_create_cli_users_for_permitted_apps: {
description: "create CLI keys for permitted apps",
},
org_manage_app_roles: {
description: "create, update, and remove app roles",
},
org_manage_org_roles: {
description: "create, update, and remove org roles",
},
org_manage_environment_roles: {
description: "create, update, and remove environment roles",
},
org_manage_teams: {
description: "create, update, and remove teams",
},
org_manage_app_groups: {
description: "create, update, and remove app groups",
},
org_manage_block_groups: {
description: "create, update, and remove block groups",
},
org_read_logs: {
description: "read org logs",
},
org_manage_firewall: {
description: "manage org permitted networks",
},
org_generate_recovery_key: {
description: "generate recovery key",
},
org_clear_tokens: {
description: "clear access tokens",
},
org_archive_import_export: {
description: "import or export .envkey-archive files",
},
org_manage_integrations: {
description: "manage integrations for the org",
},
org_delete: {
description: "delete organization",
},
apps_create: {
description: "create apps",
},
apps_delete: { description: "delete apps" },
apps_read_permitted: { description: "view permitted apps" },
blocks_create: { description: "create blocks" },
blocks_read_all: { description: "view any block" },
blocks_rename: { description: "rename any block" },
blocks_manage_settings: { description: "manage any block's settings" },
blocks_write_envs_all: { description: "update environments for any block" },
blocks_write_envs_permitted: {
description: "update permitted environments for permitted blocks",
},
blocks_manage_connections_permitted: {
description: "connect and disconnect blocks from permitted apps",
},
blocks_manage_environments: {
description: "add and remove block environments",
},
blocks_delete: { description: "delete any block" },
self_hosted_upgrade: {
description: "upgrade self-hosted EnvKey installation",
},
self_hosted_manage_host: {
description: "manage self-hosted EnvKey installation",
},
self_hosted_read_host_logs: {
description: "read host-level logs for a self-hosted EnvKey installation",
},
},
appPermissions = {
app_read: { description: "view app" },
app_rename: { description: "rename app" },
app_manage_settings: { description: "update app settings" },
app_manage_users: {
description: "add, update, or remove user access",
},
app_approve_user_devices: { description: "approve device access" },
app_manage_cli_users: {
description: "add, update, or remove CLI key access",
},
app_read_own_locals: { description: "read their own local environment" },
app_read_user_locals: { description: "read all users' local environments" },
app_read_user_locals_history: {
description: "read version history for all users' local environments",
},
app_write_user_locals: {
description: "update all users' local environments",
},
app_manage_blocks: { description: "connect and disconnect blocks" },
app_manage_environments: { description: "add and remove environments" },
app_manage_servers: { description: "create and remove servers" },
app_manage_local_keys: { description: "create and remove local keys" },
app_read_logs: { description: "read app logs" },
app_manage_included_roles: {
description: "add or remove permitted app roles",
},
app_manage_firewall: {
description: "manage app permitted networks",
},
},
environmentWritePermissions = {
write: { description: "update environment" },
write_branches: { description: "update branches" },
},
environmentReadPermissions = {
read: { description: "read environment" },
read_inherits: { description: "read environment inheritance metadata" },
read_meta: { description: "read environment metadata" },
read_history: { description: "read environment version history" },
read_branches: { description: "read branches" },
read_branches_inherits: {
description: "read branch inheritance metadata",
},
read_branches_meta: { description: "read branches' metadata" },
read_branches_history: {
description: "read branch version history",
},
},
environmentPermissions = {
...environmentWritePermissions,
...environmentReadPermissions,
};
export const OrgPermissionSchema = z.enum(
Object.keys(orgPermissions) as [
keyof typeof orgPermissions,
keyof typeof orgPermissions,
...(keyof typeof orgPermissions)[]
]
);
export type OrgPermission = z.infer<typeof OrgPermissionSchema>;
export const AppPermissionSchema = z.enum(
Object.keys(appPermissions) as [
keyof typeof appPermissions,
keyof typeof appPermissions,
...(keyof typeof appPermissions)[]
]
);
export type AppPermission = z.infer<typeof AppPermissionSchema>;
export const EnvironmentWritePermissionSchema = z.enum(
Object.keys(environmentWritePermissions) as [
keyof typeof environmentWritePermissions,
keyof typeof environmentWritePermissions,
...(keyof typeof environmentWritePermissions)[]
]
);
export type EnvironmentWritePermission = z.infer<
typeof EnvironmentWritePermissionSchema
>;
export const EnvironmentReadPermissionSchema = z.enum(
Object.keys(environmentReadPermissions) as [
keyof typeof environmentReadPermissions,
keyof typeof environmentReadPermissions,
...(keyof typeof environmentReadPermissions)[]
]
);
export type EnvironmentReadPermission = z.infer<
typeof EnvironmentReadPermissionSchema
>;
export const EnvironmentPermissionSchema = z.enum(
Object.keys(environmentPermissions) as [
keyof typeof environmentPermissions,
keyof typeof environmentPermissions,
...(keyof typeof environmentPermissions)[]
]
);
export type EnvironmentPermission = z.infer<typeof EnvironmentPermissionSchema>;
export const EnvironmentPermissionsSchema = z.record(
z.array(EnvironmentPermissionSchema)
);
export type EnvironmentPermissions = z.infer<
typeof EnvironmentPermissionsSchema
>;
export const EnvironmentReadPermissionsSchema = z.record(
z.array(EnvironmentReadPermissionSchema)
);
export type EnvironmentReadPermissions = z.infer<
typeof EnvironmentReadPermissionsSchema
>;
export const EnvironmentWritePermissionsSchema = z.record(
z.array(EnvironmentWritePermissionSchema)
);
export type EnvironmentWritePermissions = z.infer<
typeof EnvironmentWritePermissionsSchema
>;
export const DEFAULT_ORG_BASIC_USER_PERMISSIONS: OrgPermission[] = [
"apps_read_permitted",
"org_invite_users_to_permitted_apps",
"org_create_cli_users_for_permitted_apps",
"org_approve_devices_for_permitted",
"blocks_write_envs_permitted",
"blocks_manage_connections_permitted",
"org_generate_recovery_key",
],
DEFAULT_ORG_ADMIN_PERMISSIONS: OrgPermission[] = [
...DEFAULT_ORG_BASIC_USER_PERMISSIONS,
"apps_create",
"apps_delete",
"blocks_create",
"blocks_read_all",
"blocks_rename",
"blocks_manage_settings",
"blocks_write_envs_all",
"blocks_delete",
"blocks_manage_environments",
"org_manage_users",
"org_manage_user_devices",
"org_manage_cli_users",
"org_read_logs",
"org_manage_app_roles",
"org_manage_teams",
"org_manage_app_groups",
"org_manage_block_groups",
"org_manage_environment_roles",
],
DEFAULT_ORG_OWNER_PERMISSIONS = Object.keys(
orgPermissions
) as OrgPermission[],
DEFAULT_APP_DEVELOPER_PERMISSIONS: AppPermission[] = [
"app_read",
"app_manage_local_keys",
"app_read_own_locals",
],
DEFAULT_APP_DEVOPS_PERMISSIONS: AppPermission[] = [
...DEFAULT_APP_DEVELOPER_PERMISSIONS,
"app_manage_blocks",
"app_manage_servers",
],
DEFAULT_APP_ADMIN_PERMISSIONS = Object.keys(
appPermissions
) as AppPermission[],
ENV_READ_PERMISSIONS: EnvironmentPermission[] = [
"read",
"read_inherits",
"read_meta",
"read_history",
],
SUB_ENV_READ_PERMISSIONS: EnvironmentPermission[] = [
"read_branches",
"read_branches_inherits",
"read_branches_meta",
"read_branches_history",
],
ENV_WRITE_PERMISSIONS: EnvironmentPermission[] = ["write"],
SUB_ENV_WRITE_PERMISSIONS: EnvironmentPermission[] = ["write_branches"],
ENVIRONMENT_READ_WRITE_PERMISSIONS = Array.from(
new Set([
...ENV_READ_PERMISSIONS,
...ENV_WRITE_PERMISSIONS,
...SUB_ENV_READ_PERMISSIONS,
])
) as EnvironmentPermission[],
ENVIRONMENT_DEVOPS_PERMISSIONS = Array.from(
new Set([
...ENVIRONMENT_READ_WRITE_PERMISSIONS,
...SUB_ENV_WRITE_PERMISSIONS,
])
) as EnvironmentPermission[],
ENVIRONMENT_FULL_PERMISSIONS = Array.from(
new Set([...ENVIRONMENT_DEVOPS_PERMISSIONS])
) as EnvironmentPermission[],
ENVIRONMENT_META_ONLY_PERMISSIONS: EnvironmentPermission[] = [
"read_inherits",
"read_meta",
"read_branches_inherits",
"read_branches_meta",
],
ORG_PERMISSIONS_BY_DEFAULT_ROLE: {
[name: string]: OrgPermission[];
} = {
"Basic User": DEFAULT_ORG_BASIC_USER_PERMISSIONS,
"Org Admin": DEFAULT_ORG_ADMIN_PERMISSIONS,
"Org Owner": DEFAULT_ORG_OWNER_PERMISSIONS,
},
APP_PERMISSIONS_BY_DEFAULT_ROLE: {
[name: string]: AppPermission[];
} = {
Developer: DEFAULT_APP_DEVELOPER_PERMISSIONS,
DevOps: DEFAULT_APP_DEVOPS_PERMISSIONS,
Admin: DEFAULT_APP_ADMIN_PERMISSIONS,
"Org Admin": DEFAULT_APP_ADMIN_PERMISSIONS,
"Org Owner": DEFAULT_APP_ADMIN_PERMISSIONS,
},
ENVIRONMENT_PERMISSIONS_BY_DEFAULT_ROLE: {
[name: string]: {
[name: string]: EnvironmentPermission[];
};
} = {
Developer: {
Development: ENVIRONMENT_READ_WRITE_PERMISSIONS,
Staging: ENVIRONMENT_READ_WRITE_PERMISSIONS,
Production: ENVIRONMENT_META_ONLY_PERMISSIONS,
},
DevOps: {
Development: ENVIRONMENT_DEVOPS_PERMISSIONS,
Staging: ENVIRONMENT_DEVOPS_PERMISSIONS,
Production: ENVIRONMENT_DEVOPS_PERMISSIONS,
},
};