mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[PR #23580] feat: Add support for IAM token-based RDS authentication #50311
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/23580
Author: @brendanshanahan
Created: 4/10/2026
Status: 🔄 Open
Base:
dev← Head:feat/rds-iam-support📝 Commits (10+)
ca61f5aadd support for rds iam authenticationba00668verify agreement between rds host region, AWS_DEFAULT_REGION65d7183validate required env vars are present when DATABASE_ENABLE_IAM_TOKEN_AUTH=true5b93655add 60 second buffer for rds token refresh4a1eb37rm leftover debug log4ebfc10Merge branch 'dev' into feat/rds-iam-support278de36add async support1ec4a55add create_engine helper functionsacad321Merge branch 'dev' into feat/rds-iam-support8fbea2fMerge branch 'dev' into feat/rds-iam-support📊 Changes
4 files changed (+270 additions, -47 deletions)
View changed files
📝
backend/open_webui/env.py(+22 -0)📝
backend/open_webui/internal/db.py(+232 -45)📝
backend/open_webui/internal/wrappers.py(+9 -1)📝
backend/open_webui/migrations/env.py(+7 -1)📄 Description
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions to discuss your idea/fix with the community before creating a pull request, and describe your changes before submitting a pull request.
This is to ensure large feature PRs are discussed with the community first, before starting work on it. If the community does not want this feature or it is not relevant for Open WebUI as a project, it can be identified in the discussion before working on the feature and submitting the PR.
Related discussion: https://github.com/open-webui/open-webui/discussions/20783
Before submitting, make sure you've checked the following:
devdevto ensure no unrelated commits (e.g. frommain) are included. Push updates to the existing PR branch instead of closing and reopening.featChangelog Entry
Description
Adds support for AWS RDS IAM database authentication, enabling Open WebUI to connect to Amazon RDS PostgreSQL instances without static passwords. When enabled, the application obtains short-lived IAM authentication tokens via the AWS SDK and refreshes them automatically before expiry. Both sync and async SQLAlchemy engines are supported. SSL is enforced for all IAM-authenticated connections, with optional certificate verification when a CA bundle is provided.
Added
DATABASE_ENABLE_IAM_TOKEN_AUTHenvironment variable (default:false) — enables RDS IAM token authentication in place of a static database password.DATABASE_CA_PATHenvironment variable — optional path to a CA certificate bundle for full SSL certificate verification (sslmode=verify-fullfor sync /ssl.create_default_contextfor async). When omitted, connections usesslmode=require/ssl=True(encrypted but without cert verification).RDSIAMConfigclass indb.py— manages token generation, expiration tracking, sync and async engine creation, and token refresh via a SQLAlchemydo_connectevent listener attached to both engines.IAMTokenpydantic model — stores the token value (asSecretStr) and adatetimewith its expiration._create_engineand_create_async_enginehelper functions — centralize pool configuration for sync and async engines.Changed
handle_peewee_migration— accepts optionaldb_urlandconnect_argsparameters so IAM-authenticated connections (with SSL args and a token-embedded URL) can be passed through for peewee schema migrations.register_connectioninwrappers.py— accepts optionalconnect_argsdict and appliessslmode/sslrootcert/sslto the peewee PostgreSQL connection when provided.migrations/env.py— IAM auth path reuses therds_iam_configfromdb.py, creates a new sync engine for running the migrations, and attaches thedo_connecttoken-refresh listener.Fixed
UnboundLocalErrorinhandle_peewee_migrationwhenregister_connectionraised beforedbwas assigned —dbis now initialized toNonebefore the try block, and theassert db.is_closed()is guarded withif db is not None.Security
sslmode/sslrootcert; async connections use Python'sssl.SSLContextvia asyncpg — both atrequireminimum,verify-fullwhen a CA bundle is provided.SecretStrand never logged.Breaking Changes
DATABASE_ENABLE_IAM_TOKEN_AUTH=trueand has no effect on existing deployments.Additional Information
rds_iamrole granted in PostgreSQL (GRANT rds_iam TO <user>) and the EC2/ECS instance role must haverds-db:connectpermission on the target DB user ARN.do_connectevent listener is attached to theasync_engine.sync_engineinstance attribute to support IAM token refresh for async connections.sslmode=verify-full), running inside a Docker container on EC2 with an instance role.Screenshots or Videos
N/A
Contributor License Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.