k-ap 0.5.1; reqwest ring-only, sqlx no tls; bootstrap installs ring provider

This commit is contained in:
2026-10-26 03:52:49 +01:00
parent b9cdb54340
commit 0b80e48622
11 changed files with 75 additions and 282 deletions

View File

@@ -5,7 +5,7 @@ edition.workspace = true
[dependencies]
config = { workspace = true }
k-ap = { version = "0.5.0", registry = "gitea" }
k-ap = { version = "0.5.1", registry = "gitea" }
domain = { workspace = true }
axum = { workspace = true }
serde = { workspace = true }

View File

@@ -6,7 +6,7 @@ edition.workspace = true
[dependencies]
sqlx = { workspace = true }
activitypub = { workspace = true }
k-ap = { version = "0.5.0", registry = "gitea" }
k-ap = { version = "0.5.1", registry = "gitea" }
sqlite = { workspace = true }
domain = { workspace = true }
anyhow = { workspace = true }

View File

@@ -37,12 +37,14 @@ tokio = { workspace = true }
futures = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
rustls = { version = "0.23", default-features = false, features = ["ring", "std", "tls12", "logging"] }
nats = { workspace = true, optional = true }
activitypub = { workspace = true, optional = true }
sqlite-federation = { workspace = true, optional = true }
[dev-dependencies]
reqwest = { workspace = true }
chrono = { workspace = true }
uuid = { workspace = true }
serde_json = { workspace = true }

View File

@@ -13,11 +13,13 @@ mod follow_backfill_handler;
pub mod outbox_relay;
pub mod repositories;
mod server;
mod tls;
mod tracing_setup;
mod worker;
pub use build::build_deps;
pub use repositories::Repositories;
pub use server::{ServerApp, build_server, build_server_on};
pub use tls::install_crypto_provider;
pub use tracing_setup::init_tracing;
pub use worker::{WorkerApp, build_worker, build_worker_on};

View File

@@ -54,6 +54,7 @@ async fn assemble(
db: DatabaseOutput,
instance: InstanceIdentity,
) -> anyhow::Result<axum::Router> {
crate::tls::install_crypto_provider();
let app_config = AppSettings::from(config);
let (auth_service, password_hasher) = database::build_auth_adapters(&config.auth)?;

View File

@@ -0,0 +1,34 @@
//! Process-wide rustls crypto provider.
//!
//! Every HTTPS client in the graph (reqwest, object_store, async-nats,
//! k-ap) is built without a bundled provider so the binaries link `ring`
//! only. rustls therefore needs one installed before the first client is
//! built, or client construction panics.
use std::sync::Once;
/// Installs `ring` as the process default. Idempotent; a provider installed
/// earlier by someone else is left in place.
pub fn install_crypto_provider() {
static INSTALL: Once = Once::new();
INSTALL.call_once(|| {
let _ = rustls::crypto::ring::default_provider().install_default();
});
}
#[cfg(test)]
mod tests {
use super::*;
/// Runs alone in the lib test binary, so no other code (k-ap included)
/// has installed a provider first.
#[test]
fn https_client_builds_after_install() {
install_crypto_provider();
install_crypto_provider();
reqwest::Client::builder()
.build()
.expect("reqwest client builds");
assert!(rustls::crypto::CryptoProvider::get_default().is_some());
}
}

View File

@@ -99,6 +99,7 @@ async fn assemble(
db: DatabaseOutput,
#[cfg_attr(not(feature = "federation"), allow(unused_variables))] instance: InstanceIdentity,
) -> anyhow::Result<WorkerApp> {
crate::tls::install_crypto_provider();
let metadata_client = metadata::create(&config.metadata)?;
let poster_fetcher = poster_fetcher::create(&config.metadata)?;
let object_storage = object_storage::create(&config.storage)?;

View File

@@ -26,6 +26,7 @@ windows-native-keyring-store = { version = "1.0.0", optional = true }
api-types = { workspace = true }
reqwest = { workspace = true }
rustls = { version = "0.23", default-features = false, features = ["ring", "std", "tls12", "logging"] }
serde = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true }

View File

@@ -46,6 +46,8 @@ pub struct ApiClient {
impl ApiClient {
pub fn new(url: &str) -> Self {
// reqwest is built without a bundled TLS provider; install ring first.
let _ = rustls::crypto::ring::default_provider().install_default();
Self {
base_url: std::sync::RwLock::new(url.to_string()),
http: reqwest::Client::new(),