Skip to content

Commit 15ecdef

Browse files
authored
list-users-in-silo doesn't filter by silo (#1328)
1 parent d1cd2d1 commit 15ecdef

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

nexus/src/db/datastore.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3395,6 +3395,7 @@ impl DataStore {
33953395

33963396
opctx.authorize(authz::Action::Read, authz_silo).await?;
33973397
paginated(dsl::silo_user, dsl::id, pagparams)
3398+
.filter(dsl::silo_id.eq(authz_silo.id()))
33983399
.filter(dsl::time_deleted.is_null())
33993400
.select(SiloUser::as_select())
34003401
.load_async::<SiloUser>(self.pool_authorized(opctx).await?)

nexus/tests/integration_tests/silos.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,57 @@ async fn test_silo_users_list(cptestctx: &ControlPlaneTestContext) {
775775
]
776776
);
777777

778+
// Create another Silo with a Silo administrator. That user should not be
779+
// able to see the users in the first Silo.
780+
781+
let silo =
782+
create_silo(client, "silo2", true, shared::UserProvisionType::Fixed)
783+
.await;
784+
let new_silo_user_id =
785+
"6922f0b2-9a92-659b-da6b-93ad4955a3a3".parse().unwrap();
786+
let new_silo_user_name = String::from("some_silo_user");
787+
nexus
788+
.silo_user_create(
789+
silo.identity.id,
790+
new_silo_user_id,
791+
new_silo_user_name.clone(),
792+
)
793+
.await
794+
.unwrap();
795+
grant_iam(
796+
client,
797+
"/silos/silo2",
798+
SiloRole::Admin,
799+
new_silo_user_id,
800+
AuthnMode::PrivilegedUser,
801+
)
802+
.await;
803+
804+
let silo2_users: dropshot::ResultsPage<views::User> =
805+
NexusRequest::object_get(client, "/users")
806+
.authn_as(AuthnMode::SiloUser(new_silo_user_id))
807+
.execute()
808+
.await
809+
.unwrap()
810+
.parsed_body()
811+
.unwrap();
812+
assert_eq!(
813+
silo2_users.items,
814+
vec![views::User {
815+
id: new_silo_user_id,
816+
display_name: new_silo_user_name,
817+
}]
818+
);
819+
820+
// The "test-privileged" user also shouldn't see the user in this other
821+
// Silo.
822+
let new_silo_users: Vec<views::User> =
823+
NexusRequest::iter_collection_authn(client, "/users", "", Some(1))
824+
.await
825+
.expect("failed to list silo users (2)")
826+
.all_items;
827+
assert_eq!(silo_users, new_silo_users,);
828+
778829
// TODO-coverage When we have a way to remove or invalidate Silo Users, we
779830
// should test that doing so causes them to stop appearing in the list.
780831
}

0 commit comments

Comments
 (0)