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:
parent
e96f981816
commit
6a8a6e2373
2
.github/workflows/dependency-review.yml
vendored
2
.github/workflows/dependency-review.yml
vendored
@ -22,5 +22,5 @@ jobs:
|
|||||||
uses: actions/dependency-review-action@v4
|
uses: actions/dependency-review-action@v4
|
||||||
with:
|
with:
|
||||||
fail-on-severity: moderate
|
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
|
comment-summary-in-pr: always
|
||||||
|
@ -68,6 +68,7 @@
|
|||||||
"schema:update": "node ./.husky/update-openapi-spec-list.js"
|
"schema:update": "node ./.husky/update-openapi-spec-list.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@aws-sdk/rds-signer": "^3.880.0",
|
||||||
"@slack/web-api": "^7.9.1",
|
"@slack/web-api": "^7.9.1",
|
||||||
"@wesleytodd/openapi": "^1.1.0",
|
"@wesleytodd/openapi": "^1.1.0",
|
||||||
"ajv": "^8.17.1",
|
"ajv": "^8.17.1",
|
||||||
|
@ -32,6 +32,8 @@ exports[`should create default config 1`] = `
|
|||||||
"db": {
|
"db": {
|
||||||
"acquireConnectionTimeout": 30000,
|
"acquireConnectionTimeout": 30000,
|
||||||
"applicationName": "unleash",
|
"applicationName": "unleash",
|
||||||
|
"awsIamAuth": false,
|
||||||
|
"awsRegion": undefined,
|
||||||
"database": "unleash_db",
|
"database": "unleash_db",
|
||||||
"disableMigration": false,
|
"disableMigration": false,
|
||||||
"driver": "postgres",
|
"driver": "postgres",
|
||||||
|
@ -266,6 +266,8 @@ const defaultDbOptions: WithOptional<IDBOption, 'user' | 'password' | 'host'> =
|
|||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
applicationName: process.env.DATABASE_APPLICATION_NAME || 'unleash',
|
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 => ({
|
const defaultSessionOption = (isEnterprise: boolean): ISessionOption => ({
|
||||||
|
@ -3,19 +3,61 @@ import knexpkg from 'knex';
|
|||||||
const { knex } = knexpkg;
|
const { knex } = knexpkg;
|
||||||
import type { IUnleashConfig } from '../types/option.js';
|
import type { IUnleashConfig } from '../types/option.js';
|
||||||
|
|
||||||
|
import { Signer } from '@aws-sdk/rds-signer';
|
||||||
|
|
||||||
export function createDb({
|
export function createDb({
|
||||||
db,
|
db,
|
||||||
getLogger,
|
getLogger,
|
||||||
}: Pick<IUnleashConfig, 'db' | 'getLogger'>): Knex {
|
}: Pick<IUnleashConfig, 'db' | 'getLogger'>): Knex {
|
||||||
const logger = getLogger('db-pool.js');
|
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({
|
return knex({
|
||||||
client: 'pg',
|
client: 'pg',
|
||||||
version: db.version,
|
version: db.version,
|
||||||
connection: {
|
connection,
|
||||||
...db,
|
pool,
|
||||||
application_name: db.applicationName,
|
|
||||||
},
|
|
||||||
pool: db.pool,
|
|
||||||
searchPath: db.schema,
|
searchPath: db.schema,
|
||||||
asyncStackTraces: true,
|
asyncStackTraces: true,
|
||||||
log: {
|
log: {
|
||||||
|
@ -20,7 +20,7 @@ export interface ISSLOption {
|
|||||||
|
|
||||||
export interface IDBOption {
|
export interface IDBOption {
|
||||||
user: string;
|
user: string;
|
||||||
password: string;
|
password?: string;
|
||||||
host: string;
|
host: string;
|
||||||
port: number;
|
port: number;
|
||||||
database: string;
|
database: string;
|
||||||
@ -38,6 +38,8 @@ export interface IDBOption {
|
|||||||
schema: string;
|
schema: string;
|
||||||
disableMigration: boolean;
|
disableMigration: boolean;
|
||||||
applicationName?: string;
|
applicationName?: string;
|
||||||
|
awsIamAuth?: boolean;
|
||||||
|
awsRegion?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISessionOption {
|
export interface ISessionOption {
|
||||||
|
Loading…
Reference in New Issue
Block a user