Skip to content

Commit 1945ea4

Browse files
committed
added check
1 parent 5a924f6 commit 1945ea4

File tree

38 files changed

+475
-190
lines changed

38 files changed

+475
-190
lines changed

quickwit/Cargo.lock

Lines changed: 1 addition & 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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ members = [
3636
"quickwit-serve",
3737
"quickwit-storage",
3838
"quickwit-telemetry",
39-
"quickwit-telemetry",
4039
]
4140

4241
# The following list excludes `quickwit-metastore-utils` and `quickwit-lambda`
Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,46 @@
1-
use quickwit_auth::Authorization;
2-
use quickwit_auth::AuthorizationError;
3-
use quickwit_auth::AuthorizationToken;
4-
use quickwit_auth::StreamAuthorization;
1+
// The Quickwit Enterprise Edition (EE) license
2+
// Copyright (c) 2024-present Quickwit Inc.
3+
//
4+
// With regard to the Quickwit Software:
5+
//
6+
// This software and associated documentation files (the "Software") may only be
7+
// used in production, if you (and any entity that you represent) hold a valid
8+
// Quickwit Enterprise license corresponding to your usage.
9+
//
10+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16+
// SOFTWARE.
517

6-
use crate::GoodbyeRequest;
7-
use crate::HelloRequest;
8-
use crate::PingRequest;
18+
use quickwit_auth::{Authorization, AuthorizationError, AuthorizationToken, StreamAuthorization};
19+
20+
use crate::{GoodbyeRequest, HelloRequest, PingRequest};
921

1022
impl Authorization for HelloRequest {
11-
fn attenuate(&self, auth_token: quickwit_auth::AuthorizationToken) -> Result<quickwit_auth::AuthorizationToken, AuthorizationError> {
23+
fn attenuate(
24+
&self,
25+
auth_token: quickwit_auth::AuthorizationToken,
26+
) -> Result<quickwit_auth::AuthorizationToken, AuthorizationError> {
1227
Ok(auth_token)
1328
}
1429
}
1530

1631
impl Authorization for GoodbyeRequest {
17-
fn attenuate(&self, auth_token: quickwit_auth::AuthorizationToken) -> Result<AuthorizationToken, AuthorizationError> {
32+
fn attenuate(
33+
&self,
34+
auth_token: quickwit_auth::AuthorizationToken,
35+
) -> Result<AuthorizationToken, AuthorizationError> {
1836
Ok(auth_token)
1937
}
2038
}
2139

2240
impl StreamAuthorization for PingRequest {
23-
fn attenuate(auth_token: quickwit_auth::AuthorizationToken) -> Result<AuthorizationToken, AuthorizationError> {
41+
fn attenuate(
42+
auth_token: quickwit_auth::AuthorizationToken,
43+
) -> Result<AuthorizationToken, AuthorizationError> {
2444
Ok(auth_token)
2545
}
2646
}

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

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

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use std::fmt;
2121

2222
use quickwit_actors::AskError;
23+
use quickwit_auth::AuthorizationError;
2324
use quickwit_proto::error::GrpcServiceError;
2425
pub use quickwit_proto::error::{grpc_error_to_grpc_status, grpc_status_to_service_error};
2526
use quickwit_proto::{ServiceError, ServiceErrorCode};
@@ -38,6 +39,8 @@ pub enum HelloError {
3839
TooManyRequests,
3940
#[error("service unavailable: {0}")]
4041
Unavailable(String),
42+
#[error("unauthorized: {0}")]
43+
Unauthorized(#[from] AuthorizationError),
4144
}
4245

4346
impl ServiceError for HelloError {
@@ -48,6 +51,7 @@ impl ServiceError for HelloError {
4851
Self::Timeout(_) => ServiceErrorCode::Timeout,
4952
Self::TooManyRequests => ServiceErrorCode::TooManyRequests,
5053
Self::Unavailable(_) => ServiceErrorCode::Unavailable,
54+
Self::Unauthorized(_) => ServiceErrorCode::Unauthorized,
5155
}
5256
}
5357
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
mod error;
2121

22+
mod authorization;
2223
#[path = "codegen/hello.rs"]
2324
mod hello;
24-
mod authorization;
2525

2626
use std::sync::atomic::{AtomicUsize, Ordering};
2727
use std::sync::Arc;

quickwit/quickwit-codegen/src/codegen.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,14 +1167,29 @@ fn generate_grpc_client_adapter_methods(context: &CodegenContext) -> TokenStream
11671167
} else {
11681168
quote! { |response| response.into_inner() }
11691169
};
1170-
let method = quote! {
1171-
async fn #method_name(&self, request: #request_type) -> #result_type<#response_type> {
1172-
self.inner
1170+
let method = if syn_method.client_streaming {
1171+
quote! {
1172+
async fn #method_name(&self, request: #request_type) -> #result_type<#response_type> {
1173+
let tonic_request = quickwit_auth::build_tonic_stream_request_with_auth_token(request)?;
1174+
self.inner
11731175
.clone()
1174-
.#method_name(request)
1176+
.#method_name(tonic_request)
11751177
.await
11761178
.map(#into_response_type)
11771179
.map_err(|status| crate::error::grpc_status_to_service_error(status, #rpc_name))
1180+
}
1181+
}
1182+
} else {
1183+
quote! {
1184+
async fn #method_name(&self, request: #request_type) -> #result_type<#response_type> {
1185+
let tonic_request = quickwit_auth::build_tonic_request_with_auth_token(request)?;
1186+
self.inner
1187+
.clone()
1188+
.#method_name(tonic_request)
1189+
.await
1190+
.map(#into_response_type)
1191+
.map_err(|status| crate::error::grpc_status_to_service_error(status, #rpc_name))
1192+
}
11781193
}
11791194
};
11801195
stream.extend(method);
@@ -1286,8 +1301,6 @@ fn generate_grpc_server_adapter_methods(context: &CodegenContext) -> TokenStream
12861301
stream
12871302
}
12881303

1289-
1290-
12911304
/// A [`ServiceGenerator`] wrapper that appends a suffix to the name of the wrapped service. It is
12921305
/// used to add a `Grpc` suffix to the service, client, and server generated by tonic.
12931306
struct WithSuffixServiceGenerator {
Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,47 @@
1-
use quickwit_auth::Authorization;
2-
use quickwit_auth::AuthorizationError;
3-
use quickwit_auth::AuthorizationToken;
1+
// The Quickwit Enterprise Edition (EE) license
2+
// Copyright (c) 2024-present Quickwit Inc.
3+
//
4+
// With regard to the Quickwit Software:
5+
//
6+
// This software and associated documentation files (the "Software") may only be
7+
// used in production, if you (and any entity that you represent) hold a valid
8+
// Quickwit Enterprise license corresponding to your usage.
9+
//
10+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16+
// SOFTWARE.
417

5-
use crate::FetchRequest;
6-
use crate::IngestRequest;
7-
use crate::TailRequest;
18+
use quickwit_auth::{Authorization, AuthorizationError, AuthorizationToken};
19+
20+
use crate::{FetchRequest, IngestRequest, TailRequest};
821

922
impl Authorization for TailRequest {
10-
fn attenuate(&self, auth_token: AuthorizationToken) -> Result<AuthorizationToken, AuthorizationError> {
23+
fn attenuate(
24+
&self,
25+
auth_token: AuthorizationToken,
26+
) -> Result<AuthorizationToken, AuthorizationError> {
1127
Ok(auth_token)
1228
}
1329
}
1430

1531
impl Authorization for IngestRequest {
16-
fn attenuate(&self, auth_token: AuthorizationToken) -> Result<AuthorizationToken, AuthorizationError> {
32+
fn attenuate(
33+
&self,
34+
auth_token: AuthorizationToken,
35+
) -> Result<AuthorizationToken, AuthorizationError> {
1736
Ok(auth_token)
1837
}
1938
}
2039

2140
impl Authorization for FetchRequest {
22-
fn attenuate(&self, auth_token: AuthorizationToken) -> Result<AuthorizationToken, AuthorizationError> {
41+
fn attenuate(
42+
&self,
43+
auth_token: AuthorizationToken,
44+
) -> Result<AuthorizationToken, AuthorizationError> {
2345
Ok(auth_token)
2446
}
2547
}

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

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

quickwit/quickwit-ingest/src/error.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::io;
2121

2222
use mrecordlog::error::*;
2323
use quickwit_actors::AskError;
24+
use quickwit_auth::AuthorizationError;
2425
use quickwit_common::rate_limited_error;
2526
use quickwit_common::tower::BufferError;
2627
pub(crate) use quickwit_proto::error::{grpc_error_to_grpc_status, grpc_status_to_service_error};
@@ -48,6 +49,8 @@ pub enum IngestServiceError {
4849
RateLimited(RateLimitingCause),
4950
#[error("ingest service is unavailable ({0})")]
5051
Unavailable(String),
52+
#[error("unauthorized: {0}")]
53+
Unauthorized(#[from] AuthorizationError),
5154
}
5255

5356
impl From<AskError<IngestServiceError>> for IngestServiceError {
@@ -93,6 +96,9 @@ impl From<IngestV2Error> for IngestServiceError {
9396
IngestV2Error::TooManyRequests(rate_limiting_cause) => {
9497
IngestServiceError::RateLimited(rate_limiting_cause)
9598
}
99+
IngestV2Error::Unauthorized(authorization_error) => {
100+
IngestServiceError::Unauthorized(authorization_error)
101+
}
96102
}
97103
}
98104
}
@@ -134,6 +140,9 @@ impl From<IngestFailure> for IngestServiceError {
134140
IngestFailureReason::CircuitBreaker => {
135141
IngestServiceError::RateLimited(RateLimitingCause::CircuitBreaker)
136142
}
143+
IngestFailureReason::Unauthorized => {
144+
IngestServiceError::Unauthorized(AuthorizationError::PermissionDenied)
145+
}
137146
}
138147
}
139148
}
@@ -161,6 +170,7 @@ impl ServiceError for IngestServiceError {
161170
}
162171
Self::RateLimited(_) => ServiceErrorCode::TooManyRequests,
163172
Self::Unavailable(_) => ServiceErrorCode::Unavailable,
173+
Self::Unauthorized(_) => ServiceErrorCode::Unauthorized,
164174
}
165175
}
166176
}
@@ -204,6 +214,9 @@ impl From<IngestServiceError> for tonic::Status {
204214
IngestServiceError::IoError { .. } => tonic::Code::Internal,
205215
IngestServiceError::RateLimited(_) => tonic::Code::ResourceExhausted,
206216
IngestServiceError::Unavailable(_) => tonic::Code::Unavailable,
217+
IngestServiceError::Unauthorized(authorized_error) => {
218+
return (*authorized_error).into();
219+
}
207220
};
208221
let message = error.to_string();
209222
tonic::Status::new(code, message)

quickwit/quickwit-ingest/src/ingest_v2/metrics.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub(crate) struct IngestResultMetrics {
4444
pub load_shedding: IntCounter,
4545
pub shard_not_found: IntCounter,
4646
pub unavailable: IntCounter,
47+
pub unauthorized: IntCounter,
4748
}
4849

4950
impl Default for IngestResultMetrics {
@@ -72,6 +73,7 @@ impl Default for IngestResultMetrics {
7273
load_shedding: ingest_result_total_vec.with_label_values(["load_shedding"]),
7374
unavailable: ingest_result_total_vec.with_label_values(["unavailable"]),
7475
shard_not_found: ingest_result_total_vec.with_label_values(["shard_not_found"]),
76+
unauthorized: ingest_result_total_vec.with_label_values(["unauthorized"]),
7577
}
7678
}
7779
}

quickwit/quickwit-ingest/src/ingest_v2/router.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ fn update_ingest_metrics(ingest_result: &IngestV2Result<IngestResponseV2>, num_s
542542
ingest_results_metrics.router_load_shedding.inc()
543543
}
544544
IngestFailureReason::LoadShedding => ingest_results_metrics.load_shedding.inc(),
545+
IngestFailureReason::Unauthorized => ingest_results_metrics.unauthorized.inc(),
545546
}
546547
}
547548
}
@@ -588,6 +589,9 @@ fn update_ingest_metrics(ingest_result: &IngestV2Result<IngestResponseV2>, num_s
588589
IngestV2Error::Internal(_) => {
589590
ingest_results_metrics.internal.inc_by(num_subrequests);
590591
}
592+
IngestV2Error::Unauthorized(_) => {
593+
ingest_results_metrics.unauthorized.inc_by(num_subrequests);
594+
}
591595
},
592596
}
593597
}

quickwit/quickwit-ingest/src/ingest_v2/workbench.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ impl IngestWorkbench {
224224
self.record_too_many_requests(subrequest_id, rate_limiting_cause);
225225
}
226226
}
227+
IngestV2Error::Unauthorized(_) => {
228+
for subrequest_id in persist_summary.subrequest_ids {
229+
let failure = SubworkbenchFailure::Persist(PersistFailureReason::Unauthorized);
230+
self.record_failure(subrequest_id, failure);
231+
}
232+
}
227233
}
228234
}
229235

0 commit comments

Comments
 (0)