Skip to content

Commit ed70830

Browse files
committed
self-review tweaks
1 parent d3a4e62 commit ed70830

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@ tags
1818
.img/*
1919
connectivity-report.json
2020
*.local
21-
CLAUDE.md

nexus/auth/src/authz/omicron.polar

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -451,15 +451,14 @@ resource SiloUserAuthnList {
451451
# A silo admin can list a user's tokens and sessions.
452452
"list_children" if "admin" on "parent_silo";
453453
}
454-
has_relation(silo: Silo, "parent_silo", sessions: SiloUserAuthnList)
455-
if sessions.silo_user.silo = silo;
456-
457-
# also give users 'modify' and 'list_children' on their own sessions
458-
has_permission(actor: AuthenticatedActor, "modify", sessions: SiloUserAuthnList)
459-
if actor.equals_silo_user(sessions.silo_user);
460-
461-
has_permission(actor: AuthenticatedActor, "list_children", sessions: SiloUserAuthnList)
462-
if actor.equals_silo_user(sessions.silo_user);
454+
has_relation(silo: Silo, "parent_silo", authn_list: SiloUserAuthnList)
455+
if authn_list.silo_user.silo = silo;
456+
457+
# give users 'modify' and 'list_children' on their own tokens and sessions
458+
has_permission(actor: AuthenticatedActor, "modify", authn_list: SiloUserAuthnList)
459+
if actor.equals_silo_user(authn_list.silo_user);
460+
has_permission(actor: AuthenticatedActor, "list_children", authn_list: SiloUserAuthnList)
461+
if actor.equals_silo_user(authn_list.silo_user);
463462

464463
# Describes the policy for creating and managing device authorization requests.
465464
resource DeviceAuthRequestList {

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,23 @@ impl DataStore {
165165
pub async fn silo_user_session_list(
166166
&self,
167167
opctx: &OpContext,
168-
user_authn_list: authz::SiloUserAuthnList,
168+
authn_list: authz::SiloUserAuthnList,
169169
pagparams: &DataPageParams<'_, Uuid>,
170170
) -> ListResultVec<ConsoleSession> {
171-
opctx.authorize(authz::Action::ListChildren, &user_authn_list).await?;
171+
opctx.authorize(authz::Action::ListChildren, &authn_list).await?;
172172

173-
let silo_user_id = user_authn_list.silo_user().id();
173+
let user_id = authn_list.silo_user().id();
174174

175175
use nexus_db_schema::schema::console_session::dsl;
176176
paginated(dsl::console_session, dsl::id, &pagparams)
177-
.filter(dsl::silo_user_id.eq(silo_user_id))
177+
.filter(dsl::silo_user_id.eq(user_id))
178+
// TODO: unlike with tokens, we do not have expiration time here,
179+
// so we can't filter out expired sessions by comparing to now. In
180+
// the authn code, this works by dynamically comparing the created
181+
// and last used times against now + idle/absolute TTL. We may
182+
// have to do that here but it's kind of sad. It might be nicer to
183+
// make sessions work more like tokens and put idle and absolute
184+
// expiration time right there in the table at session create time.
178185
.select(ConsoleSession::as_select())
179186
.load_async(&*self.pool_connection_authorized(opctx).await?)
180187
.await
@@ -191,11 +198,11 @@ impl DataStore {
191198
// target user's own silo in particular
192199
opctx.authorize(authz::Action::Modify, authn_list).await?;
193200

201+
let user_id = authn_list.silo_user().id();
202+
194203
use nexus_db_schema::schema::console_session;
195204
diesel::delete(console_session::table)
196-
.filter(
197-
console_session::silo_user_id.eq(authn_list.silo_user().id()),
198-
)
205+
.filter(console_session::silo_user_id.eq(user_id))
199206
.execute_async(&*self.pool_connection_authorized(opctx).await?)
200207
.await
201208
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))

nexus/src/app/silo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl super::Nexus {
347347
let (_, authz_silo_user, db_silo_user) =
348348
LookupPath::new(opctx, self.datastore())
349349
.silo_user_id(silo_user_id)
350-
.fetch_for(authz::Action::Read)
350+
.fetch()
351351
.await?;
352352

353353
Ok((authz_silo_user, db_silo_user))
@@ -363,7 +363,7 @@ impl super::Nexus {
363363
let (_, authz_silo_user, _db_silo_user) =
364364
LookupPath::new(opctx, self.datastore())
365365
.silo_user_id(silo_user_id)
366-
.fetch_for(authz::Action::Read)
366+
.fetch()
367367
.await?;
368368

369369
let user_authn_list = authz::SiloUserAuthnList::new(authz_silo_user);
@@ -383,7 +383,7 @@ impl super::Nexus {
383383
let (_, authz_silo_user, _db_silo_user) =
384384
LookupPath::new(opctx, self.datastore())
385385
.silo_user_id(silo_user_id)
386-
.fetch_for(authz::Action::Read)
386+
.fetch()
387387
.await?;
388388

389389
let user_authn_list = authz::SiloUserAuthnList::new(authz_silo_user);

0 commit comments

Comments
 (0)