Permanent GCS objects access from client browser?

Viewed 110

I am working on a basic Flask application. I have a page where I want to display only a downloader link to every files present in my GCS bucket called twilio-billing. I tried to use signed-urls but it's limited to 7 days and it should not be public as it's a private document.

What I have so far:

  • A service account called twilio-gcs@mousset005.iam.gserviceaccount.com with Storage Admin, Storage Object Admin and Storage Object Viewer rights
  • generated a json authentication key for twilio-gcs@mousset005.iam.gserviceaccount.com. The file is load on my flask app using os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "config/gcp.json". I has able to upload files from my flask app directly into that bucket already.

Now I want to let the user being able to download his bills. I has able to try two different urls to access an object stored in my bucket:

  1. https://storage.cloud.google.com/twilio-billing/2021-1-Twilio-receipt.pdf: works but I must be logged in with my own Google account. If not, I am redirected to the gmail login.
  2. https://storage.googleapis.com/twilio-billing/2021-1-Twilio-receipt.pdf: never worked. getting Error 403 even with HTTP and when I am logged in on my Google Account. Anonymous caller does not have storage.objects.get access to the Google Cloud Storage object.

Do you have any suggestions?

web_messaging/blueprints/texting/templates/temporary.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <a href="https://storage.googleapis.com/twilio-billing/2021-1-Twilio-receipt.pdf">link A (error 403)</a>
    <a href="https://storage.cloud.google.com/twilio-billing/2021-1-Twilio-receipt.pdf">link B (must be logged in to my Google Cloud Account) </a>
</body>
</html>

web_messaging/blueprints/texting/routes.py

# returning the list all of files 
@texting.route("/billing", methods=['GET'])
@login_required
def billing():
    bucket = gcp_storage.get_bucket('twilio-billing')
    for blob in bucket.list_blobs(prefix=''):
        print(blob)
        # will generate my list of link here to render it on my html
    return render_template("temporary.html")
1 Answers
Related