To prevent unauthorized access or accidental exposure of sensitive information, ensure that Secrets Manager service is used to store and manage secrets instead of storing them in cleartext within Cloud Functions environment variables.
Storing secrets in Google Cloud Functions environment variables is insecure due to lack of encryption, limited access control, and inadequate audit trails. For better security use dedicated secret management services such as Google Cloud Secret Manager. Secret Manager provides additional security measures like encryption at rest and in transit, access controls, auditing, and versioning.
Note: This check can only determine whether a plaintext environment variable is defined and whether Secret Manager (secret environment variables or secret volumes) is used by the function. It cannot determine whether the value of a given environment variable is actually secret or sensitive, since environment variable values are not inspected or retained for evaluation.
Audit
To determine if Cloud Functions environment variables are configured to store secret information, perform the following operations:
Remediation / Resolution
To manage secrets using Secrets Manager service instead of Cloud Functions environment variables, perform the following operations:
Note: Secret Manager secret references are only supported for runtime environment variables (serviceConfig.environmentVariables). Google Cloud Functions does not support binding Secret Manager secrets to build-time environment variables (buildConfig.environmentVariables), in either the GCP Console or the GCP CLI. If a build-time environment variable contains secret or sensitive information, remove it entirely rather than attempting to reference it from Secret Manager, and supply the value to the function at runtime instead. References
- Google Cloud Platform (GCP) Documentation
- Cloud APIs | Google Cloud
- Configure environment variables for services | Cloud Run | Google Cloud Documentation
- Secret Manager overview | Google Cloud Documentation
- Create a secret | Secret Manager | Google Cloud Documentation
- Add a secret version | Secret Manager | Google Cloud Documentation
- GCP Command Line Interface (CLI) Documentation
- gcloud projects list | Google Cloud SDK | Google Cloud Documentation
- gcloud services enable | Google Cloud SDK | Google Cloud Documentation
- gcloud functions list | Google Cloud SDK | Google Cloud Documentation
- gcloud functions describe | Google Cloud SDK | Google Cloud Documentation
- gcloud functions deploy | Google Cloud SDK | Google Cloud Documentation
- gcloud secrets create | Google Cloud SDK | Google Cloud Documentation
- gcloud secrets add-iam-policy-binding | Google Cloud SDK | Google Cloud Documentation