Skip to content

Commit 6095922

Browse files
fix: restrict user creation without a role (#913)
server returns error `User cannot be created without a role` if no role is provided in API call
1 parent cdbab23 commit 6095922

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

server/src/handlers/http/rbac.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ pub async fn post_user(
6767
let roles: Option<HashSet<String>> = body
6868
.map(|body| serde_json::from_value(body.into_inner()))
6969
.transpose()?;
70-
70+
if roles.is_none() || roles.as_ref().unwrap().is_empty() {
71+
return Err(RBACError::RoleValidationError);
72+
}
7173
validator::user_name(&username)?;
7274
let _ = UPDATE_LOCK.lock().await;
7375
if Users.contains(&username) {
@@ -215,6 +217,8 @@ pub enum RBACError {
215217
ObjectStorageError(#[from] ObjectStorageError),
216218
#[error("invalid Username: {0}")]
217219
ValidationError(#[from] UsernameValidationError),
220+
#[error("User cannot be created without a role")]
221+
RoleValidationError,
218222
}
219223

220224
impl actix_web::ResponseError for RBACError {
@@ -225,6 +229,7 @@ impl actix_web::ResponseError for RBACError {
225229
Self::SerdeError(_) => StatusCode::BAD_REQUEST,
226230
Self::ValidationError(_) => StatusCode::BAD_REQUEST,
227231
Self::ObjectStorageError(_) => StatusCode::INTERNAL_SERVER_ERROR,
232+
Self::RoleValidationError => StatusCode::BAD_REQUEST,
228233
}
229234
}
230235

0 commit comments

Comments
 (0)