定制 promenadeco/doctrine-aws-auth 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

promenadeco/doctrine-aws-auth

最新稳定版本:1.1.1

Composer 安装命令:

composer require promenadeco/doctrine-aws-auth

包简介

RDS authentication using IAM for Doctrine DBAL/ORM

README 文档

README

This library provides Amazon RDS database authentication using IAM for Doctrine DBAL / ORM.

Features:

  • RDS auth via IAM using short-lived tokens
  • Token caching (for 10 min by default)
  • Support of EC2 and ECS environments
  • Support of PDO and MySQLi drivers

Usage

Install the package using Composer:

composer require promenadeco/doctrine-aws-auth

Enable IAM authentication in cleartext using the following environment variables:

AWS_REGION=us-east-1 RDS_USE_IAM=1 LIBMYSQL_ENABLE_CLEARTEXT_PLUGIN=1

Doctrine ORM

Register the DBAL driver middleware in Doctrine ORM:

use Doctrine\ORM\EntityManager; use Doctrine\ORM\ORMSetup; use Promenade\Doctrine\Aws\Auth\Driver\IamMiddleware; use Promenade\Doctrine\Aws\Auth\Token\RdsToken; // ... $ormConfig = ORMSetup::createAnnotationMetadataConfiguration([ 'src/Entity', ]); $tokenProvider = new RdsToken(); $ormConfig->setMiddlewares([ new IamMiddleware($tokenProvider), ]); $entityManager = EntityManager::create( [ 'host' => 'example-db.abcdefghijkl.us-east-1.rds.amazonaws.com', 'port' => 3306, 'user' => 'iam_user', 'dbname' => 'test_db', 'driver' => 'pdo_mysql', 'driverOptions' => [ PDO::MYSQL_ATTR_SSL_CA => '/etc/ssl/certs/ca-certificates.crt', PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false ], ], $ormConfig );

Encryption

Connection encryption is necessary to secure transmission of credentials as cleartext.

The SSL configuration differs between drivers, for example:

[ // ... 'driver' => 'mysqli', 'driverOptions' => [ 'flags' => MYSQLI_CLIENT_SSL, ], ]

Caching

Activate token caching to stay within rate limits and improve performance:

use Promenade\Doctrine\Aws\Auth\Token\CachingProxy; // ... $tokenProvider = new CachingProxy($tokenProvider, $ormConfig->getMetadataCache());

By default, tokens are good for 15 min and are cached for 10 min to be renewed well ahead of their expiration.

Symfony

Register the DBAL driver middleware in config/services.yaml:

services: Promenade\Doctrine\Aws\Auth\Token\TokenProvider: class: Promenade\Doctrine\Aws\Auth\Token\RdsToken Promenade\Doctrine\Aws\Auth\Driver\IamMiddleware: tags: ['doctrine.middleware']

Caching

Activate the token caching and adjust its lifetime as needed:

services: Promenade\Doctrine\Aws\Auth\Driver\IamMiddleware: arguments: $tokenProvider: '@Promenade\Doctrine\Aws\Auth\Token\CachingProxy' Promenade\Doctrine\Aws\Auth\Token\RdsToken: arguments: $lifetime: 15 Promenade\Doctrine\Aws\Auth\Token\CachingProxy: arguments: $lifetime: 14

Make sure tokens are valid some time beyond their cache expiration to compensate for potential clock drift.

Limitations

IAM authentication relies on database client sending credentials in cleartext without hashing.

The implementation has only been tested on MySQL. Other RDBMS may have their own unique limitations.

Resources

Related resources with useful information:

Contributing

Pull Requests with fixes and improvements are welcome!

License

Copyright © Promenade Group. All rights reserved.

Licensed under the Apache License, Version 2.0.

统计信息

  • 总下载量: 14.39k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固