Skip to content

Commit

Permalink
cloud: Make URL cache bucket private
Browse files Browse the repository at this point in the history
  • Loading branch information
spbnick committed Feb 12, 2024
1 parent edce5b6 commit cdeffba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion kcidb/cloud/storage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ function storage_deploy() {
TMPDIR="$TMPDIR_ORIG" gsutil -q mb -p "$project" -c STANDARD \
-l "us-central1" -b on "gs://$bucket"
fi
TMPDIR="$TMPDIR_ORIG" gsutil -q iam ch allUsers:objectViewer "gs://$bucket/"
# Revoke public read access from the bucket
TMPDIR="$TMPDIR_ORIG" gsutil -q iam ch -d allUsers:objectViewer "gs://$bucket/"
}

# Remove a Google Cloud Storage Bucket and its contents
Expand Down
7 changes: 6 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,11 @@ def kcidb_cache_urls(event, context):
cache.store(url)


# The expiration time (a timedelta) of the URLs returned by the cache
# redirect, or None to return permanent URLs pointing to the public bucket.
CACHE_REDIRECT_TTL = datetime.timedelta(seconds=10)


@functions_framework.http
def kcidb_cache_redirect(request):
"""
Expand Down Expand Up @@ -567,7 +572,7 @@ def kcidb_cache_redirect(request):

# Check if the URL is in the cache
cache_client = get_cache_client()
cache = cache_client.map(url_to_fetch)
cache = cache_client.map(url_to_fetch, ttl=CACHE_REDIRECT_TTL)
if cache:
LOGGER.debug("Redirecting to the cache at %s", cache)
# Redirect to the cached URL if it exists
Expand Down

0 comments on commit cdeffba

Please sign in to comment.