Skip to content

Commit

Permalink
cli: avoid storing sensitive configuration in snapshots
Browse files Browse the repository at this point in the history
**Summary**

Some configuration options (like the auth token) should not be included in the
snapshot to avoid leaking them.
  • Loading branch information
fracek committed Oct 17, 2023
1 parent 088d593 commit 92e0b70
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cli/src/test/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,26 @@ impl SnapshotGenerator {
return Err(eyre!("Empty snapshot, no data found for the selected options (filter, starting_block, num_batches ...)"));
}

let stream_options = sanitize_stream_options(&self.stream_options);

Ok(Snapshot {
script_path: self.script_path,
num_batches: self.num_batches,
stream_options: self.stream_options,
stream_options,
stream_configuration_options: self.stream_configuration_options,
stream,
})
}
}

/// Remove all the fields from the stream options that are not needed for the snapshot.
///
/// This is done to avoid leaking sensitive information (e.g. the bearer token) in the snapshots.
fn sanitize_stream_options(options: &StreamOptions) -> StreamOptions {
StreamOptions {
stream_url: options.stream_url.clone(),
max_message_size: options.max_message_size.clone(),
timeout_duration_seconds: options.timeout_duration_seconds,
..Default::default()
}
}
8 changes: 8 additions & 0 deletions sink-common/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,24 @@ pub struct DotenvOptions {
pub struct StreamOptions {
/// DNA stream url. If starting with `https://`, use a secure connection.
#[arg(long, env)]
#[serde(skip_serializing_if = "Option::is_none")]
pub stream_url: Option<String>,
/// Limits the maximum size of a decoded message. Accept message size in human readable form,
/// e.g. 1kb, 1MB, 1GB. If not set the default is 1MB.
#[arg(long, env)]
#[serde(skip_serializing_if = "Option::is_none")]
pub max_message_size: Option<String>,
/// Add metadata to the stream, in the `key: value` format. Can be specified multiple times.
#[arg(long, short = 'M', env, value_delimiter = ',')]
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Vec<String>>,
/// Use the authorization together when connecting to the stream.
#[arg(long, short = 'A', env)]
#[serde(skip_serializing_if = "Option::is_none")]
pub auth_token: Option<String>,
/// Maximum timeout (in seconds) between stream messages. Defaults to 45s.
#[arg(long, env)]
#[serde(skip_serializing_if = "Option::is_none")]
pub timeout_duration_seconds: Option<u64>,
}

Expand All @@ -104,10 +109,13 @@ pub struct StreamConfigurationOptions {
#[serde(flatten)]
pub filter: NetworkFilterOptions,
/// Set the response preferred batch size.
#[serde(skip_serializing_if = "Option::is_none")]
pub batch_size: Option<u64>,
/// The finality of the data to be streamed.
#[serde(skip_serializing_if = "Option::is_none")]
pub finality: Option<DataFinality>,
/// Start streaming data from the specified block.
#[serde(skip_serializing_if = "Option::is_none")]
pub starting_block: Option<u64>,
}

Expand Down

0 comments on commit 92e0b70

Please sign in to comment.