Line data Source code
1 : use utils::auth::{AuthError, Claims, Scope};
2 : use utils::id::TenantId;
3 :
4 164 : pub fn check_permission(claims: &Claims, tenant_id: Option<TenantId>) -> Result<(), AuthError> {
5 164 : match (&claims.scope, tenant_id) {
6 1 : (Scope::Tenant, None) => Err(AuthError(
7 1 : "Attempt to access management api with tenant scope. Permission denied".into(),
8 1 : )),
9 107 : (Scope::Tenant, Some(tenant_id)) => {
10 107 : if claims.tenant_id.unwrap() != tenant_id {
11 2 : return Err(AuthError("Tenant id mismatch. Permission denied".into()));
12 105 : }
13 105 : Ok(())
14 : }
15 10 : (Scope::PageServerApi, None) => Ok(()), // access to management api for PageServerApi scope
16 45 : (Scope::PageServerApi, Some(_)) => Ok(()), // access to tenant api using PageServerApi scope
17 1 : (Scope::SafekeeperData, _) => Err(AuthError(
18 1 : "SafekeeperData scope makes no sense for Pageserver".into(),
19 1 : )),
20 : }
21 164 : }
|