Skip to content

Commit 98a2766

Browse files
committed
adapter: Frontend peek sequencing -- refactor rbac::check_plan
1 parent 28e6bd5 commit 98a2766

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

src/adapter/src/coord/sequencer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,14 @@ impl Coordinator {
183183

184184
if let Err(e) = rbac::check_plan(
185185
&session_catalog,
186-
|id| {
186+
Some(|id| {
187187
// We use linear search through active connections if needed, which is fine
188188
// because the RBAC check will call the closure at most once.
189189
self.active_conns()
190190
.into_iter()
191191
.find(|(conn_id, _)| conn_id.unhandled() == id)
192192
.map(|(_, conn_meta)| *conn_meta.authenticated_role_id())
193-
},
193+
}),
194194
ctx.session(),
195195
&plan,
196196
target_cluster_id,

src/adapter/src/frontend_peek.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use mz_expr::{CollectionPlan, ResultSpec};
1919
use mz_ore::cast::{CastFrom, CastLossy};
2020
use mz_ore::now::EpochMillis;
2121
use mz_repr::optimize::{OptimizerFeatures, OverrideFrom};
22+
use mz_repr::role_id::RoleId;
2223
use mz_repr::{Datum, GlobalId, IntoRowIterator, Timestamp};
2324
use mz_sql::catalog::CatalogCluster;
2425
use mz_sql::plan::{self, Plan, QueryWhen};
@@ -300,11 +301,7 @@ impl PeekClient {
300301

301302
rbac::check_plan(
302303
&conn_catalog,
303-
|_id| {
304-
// This is only used by `Plan::SideEffectingFunc`, so it is irrelevant for us here
305-
// TODO(peek-seq): refactor `check_plan` to make this nicer
306-
unreachable!()
307-
},
304+
None::<fn(u32) -> Option<RoleId>>,
308305
session,
309306
&plan,
310307
Some(target_cluster_id),

src/sql/src/rbac.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ pub fn check_usage(
337337
pub fn check_plan(
338338
catalog: &impl SessionCatalog,
339339
// Function mapping a connection ID to an authenticated role. The roles may have been dropped concurrently.
340-
active_conns: impl FnOnce(u32) -> Option<RoleId>,
340+
// Only required for Plan::SideEffectingFunc; can be None for other plan types.
341+
active_conns: Option<impl FnOnce(u32) -> Option<RoleId>>,
341342
session: &dyn SessionMetadata,
342343
plan: &Plan,
343344
target_cluster_id: Option<ClusterId>,
@@ -377,7 +378,7 @@ pub fn is_rbac_enabled_for_session(
377378
fn generate_rbac_requirements(
378379
catalog: &impl SessionCatalog,
379380
plan: &Plan,
380-
active_conns: impl FnOnce(u32) -> Option<RoleId>,
381+
active_conns: Option<impl FnOnce(u32) -> Option<RoleId>>,
381382
target_cluster_id: Option<ClusterId>,
382383
role_id: RoleId,
383384
) -> RbacRequirements {
@@ -1464,11 +1465,12 @@ fn generate_rbac_requirements(
14641465
},
14651466
Plan::SideEffectingFunc(func) => {
14661467
let role_membership = match func {
1467-
SideEffectingFunc::PgCancelBackend { connection_id } => {
1468-
active_conns(*connection_id)
1469-
.map(|x| [x].into())
1470-
.unwrap_or_default()
1471-
}
1468+
SideEffectingFunc::PgCancelBackend { connection_id } => active_conns
1469+
.expect("active_conns is required for Plan::SideEffectingFunc")(
1470+
*connection_id
1471+
)
1472+
.map(|x| [x].into())
1473+
.unwrap_or_default(),
14721474
};
14731475
RbacRequirements {
14741476
role_membership,

0 commit comments

Comments
 (0)