Skip to content

Commit

Permalink
Support configurable log visibility in local-backend (#34060)
Browse files Browse the repository at this point in the history
Manually confirmed that it works! Command line flag affects
log visibility correctly.

GitOrigin-RevId: 6e9d27f5b60b7a54be3743a5d730a33f0d7273d4
  • Loading branch information
nipunn1313 authored and Convex, Inc. committed Feb 5, 2025
1 parent 1d36eee commit aeb63e2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
14 changes: 11 additions & 3 deletions crates/application/src/log_visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,24 @@ pub trait LogVisibility<RT: Runtime>: Send + Sync {
) -> anyhow::Result<bool>;
}

pub struct AllowLogging;
pub struct RedactLogsToClient {
redact: bool,
}

impl RedactLogsToClient {
pub fn new(redact: bool) -> Self {
Self { redact }
}
}

#[async_trait]
impl<RT: Runtime> LogVisibility<RT> for AllowLogging {
impl<RT: Runtime> LogVisibility<RT> for RedactLogsToClient {
async fn should_redact_logs_and_error(
&self,
_tx: &mut Transaction<RT>,
_identity: Identity,
_allowed_visibility: AllowedVisibility,
) -> anyhow::Result<bool> {
Ok(false)
Ok(self.redact)
}
}
4 changes: 2 additions & 2 deletions crates/application/src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ use crate::{
SchemaStatus,
StartPushRequest,
},
log_visibility::AllowLogging,
log_visibility::RedactLogsToClient,
scheduled_jobs::ScheduledJobExecutor,
Application,
};
Expand Down Expand Up @@ -275,7 +275,7 @@ impl<RT: Runtime> ApplicationTestExt<RT> for Application<RT> {
Arc::new(persistence.clone()),
actions,
Arc::new(NoopLogSender),
Arc::new(AllowLogging),
Arc::new(RedactLogsToClient::new(false)),
Arc::new(ApplicationAuth::new(
kb.clone(),
Arc::new(NullAccessTokenAuth),
Expand Down
9 changes: 9 additions & 0 deletions crates/local_backend/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ pub struct LocalConfig {
/// A tag to identify the self-hosted instance.
#[clap(long, hide = true, default_value = "self-host")]
pub beacon_tag: String,

/// If set, logs will be redacted from clients. Set this on production
/// deployments, to prevent information like stacktraces of serverside
/// code from being leaked to clients.
///
/// On development deployments, it can be helpful to have this information
/// reach the client for debugging purposes.
#[clap(long, default_value = "false")]
pub redact_logs_to_client: bool,
}

impl fmt::Debug for LocalConfig {
Expand Down
4 changes: 2 additions & 2 deletions crates/local_backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use ::storage::{
};
use application::{
api::ApplicationApi,
log_visibility::AllowLogging,
log_visibility::RedactLogsToClient,
Application,
QueryCache,
};
Expand Down Expand Up @@ -246,7 +246,7 @@ pub async fn make_app(
persistence,
actions,
Arc::new(NoopLogSender),
Arc::new(AllowLogging),
Arc::new(RedactLogsToClient::new(config.redact_logs_to_client)),
Arc::new(ApplicationAuth::new(
key_broker.clone(),
Arc::new(NullAccessTokenAuth),
Expand Down

0 comments on commit aeb63e2

Please sign in to comment.