-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathapi_resources.rs
1059 lines (924 loc) · 27.3 KB
/
api_resources.rs
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//! Authz types for resources in the API hierarchy
//!
//! The general pattern in Nexus for working with an object is to look it up
//! (see `nexus_db_queries::db::lookup::LookupPath`) and get back a so-called
//! `authz` type. This type uniquely identifies the resource regardless of
//! any other changes (e.g., name change or moving it to a different parent
//! collection). The various datastore functions that modify API resources
//! accept these `authz` types.
//!
//! The `authz` types can be passed to
//! [`crate::context::OpContext::authorize()`] to do an authorization check --
//! is the caller allowed to perform some action on the resource? This is the
//! primary way of doing authz checks in Nexus.
//!
//! `authz` types also retain information about how the resource was looked-up
//! in the first place so that if it turns out the caller is not even allowed to
//! know if the resource exists, we can produce an appropriate 404 error. For
//! example, if they look up organization "foo", and we get back one with id
//! 123, but they're not allowed to see it, then the user should get back a 404
//! that organization "foo" doesn't exist (and definitely not that organization
//! 123 doesn't exist, since that would tell the user that it _does_ exist!).
//!
//! Most `authz` types are generated by the `authz_resource!` macro.
use super::actor::AnyActor;
use super::context::AuthorizedResource;
use super::oso_generic::Init;
use super::roles::{load_roles_for_resource_tree, RoleSet};
use super::Action;
use super::{actor::AuthenticatedActor, Authz};
use crate::authn;
use crate::context::OpContext;
use authz_macros::authz_resource;
use futures::future::BoxFuture;
use futures::FutureExt;
use nexus_db_fixed_data::FLEET_ID;
use nexus_types::external_api::shared::{FleetRole, ProjectRole, SiloRole};
use omicron_common::api::external::{Error, LookupType, ResourceType};
use once_cell::sync::Lazy;
use oso::PolarClass;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
/// Describes an authz resource that corresponds to an API resource that has a
/// corresponding ResourceType and is stored in the database
pub trait ApiResource:
std::fmt::Debug + oso::ToPolar + Send + Sync + 'static
{
/// If roles can be assigned to this resource, return this object as a
/// [`ApiResourceWithRoles`]
///
/// If roles cannot be assigned to this resource, returns `None`.
fn as_resource_with_roles(&self) -> Option<&dyn ApiResourceWithRoles>;
/// If this resource has a parent in the API hierarchy whose assigned roles
/// can affect access to this resource, return the parent resource.
/// Otherwise, returns `None`.
fn parent(&self) -> Option<&dyn AuthorizedResource>;
fn resource_type(&self) -> ResourceType;
fn lookup_type(&self) -> &LookupType;
/// Returns an error as though this resource were not found, suitable for
/// use when an actor should not be able to see that this resource exists
fn not_found(&self) -> Error {
self.lookup_type().clone().into_not_found(self.resource_type())
}
}
/// Describes an authz resource on which we allow users to assign roles
pub trait ApiResourceWithRoles: ApiResource {
fn resource_id(&self) -> Uuid;
/// Returns an optional other resource whose roles should be fetched along
/// with this resource
///
/// This exists to support the behavior that Silo-level roles can confer
/// Fleet-level roles. That is, it's possible to set configuration on the
/// Silo that means "if a person has the 'admin' role on this Silo, then
/// they also get the 'admin' role on the Fleet." In order to implement
/// this, if such a policy exists on the user's Silo, then we have to load a
/// user's roles on that Silo whenever we would load the roles for the
/// Fleet.
///
/// Note this differs from "parent" in that it's not recursive. With
/// "parent", all of the roles that might affect the parent will be fetched,
/// which include all of _its_ parents. With this function, we only fetch
/// this one resource's directly-attached roles.
fn conferred_roles_by(
&self,
authn: &authn::Context,
) -> Result<Option<(ResourceType, Uuid)>, Error>;
}
/// Describes the specific roles for an `ApiResourceWithRoles`
pub trait ApiResourceWithRolesType: ApiResourceWithRoles {
type AllowedRoles: serde::Serialize
+ serde::de::DeserializeOwned
+ nexus_db_model::DatabaseString
+ Clone;
}
impl<T> AuthorizedResource for T
where
T: ApiResource + oso::PolarClass + Clone,
{
fn load_roles<'fut>(
&'fut self,
opctx: &'fut OpContext,
authn: &'fut authn::Context,
roleset: &'fut mut RoleSet,
) -> BoxFuture<'fut, Result<(), Error>> {
load_roles_for_resource_tree(self, opctx, authn, roleset).boxed()
}
fn on_unauthorized(
&self,
authz: &Authz,
error: Error,
actor: AnyActor,
action: Action,
) -> Error {
if action == Action::Read {
return self.not_found();
}
// If the user failed an authz check, and they can't even read this
// resource, then we should produce a 404 rather than a 401/403.
match authz.is_allowed(&actor, Action::Read, self) {
Err(error) => Error::internal_error(&format!(
"failed to compute read authorization to determine visibility: \
{:#}",
error
)),
Ok(false) => self.not_found(),
Ok(true) => error,
}
}
fn polar_class(&self) -> oso::Class {
Self::get_polar_class()
}
}
/// Represents the Oxide fleet for authz purposes
///
/// Fleet-level resources are essentially global. See RFD 24 for more on
/// Fleets.
///
/// This object is used for authorization checks on a Fleet by passing it as the
/// `resource` argument to [`crate::context::OpContext::authorize()`]. You
/// don't construct a `Fleet` yourself -- use the global [`FLEET`].
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub struct Fleet;
/// Singleton representing the [`Fleet`] itself for authz purposes
pub const FLEET: Fleet = Fleet;
pub static FLEET_LOOKUP: Lazy<LookupType> =
Lazy::new(|| LookupType::ById(*FLEET_ID));
impl Eq for Fleet {}
impl PartialEq for Fleet {
fn eq(&self, _: &Self) -> bool {
// There is only one Fleet.
true
}
}
impl oso::PolarClass for Fleet {
fn get_polar_class_builder() -> oso::ClassBuilder<Self> {
oso::Class::builder().with_equality_check().add_method(
"has_role",
|_: &Fleet, actor: AuthenticatedActor, role: String| {
actor.has_role_resource(ResourceType::Fleet, *FLEET_ID, &role)
},
)
}
}
impl ApiResource for Fleet {
fn as_resource_with_roles(&self) -> Option<&dyn ApiResourceWithRoles> {
Some(self)
}
fn parent(&self) -> Option<&dyn AuthorizedResource> {
None
}
fn resource_type(&self) -> ResourceType {
ResourceType::Fleet
}
fn lookup_type(&self) -> &LookupType {
&FLEET_LOOKUP
}
fn not_found(&self) -> Error {
// The Fleet is always visible.
Error::Forbidden
}
}
impl ApiResourceWithRoles for Fleet {
fn resource_id(&self) -> Uuid {
*FLEET_ID
}
fn conferred_roles_by(
&self,
authn: &authn::Context,
) -> Result<Option<(ResourceType, Uuid)>, Error> {
// If the actor is associated with a Silo, and if that Silo has a policy
// that grants fleet-level roles, then we must look up the actor's
// Silo-level roles when looking up their roles on the Fleet.
let Some(silo_id) = authn.actor().and_then(|actor| actor.silo_id())
else {
return Ok(None);
};
let silo_authn_policy = authn.silo_authn_policy().ok_or_else(|| {
Error::internal_error(&format!(
"actor had a Silo ({}) but no SiloAuthnPolicy",
silo_id
))
})?;
Ok(if silo_authn_policy.mapped_fleet_roles().is_empty() {
None
} else {
Some((ResourceType::Silo, silo_id))
})
}
}
impl ApiResourceWithRolesType for Fleet {
type AllowedRoles = FleetRole;
}
// TODO: refactor synthetic resources below
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct BlueprintConfig;
pub const BLUEPRINT_CONFIG: BlueprintConfig = BlueprintConfig;
impl oso::PolarClass for BlueprintConfig {
fn get_polar_class_builder() -> oso::ClassBuilder<Self> {
oso::Class::builder()
.with_equality_check()
.add_attribute_getter("fleet", |_: &BlueprintConfig| FLEET)
}
}
impl AuthorizedResource for BlueprintConfig {
fn load_roles<'fut>(
&'fut self,
opctx: &'fut OpContext,
authn: &'fut authn::Context,
roleset: &'fut mut RoleSet,
) -> futures::future::BoxFuture<'fut, Result<(), Error>> {
// There are no roles on the BlueprintConfig, only permissions. But we
// still need to load the Fleet-related roles to verify that the actor
// has the "admin" role on the Fleet (possibly conferred from a Silo
// role).
load_roles_for_resource_tree(&FLEET, opctx, authn, roleset).boxed()
}
fn on_unauthorized(
&self,
_: &Authz,
error: Error,
_: AnyActor,
_: Action,
) -> Error {
error
}
fn polar_class(&self) -> oso::Class {
Self::get_polar_class()
}
}
/// ConsoleSessionList is a synthetic resource used for modeling who has access
/// to create sessions.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ConsoleSessionList;
pub const CONSOLE_SESSION_LIST: ConsoleSessionList = ConsoleSessionList {};
impl oso::PolarClass for ConsoleSessionList {
fn get_polar_class_builder() -> oso::ClassBuilder<Self> {
// Roles are not directly attached to ConsoleSessionList.
oso::Class::builder()
.with_equality_check()
.add_method(
"has_role",
|_: &ConsoleSessionList,
_actor: AuthenticatedActor,
_role: String| false,
)
.add_attribute_getter("fleet", |_| FLEET)
}
}
impl AuthorizedResource for ConsoleSessionList {
fn load_roles<'fut>(
&'fut self,
opctx: &'fut OpContext,
authn: &'fut authn::Context,
roleset: &'fut mut RoleSet,
) -> futures::future::BoxFuture<'fut, Result<(), Error>> {
load_roles_for_resource_tree(&FLEET, opctx, authn, roleset).boxed()
}
fn on_unauthorized(
&self,
_: &Authz,
error: Error,
_: AnyActor,
_: Action,
) -> Error {
error
}
fn polar_class(&self) -> oso::Class {
Self::get_polar_class()
}
}
/// DnsConfig is a synthetic resource used for modeling access to the internal
/// and external DNS configuration
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct DnsConfig;
pub const DNS_CONFIG: DnsConfig = DnsConfig {};
impl oso::PolarClass for DnsConfig {
fn get_polar_class_builder() -> oso::ClassBuilder<Self> {
// Roles are not directly attached to DnsConfig
oso::Class::builder()
.with_equality_check()
.add_method(
"has_role",
|_: &DnsConfig, _actor: AuthenticatedActor, _role: String| {
false
},
)
.add_attribute_getter("fleet", |_| FLEET)
}
}
impl AuthorizedResource for DnsConfig {
fn load_roles<'fut>(
&'fut self,
opctx: &'fut OpContext,
authn: &'fut authn::Context,
roleset: &'fut mut RoleSet,
) -> futures::future::BoxFuture<'fut, Result<(), Error>> {
load_roles_for_resource_tree(&FLEET, opctx, authn, roleset).boxed()
}
fn on_unauthorized(
&self,
_: &Authz,
error: Error,
_: AnyActor,
_: Action,
) -> Error {
error
}
fn polar_class(&self) -> oso::Class {
Self::get_polar_class()
}
}
#[derive(Clone, Copy, Debug)]
pub struct IpPoolList;
/// Singleton representing the [`IpPoolList`] itself for authz purposes
pub const IP_POOL_LIST: IpPoolList = IpPoolList;
impl Eq for IpPoolList {}
impl PartialEq for IpPoolList {
fn eq(&self, _: &Self) -> bool {
true
}
}
impl oso::PolarClass for IpPoolList {
fn get_polar_class_builder() -> oso::ClassBuilder<Self> {
oso::Class::builder()
.with_equality_check()
.add_attribute_getter("fleet", |_: &IpPoolList| FLEET)
}
}
impl AuthorizedResource for IpPoolList {
fn load_roles<'fut>(
&'fut self,
opctx: &'fut OpContext,
authn: &'fut authn::Context,
roleset: &'fut mut RoleSet,
) -> futures::future::BoxFuture<'fut, Result<(), Error>> {
// There are no roles on the IpPoolList, only permissions. But we still
// need to load the Fleet-related roles to verify that the actor has the
// "admin" role on the Fleet (possibly conferred from a Silo role).
load_roles_for_resource_tree(&FLEET, opctx, authn, roleset).boxed()
}
fn on_unauthorized(
&self,
_: &Authz,
error: Error,
_: AnyActor,
_: Action,
) -> Error {
error
}
fn polar_class(&self) -> oso::Class {
Self::get_polar_class()
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct DeviceAuthRequestList;
/// Singleton representing the [`DeviceAuthRequestList`] itself for authz purposes
pub const DEVICE_AUTH_REQUEST_LIST: DeviceAuthRequestList =
DeviceAuthRequestList;
impl oso::PolarClass for DeviceAuthRequestList {
fn get_polar_class_builder() -> oso::ClassBuilder<Self> {
oso::Class::builder()
.with_equality_check()
.add_attribute_getter("fleet", |_| FLEET)
}
}
impl AuthorizedResource for DeviceAuthRequestList {
fn load_roles<'fut>(
&'fut self,
opctx: &'fut OpContext,
authn: &'fut authn::Context,
roleset: &'fut mut RoleSet,
) -> futures::future::BoxFuture<'fut, Result<(), Error>> {
// There are no roles on the DeviceAuthRequestList, only permissions. But we
// still need to load the Fleet-related roles to verify that the actor has the
// "admin" role on the Fleet.
load_roles_for_resource_tree(&FLEET, opctx, authn, roleset).boxed()
}
fn on_unauthorized(
&self,
_: &Authz,
error: Error,
_: AnyActor,
_: Action,
) -> Error {
error
}
fn polar_class(&self) -> oso::Class {
Self::get_polar_class()
}
}
/// Synthetic resource used for modeling access to low-level hardware inventory
/// data
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct Inventory;
pub const INVENTORY: Inventory = Inventory {};
impl oso::PolarClass for Inventory {
fn get_polar_class_builder() -> oso::ClassBuilder<Self> {
// Roles are not directly attached to Inventory
oso::Class::builder()
.with_equality_check()
.add_method(
"has_role",
|_: &Inventory, _actor: AuthenticatedActor, _role: String| {
false
},
)
.add_attribute_getter("fleet", |_| FLEET)
}
}
impl AuthorizedResource for Inventory {
fn load_roles<'fut>(
&'fut self,
opctx: &'fut OpContext,
authn: &'fut authn::Context,
roleset: &'fut mut RoleSet,
) -> futures::future::BoxFuture<'fut, Result<(), Error>> {
load_roles_for_resource_tree(&FLEET, opctx, authn, roleset).boxed()
}
fn on_unauthorized(
&self,
_: &Authz,
error: Error,
_: AnyActor,
_: Action,
) -> Error {
error
}
fn polar_class(&self) -> oso::Class {
Self::get_polar_class()
}
}
/// Synthetic resource describing the list of Certificates associated with a
/// Silo
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SiloCertificateList(Silo);
impl SiloCertificateList {
pub fn new(silo: Silo) -> SiloCertificateList {
SiloCertificateList(silo)
}
pub fn silo(&self) -> &Silo {
&self.0
}
}
impl oso::PolarClass for SiloCertificateList {
fn get_polar_class_builder() -> oso::ClassBuilder<Self> {
oso::Class::builder()
.with_equality_check()
.add_attribute_getter("silo", |list: &SiloCertificateList| {
list.0.clone()
})
}
}
impl AuthorizedResource for SiloCertificateList {
fn load_roles<'fut>(
&'fut self,
opctx: &'fut OpContext,
authn: &'fut authn::Context,
roleset: &'fut mut RoleSet,
) -> futures::future::BoxFuture<'fut, Result<(), Error>> {
// There are no roles on this resource, but we still need to load the
// Silo-related roles.
self.silo().load_roles(opctx, authn, roleset)
}
fn on_unauthorized(
&self,
_: &Authz,
error: Error,
_: AnyActor,
_: Action,
) -> Error {
error
}
fn polar_class(&self) -> oso::Class {
Self::get_polar_class()
}
}
/// Synthetic resource describing the list of Identity Providers associated with
/// a Silo
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SiloIdentityProviderList(Silo);
impl SiloIdentityProviderList {
pub fn new(silo: Silo) -> SiloIdentityProviderList {
SiloIdentityProviderList(silo)
}
pub fn silo(&self) -> &Silo {
&self.0
}
}
impl oso::PolarClass for SiloIdentityProviderList {
fn get_polar_class_builder() -> oso::ClassBuilder<Self> {
oso::Class::builder()
.with_equality_check()
.add_attribute_getter("silo", |list: &SiloIdentityProviderList| {
list.0.clone()
})
}
}
impl AuthorizedResource for SiloIdentityProviderList {
fn load_roles<'fut>(
&'fut self,
opctx: &'fut OpContext,
authn: &'fut authn::Context,
roleset: &'fut mut RoleSet,
) -> futures::future::BoxFuture<'fut, Result<(), Error>> {
// There are no roles on this resource, but we still need to load the
// Silo-related roles.
self.silo().load_roles(opctx, authn, roleset)
}
fn on_unauthorized(
&self,
_: &Authz,
error: Error,
_: AnyActor,
_: Action,
) -> Error {
error
}
fn polar_class(&self) -> oso::Class {
Self::get_polar_class()
}
}
/// Synthetic resource describing the list of Users in a Silo
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SiloUserList(Silo);
impl SiloUserList {
pub fn new(silo: Silo) -> SiloUserList {
SiloUserList(silo)
}
pub fn silo(&self) -> &Silo {
&self.0
}
}
impl oso::PolarClass for SiloUserList {
fn get_polar_class_builder() -> oso::ClassBuilder<Self> {
oso::Class::builder()
.with_equality_check()
.add_attribute_getter("silo", |list: &SiloUserList| list.0.clone())
}
}
impl AuthorizedResource for SiloUserList {
fn load_roles<'fut>(
&'fut self,
opctx: &'fut OpContext,
authn: &'fut authn::Context,
roleset: &'fut mut RoleSet,
) -> futures::future::BoxFuture<'fut, Result<(), Error>> {
// There are no roles on this resource, but we still need to load the
// Silo-related roles.
self.silo().load_roles(opctx, authn, roleset)
}
fn on_unauthorized(
&self,
_: &Authz,
error: Error,
_: AnyActor,
_: Action,
) -> Error {
error
}
fn polar_class(&self) -> oso::Class {
Self::get_polar_class()
}
}
// Main resource hierarchy: Projects and their resources
authz_resource! {
name = "Project",
parent = "Silo",
primary_key = Uuid,
roles_allowed = true,
polar_snippet = Custom,
}
impl ApiResourceWithRolesType for Project {
type AllowedRoles = ProjectRole;
}
authz_resource! {
name = "Disk",
parent = "Project",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = InProject,
}
authz_resource! {
name = "ProjectImage",
parent = "Project",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = InProject,
}
authz_resource! {
name = "Snapshot",
parent = "Project",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = InProject,
}
authz_resource! {
name = "Instance",
parent = "Project",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = InProject,
}
authz_resource! {
name = "AffinityGroup",
parent = "Project",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = InProject,
}
authz_resource! {
name = "AntiAffinityGroup",
parent = "Project",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = InProject,
}
authz_resource! {
name = "InstanceNetworkInterface",
parent = "Instance",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = InProject,
}
authz_resource! {
name = "Vpc",
parent = "Project",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = InProject,
}
authz_resource! {
name = "VpcRouter",
parent = "Vpc",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = InProject,
}
authz_resource! {
name = "RouterRoute",
parent = "VpcRouter",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = InProject,
}
authz_resource! {
name = "VpcSubnet",
parent = "Vpc",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = InProject,
}
authz_resource! {
name = "InternetGateway",
parent = "Vpc",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = InProject,
}
authz_resource! {
name = "InternetGatewayIpPool",
parent = "InternetGateway",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = InProject,
}
authz_resource! {
name = "InternetGatewayIpAddress",
parent = "InternetGateway",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = InProject,
}
authz_resource! {
name = "FloatingIp",
parent = "Project",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = InProject,
}
// Customer network integration resources nested below "Fleet"
authz_resource! {
name = "AddressLot",
parent = "Fleet",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = FleetChild,
}
authz_resource! {
name = "AddressLotBlock",
parent = "Fleet",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = FleetChild,
}
authz_resource! {
name = "LoopbackAddress",
parent = "Fleet",
primary_key = { uuid_kind = LoopbackAddressKind },
roles_allowed = false,
polar_snippet = FleetChild,
}
authz_resource! {
name = "SwitchPort",
parent = "Fleet",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = FleetChild,
}
authz_resource! {
name = "SwitchPortSettings",
parent = "Fleet",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = FleetChild,
}
// Miscellaneous resources nested directly below "Fleet"
authz_resource! {
name = "Blueprint",
parent = "Fleet",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = FleetChild,
}
authz_resource! {
name = "ConsoleSession",
parent = "Fleet",
primary_key = String,
roles_allowed = false,
polar_snippet = FleetChild,
}
authz_resource! {
name = "DeviceAuthRequest",
parent = "Fleet",
primary_key = String, // user_code
roles_allowed = false,
polar_snippet = FleetChild,
}
authz_resource! {
name = "DeviceAccessToken",
parent = "Fleet",
primary_key = String, // token
roles_allowed = false,
polar_snippet = FleetChild,
}
authz_resource! {
name = "RoleBuiltin",
parent = "Fleet",
primary_key = (String, String),
roles_allowed = false,
polar_snippet = FleetChild,
}
authz_resource! {
name = "UserBuiltin",
parent = "Fleet",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = FleetChild,
}
authz_resource! {
name = "Rack",
parent = "Fleet",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = FleetChild,
}
authz_resource! {
name = "Silo",
parent = "Fleet",
primary_key = Uuid,
roles_allowed = true,
polar_snippet = Custom,
}
impl ApiResourceWithRolesType for Silo {
type AllowedRoles = SiloRole;
}
authz_resource! {
name = "SiloUser",
parent = "Silo",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = Custom,
}
authz_resource! {
name = "SiloGroup",
parent = "Silo",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = Custom,
}
authz_resource! {
name = "SiloImage",
parent = "Silo",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = InSilo,
}
// This resource is a collection of _all_ images in a silo, including project images.
authz_resource! {
name = "Image",
parent = "Silo",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = InSilo,
}
authz_resource! {
name = "IdentityProvider",
parent = "Silo",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = Custom,
}
authz_resource! {
name = "SamlIdentityProvider",
parent = "Silo",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = Custom,
}
authz_resource! {
name = "SshKey",
parent = "SiloUser",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = Custom,
}
authz_resource! {
name = "Sled",
parent = "Fleet",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = FleetChild,
}
authz_resource! {
name = "Zpool",
parent = "Fleet",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = FleetChild,
}
authz_resource! {
name = "SledInstance",
parent = "Fleet",
primary_key = Uuid,
roles_allowed = false,
polar_snippet = FleetChild,
}
authz_resource! {
name = "Service",
parent = "Fleet",
primary_key = Uuid,