Enforce customer boundaries on token administration and finalize fleet navigation
This commit is contained in:
@@ -122,8 +122,10 @@ async fn list(
|
||||
) -> Result<Response, Error> {
|
||||
let (principal, allowed, mut tx) = administration(&state, &headers, tenant, false).await?;
|
||||
let rows = sqlx::query(&format!(
|
||||
"SELECT {COLUMNS} FROM mcp_tokens ORDER BY created_at DESC,token_id"
|
||||
"SELECT {COLUMNS} FROM mcp_tokens WHERE can_manage_mcp_token($1,token_id,$2) ORDER BY created_at DESC,token_id"
|
||||
))
|
||||
.bind(&principal.name)
|
||||
.bind(&principal.tenants)
|
||||
.fetch_all(&mut *tx)
|
||||
.await?;
|
||||
let can_select_all = crate::customers::can_manage(&principal, &mut tx).await?;
|
||||
@@ -267,10 +269,11 @@ async fn revoke(
|
||||
Path((tenant, id)): Path<(Uuid, Uuid)>,
|
||||
) -> Result<Response, Error> {
|
||||
let (principal, _, mut tx) = administration(&state, &headers, tenant, true).await?;
|
||||
let found: bool = sqlx::query_scalar("SELECT revoke_mcp_token($1,$2,$3)")
|
||||
let found: bool = sqlx::query_scalar("SELECT revoke_mcp_token($1,$2,$3,$4)")
|
||||
.bind(&principal.name)
|
||||
.bind(id)
|
||||
.bind(Uuid::new_v4())
|
||||
.bind(&principal.tenants)
|
||||
.fetch_one(&mut *tx)
|
||||
.await?;
|
||||
if !found {
|
||||
@@ -401,7 +404,8 @@ pub async fn issuer_enabled(
|
||||
}))
|
||||
}
|
||||
|
||||
pub async fn enabled_in(
|
||||
#[cfg(test)]
|
||||
async fn enabled_in(
|
||||
tx: &mut Transaction<'_, Postgres>,
|
||||
principal: &str,
|
||||
) -> Result<bool, sqlx::Error> {
|
||||
@@ -411,7 +415,8 @@ pub async fn enabled_in(
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn enabled(pool: &PgPool, principal: &str, tenant: Uuid) -> bool {
|
||||
#[cfg(test)]
|
||||
async fn enabled(pool: &PgPool, principal: &str, tenant: Uuid) -> bool {
|
||||
let Ok(mut tx) = rmm_persistence::tenant_tx(pool, tenant).await else {
|
||||
return false;
|
||||
};
|
||||
@@ -605,10 +610,11 @@ mod tests {
|
||||
|
||||
let (revoked_id, revoked) = mint(&app, tenant, &actor, &["inventory:read"]).await;
|
||||
let mut tx = rmm_persistence::tenant_tx(&app, tenant).await.unwrap();
|
||||
let found: bool = sqlx::query_scalar("SELECT revoke_mcp_token($1,$2,$3)")
|
||||
let found: bool = sqlx::query_scalar("SELECT revoke_mcp_token($1,$2,$3,$4)")
|
||||
.bind(&actor)
|
||||
.bind(revoked_id)
|
||||
.bind(Uuid::new_v4())
|
||||
.bind(vec![tenant])
|
||||
.fetch_one(&mut *tx)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user