Skip to content

Commit 42d7fd3

Browse files
committed
do authz checks inside datastore delete functions
1 parent 041313d commit 42d7fd3

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

nexus/db-queries/src/db/datastore/console_session.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,17 @@ impl DataStore {
161161
pub async fn silo_user_sessions_delete(
162162
&self,
163163
opctx: &OpContext,
164-
user: &authz::SiloUser,
164+
authn_list: &authz::SiloUserAuthnList,
165165
) -> Result<(), Error> {
166-
// TODO: check for silo admin on opctx
167-
// TODO: ensure this can only be used in current silo
168-
// TODO: think about dueling admins problem
166+
// authz policy enforces that the opctx actor is a silo admin on the
167+
// target user's own silo in particular
168+
opctx.authorize(authz::Action::Modify, authn_list).await?;
169169

170170
use nexus_db_schema::schema::console_session;
171171
diesel::delete(console_session::table)
172-
.filter(console_session::silo_user_id.eq(user.id()))
172+
.filter(
173+
console_session::silo_user_id.eq(authn_list.silo_user().id()),
174+
)
173175
.execute_async(&*self.pool_connection_authorized(opctx).await?)
174176
.await
175177
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))

nexus/db-queries/src/db/datastore/device_auth.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,18 @@ impl DataStore {
246246
pub async fn silo_user_tokens_delete(
247247
&self,
248248
opctx: &OpContext,
249-
user: &authz::SiloUser,
249+
authn_list: &authz::SiloUserAuthnList,
250250
) -> Result<(), Error> {
251-
// TODO: check for silo admin on opctx
252-
// TODO: ensure this can only be used in current silo
253-
// TODO: think about dueling admins problem
251+
// authz policy enforces that the opctx actor is a silo admin on the
252+
// target user's own silo in particular
253+
opctx.authorize(authz::Action::Modify, authn_list).await?;
254254

255255
use nexus_db_schema::schema::device_access_token;
256256
diesel::delete(device_access_token::table)
257-
.filter(device_access_token::silo_user_id.eq(user.id()))
257+
.filter(
258+
device_access_token::silo_user_id
259+
.eq(authn_list.silo_user().id()),
260+
)
258261
.execute_async(&*self.pool_connection_authorized(opctx).await?)
259262
.await
260263
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))

nexus/src/app/silo.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,17 +324,15 @@ impl super::Nexus {
324324
.fetch()
325325
.await?;
326326

327-
let authz_user_sessions =
327+
let authz_authn_list =
328328
authz::SiloUserAuthnList::new(authz_silo_user.clone());
329-
// TODO: would rather do this check in the datastore functions
330-
opctx.authorize(authz::Action::Modify, &authz_user_sessions).await?;
331329

332330
self.datastore()
333-
.silo_user_tokens_delete(opctx, &authz_silo_user)
331+
.silo_user_tokens_delete(opctx, &authz_authn_list)
334332
.await?;
335333

336334
self.datastore()
337-
.silo_user_sessions_delete(opctx, &authz_silo_user)
335+
.silo_user_sessions_delete(opctx, &authz_authn_list)
338336
.await?;
339337

340338
Ok(())

0 commit comments

Comments
 (0)