Skip to content

Commit

Permalink
feat: discovery_nodes not need auth. (#16392)
Browse files Browse the repository at this point in the history
  • Loading branch information
youngsofun authored Sep 6, 2024
1 parent db6a305 commit 390b9c1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/query/service/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub enum Credential {
password: Option<Vec<u8>>,
client_ip: Option<String>,
},
NoNeed,
}

impl AuthMgr {
Expand Down Expand Up @@ -79,6 +80,7 @@ impl AuthMgr {
) -> Result<Option<String>> {
let user_api = UserApiProvider::instance();
match credential {
Credential::NoNeed => Ok(None),
Credential::DatabendToken {
token,
set_user,
Expand Down
2 changes: 1 addition & 1 deletion src/query/service/src/servers/http/http_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl HttpHandler {
"/discovery_nodes",
get(discovery_nodes).with(HTTPSessionMiddleware::create(
self.kind,
EndpointKind::StartQuery,
EndpointKind::NoAuth,
)),
);

Expand Down
7 changes: 7 additions & 0 deletions src/query/service/src/servers/http/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub enum EndpointKind {
StartQuery,
PollQuery,
Clickhouse,
NoAuth,
}

const USER_AGENT: &str = "User-Agent";
Expand Down Expand Up @@ -133,6 +134,9 @@ fn get_credential(
kind: HttpHandlerKind,
endpoint_kind: EndpointKind,
) -> Result<Credential> {
if matches!(endpoint_kind, EndpointKind::NoAuth) {
return Ok(Credential::NoNeed);
}
let std_auth_headers: Vec<_> = req.headers().get_all(AUTHORIZATION).iter().collect();
if std_auth_headers.len() > 1 {
let msg = &format!("Multiple {} headers detected", AUTHORIZATION);
Expand Down Expand Up @@ -221,6 +225,9 @@ fn auth_by_header(
"clickhouse handler should not use databend auth",
));
}
EndpointKind::NoAuth => {
unreachable!()
}
};
Ok(Credential::DatabendToken {
token,
Expand Down

0 comments on commit 390b9c1

Please sign in to comment.