Sub topic 1
Configuration versus secrets: what goes where
Every application needs values that change between environments: a database host, a feature flag, a password. This tutorial covers two AWS services that store them outside your code. Before you choose one, you need a rule for deciding which values are plain configuration and which are secrets. This chapter gives you that rule and the reasoning behind it. Later chapters cover each service in detail.
Prerequisites
This chapter assumes you already have the following:
- Basic AWS concepts: accounts, Regions, and IAM users and roles.
- Comfort with the AWS CLI and reading JSON.
- Basic Python or another language with an AWS SDK.
- Familiarity with environment variables and twelve-factor style configuration, where deployment-specific values live outside the code.
You don't need to run any AWS commands in this chapter.
Why values do not belong in code
Hard-coding a value makes it part of your build artifact. That causes three problems:
- Changes need a redeploy. Switching a timeout or a hostname means rebuilding and shipping the application.
- The same artifact can't move between environments. If the production database host is compiled into the image, you can't promote the exact image you tested in staging.
- Anyone who can read the code can read the value. Source repositories are copied, forked, cached by CI systems, and kept in history. A secret committed once stays in Git history after you delete the line.
The twelve-factor approach is to build one artifact and supply environment-specific values at deploy time or at startup. Parameter Store and Secrets Manager are the places those values come from. The first question is which service fits each value, and that depends on what kind of value it is.
Configuration versus secrets
Configuration is a value that changes how the application behaves. Exposing it would not let anyone act as your application or access your data. A secret is a value that proves identity or grants access. Exposing it lets someone else do what your application can do.
A practical test is to ask what happens if the value appears in a log file, a screenshot, or a public pull request. If the answer is "nothing much," it's configuration. If the answer is "we must change it immediately," it's a secret.
| Value | Classification | Reason |
|---|---|---|
| Database hostname | Configuration | Knowing the host grants no access |
| Database password | Secret | Grants access to the data |
| Log level (`INFO`, `DEBUG`) | Configuration | Only changes behavior |
| Feature flag | Configuration | Only changes behavior |
| Third-party API key | Secret | Lets the holder call the API as you |
| TLS private key | Secret | Lets the holder impersonate your service |
| Allowed CORS origins | Configuration | Public by nature |
| Signing key for session tokens | Secret | Lets the holder forge sessions |
| Queue URL | Configuration | Access is controlled by IAM, not by the URL |
| OAuth client secret | Secret | Proves the application's identity |
The classification describes the value's sensitivity, not its format. A connection string such as postgres://app:[email protected]/orders is one string, but it contains a password, so the whole string is a secret. When one string mixes both kinds, either store the sensitive part separately or treat the whole thing as a secret.
Gray areas
Some values don't fit cleanly. Handle them by asking what an attacker gains.
- Hostnames and account IDs. These are low sensitivity, but they help someone map your environment. Treat them as configuration, and restrict who can read them with IAM.
- Internal URLs with embedded tokens. The token makes the URL a secret.
- Customer-specific settings. A tenant's display name is configuration. A tenant's integration credentials are secrets.
- Values that are secret only in production. A development database password may be a throwaway. Still, classify by the production role of the value, so the code path is identical in every environment.
When in doubt, treat the value as a secret. The cost of protecting a harmless value is small. The cost of leaking a sensitive one is much larger.
Why the distinction drives the AWS design
The two AWS services have different strengths, and the classification maps onto them:
- AWS Systems Manager Parameter Store is a hierarchical key-value store. It handles plain configuration well, and it can also hold encrypted values (the
SecureStringtype) at low cost. - AWS Secrets Manager is built for secrets. It adds managed rotation, versioning with staging labels, and cross-Region replication.
Configuration is typically read often, changes rarely, and is safe to cache. Secrets need tighter access control, an audit trail, and ideally a rotation schedule. The following chapters show what each service offers. For now, use this rule: put configuration in Parameter Store, and put secrets in Parameter Store as SecureString or in Secrets Manager, depending on rotation and sharing needs. The later chapter on choosing between the services gives the full criteria.
Passing references instead of values
Even after classifying a value, you still need to get it to the application. A good pattern is to pass the application the location of a value instead of the value itself. The application then fetches the value at startup.
The following Python snippet shows the idea. It reads two environment variables: one holds a plain configuration value, and the other holds only the name of a secret.
import os
# Plain configuration: safe to appear in environment variables and logs.
DB_HOST = os.environ["DB_HOST"]
# A reference to a secret: the name is not sensitive, the value is.
DB_SECRET_NAME = os.environ["DB_SECRET_NAME"]
print(f"Connecting to {DB_HOST}; credentials come from secret '{DB_SECRET_NAME}'")Run it with DB_HOST=db.example.internal DB_SECRET_NAME=myapp/prod/db python app.py. The secret's name tells an attacker very little, because reading the secret still requires IAM permission. The password never enters the process environment, so it doesn't show up in crash dumps, docker inspect output, or the deployment template. A later chapter shows how to fetch the value by name.
Common errors
- Classifying by file instead of by value. A
.envfile often mixes a log level with a database password. Split it value by value. - Storing secrets in Parameter Store as plain
String. The value is then readable in clear text by anyone withssm:GetParameter. Choosing the right type is covered in the chapter on parameter types. - Over-protecting everything. Putting every flag and hostname in a secret store adds cost, API calls, and permissions without a security benefit. It can also lead engineers to bypass the store entirely because it feels heavy.
- Treating encryption as the whole control. An encrypted value that every role in the account can decrypt is barely protected. Access control, covered in the IAM chapter, matters as much as the storage choice.
- Forgetting that old values live on. Deleting a secret from code does not remove it from Git history, build caches, or earlier image layers. If a secret was ever committed, treat it as compromised and replace it.
Summary of the rule
- Classify each value by what an attacker gains from seeing it.
- Keep both kinds out of your code and build artifacts.
- Store configuration as plain parameters. Store secrets encrypted, with tighter permissions and an audit trail.
- Give the application names or paths, and let it fetch values at runtime.
Exercise
Your service has this configuration file: LOGLEVEL=INFO, QUEUEURL=https://sqs.us-east-1.amazonaws.com/111122223333/orders, STRIPEAPIKEY=skliveabc123, and DATABASEURL=postgres://app:[email protected]/orders. Which values are configuration, which are secrets, and how would you handle DATABASEURL?
Show answer
LOGLEVEL and QUEUEURL are configuration. Access to the queue is controlled by IAM, not by knowing its URL. STRIPEAPIKEY is a secret because it lets the holder call the API as you. DATABASE_URL is a secret because it embeds the password s3cret, so the whole string is sensitive. Either store the whole string as a secret, or split it into a host (configuration) and credentials (a secret) and build the URL in code at startup.