Skip to content
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

Should policy response body have resource ID and type on it? #1165

Closed
david-crespo opened this issue Jun 6, 2022 · 2 comments
Closed

Should policy response body have resource ID and type on it? #1165

david-crespo opened this issue Jun 6, 2022 · 2 comments

Comments

@david-crespo
Copy link
Contributor

david-crespo commented Jun 6, 2022

I'm starting to work with the GET and PUT org and project policy endpoints in the console and found it surprising that the policy response body has no reference to the resource the policy is for. I assume this was to keep the Policy type simple by not having it know about the resource:

/// Client view of a [`Policy`], which describes how this resource may be
/// accessed
///
/// Note that the Policy only describes access granted explicitly for this
/// resource. The policies of parent resources can also cause a user to have
/// access to this resource.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, JsonSchema)]
#[schemars(rename = "{AllowedRoles}Policy")]
pub struct Policy<AllowedRoles: serde::de::DeserializeOwned> {
/// Roles directly assigned on this resource
#[serde(deserialize_with = "role_assignments_deserialize")]
pub role_assignments: Vec<RoleAssignment<AllowedRoles>>,
}

The simplest thing we could do is add a resource_id field, though it would be a bit weird if it didn't also indicate the resource type. So that could either be resource_id: "abc" and resource_type: "project" or we could combine that into one thing: project_id. On one hand project_id is neater. On the other hand, if a client has a policy and wants to know what kind of resource it is for, policy.resource_type === "project" makes a lot more sense than "is project_id present?" or some horrible /^(.+)_id$/ situation. On the other other hand, I don't know why a client would have a policy on hand but not know what kind of resource it came from. You just made the request, buddy.

So I guess the change I'm suggesting is this (sorry for the TS syntax, it's the most concise way to put it):

 type IdentityType = 'silo_user'

 type ProjectRoles = 'admin' | 'collaborator' | 'viewer'

 type ProjectRolesRoleAssignment = {
   identity_id: string
   identity_type: IdentityType
   role_name: ProjectRoles
 }
 
 type ProjectRolesPolicy = {
+  project_id: string
   role_assignments: ProjectRolesRoleAssignment[]
 }

 type OrganizationRolesPolicy = {
+  organization_id: string
   role_assignments: OrganizationRolesRoleAssignment[]
 }

// etc

cc @davepacheco @plotnick

@davepacheco
Copy link
Collaborator

I think I left it out because it seemed weird to include the type and id when you just made the request on a specific resource. I don't object to leaving it in though. I like resource_id and resource_type (and it seems a lot easier to implement).

@david-crespo
Copy link
Contributor Author

It's true, we don't have resource_type: 'project' on the response when you fetch a project.

I would say this is pretty low priority for now. Originally what prompted this is that I wanted to store policy response JSON in my mock API DB basically as-is, which requires resource type and ID because you need to distinguish between org policies and project policies. But then I realized if I have to mess with the object anyway, I might as well imitate the API's actual data model, i.e., each row is a (resource type, resource id, actor type, actor id) tuple and then the endpoint aggregates those into a policy object (source here). So, bottom line is I don't need the above. In fact, I think I'll close the issue because I don't see a practical problem this solves.

leftwo pushed a commit that referenced this issue Mar 4, 2024
Crucible changes:
Per client, queue-based backpressure (#1186)
A builder for the Downstairs Downstairs struct. (#1152)
Update Rust to v1.76.0 (#1153)
Deactivate the read only parent after a scrub (#1180)
Start byte-based backpressure earlier (#1179)
Tweak CI scripts to fix warnings (#1178)
Make `gw_ds_complete` less public (#1175)
Verify extent under repair is valid after copying files (#1159)
Remove individual panic setup, use global panic settings (#1174)
[smf] Use new zone network config service (#1096)
Move a few methods into downstairs (#1160)
Remove extra clone in upstairs read (#1163)
Make `crucible-downstairs` not depend on upstairs (#1165)
Update Rust crate rusqlite to 0.31 (#1171)
Update Rust crate reedline to 0.29.0 (#1170)
Update Rust crate clap to 4.5 (#1169)
Update Rust crate indicatif to 0.17.8 (#1168)
Update progenitor to bc0bb4b (#1164)
Do not 500 on snapshot delete for deleted region (#1162)
Drop jobs from Offline downstairs. (#1157)
`Mutex<Work>` → `Work` (#1156)
Added a contributing.md (#1158)
Remove ExtentFlushClose::source_downstairs (#1154)
Remove unnecessary mutexes from Downstairs (#1132)

Propolis changes:
PHD: improve Windows reliability (#651)
Update progenitor and omicron deps
Clean up VMM resource on server shutdown
Remove Inventory mechanism
Update vergen dependency
Properly handle pre/post illumos#16183 fixups
PHD: add `pfexec` to xtask phd-runner invocation (#647)
PHD: add Windows Server 2016 adapter & improve WS2016/2019 reliability (#646)
PHD: use `clap` for more `cargo xtask phd` args (#645)
PHD: several `cargo xtask phd` CLI fixes (#642)
PHD: Use ZFS clones for file-backed disks (#640)
PHD: improve ctrl-c handling (#634)
leftwo added a commit that referenced this issue Mar 4, 2024
Crucible changes:
Per client, queue-based backpressure (#1186)
A builder for the Downstairs Downstairs struct. (#1152) Update Rust to
v1.76.0 (#1153)
Deactivate the read only parent after a scrub (#1180) Start byte-based
backpressure earlier (#1179)
Tweak CI scripts to fix warnings (#1178)
Make `gw_ds_complete` less public (#1175)
Verify extent under repair is valid after copying files (#1159) Remove
individual panic setup, use global panic settings (#1174) [smf] Use new
zone network config service (#1096)
Move a few methods into downstairs (#1160)
Remove extra clone in upstairs read (#1163)
Make `crucible-downstairs` not depend on upstairs (#1165) Update Rust
crate rusqlite to 0.31 (#1171)
Update Rust crate reedline to 0.29.0 (#1170)
Update Rust crate clap to 4.5 (#1169)
Update Rust crate indicatif to 0.17.8 (#1168)
Update progenitor to bc0bb4b (#1164)
Do not 500 on snapshot delete for deleted region (#1162) Drop jobs from
Offline downstairs. (#1157)
`Mutex<Work>` → `Work` (#1156)
Added a contributing.md (#1158)
Remove ExtentFlushClose::source_downstairs (#1154) Remove unnecessary
mutexes from Downstairs (#1132)

Propolis changes:
PHD: improve Windows reliability (#651)
Update progenitor and omicron deps
Clean up VMM resource on server shutdown
Remove Inventory mechanism
Update vergen dependency
Properly handle pre/post illumos#16183 fixups
PHD: add `pfexec` to xtask phd-runner invocation (#647) PHD: add Windows
Server 2016 adapter & improve WS2016/2019 reliability (#646) PHD: use
`clap` for more `cargo xtask phd` args (#645) PHD: several `cargo xtask
phd` CLI fixes (#642)
PHD: Use ZFS clones for file-backed disks (#640)
PHD: improve ctrl-c handling (#634)

Co-authored-by: Alan Hanson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants