- Secure Storage of Sensitive Data: Sensitive information, such as database credentials or API keys, is not embedded directly into the code, reducing the risk of exposure.
- Ease of Configuration Management: Configuration can be easily managed and adapted based on the environment (development, staging, production, etc.), without modifying the code.
Example: Hardcoding Information vs. Using Environment Variables
For instance, consider accessing database from a Service in a traditional approach. You might hardcode the connection details directly into the code:YOUR-DATABASE-URL
, YOUR-USERNAME
, and YOUR-PASSWORD
during deployment configuration, and retrieve them within your code using os.environ(ENV_VAR_NAME)
Secrets: Enhanced Protection for Highly Sensitive Data
For sensitive keys like database passwords, api-keys, its not advisable to provide them directly as environment variables in the deployment configuration since everyone can see the deployment spec and get access to these sensitive passwords. Hence, we usually store such sensitive values in secret managers (AWS SSM, AWS Secret Manager, GCP Secret Manager, Azure Vault or Hashicorp Vault) and then only provide the key to the secret in the environment configuration. Translating the key to the actual value is done at a different step. TrueFoundry provides an easy way to put the sensitive values in Secret Managers and then just provide the FQN of the secret (of the formtfy-secret://user:my-secret-group:my-secret
) in the deployment spec. You can read about how to create the secrets here . TrueFoundry will automatically fetch the value and inject it into the environment at runtime.
Setting environment variables and secrets
You can directly provide the value of the environment variable in theValue
field if its not sensitive. If the value is sensitive, you can first create the secret and then provide the FQN of the secret in the Value
field.
To search for secrets, start typing
tfy
in the Value field and a dropdown will appear with all the secrets that you have access to.If you want to paste a lot of environment variables in one shot, you can do so by switching to Raw Mode and pasting the content of .env file.
