Skip to content

Commit 5a924f6

Browse files
committed
authorization layer
1 parent 33b8e7d commit 5a924f6

21 files changed

+894
-187
lines changed

quickwit/Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

quickwit/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
resolver = "2"
33
members = [
44
"quickwit-actors",
5+
"quickwit-auth",
56
"quickwit-aws",
67
"quickwit-cli",
78
"quickwit-cluster",
@@ -20,6 +21,7 @@ members = [
2021
"quickwit-jaeger",
2122
"quickwit-janitor",
2223
"quickwit-lambda",
24+
"quickwit-license",
2325
"quickwit-macros",
2426
"quickwit-metastore",
2527

@@ -34,13 +36,14 @@ members = [
3436
"quickwit-serve",
3537
"quickwit-storage",
3638
"quickwit-telemetry",
37-
"quickwit-license",
39+
"quickwit-telemetry",
3840
]
3941

4042
# The following list excludes `quickwit-metastore-utils` and `quickwit-lambda`
4143
# from the default member to ease build/deps.
4244
default-members = [
4345
"quickwit-actors",
46+
"quickwit-auth",
4447
"quickwit-aws",
4548
"quickwit-cli",
4649
"quickwit-cluster",
@@ -52,6 +55,7 @@ default-members = [
5255
"quickwit-datetime",
5356
"quickwit-directories",
5457
"quickwit-doc-mapper",
58+
"quickwit-license",
5559
"quickwit-index-management",
5660
"quickwit-indexing",
5761
"quickwit-ingest",
@@ -89,7 +93,6 @@ async-trait = "0.1"
8993
base64 = "0.22"
9094
binggan = { version = "0.14" }
9195
biscuit-auth = "5.0.0"
92-
9396
bytes = { version = "1", features = ["serde"] }
9497
bytesize = { version = "1.3.0", features = ["serde"] }
9598
bytestring = "1.3.0"
@@ -303,6 +306,7 @@ opendal = { version = "0.44", default-features = false }
303306
reqsign = { version = "0.14", default-features = false }
304307

305308
quickwit-actors = { path = "quickwit-actors" }
309+
quickwit-auth = { path = "quickwit-auth" }
306310
quickwit-aws = { path = "quickwit-aws" }
307311
quickwit-cli = { path = "quickwit-cli" }
308312
quickwit-cluster = { path = "quickwit-cluster" }

quickwit/quickwit-codegen/example/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ tower = { workspace = true }
2727
utoipa = { workspace = true }
2828

2929
quickwit-actors = { workspace = true }
30+
quickwit-auth = { workspace = true }
3031
quickwit-common = { workspace = true }
3132
quickwit-proto = { workspace = true }
3233

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use quickwit_auth::Authorization;
2+
use quickwit_auth::AuthorizationError;
3+
use quickwit_auth::AuthorizationToken;
4+
use quickwit_auth::StreamAuthorization;
5+
6+
use crate::GoodbyeRequest;
7+
use crate::HelloRequest;
8+
use crate::PingRequest;
9+
10+
impl Authorization for HelloRequest {
11+
fn attenuate(&self, auth_token: quickwit_auth::AuthorizationToken) -> Result<quickwit_auth::AuthorizationToken, AuthorizationError> {
12+
Ok(auth_token)
13+
}
14+
}
15+
16+
impl Authorization for GoodbyeRequest {
17+
fn attenuate(&self, auth_token: quickwit_auth::AuthorizationToken) -> Result<AuthorizationToken, AuthorizationError> {
18+
Ok(auth_token)
19+
}
20+
}
21+
22+
impl StreamAuthorization for PingRequest {
23+
fn attenuate(auth_token: quickwit_auth::AuthorizationToken) -> Result<AuthorizationToken, AuthorizationError> {
24+
Ok(auth_token)
25+
}
26+
}

quickwit/quickwit-codegen/example/src/codegen/hello.rs

Lines changed: 24 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

quickwit/quickwit-codegen/example/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ mod error;
2121

2222
#[path = "codegen/hello.rs"]
2323
mod hello;
24+
mod authorization;
2425

2526
use std::sync::atomic::{AtomicUsize, Ordering};
2627
use std::sync::Arc;

quickwit/quickwit-codegen/src/codegen.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,12 @@ fn generate_grpc_server_adapter_methods(context: &CodegenContext) -> TokenStream
12311231
}
12321232
}
12331233
} else {
1234-
quote! { request.into_inner() }
1234+
quote! {
1235+
{
1236+
let req = request.into_inner();
1237+
req
1238+
}
1239+
}
12351240
};
12361241
let response_type = if syn_method.server_streaming {
12371242
let associated_type_name = quote::format_ident!("{}Stream", syn_method.proto_name);
@@ -1253,14 +1258,25 @@ fn generate_grpc_server_adapter_methods(context: &CodegenContext) -> TokenStream
12531258
} else {
12541259
quote! { tonic::Response::new }
12551260
};
1261+
1262+
let authorize_block = if syn_method.client_streaming {
1263+
let stream_item = &syn_method.request_type;
1264+
quote! {
1265+
quickwit_auth::authorize_stream::<#stream_item>(&auth_token)?;
1266+
}
1267+
} else {
1268+
quote! {
1269+
quickwit_auth::authorize(&req, &auth_token)?;
1270+
}
1271+
};
12561272
let method = quote! {
12571273
#associated_type
12581274

12591275
async fn #method_name(&self, request: tonic::Request<#request_type>) -> Result<tonic::Response<#response_type>, tonic::Status> {
1260-
self.inner
1261-
.0
1262-
.#method_name(#method_arg)
1263-
.await
1276+
let auth_token = quickwit_auth::get_auth_token(request.metadata())?;
1277+
let req = #method_arg;
1278+
#authorize_block;
1279+
quickwit_auth::AUTHORIZATION_TOKEN.scope(auth_token, self.inner.0.#method_name(req)).await
12641280
.map(#into_response_type)
12651281
.map_err(crate::error::grpc_error_to_grpc_status)
12661282
}
@@ -1270,6 +1286,8 @@ fn generate_grpc_server_adapter_methods(context: &CodegenContext) -> TokenStream
12701286
stream
12711287
}
12721288

1289+
1290+
12731291
/// A [`ServiceGenerator`] wrapper that appends a suffix to the name of the wrapped service. It is
12741292
/// used to add a `Grpc` suffix to the service, client, and server generated by tonic.
12751293
struct WithSuffixServiceGenerator {

quickwit/quickwit-ingest/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ ulid = { workspace = true }
3636
utoipa = { workspace = true }
3737

3838
quickwit-actors = { workspace = true }
39+
quickwit-auth = { workspace = true }
3940
quickwit-cluster = { workspace = true }
4041
quickwit-common = { workspace = true, features = ["testsuite"] }
4142
quickwit-config = { workspace = true }
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use quickwit_auth::Authorization;
2+
use quickwit_auth::AuthorizationError;
3+
use quickwit_auth::AuthorizationToken;
4+
5+
use crate::FetchRequest;
6+
use crate::IngestRequest;
7+
use crate::TailRequest;
8+
9+
impl Authorization for TailRequest {
10+
fn attenuate(&self, auth_token: AuthorizationToken) -> Result<AuthorizationToken, AuthorizationError> {
11+
Ok(auth_token)
12+
}
13+
}
14+
15+
impl Authorization for IngestRequest {
16+
fn attenuate(&self, auth_token: AuthorizationToken) -> Result<AuthorizationToken, AuthorizationError> {
17+
Ok(auth_token)
18+
}
19+
}
20+
21+
impl Authorization for FetchRequest {
22+
fn attenuate(&self, auth_token: AuthorizationToken) -> Result<AuthorizationToken, AuthorizationError> {
23+
Ok(auth_token)
24+
}
25+
}

quickwit/quickwit-ingest/src/codegen/ingest_service.rs

Lines changed: 24 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)