What are environment variables in cloud applications?
Environment variables are key-value pairs used to store configuration settings outside the code. They help apps know things like database addresses or API keys without hardcoding them.
Click to reveal answer
beginner
Why should secrets not be stored directly in environment variables?
Storing secrets directly in environment variables can expose sensitive data if logs or error messages leak them. Instead, secrets should be stored securely using dedicated secret management services.
Click to reveal answer
beginner
What GCP service is recommended for managing secrets securely?
Google Cloud Secret Manager is the recommended service to store, manage, and access secrets securely in GCP projects.
Click to reveal answer
intermediate
How does an application access secrets stored in Google Cloud Secret Manager?
The application uses the Secret Manager API or client libraries to fetch secrets at runtime, ensuring secrets are not stored in code or environment variables directly.
Click to reveal answer
intermediate
What is a best practice when using environment variables and secrets in cloud apps?
Use environment variables for non-sensitive config and Secret Manager for sensitive data. Limit access permissions and rotate secrets regularly to keep data safe.
Click to reveal answer
Which GCP service is designed specifically to store and manage secrets securely?
AGoogle Cloud Storage
BGoogle Cloud Pub/Sub
CGoogle Cloud Secret Manager
DGoogle Cloud Functions
✗ Incorrect
Google Cloud Secret Manager is the dedicated service for securely storing and managing secrets.
Why is it risky to store secrets directly in environment variables?
AThey can be exposed in logs or error messages
BThey are encrypted automatically
CThey are only accessible by admins
DThey cannot be changed once set
✗ Incorrect
Secrets in environment variables can accidentally appear in logs or error outputs, risking exposure.
What is a good use for environment variables in cloud apps?
AStoring database connection strings without passwords
BStoring user passwords
CStoring API keys in plain text
DStoring large files
✗ Incorrect
Environment variables are good for non-sensitive config like database hostnames, but not for secrets.
How should an app retrieve secrets from Google Cloud Secret Manager?
ADownloading secrets manually before deployment
BHardcoding secrets in the app code
CStoring secrets in environment variables permanently
DUsing Secret Manager API or client libraries at runtime
✗ Incorrect
Apps should fetch secrets securely at runtime using the Secret Manager API or libraries.
Which practice helps keep secrets safe in cloud environments?
AShare secrets openly among all team members
BRotate secrets regularly and limit access permissions
CStore secrets in public repositories
DUse the same secret for all services
✗ Incorrect
Regular rotation and strict access control reduce the risk of secret leaks.
Explain how environment variables and secrets should be managed in a GCP cloud application.
Think about separating config from secrets and how GCP helps secure secrets.
You got /5 concepts.
Describe the risks of storing secrets directly in environment variables and how to mitigate them.
Consider what can happen if secrets are exposed and how to keep them safe.
You got /5 concepts.
Practice
(1/5)
1. What is the main purpose of environment variables in a Google Cloud application?
easy
A. To permanently save user data in the cloud
B. To create virtual machines automatically
C. To encrypt all data sent over the network
D. To store configuration values that the app can use at runtime
Solution
Step 1: Understand environment variables
Environment variables hold configuration values like API URLs or feature flags that apps read when running.
Step 2: Eliminate distractor options
Permanent data storage, network encryption, and VM creation are unrelated to environment variables.
Final Answer:
To store configuration values that the app can use at runtime -> Option D
Quick Check:
Environment variables = config values [OK]
Hint: Environment variables hold settings your app reads [OK]
Common Mistakes:
Confusing environment variables with data storage
Thinking environment variables encrypt data
Mixing environment variables with cloud resource creation
2. Which of the following is the correct way to set an environment variable named API_KEY with value 12345 in a Google Cloud Run service YAML?
easy
A. env:
- name: API_KEY
value: '12345'
B. environment_variables:
API_KEY: 12345
C. variables:
API_KEY = '12345'
D. set_env:
API_KEY: '12345'
Solution
Step 1: Recall Cloud Run YAML env syntax
Cloud Run uses the env list with name and value keys to set environment variables.
Step 2: Check options for correct YAML format
env:
- name: API_KEY
value: '12345' matches the correct syntax. Other options use incorrect keys or formats not supported by Cloud Run.
Final Answer:
env:
- name: API_KEY
value: '12345' -> Option A
Quick Check:
Cloud Run env uses name and value keys [OK]
Hint: Look for 'env' with name and value keys in YAML [OK]
Common Mistakes:
Using incorrect keys like environment_variables or variables
Assigning values with '=' instead of colon
Not using a list for env variables
3. Given this Python code snippet running in a Google Cloud Function:
import os
api_key = os.getenv('API_KEY')
print(f"Key: {api_key}")
If the environment variable API_KEY is not set, what will be printed?
medium
A. Key: API_KEY
B. Key:
C. Key: None
D. Error: Environment variable not found
Solution
Step 1: Understand os.getenv behavior
When the environment variable is missing, os.getenv returns None by default.
Step 2: Analyze the print output
The f-string converts None to the string 'None', so the output is 'Key: None'.
Final Answer:
Key: None -> Option C
Quick Check:
Missing env var returns None [OK]
Hint: os.getenv returns None if variable missing [OK]
Common Mistakes:
Assuming empty string is returned
Expecting an error to be raised
Thinking variable name is printed
4. You deployed a Cloud Run service that uses a secret from Secret Manager, but the service fails to access the secret. Which is the most likely cause?
medium
A. The Cloud Run service account lacks permission to access the secret
B. The secret value is empty
C. The environment variable name is misspelled in the code
D. The secret was created in a different Google Cloud project
Solution
Step 1: Check permissions for Secret Manager access
Cloud Run uses a service account that must have Secret Manager access roles to read secrets.
Step 2: Evaluate other options
While empty secret values, misspelled variable names, or secrets in different projects can cause issues, the most common cause is missing permissions blocking secret access.
Final Answer:
The Cloud Run service account lacks permission to access the secret -> Option A
Quick Check:
Missing permissions block secret access [OK]
Hint: Check service account permissions first [OK]
Common Mistakes:
Ignoring IAM roles for service accounts
Assuming secret value is always the problem
Not verifying project alignment for secrets
5. You want to securely provide a database password to a Google Cloud Run service without hardcoding it. Which approach follows best practices?
hard
A. Hardcode the password in the Cloud Run service YAML file
B. Store the password in Secret Manager and mount it as an environment variable in Cloud Run
C. Save the password in a public Google Cloud Storage bucket and read it at runtime
D. Send the password as a query parameter in API requests
Solution
Step 1: Identify secure secret storage
Google Secret Manager is designed to store sensitive info like passwords securely.
Step 2: Use environment variables for app access
Mounting secrets as environment variables in Cloud Run keeps secrets out of code and config files.
Step 3: Evaluate other options
Hardcoding, public storage, or sending passwords in URLs expose secrets and are insecure.
Final Answer:
Store the password in Secret Manager and mount it as an environment variable in Cloud Run -> Option B
Quick Check:
Secret Manager + env vars = secure best practice [OK]
Hint: Use Secret Manager and env vars, never hardcode secrets [OK]
Common Mistakes:
Hardcoding secrets in config files
Using public storage for sensitive data
Exposing secrets in URLs or logs
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.