tacticmedia/rds-auth-middleware

Doctrine DBAL driver middleware for Amazon RDS: IAM token authentication and master-password refresh from Secrets Manager.

Maintainers

Package info

github.com/tacticmedia/rds-auth-middleware

pkg:composer/tacticmedia/rds-auth-middleware

Transparency log

Statistics

Installs: 0

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-08-15 00:52 UTC

This package is auto-updated.

Last update: 2026-08-15 00:53:03 UTC


README

codecov

Important: Symfony users should install tacticmedia/rds-auth-bundle instead, which configures this package through bundle configuration.

A Doctrine DBAL driver middleware that supplies the database credential for an Amazon RDS instance. At connection time it selects one of three modes:

  • When IAM username is configured: replace the user and password with a short-lived RDS IAM authentication token.
  • When the Secret ARN is configured: connect with the configured password; when the database rejects it, read the current password from Secrets Manager and retry once. This recovers from automated RDS ManageMasterUserPassword rotation without a deployment.
  • Neither configured: pass the connection parameters through unchanged.

Before you choose IAM authentication, read its limitations: AWS requires 300 to 1000 MiB extra database memory for it, which rules out small instances. The managed password mode exists for exactly those deployments.

Installation

composer require tacticmedia/rds-auth-middleware

Quick start

use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\DriverManager;
use TacticMedia\RdsAuth\RdsAuthMiddleware;
use TacticMedia\RdsAuth\RdsIamTokenProvider;
use TacticMedia\RdsAuth\RdsSecretPasswordProvider;

$region = getenv('AWS_REGION') ?: 'us-east-1';

$middleware = new RdsAuthMiddleware(
    new RdsIamTokenProvider($region),
    new RdsSecretPasswordProvider($region),
    getenv('RDS_IAM_USERNAME') ?: null,          // null disables the IAM path
    getenv('RDS_SECRET_ARN') ?: null,            // null disables the refresh path
    $cachePool,                                  // any PSR-6 pool; omit to disable caching
);

$configuration = new Configuration();
$configuration->setMiddlewares([$middleware]);

$connection = DriverManager::getConnection($params, $configuration);

Documentation

Development

composer test               # PHPUnit unit suite
composer test:integration   # PHPUnit integration suite, needs Docker services
composer qa                 # rector, cs, stan, test in sequence

See docs/testing.md for the Docker services, environment variables, and reference fixtures.

License

MIT. See LICENSE.