Skip to main content

A program to rotate the password of an RDS database accessed via a RDS proxy

Project description

rds-proxy-password-rotation

:warning: Work in progress :warning:

  • add Terraform module

Python script for multi-user password rotation using RDS and RDS proxy. It supports credentials for the application and the RDS proxy.

We implemented this logic again, because current implementations

  • have no tests
  • have no release process
  • are not published to PyPI
  • have no Docker image available
  • have no Terraform module available

Pre-requisites

  1. Python 3.10 or later

  2. For each db user:

    1. Clone the user in the database and grant the necessary permissions. We suggest to add a -clone suffix to the username.

    2. Create a secret in AWS Secrets Manager with the following key-value pairs (for every user and its clone):

      • rotation_type: "AWS RDS"
      • rotation_usernames: Optional. The list of usernames that a part of the rotation, e.g. ["app_user", "app_user-clone"]. If not provided, username is used only.
      • proxy_secret_ids: Optional. The list of ARNs of the secrets that are attached to the RDS Proxy, e.g. ["arn:aws:secretsmanager:region:account-id:secret:secret-name"]. If not provided, the proxy credentials are not adjusted.
      • database_host: The hostname of the database
      • database_port: The port of the database
      • database_name: The name of the database
      • username: The username for the user
      • password: The password for the user

      This credential will be used by the application to connect to the proxy. You may add additional key-value pairs as needed.

  3. If you are using RDS Proxy:

    1. Create a secret in AWS Secrets Manager with the following key-value pairs:
      • username: The username for the user that the proxy will use to connect to the database
      • password: The password for the user that the proxy will use to connect to the database
    2. Attach the secret to the RDS Proxy.
  4. The docker image can be pulled from GHCR:

    docker pull ghcr.io/Hapag-Lloyd/rds-proxy-password-rotation:edge
    

    :warning: The edge tag is used for the latest build. You SHOULD use a specific version tag in production.

Architecture

Architecture

Challenges with RDS and RDS Proxy

RDS Proxy is a fully managed, highly available database proxy for Amazon Relational Database Service (RDS) that makes applications more scalable, more resilient to database failures, and more secure. It allows applications to pool and share database connections to improve efficiency and reduce the load on your database instances.

However, RDS Proxy does not support multi-user password rotation out of the box. This script provides a solution to this problem.

Using an RDS Proxy requires a secret in AWS Secrets Manager with the credentials to connect to the database. This secret is used by the proxy to connect to the database. The proxy allows the application to connect to the database using the same credentials and then forwards the requests to the database with the same credentials. This means that the credentials in the secret must be valid in the database at all times. But what if you want to rotate the password for the user that the proxy uses to connect to the database? You can’t just update the secret in SecretsManager because the proxy will stop working as soon as the secret is updated. And you can’t just update the password in the database because the proxy will stop working as soon as the password is updated.

Why password rotation is a good practice

Password rotation is a good idea for several reasons:

  1. Enhanced Security: Regularly changing passwords reduces the risk of unauthorized access due to compromised credentials.
  2. Mitigates Risk: Limits the time window an attacker has to exploit a stolen password.
  3. Compliance: Many regulatory standards and security policies require periodic password changes.
  4. Reduces Impact of Breaches: If a password is compromised, rotating it ensures that the compromised password is no longer valid.
  5. Encourages Good Practices: Promotes the use of strong, unique passwords and discourages password reuse.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rds_proxy_password_rotation-0.6.253.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rds_proxy_password_rotation-0.6.253-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file rds_proxy_password_rotation-0.6.253.tar.gz.

File metadata

File hashes

Hashes for rds_proxy_password_rotation-0.6.253.tar.gz
Algorithm Hash digest
SHA256 9f25723ed52be75b3e5a9a95495c2dbf9552875357f8efc28387ecff346a7ded
MD5 b9ad16fe4b36bfce3b828311da86e46f
BLAKE2b-256 f21928c7a24f0ab0e150ce5d030429fcae7c0abc2e527574269c65f5958fe0c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds_proxy_password_rotation-0.6.253.tar.gz:

Publisher: pypi_publish.yml on Hapag-Lloyd/rds-proxy-password-rotation

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rds_proxy_password_rotation-0.6.253-py3-none-any.whl.

File metadata

File hashes

Hashes for rds_proxy_password_rotation-0.6.253-py3-none-any.whl
Algorithm Hash digest
SHA256 3e2daea522023aa965b9282d9419378d3ed4418568c5c2a36bfa67094d05b789
MD5 29383bd49484417501c9ab5efd7ae393
BLAKE2b-256 7bb5637047545760d4b85f642d0a37cf0a16e4c6927e397efe6256a2c5614cb2

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds_proxy_password_rotation-0.6.253-py3-none-any.whl:

Publisher: pypi_publish.yml on Hapag-Lloyd/rds-proxy-password-rotation

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page