I'm trying to figure out the minimum set of permissions that a service account needs in order to write a file to a GCS bucket. I was thinking I could use storage.objectAdmin, but using the sample code provided for the Python SDK it fails with an error: my-service-account@my-project.googleapis.com does not have storage.buckets.get access to my-bucket
client = _get_storage_client()
bucket = client.bucket(current_app.config['CLOUD_STORAGE_BUCKET'])
blob = bucket.blob(filename)
blob.upload_from_string(
file_stream,
content_type=content_type)
This is because the client.bucket call actually reads metadata from the bucket, which storage.objectAdmin does NOT grant. It fixes itself when I use storage.admin permissions, but that also allows the account to delete the entire bucket, which I don't want. Adding storage.legacyBucketReader also works, but then I'm using a legacy role which I'm not sure I should be doing anymore.
What's the best practice here?