Lesson 3 of 6 Data Security

Storing and Rotating Pipeline Credentials

This lesson explains how the credentials that some pipeline steps still need, database passwords, SaaS API keys and partner tokens, are stored securely, rotated and kept out of code.

Learning outcomes

After completing this lesson, you will be able to:

  • Choose between Secrets Manager and Parameter Store.
  • Use secrets from Glue, Lambda, MWAA and Redshift.
  • Protect secrets with access policies and KMS.

Credential stores

Pipelines need credentials, such as database passwords and API keys, and these belong in a managed store, not in code or job parameters. AWS Secrets Manager is built for secrets: it encrypts them with KMS, logs access through CloudTrail, and rotates them automatically, with built-in rotation for RDS, Aurora and Redshift. Glue connections, MWAA, DMS and Lambda can all reference a secret directly. Parameter Store SecureString parameters are also encrypted and cost less, but have no built-in rotation, so they suit simpler configuration secrets. The following table summarises the stores.

StoreUse for
AWS Secrets ManagerDatabase passwords with automatic rotation (built in for RDS, Aurora and Redshift), referenced from Glue connections, MWAA, DMS and Lambda
Parameter Store SecureStringSimpler configuration secrets without rotation
Sort into groups

Secrets Manager or Parameter Store?

Exam skills 4.2.2 · 4.1.3

Choose the store for each value.

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

Using secrets in pipelines

Data pipelines connect to many systems that require credentials, and AWS data services integrate with AWS Secrets Manager so those credentials never appear in code or configuration. AWS Glue connections and AWS DMS endpoints reference a secret instead of holding a password. Amazon MWAA can use Secrets Manager as the backend for Airflow connections and variables, so DAGs retrieve credentials at run time.

Redshift federated queries and Athena data source connectors read source database credentials from secrets. Lambda functions retrieve secrets at run time, and the AWS Parameters and Secrets Lambda Extension caches them, which reduces latency and cost while still picking up rotated values.

The following diagram compares a pipeline's credentials before and after they are moved out of job scripts.

Moving credentials out of job scripts. Before, passwords were written into three Glue scripts and an Airflow variable. After, Glue connections reference a Secrets Manager secret, MWAA uses Secrets Manager as its secrets backend, the managed rotation function changes the password every 30 days, and each job role can read only its own secret. The exposed passwords were rotated at once, because Git history still holds them.
The scenario is illustrative.
Spot the bug

Credentials in a script

Exam skills 4.2.2 · 4.1.3

Find the lines that expose credentials in this Lambda function.

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

Protecting secrets

Storing credentials in AWS Secrets Manager protects them only if access to the secrets themselves is controlled. Each secret is made readable only by the roles that need it, through IAM policies and the secret's resource policy, so a pipeline's role can read its own database credentials but not those of other systems. Secrets can be encrypted with a customer managed KMS key, which adds a second permission check and allows access to be revoked by changing the key policy.

AWS CloudTrail records every retrieval of a secret, so unexpected access can be detected and investigated. Rotation changes passwords regularly without code changes. More broadly, managed and serverless services reduce what must be patched and secured compared with self-managed software on EC2, which shrinks the number of places credentials and vulnerabilities can hide.

True or false

Protecting secrets

Exam skills 4.2.2

Decide whether each statement about protecting secrets is true.

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

Removing passwords from job scripts

A review finds database passwords written into three Glue scripts and an Airflow variable. The team moves every credential to Secrets Manager, as described in the following table.

ConsumerChange
Glue jobsGlue connections reference the secret; scripts no longer contain credentials
Amazon MWAASecrets Manager configured as the Airflow secrets backend
DatabaseAutomatic rotation every 30 days with the managed rotation function
AccessEach job role may read only its own secret

The passwords that appeared in the scripts are rotated immediately, because Git history still holds them. From then on, rotation needs no change to any job.

Check yourself

Where can MWAA keep its Airflow connections?

Show answer

In AWS Secrets Manager, instead of in the Airflow metadata database.

Exam Tips

Remember for the exam

  • To rotate database passwords automatically, use Secrets Manager.
  • Reference secrets from Glue connections and DMS endpoints instead of storing passwords.
  • MWAA can store Airflow connections in Secrets Manager.
  • Parameter Store SecureString suits simple secrets that do not need rotation.
  • Grant each secret only to the roles that need it.