Skip to content

Commit 605d12d

Browse files
committed
fix(cubesql): Hide security context from logs
1 parent 3a96b22 commit 605d12d

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

packages/cubejs-backend-native/src/auth.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::gateway::{
1818
GatewayAuthContext, GatewayAuthContextRef, GatewayAuthService, GatewayAuthenticateResponse,
1919
GatewayCheckAuthRequest,
2020
};
21+
use crate::utils::NonDebugInRelease;
2122

2223
#[derive(Debug)]
2324
pub struct NodeBridgeAuthService {
@@ -90,7 +91,7 @@ struct CheckSQLAuthTransportResponse {
9091
pub struct NativeSQLAuthContext {
9192
pub user: Option<String>,
9293
pub superuser: bool,
93-
pub security_context: Option<serde_json::Value>,
94+
pub security_context: NonDebugInRelease<Option<serde_json::Value>>,
9495
}
9596

9697
impl AuthContext for NativeSQLAuthContext {

packages/cubejs-backend-native/src/utils.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use cubesql::{compile::engine::df::scan::RecordBatch, sql::dataframe, CubeError};
22
use neon::prelude::*;
33
use serde_json::Value;
4+
use std::fmt::Debug;
5+
use std::ops::{Deref, DerefMut};
46

57
#[inline(always)]
68
pub fn call_method<'a, AS>(
@@ -38,3 +40,49 @@ pub fn batch_to_rows(batch: RecordBatch) -> Result<(Value, Vec<Value>), CubeErro
3840

3941
Ok((columns, rows))
4042
}
43+
44+
/// Allow skipping Debug output in release builds for specific field or type.
45+
pub struct NonDebugInRelease<T: Debug> {
46+
inner: T,
47+
}
48+
49+
impl<T: Debug> Debug for NonDebugInRelease<T> {
50+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51+
if cfg!(debug_assertions) {
52+
f.debug_struct("skipped in release build").finish()
53+
} else {
54+
self.inner.fmt(f)
55+
}
56+
}
57+
}
58+
59+
impl<T: Debug> From<T> for NonDebugInRelease<T> {
60+
fn from(value: T) -> Self {
61+
Self { inner: value }
62+
}
63+
}
64+
65+
impl<T: Debug> Deref for NonDebugInRelease<T> {
66+
type Target = T;
67+
68+
fn deref(&self) -> &Self::Target {
69+
&self.inner
70+
}
71+
}
72+
73+
impl<T: Debug> DerefMut for NonDebugInRelease<T> {
74+
fn deref_mut(&mut self) -> &mut Self::Target {
75+
&mut self.inner
76+
}
77+
}
78+
79+
impl<T: Debug> Default for NonDebugInRelease<T>
80+
where
81+
T: Default,
82+
{
83+
fn default() -> Self {
84+
Self {
85+
inner: T::default(),
86+
}
87+
}
88+
}

rust/cubesql/cubesql/src/compile/router.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,9 @@ impl QueryRouter {
466466
.set_auth_context(Some(authenticate_response.context));
467467
} else {
468468
return Err(CompilationError::user(format!(
469-
"{:?} is not allowed to switch to '{}'",
470-
auth_context, to_user
469+
"user '{:?}' is not allowed to switch to '{}'",
470+
auth_context.user(),
471+
to_user
471472
)));
472473
}
473474
}

0 commit comments

Comments
 (0)