jetcod/laravel-iam-db-auth

AWS IAM db auth package for laravel

Installs: 437

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 7

Type:package

1.0.0 2024-03-22 14:55 UTC

This package is not auto-updated.

Last update: 2024-11-19 10:18:02 UTC


README

This is a package to connect Laravel with a AWS RDS instance using IAM authentication.

It includes a service provider that gives the framework our overridden MySQL/PGSQL connector class when it asks for an MySQL/PGSQL connection.

Installation

require this package with composer:

composer require jetcod/laravel-iam-db-auth

Add a missing variables in connection to the config array in config/database.php

<?php [
    'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'database_name'),
        'username' => env('DB_USERNAME', 'database_username'),
        'password' => '',
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => false,
        'engine' => null,
        'aws_region' => env('AWS_REGION'),
        'use_iam_auth' => env('DB_USE_IAM_AUTH', true),
        'options' => array(
            'MYSQLI_READ_DEFAULT_FILE' => env('MYSQL_CNF_FILE', '/path/to/cnf/file'),
            PDO::MYSQL_ATTR_SSL_CA    => base_path('vendor/pixelvide/laravel-iam-db-auth/certs/rds-ca-2019-root.pem'),
        ),
    ],
];
<?php [
    'pgsql' => [
        'driver' => 'pgsql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '5432'),
        'database' => env('DB_DATABASE', 'database_name'),
        'username' => env('DB_USERNAME', 'database_username'),
        'password' => '',
        'charset' => 'utf8mb4',
        'aws_region' => env('AWS_REGION'),
        'use_iam_auth' => env('DB_USE_IAM_AUTH', true),
        'options' => array(
            PDO::ATTR_PERSISTENT => env('DB_PERSISTENT', false),      
        ),
    ],
];

Obtain the rds-combined-ca-bundle.pem from https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html