Skip to content

Commit 651f067

Browse files
authored
fix: RBAC issue for internal datasets (#1375)
1 parent 932daa0 commit 651f067

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

src/rbac/map.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,16 @@ impl Sessions {
239239
| ParseableResourceType::Llm(resource_id) => {
240240
let ok_resource =
241241
if let Some(context_resource_id) = context_resource {
242-
resource_id == context_resource_id || resource_id == "*"
242+
let is_internal = PARSEABLE
243+
.get_stream(context_resource_id)
244+
.is_ok_and(|stream| {
245+
stream
246+
.get_stream_type()
247+
.eq(&crate::storage::StreamType::Internal)
248+
});
249+
resource_id == context_resource_id
250+
|| resource_id == "*"
251+
|| is_internal
243252
} else {
244253
// if no resource to match then resource check is not needed
245254
// WHEN IS THIS VALID??

src/utils/mod.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ pub mod uid;
2626
pub mod update;
2727

2828
use crate::handlers::http::rbac::RBACError;
29+
use crate::parseable::PARSEABLE;
2930
use crate::query::{TableScanVisitor, QUERY_SESSION};
3031
use crate::rbac::map::SessionKey;
31-
use crate::rbac::role::{Action, Permission};
32+
use crate::rbac::role::{Action, ParseableResourceType, Permission};
3233
use crate::rbac::Users;
3334
use actix::extract_session_key_from_req;
3435
use actix_web::HttpRequest;
@@ -113,14 +114,33 @@ pub fn user_auth_for_datasets(
113114
authorized = true;
114115
break;
115116
}
116-
Permission::Resource(
117-
Action::Query,
118-
crate::rbac::role::ParseableResourceType::Stream(stream),
119-
) => {
120-
if stream == table_name || stream == "*" {
117+
Permission::Resource(Action::Query, ParseableResourceType::Stream(stream)) => {
118+
let is_internal = PARSEABLE.get_stream(table_name).is_ok_and(|stream| {
119+
stream
120+
.get_stream_type()
121+
.eq(&crate::storage::StreamType::Internal)
122+
});
123+
124+
if stream == table_name || stream == "*" || is_internal {
121125
authorized = true;
122126
}
123127
}
128+
Permission::Resource(action, ParseableResourceType::All)
129+
if ![
130+
Action::All,
131+
Action::PutUser,
132+
Action::PutRole,
133+
Action::DeleteUser,
134+
Action::DeleteRole,
135+
Action::ModifyUserGroup,
136+
Action::CreateUserGroup,
137+
Action::DeleteUserGroup,
138+
Action::DeleteNode,
139+
]
140+
.contains(action) =>
141+
{
142+
authorized = true;
143+
}
124144
_ => (),
125145
}
126146
}

0 commit comments

Comments
 (0)