Skip to content

Commit 0419e33

Browse files
committed
update policy test for session list
1 parent b00d8ba commit 0419e33

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

nexus/auth/src/authz/api_resources.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,10 @@ impl UserSessions {
683683
pub fn silo_user(&self) -> &SiloUser {
684684
&self.0
685685
}
686+
687+
pub fn silo(&self) -> &Silo {
688+
&self.0.parent
689+
}
686690
}
687691

688692
impl oso::PolarClass for UserSessions {

nexus/db-queries/src/policy_test/resource_builder.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,20 @@ impl DynAuthorizedResource for authz::SiloUserList {
345345
format!("{}: user list", self.silo().resource_name())
346346
}
347347
}
348+
349+
impl DynAuthorizedResource for authz::UserSessions {
350+
fn do_authorize<'a, 'b>(
351+
&'a self,
352+
opctx: &'b OpContext,
353+
action: authz::Action,
354+
) -> BoxFuture<'a, Result<(), Error>>
355+
where
356+
'b: 'a,
357+
{
358+
opctx.authorize(action, self).boxed()
359+
}
360+
361+
fn resource_name(&self) -> String {
362+
format!("{}: session list", self.silo_user().resource_name())
363+
}
364+
}

nexus/db-queries/src/policy_test/resources.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ async fn make_silo(
265265
builder.new_resource(silo_user.clone());
266266
let ssh_key_id = Uuid::new_v4();
267267
builder.new_resource(authz::SshKey::new(
268-
silo_user,
268+
silo_user.clone(),
269269
ssh_key_id,
270270
LookupType::ByName(format!("{}-user-ssh-key", silo_name)),
271271
));
@@ -281,6 +281,7 @@ async fn make_silo(
281281
silo_image_id,
282282
LookupType::ByName(format!("{}-silo-image", silo_name)),
283283
));
284+
builder.new_resource(authz::UserSessions::new(silo_user));
284285

285286
// Image is a special case in that this resource is technically just a
286287
// pass-through for `SiloImage` and `ProjectImage` resources.

nexus/db-queries/tests/output/authz-roles.out

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,20 @@ resource: SiloImage "silo1-silo-image"
306306
silo1-proj1-viewer ✘ ✘ ✘ ✘ ✘ ✘ ✘ ✘
307307
unauthenticated ! ! ! ! ! ! ! !
308308

309+
resource: SiloUser "silo1-user": session list
310+
311+
USER Q R LC RP M MP CC D
312+
fleet-admin ✘ ✘ ✘ ✘ ✘ ✘ ✘ ✘
313+
fleet-collaborator ✘ ✘ ✘ ✘ ✘ ✘ ✘ ✘
314+
fleet-viewer ✘ ✘ ✘ ✘ ✘ ✘ ✘ ✘
315+
silo1-admin ✘ ✘ ✘ ✘ ✔ ✔ ✘ ✔
316+
silo1-collaborator ✘ ✘ ✘ ✘ ✘ ✘ ✘ ✘
317+
silo1-viewer ✘ ✘ ✘ ✘ ✘ ✘ ✘ ✘
318+
silo1-proj1-admin ✘ ✘ ✘ ✘ ✘ ✘ ✘ ✘
319+
silo1-proj1-collaborator ✘ ✘ ✘ ✘ ✘ ✘ ✘ ✘
320+
silo1-proj1-viewer ✘ ✘ ✘ ✘ ✘ ✘ ✘ ✘
321+
unauthenticated ! ! ! ! ! ! ! !
322+
309323
resource: Image "silo1-image"
310324

311325
USER Q R LC RP M MP CC D
@@ -866,6 +880,20 @@ resource: SiloImage "silo2-silo-image"
866880
silo1-proj1-viewer ✘ ✘ ✘ ✘ ✘ ✘ ✘ ✘
867881
unauthenticated ! ! ! ! ! ! ! !
868882

883+
resource: SiloUser "silo2-user": session list
884+
885+
USER Q R LC RP M MP CC D
886+
fleet-admin ✘ ✘ ✘ ✘ ✘ ✘ ✘ ✘
887+
fleet-collaborator ✘ ✘ ✘ ✘ ✘ ✘ ✘ ✘
888+
fleet-viewer ✘ ✘ ✘ ✘ ✘ ✘ ✘ ✘
889+
silo1-admin ✘ ✘ ✘ ✘ ✘ ✘ ✘ ✘
890+
silo1-collaborator ✘ ✘ ✘ ✘ ✘ ✘ ✘ ✘
891+
silo1-viewer ✘ ✘ ✘ ✘ ✘ ✘ ✘ ✘
892+
silo1-proj1-admin ✘ ✘ ✘ ✘ ✘ ✘ ✘ ✘
893+
silo1-proj1-collaborator ✘ ✘ ✘ ✘ ✘ ✘ ✘ ✘
894+
silo1-proj1-viewer ✘ ✘ ✘ ✘ ✘ ✘ ✘ ✘
895+
unauthenticated ! ! ! ! ! ! ! !
896+
869897
resource: Image "silo2-image"
870898

871899
USER Q R LC RP M MP CC D

0 commit comments

Comments
 (0)