:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(pgcollector): install rustls crypto provider and enable TLS for pgapi (#94729)
Nick Best1a3213f8ca13
diff --git a/rust/Cargo.lock b/rust/Cargo.lockindex a117e2f09e6d..64c850128bd1 100644--- a/rust/Cargo.lock+++ b/rust/Cargo.lock@@ -8987,14 +8987,17 @@ dependencies = ["reqwest 0.12.28","rmcp","rust_decimal",+ "rustls 0.23.37","schemars 1.2.1","serde","serde_json","tokio","tokio-postgres",+ "tokio-postgres-rustls","tower-http 0.5.2","tracing","tracing-subscriber",+ "webpki-roots 1.0.6",][[package]]diff --git a/rust/pgapi/Cargo.toml b/rust/pgapi/Cargo.tomlindex 41a02e8f5d14..c9d5952ed431 100644--- a/rust/pgapi/Cargo.toml+++ b/rust/pgapi/Cargo.toml@@ -21,14 +21,17 @@ regex = { workspace = true }reqwest = { workspace = true }rmcp = { version = "3", features = ["server", "macros", "transport-streamable-http-server"] }rust_decimal = { version = "1", features = ["db-tokio-postgres"] }+rustls = { workspace = true }schemars = "1"serde = { workspace = true }serde_json = { workspace = true }tokio = { workspace = true }tokio-postgres = { version = "0.7", features = ["with-chrono-0_4", "with-serde_json-1"] }+tokio-postgres-rustls = "0.13"tower-http = { workspace = true }tracing = { workspace = true }tracing-subscriber = { workspace = true }+webpki-roots = "1"[lints]workspace = truediff --git a/rust/pgapi/src/db.rs b/rust/pgapi/src/db.rsindex 48e7292b276d..76b595560b4c 100644--- a/rust/pgapi/src/db.rs+++ b/rust/pgapi/src/db.rs@@ -6,7 +6,6 @@ use chrono::{DateTime, Utc};use deadpool_postgres::{Manager, ManagerConfig, Pool, RecyclingMethod};use serde_json::{json, Map, Value};use tokio_postgres::types::{ToSql, Type};-use tokio_postgres::NoTls;/// Serialised-response ceiling for raw SQL. Row count is bounded by LIMIT; this bounds/// bytes so a wide or `repeat()`-style query can't exhaust the pod's memory.@@ -19,10 +18,17 @@ pub struct Db {impl Db {pub async fn connect(url: &str) -> Result<Self> {- let cfg: tokio_postgres::Config = url.parse().context("parsing PGAPI_DATABASE_URL")?;+ let mut cfg: tokio_postgres::Config = url.parse().context("parsing PGAPI_DATABASE_URL")?;+ cfg.ssl_mode(tokio_postgres::config::SslMode::Require);+ let tls_cfg = rustls::ClientConfig::builder()+ .with_root_certificates(rustls::RootCertStore {+ roots: webpki_roots::TLS_SERVER_ROOTS.to_vec(),+ })+ .with_no_client_auth();+ let tls = tokio_postgres_rustls::MakeRustlsConnect::new(tls_cfg);let mgr = Manager::from_config(cfg,- NoTls,+ tls,ManagerConfig {recycling_method: RecyclingMethod::Fast,},diff --git a/rust/pgapi/src/main.rs b/rust/pgapi/src/main.rsindex a40b3878795b..ec059a2482e9 100644--- a/rust/pgapi/src/main.rs+++ b/rust/pgapi/src/main.rs@@ -81,6 +81,10 @@ pub struct AppState {#[tokio::main]async fn main() -> Result<()> {+ rustls::crypto::aws_lc_rs::default_provider()+ .install_default()+ .expect("failed to install rustls CryptoProvider");+tracing_subscriber::fmt().with_env_filter(EnvFilter::try_from_default_env().unwrap_or_else(|_| "info,tokio_postgres=warn".into()),diff --git a/rust/pgcollector/src/main.rs b/rust/pgcollector/src/main.rsindex d164d1691a11..53cd3c1c1d07 100644--- a/rust/pgcollector/src/main.rs+++ b/rust/pgcollector/src/main.rs@@ -42,6 +42,10 @@ struct Cli {#[tokio::main]async fn main() -> Result<()> {+ rustls::crypto::aws_lc_rs::default_provider()+ .install_default()+ .expect("failed to install rustls CryptoProvider");+tracing_subscriber::fmt().with_env_filter(EnvFilter::try_from_default_env().unwrap_or_else(|_| "info,tokio_postgres=warn".into()),