Lesson 7 of 7 Amazon RDS and Aurora

Securing Relational Databases

This lesson explains how securing a relational database combines network isolation, encryption, authentication without stored passwords, and monitoring of database activity.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe the network, encryption and monitoring controls for databases.
  • Explain how an existing unencrypted database is encrypted.
  • Explain how IAM database authentication replaces stored passwords.

Controls

A database is secured in several layers. On the network, it runs in private subnets with no internet route, and its security group allows the database port only from the application tier's security group. Encryption at rest with KMS must be chosen when the database is created; an existing unencrypted database is encrypted by taking a snapshot, copying it with encryption enabled and restoring from the copy.

Encryption in transit is enforced by a parameter that rejects unencrypted connections, rds.force_ssl for PostgreSQL and SQL Server or require_secure_transport for MySQL. For authentication, IAM database authentication lets applications connect with short-lived tokens instead of passwords, and Secrets Manager stores and rotates the master password. For monitoring, database logs go to CloudWatch Logs, and Database Activity Streams send a near real-time record of database activity for auditing. The following table summarises the controls.

AreaControl
NetworkPrivate subnets; security groups allowing only the application tier
Encryption at restKMS, chosen at creation; to encrypt an existing DB, restore an encrypted snapshot copy
Encryption in transitrds.force_ssl (PostgreSQL, SQL Server) or require_secure_transport (MySQL)
AuthenticationIAM database authentication (MySQL, PostgreSQL); Secrets Manager for the master password, with rotation
MonitoringLogs to CloudWatch Logs; Database Activity Streams for near real-time activity monitoring
Match the pairs

Database security controls

Exam skills 1.3.2 · 1.3.3 · 1.2.1

Match each requirement with the RDS security control that meets it.

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

Encrypting an existing database

Encryption must be chosen when an RDS instance is created; it cannot be enabled on an existing unencrypted instance directly. An encrypted copy is created instead.

  1. Snapshot

    Take a snapshot of the unencrypted instance.

  2. Copy with encryption

    Copy the snapshot with encryption enabled, choosing the KMS key.

  3. Restore and switch

    Restore a new instance from the encrypted snapshot copy and switch the application to it.

Read replicas of an encrypted instance are encrypted with the same key, and an unencrypted instance cannot have an encrypted read replica, so this procedure is the only route to encryption.

Put in order

Encrypting a database

Exam skills 1.3.2

Put the steps of encrypting an existing RDS database in order.

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

IAM database authentication

The application generates a short-lived authentication token with its IAM role and uses it as the password over TLS, so no password is stored. The role needs rds-db:connect for the database user.

Worked example

Securing database access

Database access must be secured at several levels. The following table identifies the control that meets each requirement.

RequirementControl
No passwords in application codeSecrets Manager with rotation, or IAM database authentication
Only the application tier can connectDatabase security group allowing the application's security group
Not reachable from the internetPrivate subnets; Publicly accessible set to No
Encrypted at restEnabled at creation with KMS (an existing database needs snapshot, encrypted copy, restore)
Encrypted in transitRequire TLS with rds.force_ssl or require_secure_transport
Thousands of Lambda connectionsRDS Proxy

Encryption at rest is a common trap: it cannot be switched on for a running unencrypted instance, so the architect enables it from the start.

Check yourself

How can an application connect to RDS without a stored database password?

Show answer

With IAM database authentication: the application gets a short-lived token with its IAM role and uses it as the password.

Exam Tips

Remember for the exam

  • To connect to MySQL or PostgreSQL with IAM instead of passwords, use IAM database authentication.
  • To encrypt an unencrypted RDS instance, take a snapshot, make an encrypted copy and restore it.
  • For near real-time monitoring of database activity for compliance, use Database Activity Streams.
  • To rotate the master password automatically, store it in Secrets Manager.