@@ -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.\n This is a bug. Please report it to the application developers."
0 commit comments