Managing Secrets in Colab
#colab
To properly manage (hide) a secret, e.g. an API key, in colab, one can use GCP’s Secret Manager. Here are some instructions, borrowed from this stackoverflow answer:
- Enable “Secret Manager API” for the project on market place: https://console.cloud.google.com/marketplace/product/google/secretmanager.googleapis.com
- Create a secret in “Secret Manager”: https://console.cloud.google.com/security/secret-manager
- Copy the resource name from the console
- Access the resource key using the python script below
!pip install google-cloud-secret-manager from google.cloud import secretmanager client = secretmanager.SecretManagerServiceClient() resource_name = "xxxxxxx" # String copied from above response = client.access_secret_version(request={"name": resource_name}) OPENAI_API_KEY = response.payload.data.decode('UTF-8')