-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathomicron.polar
463 lines (400 loc) · 16.5 KB
/
omicron.polar
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
#
# Oso configuration for Omicron
# This file is augmented by generated snippets.
#
#
# ACTOR TYPES AND BASIC RULES
#
# `AnyActor` includes both authenticated and unauthenticated users.
actor AnyActor {}
# An `AuthenticatedActor` has an identity in the system. All of our operations
# today require that an actor be authenticated.
actor AuthenticatedActor {}
# For any resource, `actor` can perform action `action` on it if they're
# authenticated and their role(s) give them the corresponding permission on that
# resource.
allow(actor: AnyActor, action: Action, resource) if
actor.authenticated and
has_permission(actor.authn_actor.unwrap(), action.to_perm(), resource);
# Define role relationships
has_role(actor: AuthenticatedActor, role: String, resource: Resource)
if resource.has_role(actor, role);
#
# ROLES AND PERMISSIONS IN THE FLEET/SILO/ORGANIZATION/PROJECT HIERARCHY
#
# We define the following permissions for most resources in the system:
#
# - "create_child": required to create child resources (of any type)
#
# - "list_children": required to list child resources (of all types) of a
# resource
#
# - "modify": required to modify or delete a resource
#
# - "read": required to read a resource
#
# We define the following predefined roles for only a few high-level resources:
# the Fleet (see below), Silo, Organization, and Project. The specific roles
# are oriented around intended use-cases:
#
# - "admin": has all permissions on the resource
#
# - "collaborator": has "read", "list_children", and "create_child", plus
# the "admin" role for child resources. The idea is that if you're an
# Organization Collaborator, you have full control over the Projects within
# the Organization, but you cannot modify or delete the Organization itself.
#
# - "viewer": has "read" and "list_children" on a resource
#
# Below the Project level, permissions are granted via roles at the Project
# level. For example, for someone to be able to create, modify, or delete any
# Instances, they must be granted project.collaborator, which means they can
# create, modify, or delete _all_ resources in the Project.
#
# The complete set of predefined roles:
#
# - fleet.admin (superuser for the whole system)
# - fleet.collaborator (can manage Silos)
# - fleet.viewer (can read most resources in the system)
# - silo.admin (superuser for the silo)
# - silo.collaborator (can create and own Organizations)
# - silo.viewer (can read most resources within the Silo)
# - organization.admin (complete control over an organization)
# - organization.collaborator (can manage Projects)
# - organization.viewer (can read most resources within the Organization)
# - project.admin (complete control over a Project)
# - project.collaborator (can manage all resources within the Project)
# - project.viewer (can read most resources within the Project)
#
# Outside the Silo/Organization/Project hierarchy, we (currently) treat most
# resources as nested under Fleet or else a synthetic resource (see below). We
# do not yet support role assignments on anything other than Fleet, Silo,
# Organization, or Project.
#
# "Fleet" is a global singleton representing the whole system. The name comes
# from the idea described in RFD 24, but it's not quite right. This probably
# should be more like "Region" or "AvailabilityZone". The precise boundaries
# have not yet been figured out.
resource Fleet {
permissions = [
"list_children",
"modify",
"read",
"create_child",
];
roles = [
# Roles that can be attached by users
"admin",
"collaborator",
"viewer",
# Internal-only roles
"external-authenticator"
];
# Roles implied by other roles on this resource
"viewer" if "collaborator";
"collaborator" if "admin";
# Permissions granted directly by roles on this resource
"list_children" if "viewer";
"read" if "viewer";
"create_child" if "collaborator";
"modify" if "admin";
}
resource Silo {
permissions = [
"list_children",
"modify",
"read",
"create_child",
"list_identity_providers",
];
roles = [ "admin", "collaborator", "viewer" ];
# Roles implied by other roles on this resource
"viewer" if "collaborator";
"collaborator" if "admin";
# Permissions granted directly by roles on this resource
"list_children" if "viewer";
"read" if "viewer";
"create_child" if "collaborator";
"modify" if "admin";
# Roles implied by roles on this resource's parent (Fleet)
relations = { parent_fleet: Fleet };
"admin" if "collaborator" on "parent_fleet";
"viewer" if "viewer" on "parent_fleet";
# external authenticator has to create silo users
"list_children" if "external-authenticator" on "parent_fleet";
"create_child" if "external-authenticator" on "parent_fleet";
}
has_relation(fleet: Fleet, "parent_fleet", silo: Silo)
if silo.fleet = fleet;
# As a special case, all authenticated users can read their own Silo. That's
# not quite the same as having the "viewer" role. For example, they cannot list
# Organizations in the Silo.
#
# One reason this is necessary is because if an unprivileged user tries to
# create an Organization using "POST /organizations", they should get back a 403
# (which implies they're able to see /organizations, which is essentially seeing
# the Silo itself) rather than a 404. This behavior isn't a hard constraint
# (i.e., you could reasonably get a 404 for an API you're not allowed to call).
# Nor is the implementation (i.e., we could special-case this endpoint somehow).
# But granting this permission is the simplest way to keep this endpoint's
# behavior consistent with the rest of the API.
#
# It's unclear what else would break if users couldn't see their own Silo.
has_permission(actor: AuthenticatedActor, "read", silo: Silo)
if silo in actor.silo;
# Any authenticated user should be allowed to list the identity providers of
# their silo.
has_permission(actor: AuthenticatedActor, "list_identity_providers", silo: Silo)
if silo in actor.silo;
resource Organization {
permissions = [
"list_children",
"modify",
"read",
"create_child",
];
roles = [ "admin", "collaborator", "viewer" ];
# Roles implied by other roles on this resource
"viewer" if "collaborator";
"collaborator" if "admin";
# Permissions granted directly by roles on this resource
"list_children" if "viewer";
"read" if "viewer";
"create_child" if "collaborator";
"modify" if "admin";
# Roles implied by roles on this resource's parent (Silo)
relations = { parent_silo: Silo };
"admin" if "collaborator" on "parent_silo";
"viewer" if "viewer" on "parent_silo";
}
has_relation(silo: Silo, "parent_silo", organization: Organization)
if organization.silo = silo;
resource Project {
permissions = [
"list_children",
"modify",
"read",
"create_child",
];
roles = [ "admin", "collaborator", "viewer" ];
# Roles implied by other roles on this resource
"viewer" if "collaborator";
"collaborator" if "admin";
# Permissions granted directly by roles on this resource
"list_children" if "viewer";
"read" if "viewer";
"create_child" if "collaborator";
"modify" if "admin";
# Roles implied by roles on this resource's parent (Organization)
relations = { parent_organization: Organization };
"admin" if "collaborator" on "parent_organization";
"viewer" if "viewer" on "parent_organization";
}
has_relation(organization: Organization, "parent_organization", project: Project)
if project.organization = organization;
#
# GENERAL RESOURCES OUTSIDE THE SILO/ORGANIZATION/PROJECT HIERARCHY
#
# Many resources use snippets of Polar generated by the `authz_resource!` Rust
# macro. Some resources require custom Polar code. Those appear here.
#
resource SiloUser {
permissions = [
"list_children",
"modify",
"read",
"create_child",
];
relations = { parent_silo: Silo };
"list_children" if "viewer" on "parent_silo";
"read" if "viewer" on "parent_silo";
"modify" if "admin" on "parent_silo";
"create_child" if "admin" on "parent_silo";
}
has_relation(silo: Silo, "parent_silo", user: SiloUser)
if user.silo = silo;
# authenticated actors have all permissions on themselves
has_permission(actor: AuthenticatedActor, _perm: String, silo_user: SiloUser)
if actor.equals_silo_user(silo_user);
resource SiloGroup {
permissions = [
"list_children",
"modify",
"read",
"create_child",
];
relations = { parent_silo: Silo };
"list_children" if "viewer" on "parent_silo";
"read" if "viewer" on "parent_silo";
"modify" if "admin" on "parent_silo";
"create_child" if "admin" on "parent_silo";
}
has_relation(silo: Silo, "parent_silo", group: SiloGroup)
if group.silo = silo;
resource SshKey {
permissions = [ "read", "modify" ];
relations = { silo_user: SiloUser };
"read" if "read" on "silo_user";
"modify" if "modify" on "silo_user";
}
has_relation(user: SiloUser, "silo_user", ssh_key: SshKey)
if ssh_key.silo_user = user;
resource IdentityProvider {
permissions = [
"read",
"modify",
"create_child",
"list_children",
];
relations = { parent_silo: Silo };
"read" if "viewer" on "parent_silo";
"list_children" if "viewer" on "parent_silo";
# Only silo admins can create silo identity providers
"modify" if "admin" on "parent_silo";
"create_child" if "admin" on "parent_silo";
}
has_relation(silo: Silo, "parent_silo", identity_provider: IdentityProvider)
if identity_provider.silo = silo;
resource SamlIdentityProvider {
permissions = [
"read",
"modify",
"create_child",
"list_children",
];
relations = { parent_silo: Silo };
# Only silo admins have permissions for specific identity provider details
"read" if "admin" on "parent_silo";
"list_children" if "admin" on "parent_silo";
"modify" if "admin" on "parent_silo";
"create_child" if "admin" on "parent_silo";
}
has_relation(silo: Silo, "parent_silo", saml_identity_provider: SamlIdentityProvider)
if saml_identity_provider.silo = silo;
#
# SYNTHETIC RESOURCES OUTSIDE THE SILO HIERARCHY
#
# The resources here do not correspond to anything that appears explicitly in
# the API or is stored in the database. These are used either at the top level
# of the API path (e.g., "/images") or as an implementation detail of the system
# (in the case of console sessions and "Database"). The policies are
# either statically-defined in this file or driven by role assignments on the
# Fleet. None of these resources defines their own roles.
#
# Describes the policy for accessing "/ip-pools" in the API
resource IpPoolList {
permissions = [
"list_children",
"modify",
"create_child",
];
# Fleet Administrators can create or modify the IP Pools list.
relations = { parent_fleet: Fleet };
"modify" if "admin" on "parent_fleet";
"create_child" if "admin" on "parent_fleet";
# Fleet Viewers can list IP Pools
"list_children" if "viewer" on "parent_fleet";
}
has_relation(fleet: Fleet, "parent_fleet", ip_pool_list: IpPoolList)
if ip_pool_list.fleet = fleet;
# Describes the policy for accessing "/images" (in the API)
resource GlobalImageList {
permissions = [
"list_children",
"modify",
"create_child",
];
# Fleet Administrators can create or modify the global images list.
relations = { parent_fleet: Fleet };
"modify" if "admin" on "parent_fleet";
"create_child" if "admin" on "parent_fleet";
# Fleet Viewers can list global images.
"list_children" if "viewer" on "parent_fleet";
}
has_relation(fleet: Fleet, "parent_fleet", global_image_list: GlobalImageList)
if global_image_list.fleet = fleet;
# Any authenticated user can list and read global images
has_permission(_actor: AuthenticatedActor, "list_children", _global_image_list: GlobalImageList);
has_permission(_actor: AuthenticatedActor, "read", _global_image: GlobalImage);
# Describes the policy for creating and managing web console sessions.
resource ConsoleSessionList {
permissions = [ "create_child" ];
relations = { parent_fleet: Fleet };
"create_child" if "external-authenticator" on "parent_fleet";
}
has_relation(fleet: Fleet, "parent_fleet", collection: ConsoleSessionList)
if collection.fleet = fleet;
# Describes the policy for creating and managing device authorization requests.
resource DeviceAuthRequestList {
permissions = [ "create_child" ];
relations = { parent_fleet: Fleet };
"create_child" if "external-authenticator" on "parent_fleet";
}
has_relation(fleet: Fleet, "parent_fleet", collection: DeviceAuthRequestList)
if collection.fleet = fleet;
# These rules grants the external authenticator role the permissions it needs to
# read silo users and modify their sessions. This is necessary for login to
# work.
has_permission(actor: AuthenticatedActor, "read", silo: Silo)
if has_role(actor, "external-authenticator", silo.fleet);
has_permission(actor: AuthenticatedActor, "read", user: SiloUser)
if has_role(actor, "external-authenticator", user.silo.fleet);
has_permission(actor: AuthenticatedActor, "modify", user: SiloUser)
if has_role(actor, "external-authenticator", user.silo.fleet);
has_permission(actor: AuthenticatedActor, "read", group: SiloGroup)
if has_role(actor, "external-authenticator", group.silo.fleet);
has_permission(actor: AuthenticatedActor, "modify", group: SiloGroup)
if has_role(actor, "external-authenticator", group.silo.fleet);
has_permission(actor: AuthenticatedActor, "read", session: ConsoleSession)
if has_role(actor, "external-authenticator", session.fleet);
has_permission(actor: AuthenticatedActor, "modify", session: ConsoleSession)
if has_role(actor, "external-authenticator", session.fleet);
# All authenticated users can read and delete device authn requests because
# by necessity these operations happen before we've figured out what user (or
# even Silo) the device auth is associated with. Any user can claim a device
# auth request with the right user code (that's how it works) -- it's the user
# code and associated logic that prevents unauthorized access here.
has_permission(_actor: AuthenticatedActor, "read", _device_auth: DeviceAuthRequest);
has_permission(_actor: AuthenticatedActor, "modify", _device_auth: DeviceAuthRequest);
has_permission(actor: AuthenticatedActor, "read", device_token: DeviceAccessToken)
if has_role(actor, "external-authenticator", device_token.fleet);
has_permission(actor: AuthenticatedActor, "read", identity_provider: IdentityProvider)
if has_role(actor, "external-authenticator", identity_provider.silo.fleet);
has_permission(actor: AuthenticatedActor, "list_identity_providers", identity_provider: IdentityProvider)
if has_role(actor, "external-authenticator", identity_provider.silo.fleet);
has_permission(actor: AuthenticatedActor, "read", saml_identity_provider: SamlIdentityProvider)
if has_role(actor, "external-authenticator", saml_identity_provider.silo.fleet);
has_permission(actor: AuthenticatedActor, "list_identity_providers", saml_identity_provider: SamlIdentityProvider)
if has_role(actor, "external-authenticator", saml_identity_provider.silo.fleet);
# Describes the policy for who can access the internal database.
resource Database {
permissions = [
# "query" is required to perform any query against the database,
# whether a read or write query. This is checked when an operation
# checks out a database connection from the connection pool.
#
# Any authenticated user gets this permission. There's generally
# some other authz check involved in the database query. For
# example, if you're querying the database to "read" a "Project", we
# should also be checking that. So why do we do this at all? It's
# a belt-and-suspenders measure so that if we somehow introduced an
# unauthenticated code path that hits the database, it cannot be
# used to DoS the database because we won't allow the operation to
# make the query. (As long as the code path _is_ authenticated, we
# can use throttling mechanisms to prevent DoS.)
"query",
# "modify" is required to populate database data that's delivered
# with the system. It should also be required for schema changes,
# when we support those. This is separate from "query" so that we
# cannot accidentally invoke these code paths from API calls and
# other general functions.
"modify"
];
}
# All authenticated users have the "query" permission on the database.
has_permission(_actor: AuthenticatedActor, "query", _resource: Database);
# The "db-init" user is the only one with the "init" role.
has_permission(actor: AuthenticatedActor, "modify", _resource: Database)
if actor = USER_DB_INIT;
has_permission(actor: AuthenticatedActor, "create_child", _resource: IpPoolList)
if actor = USER_DB_INIT;