Skip to content

Commit b7f7201

Browse files
committed
Add chunk_cache_bypass_auth flag
1 parent 195e663 commit b7f7201

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

deployment/group_vars/all

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ reductionist_env:
3131
REDUCTIONIST_CHUNK_CACHE_PRUNE_INTERVAL: "3600"
3232
REDUCTIONIST_CHUNK_CACHE_SIZE_LIMIT: "10GB"
3333
REDUCTIONIST_CHUNK_CACHE_QUEUE_SIZE: "32"
34+
REDUCTIONIST_CHUNK_CACHE_BYPASS_AUTH: "false"
3435
# Path to certificates directory on remote host.
3536
reductionist_remote_certs_path: "{{ ansible_facts.env.HOME }}/certs"
3637
# Path to certificates directory in container.

src/app.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ async fn download_and_cache_s3_object<'a>(
232232
resource_manager: &'a ResourceManager,
233233
mut mem_permits: Option<SemaphorePermit<'a>>,
234234
chunk_cache: &ChunkCache,
235+
allow_cache_auth_bypass: bool,
235236
) -> Result<Bytes, ActiveStorageError> {
236237
// We chose a cache key such that any changes to request data
237238
// which may feasibly indicate a change to the upstream object
@@ -247,16 +248,18 @@ async fn download_and_cache_s3_object<'a>(
247248
);
248249

249250
if let Some(metadata) = chunk_cache.get_metadata(&key).await {
250-
// To avoid having to include the S3 client ID as part of the cache key
251-
// (which means we'd have a separate cache for each authorised user and
252-
// waste storage space) we instead make a lightweight check against the
253-
// object store to ensure the user is authorised, even if the object data
254-
// is already in the local cache.
255-
let authorised = client
256-
.is_authorised(&request_data.bucket, &request_data.object)
257-
.await?;
258-
if !authorised {
259-
return Err(ActiveStorageError::Forbidden);
251+
if !allow_cache_auth_bypass {
252+
// To avoid having to include the S3 client ID as part of the cache key
253+
// (which means we'd have a separate cache for each authorised user and
254+
// waste storage space) we instead make a lightweight check against the
255+
// object store to ensure the user is authorised, even if the object data
256+
// is already in the local cache.
257+
let authorised = client
258+
.is_authorised(&request_data.bucket, &request_data.object)
259+
.await?;
260+
if !authorised {
261+
return Err(ActiveStorageError::Forbidden);
262+
}
260263
}
261264

262265
// Update memory requested from resource manager to account for actual
@@ -343,8 +346,14 @@ async fn operation_handler<T: operation::Operation>(
343346
.await?
344347
}
345348
(true, Some(cache)) => {
346-
download_and_cache_s3_object(&s3_client, &request_data, &state.resource_manager, _mem_permits, cache)
347-
.await?
349+
download_and_cache_s3_object(
350+
&s3_client,
351+
&request_data,
352+
&state.resource_manager,
353+
_mem_permits,
354+
cache,
355+
state.args.chunk_cache_bypass_auth
356+
).await?
348357
}
349358
(true, None) => panic!(
350359
"Chunk cache enabled but no chunk cache provided.\nThis is a bug. Please report it to the application developers."

src/cli.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ pub struct CommandLineArgs {
7777
/// Defaults to the number of CPUs detected.
7878
#[arg(long, env = "REDUCTIONIST_CHUNK_CACHE_QUEUE_SIZE")]
7979
pub chunk_cache_buffer_size: Option<usize>,
80+
/// Whether to bypass the upstream S3 auth checks to improve performance
81+
/// when operating on cached chunks. Auth bypass should only be enabled
82+
/// if the server is running on a private network with sufficient access
83+
/// controls since it allows anyone with access to the server to operate
84+
/// on any cached chunk, even if they do not have permission to fetch the
85+
/// original object from the upstream S3 storage server.
86+
#[arg(
87+
long,
88+
default_value_t = false,
89+
env = "REDUCTIONIST_CHUNK_CACHE_BYPASS_AUTH"
90+
)]
91+
pub chunk_cache_bypass_auth: bool,
8092
}
8193

8294
/// Returns parsed command line arguments.

0 commit comments

Comments
 (0)