Skip to content

Commit

Permalink
fix: restrict user creation without a role (#913)
Browse files Browse the repository at this point in the history
server returns error `User cannot be created 
without a role` if no role is provided in API call
  • Loading branch information
nikhilsinhaparseable authored Sep 5, 2024
1 parent cdbab23 commit 6095922
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion server/src/handlers/http/rbac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ pub async fn post_user(
let roles: Option<HashSet<String>> = body
.map(|body| serde_json::from_value(body.into_inner()))
.transpose()?;

if roles.is_none() || roles.as_ref().unwrap().is_empty() {
return Err(RBACError::RoleValidationError);
}
validator::user_name(&username)?;
let _ = UPDATE_LOCK.lock().await;
if Users.contains(&username) {
Expand Down Expand Up @@ -215,6 +217,8 @@ pub enum RBACError {
ObjectStorageError(#[from] ObjectStorageError),
#[error("invalid Username: {0}")]
ValidationError(#[from] UsernameValidationError),
#[error("User cannot be created without a role")]
RoleValidationError,
}

impl actix_web::ResponseError for RBACError {
Expand All @@ -225,6 +229,7 @@ impl actix_web::ResponseError for RBACError {
Self::SerdeError(_) => StatusCode::BAD_REQUEST,
Self::ValidationError(_) => StatusCode::BAD_REQUEST,
Self::ObjectStorageError(_) => StatusCode::INTERNAL_SERVER_ERROR,
Self::RoleValidationError => StatusCode::BAD_REQUEST,
}
}

Expand Down

0 comments on commit 6095922

Please sign in to comment.