-
Notifications
You must be signed in to change notification settings - Fork 68
Create a synthetic authz resource for trust quorum and use it #9946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
c4c8aa9
f7fddb3
48545ff
c36066f
1f27a94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -681,6 +681,84 @@ impl AuthorizedResource for Inventory { | |
| } | ||
| } | ||
|
|
||
| /// Synthetic resource to model accessing trust quorum configurations for a | ||
| /// given rack | ||
| #[derive(Clone, Debug, Eq, PartialEq)] | ||
| pub struct TrustQuorumConfig(Rack); | ||
|
|
||
| impl TrustQuorumConfig { | ||
| pub fn new(rack: Rack) -> TrustQuorumConfig { | ||
| TrustQuorumConfig(rack) | ||
| } | ||
|
|
||
| pub fn rack(&self) -> &Rack { | ||
| &self.0 | ||
| } | ||
|
|
||
| fn not_found(&self) -> Error { | ||
| // The information that we are preventing from leaking is anything | ||
| // having to do with a given rack. | ||
| LookupType::ById(self.0.id()).into_not_found(ResourceType::Rack) | ||
| } | ||
| } | ||
|
|
||
| impl oso::PolarClass for TrustQuorumConfig { | ||
| fn get_polar_class_builder() -> oso::ClassBuilder<Self> { | ||
| oso::Class::builder() | ||
| .with_equality_check() | ||
| .add_attribute_getter("rack", |config: &TrustQuorumConfig| { | ||
| config.0.clone() | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl AuthorizedResource for TrustQuorumConfig { | ||
| 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 walk the | ||
| // tree to get to the `fleet`. | ||
| self.rack().load_roles(opctx, authn, roleset) | ||
| } | ||
|
|
||
| // We want the trust quorum config to have the same visibility as the rack | ||
| // it is a part of. | ||
| // | ||
| // In a multirack world, we'll probably end up providing roles for racks. | ||
| // For now though, we just ensure that unauthorized users cannot know that a | ||
| // rack id exists, in the same manner as is done for an [`ApiResource`]. | ||
| 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() | ||
| } | ||
| } | ||
|
|
||
| /// Synthetic resource describing the list of Certificates associated with a | ||
| /// Silo | ||
| #[derive(Clone, Debug, Eq, PartialEq)] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
self.rack().not_found()?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The need for this actually goes away when calling
self.rack().on_unauthorized()below.