-
Notifications
You must be signed in to change notification settings - Fork 40
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
store role assignments in the database #520
Merged
Merged
Changes from 58 commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
0b68b13
populate built-in roles into database
davepacheco b003327
Merge branch 'main' into authz-roles
davepacheco 22ce267
lots of rework
davepacheco 9aa6369
more work
davepacheco 0635bb3
fix pagination condition
davepacheco a006cd4
give up on diesel
davepacheco 28c2a21
remove cruft
davepacheco d1f8019
starting test
davepacheco b481442
fix broken tests
davepacheco abf9e26
flesh out test
davepacheco a163fb9
merge fix
davepacheco 7983cd9
fix up roles test
davepacheco 5d53966
fix up iter impl
davepacheco 0841cf3
remove duplication in populate()
davepacheco 47196c5
add API to fetch one built-in role
davepacheco eb48065
remove vestigial oso patch
davepacheco 3591dca
remove spurious delta
davepacheco d69d119
fix style
davepacheco 0f6a9fc
add role assignments to the database
davepacheco ecaed59
some work
davepacheco a4170c5
tests pass, no more hardcoded test user policies
davepacheco 1a9ca7c
fix some tests
davepacheco fd247a1
fix test, commonize code, split out actors
davepacheco 04e58f9
fix more tests
davepacheco 2b208b8
clean up some role impl
davepacheco dfd9271
todos
davepacheco 432550b
move, clean up, and document API resources
davepacheco fb81b27
more cleanup and docs
davepacheco 4c8ca6d
compiler panic
davepacheco 71f45c9
document authz and roles a bit better
davepacheco 78651ad
doc cleanup
davepacheco 8184cb8
clean up db-init authz
davepacheco 98ec479
doc edits
davepacheco b01cc67
some doc fixes
davepacheco 29d9063
fix style
davepacheco f410fd6
Add multi-column pagination support
smklein ee21650
Add unused attr, fix comment typo
smklein c00fd91
fix docs; figured out unexpected Oso behavior
davepacheco 4df6a71
doc nits
davepacheco 96cb462
remove xxx
davepacheco f177556
review feedback
davepacheco 7799728
add newtype for role names
davepacheco a4524ba
don't parse role name resource type
davepacheco bd843dd
Add tests
smklein aa8837b
Remove errant println
smklein 1207b13
Merge branch 'main' into pag_multicolumn
smklein 38fccbf
review feedback: underscores to hyphens, extra comment
davepacheco 600c9fa
Merge remote-tracking branch 'origin/main' into authz-roles
davepacheco 59e6bfd
fix mismerge
davepacheco 346666f
Merge remote-tracking branch 'origin/pag_multicolumn' into authz-roles
davepacheco 7c8f57b
use new paginated_multicolumn
davepacheco 0f7ee09
remove vestigial comment
davepacheco 3f322dc
Merge remote-tracking branch 'origin/authz-roles' into authz-role-ass…
davepacheco 00ac778
review feedback
davepacheco 1788bab
Merge remote-tracking branch 'origin/main' into authz-role-assignments
davepacheco a920a06
Merge remote-tracking branch 'origin/main' into authz-role-assignments
davepacheco 9d12b9e
example could be a bit better
davepacheco 2ffc5b9
remove vestigial AnyActor Eq/PartialEq
davepacheco 7020feb
clarify Perm struct
davepacheco cc17658
Merge branch 'main' into authz-role-assignments
davepacheco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// 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/. | ||
|
||
//! Oso integration for Actor types | ||
|
||
use super::roles::RoleSet; | ||
use crate::authn; | ||
use omicron_common::api::external::ResourceType; | ||
use uuid::Uuid; | ||
|
||
/// Represents [`authn::Context`] (which is either an authenticated or | ||
/// unauthenticated actor) for Polar | ||
#[derive(Clone, Debug)] | ||
pub struct AnyActor { | ||
authenticated: bool, | ||
actor_id: Option<Uuid>, | ||
roles: RoleSet, | ||
} | ||
|
||
impl AnyActor { | ||
pub fn new(authn: &authn::Context, roles: RoleSet) -> Self { | ||
let actor = authn.actor(); | ||
AnyActor { | ||
authenticated: actor.is_some(), | ||
actor_id: actor.map(|a| a.0), | ||
roles, | ||
} | ||
} | ||
} | ||
|
||
impl oso::PolarClass for AnyActor { | ||
fn get_polar_class_builder() -> oso::ClassBuilder<Self> { | ||
oso::Class::builder() | ||
.add_attribute_getter("authenticated", |a: &AnyActor| { | ||
a.authenticated | ||
}) | ||
.add_attribute_getter("authn_actor", |a: &AnyActor| { | ||
a.actor_id.map(|actor_id| AuthenticatedActor { | ||
actor_id, | ||
roles: a.roles.clone(), | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
/// Represents an authenticated [`authn::Context`] for Polar | ||
#[derive(Clone, Debug)] | ||
pub struct AuthenticatedActor { | ||
actor_id: Uuid, | ||
roles: RoleSet, | ||
} | ||
|
||
impl AuthenticatedActor { | ||
/// Returns whether this actor has the given role for the given resource | ||
pub fn has_role_resource( | ||
&self, | ||
resource_type: ResourceType, | ||
resource_id: Uuid, | ||
role: &str, | ||
) -> bool { | ||
self.roles.has_role(resource_type, resource_id, role) | ||
} | ||
} | ||
|
||
impl PartialEq for AuthenticatedActor { | ||
fn eq(&self, other: &Self) -> bool { | ||
self.actor_id == other.actor_id | ||
} | ||
} | ||
|
||
impl Eq for AuthenticatedActor {} | ||
|
||
impl oso::PolarClass for AuthenticatedActor { | ||
fn get_polar_class_builder() -> oso::ClassBuilder<Self> { | ||
oso::Class::builder().with_equality_check().add_constant( | ||
AuthenticatedActor { | ||
actor_id: authn::USER_DB_INIT.id, | ||
roles: RoleSet::new(), | ||
}, | ||
"USER_DB_INIT", | ||
) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is this called
AnyActor
instead ofActor
?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.
Just to better distinguish it from
AuthenticatedActor
.(That predates this change -- this code just moved.)