Access control for media files on Google Cloud Storage

281 Views Asked by At

I have a social media app deployed on App Engine where users can upload and share photos/videos with a private group of people. For writes, I have a POST endpoint that accepts uploaded files and writes them to one GCS bucket that's not public. For reading, a GET endpoint checks with Cloud SQL if this user is authorized to access the media file - if yes, it returns the file stream. The file is stored only for 48 hours and average retrieval is 20 times per day. Users are authenticated using Firebase email link login.

  1. The issue with the current approach is that my GET endpoint is an expensive middleman for reading the GCS file stream and passing it on to the clients, adding to the cost as may times the API is invoked.
  2. There's no point caching the file on App Engine because cache hit ratio will be extremely low for my use case.
  3. The GET API could return a GCS file URL instead of File Stream, if I make the GCS bucket public. But that would mean anyone can access the file with this public URL, not just my app or limited user. Plus, the entire bucket is vulnerable now.
  4. I could create an ACL for each GCS file object, but ACLs work only for users with Google accounts and my app uses email link authentication. There's also a limit on ACL entries per object in case the file needs to be shared with more than 100 people.
  5. The last option I have is to create a signed link that works for a short duration, enabling limited unauthorized sharing.
  6. Also tagging Google Photos. In case the partner sharing program can help with this problem, then I can migrate from GCS to Google Photos for storage.

This looks like a common use-case for media based apps. Are there any recommended design patterns to achieve the goal in a cost effective way?

This is my first week learning GCP, so I maybe wrong in some of the points shared above.

0

There are 0 best solutions below