When using PostgreSQL over TLS, what's the recommended way to specify the paths to client cert and key in the postgres connection url? I used ENV_PHOENIX_SQL_DATABASE_URL with a formatted connection url: postgresql://<username>:***@<hostname>/<dbname>?sslcert=<path-to-client-cert>&sslkey=<path-to-client-key>&sslmode=require&sslrootcert=<path-toserver-ca> but got the following error 馃У
It could be possible that specifying sslcert, sslkey, and sslrootcert as query parameters in the PHOENIX_SQL_DATABASE_URL is not fully supported or may be stripped/ignored by Phoenix, especially since there have been issues with SSL parameters being lost due to internal connection string manipulation (see this issue). The official documentation and code examples only mention using sslmode=require or ssl=require as a query parameter, but do not explicitly document support for sslcert, sslkey, or sslrootcert in the connection URL (docs, test code).Though I'm not entirely certain, it might be that Phoenix currently does not support passing client certificate and key paths via the connection URL, or that these parameters are not passed through to the underlying driver. If you need client certificate authentication, you may need to open a feature request or check for recent updates. Would you like more detail on possible workarounds or the current state of TLS support in Phoenix?Sources:
- see this issue
- docs
- test code
馃挕聽Hint: Mention RunLLM in the thread for followups.
It actually looks like sqlalchemy's asyncpg dialect does support this:
import asyncio
import asyncpg
async def async_main():
conn = await asyncpg.connect(
"postgresql://<username>:***@<hostname>/<dbname>?sslcert=%2Fcerts%2Fdb%2Fclient-cert.pem&sslkey=%2Fcerts%2Fdb%2Fclient-key.pem&sslmode=require&sslrootcert=%2Fcerts%2Fdb%2Fserver-ca.pem"
)
row = await conn.fetchrow("SELECT 1")
print(f">>> {row}")
asyncio.run(async_main())^ above script runs fine and return my query result
Maybe try ssl=require (instead of sslmode). I don't use client certs, but that's the parameter that gets it to use TLS.
We're not using client certs, we still/only use password auth
phoenix is using sqlalchemy make_url which does some translation of parameters for different drivers. https://github.com/Arize-ai/phoenix/blob/main/src/phoenix/db/engines.py#L40-L46
You could try passing your input to make_url and see if the output is accepted by the driver
based on my python code above, where I'm using asyncpg.connect directly without sqlalchemy in the middle, the connection was successful
Yeah, so sqlalchemy (used in phoenix) might be changing your URL
Sorry, I don't have much to add. I'll let the phoenix folks comment.
we actually have two pg clients, so this may require some investigation on our end. could you please file us a ticket to track? thanks
Specifically, we found this code block: https://github.com/Arize-ai/phoenix/blob/main/src/phoenix/db/engines.py#L40-L62 I printed out all the url params and they look all good. I see phoenix is overriding driver name here: url.set(drivername="postgresql+asyncpg") , which seems to ask sqlalchemy to use asyncpg dialect -- and it really should work based on this plain vanilla python code below:
import asyncio
import asyncpg
async def async_main():
conn = await asyncpg.connect(
"postgresql://<username>:***@<hostname>/<dbname>?sslcert=%2Fcerts%2Fdb%2Fclient-cert.pem&sslkey=%2Fcerts%2Fdb%2Fclient-key.pem&sslmode=require&sslrootcert=%2Fcerts%2Fdb%2Fserver-ca.pem"
)
row = await conn.fetchrow("SELECT 1")
print(f">>> {row}")
asyncio.run(async_main())Maybe there's a mismatch in the sqlalchemy version phoenix is using?
