fix: adding root auth for config/reload API (#12279)

This commit is contained in:
Harsh Mahajan
2026-05-31 08:55:06 +08:00
committed by GitHub
parent 6ef8c85a75
commit ddce5bd8f2
2 changed files with 20 additions and 6 deletions
+16 -6
View File
@@ -76,10 +76,14 @@ use {
};
use crate::{
common::meta::{
http::HttpResponse as MetaHttpResponse,
user::{AuthTokens, AuthTokensExt},
common::{
meta::{
http::HttpResponse as MetaHttpResponse,
user::{AuthTokens, AuthTokensExt},
},
utils::auth::{UserEmail, is_root_user},
},
handler::http::extractors::Headers,
service::{
db,
search::{
@@ -787,7 +791,14 @@ pub async fn cache_status() -> impl IntoResponse {
axum::Json(stats)
}
pub async fn config_reload() -> impl IntoResponse {
pub async fn config_reload(Headers(user_email): Headers<UserEmail>) -> impl IntoResponse {
let user_id = user_email.user_id.as_str();
if !is_root_user(user_id) {
return (
StatusCode::FORBIDDEN,
axum::Json(serde_json::json!({"message": "Only root users can reload config"})),
);
}
if let Err(e) = config::refresh_config() {
return (
StatusCode::INTERNAL_SERVER_ERROR,
@@ -805,8 +816,7 @@ pub async fn config_reload() -> impl IntoResponse {
// Audit this event
#[cfg(feature = "enterprise")]
audit(AuditMessage {
// Since this is not a protected route, there is no way to get the user email
user_email: "".to_string(),
user_email: user_id.to_string(),
org_id: "".to_string(),
_timestamp: now_micros(),
protocol: Protocol::Http,
+4
View File
@@ -550,6 +550,8 @@ pub fn basic_routes() -> Router {
#[cfg(not(feature = "enterprise"))]
pub fn config_routes() -> Router {
Router::new()
.route("/reload", get(status::config_reload))
.route_layer(middleware::from_fn(auth_middleware))
.route("/", get(status::zo_config))
.route("/logout", get(status::logout))
}
@@ -557,6 +559,8 @@ pub fn config_routes() -> Router {
#[cfg(feature = "enterprise")]
pub fn config_routes() -> Router {
Router::new()
.route("/reload", get(status::config_reload))
.route_layer(middleware::from_fn(auth_middleware))
.route("/", get(status::zo_config))
.route("/logout", get(status::logout))
.route("/redirect", get(status::redirect))