Lesson 2 of 6 Edge Protection and Application Security

Removing Long-Term Credentials and Managing Secrets Centrally

This lesson explains how professional-level designs remove long-term credentials wherever possible and manage the remaining secrets centrally with encryption, rotation and audit.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain how IAM roles and federation replace credentials.
  • Choose between Secrets Manager and Parameter Store.
  • Explain how secrets are rotated without downtime.
  • Describe how secrets are protected and audited.

Removing credentials altogether

The safest credential is one that does not exist. Workloads on AWS obtain temporary credentials from IAM roles, through instance profiles, ECS task roles, Lambda execution roles or EKS Pod Identity, so no access key ever needs to be stored in code, configuration or images. Workloads outside AWS use federation instead: on-premises servers use IAM Roles Anywhere, which exchanges an X.509 certificate for temporary credentials, and CI/CD systems use OIDC federation.

Database passwords can often be removed too. IAM database authentication for RDS, Aurora and Redshift lets applications connect with short-lived tokens generated from their IAM role. People sign in through IAM Identity Center rather than as IAM users with access keys. Each credential removed in this way is one that cannot leak.

Secrets Manager and Parameter Store

Where secrets remain, such as third-party API keys and database passwords, they belong in a managed store, and the two options differ in capability and cost. Secrets Manager rotates secrets automatically, with managed rotation for RDS, Aurora, Redshift and DocumentDB. It can replicate secrets to other Regions for disaster recovery, and its resource policies allow access from other accounts. It is charged per secret per month and per API call, and suits credentials that must rotate.

Parameter Store has no built-in rotation and does not replicate parameters. Advanced parameters can be shared with other accounts through RAM, and standard parameters are free, which makes it suitable for configuration and simple secrets stored as SecureString. The following table summarises the comparison.

Secrets Manager
RotationBuilt-in automatic rotation, with managed rotation for RDS, Aurora, Redshift and DocumentDB
Multi-RegionReplicates secrets to other Regions for DR
Cross-accountResource policies allow access from other accounts
CostPer secret per month and per API call
Suited toCredentials that must rotate
Parameter Store
RotationNone built in
Multi-RegionNot replicated
Cross-accountAdvanced parameters can be shared through RAM
CostStandard parameters free
Suited toConfiguration and simple secrets as SecureString

Rotation without downtime

Rotation replaces a secret's value on a schedule. Secrets Manager keeps staging labels (AWSCURRENT, AWSPENDING, AWSPREVIOUS) so that applications fetching the current value move to the new one, and the alternating users strategy keeps the previous credentials valid while clients refresh. Applications should retrieve secrets at run time and cache them briefly, using the AWS SDK caching libraries or the Lambda extension, rather than reading them once at start-up.

The following diagram shows how the staging labels move during one rotation.

Secret rotation with staging labels. Before rotation, version 1 is labelled AWSCURRENT. Rotation creates version 2 as AWSPENDING, sets and tests it, and then moves AWSCURRENT to version 2 and AWSPREVIOUS to version 1. Applications that ask for the current value move to the new version when their cache refreshes, and the alternating users strategy keeps version 1 valid meanwhile.
Applications never name a version; they ask for AWSCURRENT, so moving the label is what moves them to the new credentials.
Scenario questions

Rotating without downtime

Exam skills 5.1.3 · 2.2.1

Choose rotation strategies that avoid outages.

Log in to try this activity Interactive activities are free with an account.

Protecting and auditing secrets

Secrets are encrypted with a customer managed KMS key when access must be controlled through the key policy as well, which adds a second permission that a reader needs. Access is granted by secret ARN, or by tag with attribute-based access control, which scales to many teams without a policy per secret.

Every retrieval is a GetSecretValue call recorded in CloudTrail, so unexpected access, such as a secret read from an unfamiliar role or Region, can trigger an alert. Secrets that have escaped into the wrong places are found with Amazon Inspector code scanning, which detects credentials committed to code.

Worked example

Rotating database credentials without downtime

An order service reads its Aurora PostgreSQL password from a configuration file baked into its container image, and the password has not changed in three years. The architect moves the credential into Secrets Manager with managed rotation every 30 days, and replicates it to the DR Region so that failover does not depend on the primary Region:

aws secretsmanager create-secret --name prod/orders/db --kms-key-id alias/orders-secrets \
  --secret-string file://initial-credentials.json
aws secretsmanager rotate-secret --secret-id prod/orders/db \
  --rotation-rules '{"ScheduleExpression":"rate(30 days)"}' \
  --rotation-lambda-arn arn:aws:lambda:eu-west-1:111111111111:function:SecretsManagerPostgreSQLMultiUser
aws secretsmanager replicate-secret-to-regions --secret-id prod/orders/db \
  --add-replica-regions Region=eu-central-1,KmsKeyId=alias/orders-secrets

The multi-user (alternating users) rotation strategy creates a clone user with the new password and switches AWSCURRENT to it, so connections using the previous user keep working until they reconnect. The application fetches the secret at run time through the AWS SDK caching client, which refreshes it periodically. For a further step, IAM database authentication would remove the password entirely for this service, at the cost of a token request on each new connection.

Check yourself

What is better than storing a credential securely?

Show answer

Removing it: IAM roles, IAM database authentication and OIDC federation leave no long-term secret to steal or rotate.

Exam Tips

Remember for the exam

  • Workloads use IAM roles; on-premises workloads use IAM Roles Anywhere.
  • To rotate secrets and replicate them for disaster recovery, use Secrets Manager.
  • For database access without stored passwords, use IAM database authentication.
  • Use the alternating users rotation strategy to avoid downtime during rotation.
  • Fetch secrets at run time with caching rather than baking them into images or code.