Hello,
I’d like to address your questions but before I do, I would like you to know that there would be no by and large answer on security. It depends on your requirements. Depending on the answers to some questions, I would be guiding you to a point where you may benefit.
To begin, you mentioned that you wish to use a service key to your Cloud Function.
Is there a reason why you chose this approach in that a Cloud Function has a service account?
Why are you using a Cloud Function to store your key?
What specific security concerns do you have?
I was able to look further and was suggested this thread
here that has several views that may assist you. Perhaps it may provide you with further insight.
Encrypt your service account credential json file using Cloud KMS/vault and upload it to Cloud Storage.
Fetch service account credential json file from Cloud Storage and decrypt it using a Cloud KMS service account which has encrypt/decrypt permission.
Parse service account credential json file at runtime and get private_key, client_email and ProjectId.
Pass these three secret variables to the client library
We must not store secret things like plain text, e.g cloud function environment variables.
I hope this helps.