Skip to content

Commit b65f2b5

Browse files
committed
blop
1 parent 94b575a commit b65f2b5

33 files changed

+387
-139
lines changed

config/quickwit.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,9 @@ indexer:
150150

151151
jaeger:
152152
enable_endpoint: ${QW_ENABLE_JAEGER_ENDPOINT:-true}
153+
154+
license: ${QW_LICENSE}
155+
156+
# authorization:
157+
# root_key: ${QW_ROOT_KEY}
158+
# node_token: ${QW_NODE_TOKEN}

quickwit/Cargo.lock

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

quickwit/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ tikv-jemalloc-ctl = "0.5"
240240
tikv-jemallocator = "0.5"
241241
time = { version = "0.3", features = ["std", "formatting", "macros"] }
242242
tokio = { version = "1.40", features = ["full"] }
243+
tokio-inherit-task-local = "0.2"
243244
tokio-metrics = { version = "0.3.1", features = ["rt"] }
244245
tokio-stream = { version = "0.1", features = ["sync"] }
245246
tokio-util = { version = "0.7", features = ["full"] }

quickwit/quickwit-authorize/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ authors.workspace = true
99
license.workspace = true
1010

1111
[dependencies]
12+
anyhow = { workspace = true, optional = true }
1213
tower = { workspace = true}
1314
biscuit-auth = { workspace = true, optional=true }
1415
futures = { workspace = true }
1516
http = { workspace = true }
17+
tokio-inherit-task-local = { workspace = true }
1618
serde = { workspace = true }
1719
thiserror = { workspace = true }
1820
tonic = { workspace = true }
@@ -23,4 +25,4 @@ pin-project = { workspace = true }
2325
quickwit-common = { workspace = true }
2426

2527
[features]
26-
enterprise = ["biscuit-auth"]
28+
enterprise = ["dep:biscuit-auth", "dep:anyhow"]

quickwit/quickwit-authorize/src/community.rs renamed to quickwit/quickwit-authorize/src/community/mod.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub trait StreamAuthorization {
4444

4545
impl<T> StreamAuthorization for T {}
4646

47-
pub fn get_auth_token(
47+
pub fn extract_auth_token(
4848
_req_metadata: &tonic::metadata::MetadataMap,
4949
) -> Result<AuthorizationToken, AuthorizationError> {
5050
Ok(())
@@ -63,12 +63,6 @@ pub fn authorize<R: Authorization>(
6363
Ok(())
6464
}
6565

66-
pub fn build_tonic_stream_request_with_auth_token<R>(
67-
req: R,
68-
) -> Result<tonic::Request<R>, AuthorizationError> {
69-
Ok(tonic::Request::new(req))
70-
}
71-
7266
pub fn build_tonic_request_with_auth_token<R: Authorization>(
7367
req: R,
7468
) -> Result<tonic::Request<R>, AuthorizationError> {

quickwit/quickwit-authorize/src/authorization_layer.rs renamed to quickwit/quickwit-authorize/src/enterprise/authorization_layer.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
// Copyright (C) 2024 Quickwit, Inc.
2+
//
3+
// Quickwit is offered under the AGPL v3.0 and as commercial software.
4+
// For commercial licensing, contact us at [email protected].
5+
//
6+
// AGPL:
7+
// This program is free software: you can redistribute it and/or modify
8+
// it under the terms of the GNU Affero General Public License as
9+
// published by the Free Software Foundation, either version 3 of the
10+
// License, or (at your option) any later version.
11+
//
12+
// This program is distributed in the hope that it will be useful,
13+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
// GNU Affero General Public License for more details.
16+
//
17+
// You should have received a copy of the GNU Affero General Public License
18+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
120
use std::fmt;
221
use std::task::{Context, Poll};
322

@@ -7,6 +26,7 @@ use tower::{Layer, Service};
726

827
use crate::AuthorizationError;
928

29+
#[derive(Clone, Copy, Debug)]
1030
pub struct AuthorizationLayer;
1131

1232
impl<S: Clone> Layer<S> for AuthorizationLayer {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (C) 2024 Quickwit, Inc.
2+
//
3+
// Quickwit is offered under the AGPL v3.0 and as commercial software.
4+
// For commercial licensing, contact us at [email protected].
5+
//
6+
// AGPL:
7+
// This program is free software: you can redistribute it and/or modify
8+
// it under the terms of the GNU Affero General Public License as
9+
// published by the Free Software Foundation, either version 3 of the
10+
// License, or (at your option) any later version.
11+
//
12+
// This program is distributed in the hope that it will be useful,
13+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
// GNU Affero General Public License for more details.
16+
//
17+
// You should have received a copy of the GNU Affero General Public License
18+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
20+
use std::task::{Context, Poll};
21+
22+
use futures::future::Either;
23+
use http::Request;
24+
use tokio::task::futures::TaskLocalFuture;
25+
use tokio_inherit_task_local::TaskLocalInheritableTable;
26+
use tower::{Layer, Service};
27+
use tracing::debug;
28+
29+
use super::AuthorizationToken;
30+
31+
#[derive(Clone, Copy, Debug)]
32+
pub struct AuthorizationTokenExtractionLayer;
33+
34+
impl<S: Clone> Layer<S> for AuthorizationTokenExtractionLayer {
35+
type Service = AuthorizationTokenExtractionService<S>;
36+
37+
fn layer(&self, service: S) -> Self::Service {
38+
AuthorizationTokenExtractionService { service }
39+
}
40+
}
41+
42+
#[derive(Clone)]
43+
pub struct AuthorizationTokenExtractionService<S> {
44+
service: S,
45+
}
46+
47+
fn get_authorization_token_opt(headers: &http::HeaderMap) -> Option<AuthorizationToken> {
48+
let authorization_header_value = headers.get("Authorization")?;
49+
let authorization_header_str = authorization_header_value.to_str().ok()?;
50+
crate::get_auth_token_from_str(authorization_header_str).ok()
51+
}
52+
53+
impl<B, S> Service<Request<B>> for AuthorizationTokenExtractionService<S>
54+
where S: Service<Request<B>>
55+
{
56+
type Response = S::Response;
57+
type Error = S::Error;
58+
type Future = Either<S::Future, TaskLocalFuture<TaskLocalInheritableTable, S::Future>>;
59+
60+
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
61+
self.service.poll_ready(cx)
62+
}
63+
64+
fn call(&mut self, request: Request<B>) -> Self::Future {
65+
let authorization_token_opt = get_authorization_token_opt(request.headers());
66+
debug!(authorization_token_opt = ?authorization_token_opt, "Authorization token extracted");
67+
let fut = self.service.call(request);
68+
if let Some(authorization_token) = authorization_token_opt {
69+
Either::Right(crate::execute_with_authorization(authorization_token, fut))
70+
} else {
71+
Either::Left(fut)
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)