Skip to content

Commit 51e3f7e

Browse files
committed
fix: user login/logout sync
1 parent f1278d2 commit 51e3f7e

4 files changed

Lines changed: 52 additions & 10 deletions

File tree

src/cli.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,14 @@ pub struct Options {
407407
)]
408408
pub querier_endpoint: String,
409409

410+
#[arg(
411+
long,
412+
env = "P_PRISM_ENDPOINT",
413+
default_value = "",
414+
help = "URL to connect to the prism node. Default is the address of the server"
415+
)]
416+
pub prism_endpoint: String,
417+
410418
#[command(flatten)]
411419
pub oidc: Option<OidcConfig>,
412420

@@ -593,6 +601,7 @@ impl Options {
593601
Mode::Ingest => self.get_endpoint(&self.ingestor_endpoint, "P_INGESTOR_ENDPOINT"),
594602
Mode::Index => self.get_endpoint(&self.indexer_endpoint, "P_INDEXER_ENDPOINT"),
595603
Mode::Query => self.get_endpoint(&self.querier_endpoint, "P_QUERIER_ENDPOINT"),
604+
Mode::Prism => self.get_endpoint(&self.prism_endpoint, "P_PRISM_ENDPOINT"),
596605
_ => return self.build_url(&self.address),
597606
};
598607

src/handlers/http/oidc.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use tokio::sync::RwLock;
3333
use ulid::Ulid;
3434
use url::Url;
3535

36-
use crate::utils::login_sync;
36+
use crate::utils::{login_sync, logout_sync};
3737
use crate::{
3838
handlers::{
3939
COOKIE_AGE_DAYS, SESSION_COOKIE_NAME, USER_COOKIE_NAME, USER_ID_COOKIE_NAME,
@@ -176,14 +176,16 @@ pub async fn logout(req: HttpRequest, query: web::Query<RedirectAfterLogin>) ->
176176
None
177177
};
178178

179-
match (user, logout_endpoint) {
179+
let res = match (user, logout_endpoint) {
180180
(Some(username), Some(logout_endpoint))
181181
if Users.is_oauth(&username, &tenant_id).unwrap_or_default() =>
182182
{
183183
redirect_to_oidc_logout(logout_endpoint, &query.redirect)
184184
}
185185
_ => redirect_to_client(query.redirect.as_str(), None),
186-
}
186+
};
187+
let _ = logout_sync(session, &tenant_id).await;
188+
res
187189
}
188190

189191
/// Handler for code callback

src/rbac/user.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ impl UserGroup {
376376
// validate that the users exist and no protected user is included
377377
if let Some(tenant_users) = users().get(tenant) {
378378
for group_user in &self.users {
379-
tracing::warn!(group_user=?group_user);
380379
if let Some(user) = tenant_users.get(group_user.userid())
381380
&& !user.protected
382381
&& user.tenant.eq(tenant_id)

src/utils/mod.rs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ pub async fn user_auth_for_datasets(
173173
Some(ParseableResourceType::Stream(stream)),
174174
) => {
175175
if !PARSEABLE.check_or_load_stream(stream, tenant_id).await {
176-
tracing::warn!("unable to find stream");
177176
return Err(actix_web::error::ErrorUnauthorized(format!(
178177
"Stream not found: {table_name}"
179178
)));
@@ -254,11 +253,14 @@ pub fn create_intracluster_auth_headermap(
254253
reqwest::header::AUTHORIZATION,
255254
reqwest::header::HeaderValue::from_bytes(auth.as_bytes()).unwrap(),
256255
);
257-
} else if let Some(auth) = req.get(actix_web::http::header::COOKIE) {
258-
map.insert(
259-
reqwest::header::COOKIE,
260-
reqwest::header::HeaderValue::from_bytes(auth.as_bytes()).unwrap(),
261-
);
256+
} else if req.contains_key(actix_web::http::header::COOKIE) {
257+
// multiple cookies
258+
for cookie in req.get_all(actix_web::http::header::COOKIE) {
259+
map.insert(
260+
reqwest::header::COOKIE,
261+
reqwest::header::HeaderValue::from_bytes(cookie.as_bytes()).unwrap(),
262+
);
263+
}
262264
} else {
263265
map.insert(
264266
reqwest::header::AUTHORIZATION,
@@ -303,3 +305,33 @@ pub async fn login_sync(
303305
})
304306
.await
305307
}
308+
309+
pub async fn logout_sync(
310+
session: SessionKey,
311+
tenant_id: &Option<String>,
312+
) -> Result<(), anyhow::Error> {
313+
for_each_live_node(tenant_id, move |node| {
314+
let url = format!(
315+
"{}{}/o/logout/sync",
316+
node.domain_name,
317+
base_path_without_preceding_slash(),
318+
);
319+
let _session = session.clone();
320+
321+
async move {
322+
INTRA_CLUSTER_CLIENT
323+
.post(url)
324+
.header(header::AUTHORIZATION, node.token)
325+
.header(header::CONTENT_TYPE, "application/json")
326+
.json(&json!(
327+
{
328+
"sessionKey": _session
329+
}
330+
))
331+
.send()
332+
.await?;
333+
Ok::<(), anyhow::Error>(())
334+
}
335+
})
336+
.await
337+
}

0 commit comments

Comments
 (0)