I am trying to generate signed urls in my python Cloud Functions. I initialize the google-cloud-storage
client sdk by :
firebase_admin.initialize_app()
storage_client = storage.Client() # Use default credentials
bucket_name = os.environ.get("BUCKET_NAME")
bucket = storage_client.get_bucket(bucket_name)
And when i deploy my Cloud Function, i specify the service account email using the --service-account
flag.
Once it is uploaded and the Function is running the Cloud, i am getting the following error :
you need a private key to sign credentials. the credentials you are currently using <class 'google.auth.compute_engine.credentials.Credentials'> just contains a token. see https://googleapis.dev/python/google-api-core/latest/auth.html#setting-up-a-service-account for more details.
It's working fine if i serve the Cloud Function locally on my Mac using : functions-framework --target myfunction --debug --port=8081
So i am pretty sure this is a service account issue but i am completely lost because there is no other service account i have on my Mac than this one (generated for firebase admin SDK). On my mac i have done :
export GOOGLE_APPLICATION_CREDENTIALS=/Users/foxtom/PycharmProjects/MyProject/firebase-adminsdk.json
And this is the same email inside firebase-adminsdk.json
than the one i am passing to gcloud deploy myfunction --service-account="firebase-adminsdk-email@gserviceaccount.com"
Note : which is weird is that the service account is actually used otherwise i could not call the verify_token
method from the auth
module, because i don't specify a specific account in firebase_admin.initialize_app()
.
Note 2 : I do see the correct service account in General information
under the Cloud Function Details but it's not working only for storage.Client()
.
What am i missing here ?
EDIT : Additional steps i have made is to add the Storage Object Viewer and Storage Object Creator permissions to this service account from my Cloud Storage bucket but it's still not working (I have also tried using the Storage Admin
permission but not working either).