Application secret storage: choosing a store and delivering secrets at runtime
Values that can grant access to other systems—such as API keys, database passwords, and signing keys—belong in a dedicated, access-controlled secret-management path that can be audited, not in source code, ordinary configuration files, or client bundles. Grant access only to the deployment or workload that needs it, and provide only the required values at runtime. A dedicated store alone does not make a system secure: identity, permissions, delivery, logging, and recovery all need to be designed.
Values that can grant access to other systems—such as API keys, database passwords, and signing keys—belong in a dedicated, access-controlled secret-management path that can be audited, not in source code, ordinary configuration files, or client bundles. Grant access only to the deployment or workload that needs it, and provide only the required values at runtime. A dedicated store alone does not make a system secure: identity, permissions, delivery, logging, and recovery all need to be designed.
Choosing a store
First distinguish the kind of value. A secret-management service is often suitable for changeable API keys and database credentials, as well as passwords, certificates, or tokens whose lifecycle and access need auditing. A key-management service or HSM may better fit generation, protection, and cryptographic operations for encryption keys. It does not automatically replace a secret store for issuing and rotating application credentials.
Compare a general configuration store and a dedicated secret feature using these criteria:
| Criterion | What to check |
|---|---|
| Access scope | Can least-privilege access be limited by user, workload, project, individual secret, or version? Can development, staging, and production be separated? |
| Lifecycle | Are versions, revocation, recovery, automated or staged rotation, and owner/purpose metadata supported? |
| Visibility | Can read and update permissions and access records be reviewed and alerted on? Are secret values kept out of logs? |
| Delivery and availability | Can workloads retrieve values safely at runtime? Are quota and latency sufficient during deployment spikes, and is there a recovery path during an outage? |
| Requirements | Does the service meet storage-location, encryption, retention, audit, and organizational residency or regulatory requirements? |
AWS ECS documentation describes storing API keys and database credentials in AWS Secrets Manager or encrypted Systems Manager Parameter Store. It points to Secrets Manager when automatic rotation, random generation, or cross-account sharing is needed, and encrypted parameters otherwise. This is an AWS-specific product choice. Google Cloud Secret Manager recommends fine-grained IAM and deploying pinned version numbers so validation and rollback can follow existing release processes. Compare the actual access model and lifecycle features of your provider rather than choosing by product name alone.
Delivering secrets to an application
**Establish workload identity.** Do not embed a long-lived access key in code or deployment variables to let an application reach the secret store. Prefer an identity bound to the runtime, such as a cloud workload identity, managed role, or short-lived federated token. Identity verification and permission to read a secret are separate controls.
**Grant access only to required secrets.** Limit each application or deployment job to the permitted secrets and actions. Separate development, test, and production values, and minimize who can read or change production secrets. If a rotation function or pipeline needs elevated rights, restrict both the identity that can assume them and the permitted job.
**Read the secret safely.** When possible, use the provider API or official client library to retrieve the needed version at runtime. Process environment variables, mounted files, and sidecars may be supported delivery methods, but they have different risks. Environment variables can leak through debug features, dumps, child processes, or logs. Files can be exposed through path traversal flaws or overly broad file permissions. Choose a path supported by the platform and restrict other processes and logs from reading the value.
**Inspect logs and errors.** Do not write secret values, authorization headers, or sensitive request payloads to application, deployment, or debug logs. Do not rely only on log masking: remove sensitive values before logging and check for exposure in tests. Record the identity, time, target resource, and action for secret reads without recording the value itself.
**Connect version changes to deployment.** Validate a new version, then pin its identifier in application configuration or a release and roll it out through the existing deployment process. Google Cloud recommends referencing a version number rather than the `latest` alias so validation and rollback can use that process. Provider update behavior differs, so check whether a restart or redeployment is needed for the workload to retrieve a changed secret. In ECS, a new task or forced service deployment may be required.
Preparing for outages and recovery
If the secret-management service is unavailable, application startup or requests may fail. Review retrieval latency, retries, caching, availability objectives, and quotas. Caching an old value indefinitely can delay rotation or revocation, so set cache lifetime according to risk tolerance and incident procedures.
If backups are needed, protect both the secrets and the keys or accounts that can access the backups. Store them encrypted with restricted access and regularly test restoration. Keep emergency recovery credentials in a separate protected management path and monitor their use. Before deleting a secret, consider disabling it first and observing whether dependencies remain. Google Cloud describes disabling a version as a reversible checkpoint before permanent deletion. Expiration on production secrets may cause irreversible deletion, so verify its behavior before enabling it.
If a leak is suspected, review access records, rotate or revoke the secret, and separately assess affected services and tokens already issued. Centralization does not eliminate blast radius: compromise of a highly privileged administrator or secret store can expose many values, so segment boundaries and enforce least privilege.
Operational checklist
Is each secret documented with an owner, purpose, allowed consumers, storage location, rotation, and revocation method?
Is access to the store tied to workload identity instead of a long-lived static key, with least privilege for only the required secrets?
Are values and permission boundaries separated across development, test, production, and distinct applications?
Have runtime delivery, caching, restart/deployment behavior, logs, and error messages been checked for leakage?
Are there named owners and procedures for access auditing, anomaly alerts, recovery backups, and rollback?
Good secret storage is more than choosing a place to keep values. It limits which identities can access which values and why, controls delivery and change history at runtime, and supports revocation and recovery after exposure or outage.
References
[OWASP Secrets Management Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html)
[Google Cloud: Secret Manager best practices](https://docs.cloud.google.com/secret-manager/docs/best-practices?hl=en)
[AWS ECS: Pass sensitive data to a container](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data.html)