Skip to content

Commit e2dc5d7

Browse files
add owner to tenant metadata
1 parent 08cdb38 commit e2dc5d7

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/handlers/http/modal/query/querier_rbac.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ use crate::{
2929
modal::utils::rbac_utils::{get_metadata, put_metadata},
3030
rbac::{RBACError, UPDATE_LOCK},
3131
},
32-
parseable::DEFAULT_TENANT,
32+
parseable::{DEFAULT_TENANT, PARSEABLE},
3333
rbac::{
3434
Users,
3535
map::{roles, users, write_user_groups},
3636
user::{self, UserType},
3737
},
38+
tenants::TENANT_METADATA,
3839
utils::{get_tenant_id_from_request, get_user_from_request},
3940
validator,
4041
};
@@ -292,6 +293,23 @@ pub async fn remove_roles_from_user(
292293
)));
293294
}
294295

296+
// In multi-tenant, prevent removing the admin role from the tenant owner
297+
if PARSEABLE.options.is_multi_tenant()
298+
&& roles_to_remove.contains("admin")
299+
&& let Some(tid) = tenant_id.as_deref()
300+
{
301+
let is_owner = TENANT_METADATA
302+
.get_tenant_meta(tid)
303+
.and_then(|meta| meta.owner)
304+
.map(|owner| owner == userid)
305+
.unwrap_or(false);
306+
if is_owner {
307+
return Err(RBACError::InvalidDeletionRequest(
308+
"Cannot remove the admin role from the tenant owner".to_string(),
309+
));
310+
}
311+
}
312+
295313
// update parseable.json first
296314
let mut metadata = get_metadata(&tenant_id).await?;
297315
if let Some(user) = metadata

src/storage/store_metadata.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ pub struct StorageMetadata {
7878
pub end_date: Option<String>,
7979
#[serde(default, skip_serializing_if = "Option::is_none")]
8080
pub plan: Option<String>,
81+
#[serde(default, skip_serializing_if = "Option::is_none")]
82+
pub owner: Option<String>,
8183
}
8284

8385
impl Default for StorageMetadata {
@@ -100,6 +102,7 @@ impl Default for StorageMetadata {
100102
start_date: None,
101103
end_date: None,
102104
plan: None,
105+
owner: None,
103106
}
104107
}
105108
}

0 commit comments

Comments
 (0)