fix: apply RDS IAM token auth to the pgvector engine (#27754)
With `DATABASE_ENABLE_IAM_TOKEN_AUTH=true` and `VECTOR_DB=pgvector`, startup failed at vector store initialisation with `fe_sendauth: no password supplied`, so the two features could not be used together. `PgvectorClient` builds its own engine and never got the `do_connect` listener that refreshes the RDS IAM token, and the `ScopedSession` branch that would have reused the instrumented main engine is unreachable because `PGVECTOR_DB_URL` defaults to `DATABASE_URL` and is therefore never falsy. The pgvector engine now goes through `enable_iam_token_auth()` like the main and Alembic engines. Since a token authenticates exactly one host/port/user, that function now attaches the listener only to engines pointing at the same target, so a `PGVECTOR_DB_URL` aimed at a separate database keeps the password from its own URL instead of having it overwritten; the skip is logged with both identities. Fixes #27752
This commit is contained in:
1 parent
16b20c651d
commit
baeb2dfb83
2 files changed
+16
-2
No files matched your search
@@ -202,6 +202,20 @@ def enable_iam_token_auth(connectable) -> None:
|
|||||||
return
|
return
|
||||||
|
|
||||||
engine = getattr(connectable, 'sync_engine', connectable)
|
engine = getattr(connectable, 'sync_engine', connectable)
|
||||||
|
url = engine.url
|
||||||
|
auth = _rds_iam_token_auth
|
||||||
|
# The token is bound to one host/port/user pair; leave other databases on their own credentials.
|
||||||
|
if (url.host, url.port or 5432, url.username) != (auth.host, auth.port, auth.username):
|
||||||
|
log.warning(
|
||||||
|
'AWS RDS IAM token auth not applied to %s: the token is issued for %s@%s:%s, '
|
||||||
|
'so this connection uses the password from its own URL',
|
||||||
|
url.render_as_string(hide_password=True),
|
||||||
|
auth.username,
|
||||||
|
auth.host,
|
||||||
|
auth.port,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
if not event.contains(engine, 'do_connect', _set_iam_token_password):
|
if not event.contains(engine, 'do_connect', _set_iam_token_password):
|
||||||
event.listen(engine, 'do_connect', _set_iam_token_password)
|
event.listen(engine, 'do_connect', _set_iam_token_password)
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ from open_webui.config import (
|
|||||||
PGVECTOR_POOL_TIMEOUT,
|
PGVECTOR_POOL_TIMEOUT,
|
||||||
PGVECTOR_USE_HALFVEC,
|
PGVECTOR_USE_HALFVEC,
|
||||||
)
|
)
|
||||||
|
from open_webui.internal.db import ScopedSession, enable_iam_token_auth
|
||||||
from open_webui.retrieval.vector.main import (
|
from open_webui.retrieval.vector.main import (
|
||||||
GetResult,
|
GetResult,
|
||||||
SearchResult,
|
SearchResult,
|
||||||
@@ -87,8 +88,6 @@ class PgvectorClient(VectorDBBase):
|
|||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
# if no pgvector uri, use the existing database connection
|
# if no pgvector uri, use the existing database connection
|
||||||
if not PGVECTOR_DB_URL:
|
if not PGVECTOR_DB_URL:
|
||||||
from open_webui.internal.db import ScopedSession
|
|
||||||
|
|
||||||
self.session = ScopedSession
|
self.session = ScopedSession
|
||||||
else:
|
else:
|
||||||
if isinstance(PGVECTOR_POOL_SIZE, int):
|
if isinstance(PGVECTOR_POOL_SIZE, int):
|
||||||
@@ -107,6 +106,7 @@ class PgvectorClient(VectorDBBase):
|
|||||||
else:
|
else:
|
||||||
engine = create_engine(PGVECTOR_DB_URL, pool_pre_ping=True)
|
engine = create_engine(PGVECTOR_DB_URL, pool_pre_ping=True)
|
||||||
|
|
||||||
|
enable_iam_token_auth(engine)
|
||||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine, expire_on_commit=False)
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine, expire_on_commit=False)
|
||||||
self.session = scoped_session(SessionLocal)
|
self.session = scoped_session(SessionLocal)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user