1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-05 17:53:12 +02:00

chore: add IAM db auth support (#10609)

https://linear.app/unleash/issue/2-3829/investigate-aws-iam-connection-support-for-unleash-docker

Adds AWS IAM DB connection support.
This commit is contained in:
Nuno Góis 2025-09-04 10:29:43 +01:00 committed by GitHub
parent e96f981816
commit 6a8a6e2373
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 1128 additions and 8 deletions

View File

@ -22,5 +22,5 @@ jobs:
uses: actions/dependency-review-action@v4
with:
fail-on-severity: moderate
allow-licenses: Apache-2.0, MIT, BSD-2-Clause, BSD-3-Clause, ISC, 0BSD, CC0-1.0, Unlicense, BlueOak-1.0.0, CC-BY-4.0, Artistic-2.0, PSF-2.0, MPL-2.0
allow-licenses: Apache-2.0, MIT, BSD-2-Clause, BSD-3-Clause, ISC, 0BSD, CC0-1.0, Unlicense, BlueOak-1.0.0, CC-BY-4.0, Artistic-2.0, PSF-2.0, MPL-2.0, MITNFA
comment-summary-in-pr: always

View File

@ -68,6 +68,7 @@
"schema:update": "node ./.husky/update-openapi-spec-list.js"
},
"dependencies": {
"@aws-sdk/rds-signer": "^3.880.0",
"@slack/web-api": "^7.9.1",
"@wesleytodd/openapi": "^1.1.0",
"ajv": "^8.17.1",

View File

@ -32,6 +32,8 @@ exports[`should create default config 1`] = `
"db": {
"acquireConnectionTimeout": 30000,
"applicationName": "unleash",
"awsIamAuth": false,
"awsRegion": undefined,
"database": "unleash_db",
"disableMigration": false,
"driver": "postgres",

View File

@ -266,6 +266,8 @@ const defaultDbOptions: WithOptional<IDBOption, 'user' | 'password' | 'host'> =
false,
),
applicationName: process.env.DATABASE_APPLICATION_NAME || 'unleash',
awsIamAuth: parseEnvVarBoolean(process.env.DATABASE_AWS_IAM, false),
awsRegion: process.env.AWS_REGION,
};
const defaultSessionOption = (isEnterprise: boolean): ISessionOption => ({

View File

@ -3,19 +3,61 @@ import knexpkg from 'knex';
const { knex } = knexpkg;
import type { IUnleashConfig } from '../types/option.js';
import { Signer } from '@aws-sdk/rds-signer';
export function createDb({
db,
getLogger,
}: Pick<IUnleashConfig, 'db' | 'getLogger'>): Knex {
const logger = getLogger('db-pool.js');
const {
host,
port,
user,
database,
ssl,
applicationName,
password,
awsIamAuth,
awsRegion,
pool,
} = db;
let resolvedPassword: string | (() => Promise<string>) | undefined =
password;
if (awsIamAuth) {
if (!awsRegion) {
throw new Error(
'AWS_REGION is required when DATABASE_AWS_IAM=true',
);
}
const signer = new Signer({
region: awsRegion,
hostname: host,
port,
username: user,
});
resolvedPassword = async () => signer.getAuthToken();
}
const connection = {
host,
port,
user,
database,
ssl,
application_name: applicationName,
password: resolvedPassword,
};
return knex({
client: 'pg',
version: db.version,
connection: {
...db,
application_name: db.applicationName,
},
pool: db.pool,
connection,
pool,
searchPath: db.schema,
asyncStackTraces: true,
log: {

View File

@ -20,7 +20,7 @@ export interface ISSLOption {
export interface IDBOption {
user: string;
password: string;
password?: string;
host: string;
port: number;
database: string;
@ -38,6 +38,8 @@ export interface IDBOption {
schema: string;
disableMigration: boolean;
applicationName?: string;
awsIamAuth?: boolean;
awsRegion?: string;
}
export interface ISessionOption {

1073
yarn.lock

File diff suppressed because it is too large Load Diff