diff --git a/Cargo.lock b/Cargo.lock index 2cce09f..d90fb14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -105,6 +105,12 @@ version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" +[[package]] +name = "arc-swap" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bddcadddf5e9015d310179a59bb28c4d4b9920ad0f11e8e14dbadf654890c9a6" + [[package]] name = "async-trait" version = "0.1.77" @@ -159,13 +165,46 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" dependencies = [ "async-trait", - "axum-core", + "axum-core 0.3.4", "bitflags 1.3.2", "bytes", "futures-util", - "http", - "http-body", - "hyper", + "http 0.2.11", + "http-body 0.4.6", + "hyper 0.14.28", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1236b4b292f6c4d6dc34604bb5120d85c3fe1d1aa596bd5cc52ca054d13e7b9e" +dependencies = [ + "async-trait", + "axum-core 0.4.3", + "bytes", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.1.0", + "hyper-util", "itoa", "matchit", "memchr", @@ -182,6 +221,7 @@ dependencies = [ "tower", "tower-layer", "tower-service", + "tracing", ] [[package]] @@ -193,14 +233,58 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http", - "http-body", + "http 0.2.11", + "http-body 0.4.6", "mime", "rustversion", "tower-layer", "tower-service", ] +[[package]] +name = "axum-core" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-server" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1ad46c3ec4e12f4a4b6835e173ba21c25e484c9d02b49770bf006ce5367c036" +dependencies = [ + "arc-swap", + "bytes", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.1.0", + "hyper-util", + "pin-project-lite", + "rustls", + "rustls-pemfile 2.0.0", + "tokio", + "tokio-rustls", + "tower", + "tower-service", +] + [[package]] name = "backtrace" version = "0.3.69" @@ -792,7 +876,26 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", + "http 0.2.11", + "indexmap 2.1.0", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "h2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31d030e59af851932b72ceebadf4a2b5986dba4c3b99dd2493f8273a0f151943" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 1.0.0", "indexmap 2.1.0", "slab", "tokio", @@ -903,6 +1006,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http-body" version = "0.4.6" @@ -910,7 +1024,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", - "http", + "http 0.2.11", + "pin-project-lite", +] + +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http 1.0.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" +dependencies = [ + "bytes", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", "pin-project-lite", ] @@ -942,9 +1079,9 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2", - "http", - "http-body", + "h2 0.3.24", + "http 0.2.11", + "http-body 0.4.6", "httparse", "httpdate", "itoa", @@ -956,6 +1093,25 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5aa53871fc917b1a9ed87b683a5d86db645e23acb32c2e0785a353e522fb75" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2 0.4.2", + "http 1.0.0", + "http-body 1.0.0", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "tokio", +] + [[package]] name = "hyper-rustls" version = "0.24.2" @@ -963,13 +1119,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", - "http", - "hyper", + "http 0.2.11", + "hyper 0.14.28", "rustls", "tokio", "tokio-rustls", ] +[[package]] +name = "hyper-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdea9aac0dbe5a9240d68cfd9501e2db94222c6dc06843e06640b9e07f0fdc67" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "hyper 1.1.0", + "pin-project-lite", + "socket2 0.5.5", + "tokio", + "tracing", +] + [[package]] name = "idna" version = "0.3.0" @@ -1087,7 +1261,7 @@ dependencies = [ "once_cell", "quoted_printable", "rustls", - "rustls-pemfile", + "rustls-pemfile 1.0.4", "socket2 0.4.10", "tokio", "tokio-rustls", @@ -1160,8 +1334,8 @@ version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0bab19cef8a7fe1c18a43e881793bfc9d4ea984befec3ae5bd0415abf3ecf00" dependencies = [ - "axum-core", - "http", + "axum-core 0.3.4", + "http 0.2.11", "itoa", "maud_macros", ] @@ -1657,10 +1831,10 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "h2", - "http", - "http-body", - "hyper", + "h2 0.3.24", + "http 0.2.11", + "http-body 0.4.6", + "hyper 0.14.28", "hyper-rustls", "ipnet", "js-sys", @@ -1670,7 +1844,7 @@ dependencies = [ "percent-encoding", "pin-project-lite", "rustls", - "rustls-pemfile", + "rustls-pemfile 1.0.4", "serde", "serde_json", "serde_urlencoded", @@ -1775,6 +1949,22 @@ dependencies = [ "base64", ] +[[package]] +name = "rustls-pemfile" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35e4980fa29e4c4b212ffb3db068a564cbf560e51d3944b7c88bd8bf5bec64f4" +dependencies = [ + "base64", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e9d979b3ce68192e42760c7810125eb6cf2ea10efae545a156063e61f314e2a" + [[package]] name = "rustls-webpki" version = "0.100.3" @@ -1993,10 +2183,11 @@ name = "soldr" version = "0.1.0" dependencies = [ "anyhow", - "axum", + "axum 0.7.4", + "axum-server", "clap 4.4.18", "criterion", - "hyper", + "hyper 0.14.28", "lettre", "parking_lot", "rand", @@ -2008,7 +2199,7 @@ dependencies = [ "tokio", "toml", "tower", - "tower-http", + "tower-http 0.5.1", "tracing", "tracing-subscriber", ] @@ -2018,7 +2209,7 @@ name = "soldr-ui" version = "0.0.0" dependencies = [ "anyhow", - "axum", + "axum 0.6.20", "bpaf", "maud", "reqwest", @@ -2026,7 +2217,7 @@ dependencies = [ "serde_json", "shared_types", "tokio", - "tower-http", + "tower-http 0.4.4", "tracing", "tracing-subscriber", "url", @@ -2110,7 +2301,7 @@ dependencies = [ "paste", "percent-encoding", "rustls", - "rustls-pemfile", + "rustls-pemfile 1.0.4", "serde", "serde_json", "sha2", @@ -2538,8 +2729,8 @@ dependencies = [ "bytes", "futures-core", "futures-util", - "http", - "http-body", + "http 0.2.11", + "http-body 0.4.6", "http-range-header", "httpdate", "mime", @@ -2553,6 +2744,23 @@ dependencies = [ "tracing", ] +[[package]] +name = "tower-http" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0da193277a4e2c33e59e09b5861580c33dd0a637c3883d0fa74ba40c0374af2e" +dependencies = [ + "bitflags 2.4.2", + "bytes", + "http 1.0.0", + "http-body 1.0.0", + "http-body-util", + "pin-project-lite", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "tower-layer" version = "0.3.2" diff --git a/certs/README.md b/certs/README.md new file mode 100644 index 0000000..4bbc624 --- /dev/null +++ b/certs/README.md @@ -0,0 +1,17 @@ +# TLS Certs + +> [!CAUTION] +> These are intended for development only! + +This directory contains TLS certs for localhost. These are used to make development easier. + +## Making your own certificates + +``` +openssl req -x509 -out localhost.crt -keyout localhost.key \ + -newkey rsa:2048 -nodes -sha256 \ + -subj '/CN=localhost' -extensions EXT -config <( \ + printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth") +``` + +[source](https://letsencrypt.org/docs/certificates-for-localhost/#making-and-trusting-your-own-certificates) diff --git a/certs/localhost.crt b/certs/localhost.crt new file mode 100644 index 0000000..47f3977 --- /dev/null +++ b/certs/localhost.crt @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIDDzCCAfegAwIBAgIUWSq6qNcWO52SspWx9KyPKMaS/UkwDQYJKoZIhvcNAQEL +BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTI0MDEyODEzNDcyNFoXDTI0MDIy +NzEzNDcyNFowFDESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEF +AAOCAQ8AMIIBCgKCAQEAoyXbnny+Plmo0syJX7r5R0FSlV0NQWmfapKyi3ChZ6ez +H4e21SXAo0UPOvBFUfp+Gj1t2uTP86XGP8tN59/T1iI8Rvzy7bmfm433Ql2JoUFN +iOjqQYyIH6cepM160nXjupS5gbtWbO2Q/4uYgqcPQegK3gKXkA9rKQmj6toRAyBy +e8lxrE+ULQdjxifjlP5IFpukyWdlq+Meuza+Hzzrp/x2EHsidzhNZvwfO8HAB/Ej +phL6bnmQM0ZkmVhoq5L8F3RnrZlw/I62qp6fq8iF64rZoJtuyvg6xu8UhaCHmI4J +bhA6i56UFBDrZ9Om37zxyMlzKxePoeZh0ieVw5ANMwIDAQABo1kwVzAUBgNVHREE +DTALgglsb2NhbGhvc3QwCwYDVR0PBAQDAgeAMBMGA1UdJQQMMAoGCCsGAQUFBwMB +MB0GA1UdDgQWBBS/imYFn4ntU1xD5Z5lUfYSVigy7TANBgkqhkiG9w0BAQsFAAOC +AQEAkzZCmv49YZfIHEDEl84pKMLKO81FY9l+0lhB6y9F1fV93Ch8EByEvmBG6G5m +mdfJi7+4LGVkPNsMs0eD6b4MUmV71pHl+NSKtXuMc2YS8oAL8g6+IFDQAZhl0Mpo +bElR86QvW3AoiC1QDJUFzfVC0WMMRA7YmDzWYyJX9H/zPWPyNvkvAppeVGBj+f1V +AaGcg6yBpM9XZB2jYkIXiPO1J+/X0YnMqn6RqF+Zg+nZROPNwYVzn+TUcffwP47D +az/Itnlh0t3aWQ2rI7NkjPDJQ4FJUfseAWd244un8IE0MO6PLvD1hSWiMG4Dn0BE +j3xFGLw7g67KwKxl9rVDAoPGBg== +-----END CERTIFICATE----- diff --git a/certs/localhost.key b/certs/localhost.key new file mode 100644 index 0000000..b87e22c --- /dev/null +++ b/certs/localhost.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCjJduefL4+WajS +zIlfuvlHQVKVXQ1BaZ9qkrKLcKFnp7Mfh7bVJcCjRQ868EVR+n4aPW3a5M/zpcY/ +y03n39PWIjxG/PLtuZ+bjfdCXYmhQU2I6OpBjIgfpx6kzXrSdeO6lLmBu1Zs7ZD/ +i5iCpw9B6AreApeQD2spCaPq2hEDIHJ7yXGsT5QtB2PGJ+OU/kgWm6TJZ2Wr4x67 +Nr4fPOun/HYQeyJ3OE1m/B87wcAH8SOmEvpueZAzRmSZWGirkvwXdGetmXD8jraq +np+ryIXritmgm27K+DrG7xSFoIeYjgluEDqLnpQUEOtn06bfvPHIyXMrF4+h5mHS +J5XDkA0zAgMBAAECggEAEHFHUhDGZ6hHoH8mtTQ13V2TAiSvqlEH1QjV38HJMpYv +MlVOMussIAhcwZbnlZyGSwS35qC66JZjhZhq0Jy5T9KBerIRla3ojRfgvJqKvWrE +crDusw6DxZTlPLzMzRs+iVZl39JOoonK3EZoZ3qIyh6lwbxHJCi5pxgmogu6PTNF +nf8zULHWP/8D+vsVWWY7scnZbH5Z/6L0fodeNYnsfs4lh9dStbqs0wKVrcbQnPW7 +JYpqdJ0Rr5KpWlrPvqZlzUIlkryihZBhIl5eRIa49fOOcliSxH8QWtBczBYTf/Y8 +EiPxcEBURxx9q2SruImhFmkI6T42u2rUtFGyaUFswQKBgQDerRB05P5NBGM+f9PN +cV2mQKAqyHyzq6srLQo2a0X//6xN+NsvtBasm2hOYWSg9+wV2/yeF0TA/2UBFkOh +Iza1l0Fb0MjQGGJLH0YDfSw004v54tahhQQR3l3BI5qBUHjNQDfwRIG1/JaOfJ5l +Y8xUi1I0OT0lM0soBOl3VAIw4QKBgQC7kDZSAzt1hTmZbyOCX3yfMw8oXWc/ATpj +WtzuJTY2PUal00yYm58bUrZmhj0XeYHQOvgXJ9KzMbJMzIWt20xUAIflL6JDZebw +Eceq1j3X6JLqhRpgUgOhVf5yLbRWbsY0h3Q7YxEQf90W4vpgj3XrVkQ6KqsXsml0 +g9tzPcF8kwKBgQDMJRfoQyRNEY+29dQFDkDQMYFll8aTpffYLoOlXnWffBPIrDSu +qEj9V8Cp0ypBVOnRJIyVlzmGQt6jv3ijGziGBLR7646fESvUOUij3DcR+zviDS++ +hsczZozHi8+TbGZDrfNayEOux3J0ERXaWEM040Gq9Sr0lvD5MH+l0ZPsoQKBgB0Q +JIqiu5TjNuCiiwMJnrrgY4nipzvpCc4ZZ0Bzfan75rWNP0IqYwYN0/ug81hu2IGW +kZis8AYaPkGOM2yUHYiqqGQH9IGzCYzLhH/hQKXzAMjcJRElxDA8rfetQ1NdSNMc +5hLJr/w5g92nABr0P9ZegKXutKIwYAzQ3bFGsXOHAoGAdo2A6Ug9wuGUDrJjSSRW +6B3DomKUB47OQbsOjLi0VY8jTp1YJ1WD4ZV7sjgDjcTeit7g5B5dkoLttwT4/ctj +Zz/4YAmtsJTUxIpk8b2jT79HeWrSrT+zmF/zoIGkx9dCks01dh+DfCQeNHx9PDGz +dAGBSME1eIbMfXkKEYbDpI4= +-----END PRIVATE KEY----- diff --git a/crates/proxy/Cargo.toml b/crates/proxy/Cargo.toml index 2450f47..87040dd 100644 --- a/crates/proxy/Cargo.toml +++ b/crates/proxy/Cargo.toml @@ -6,7 +6,8 @@ default-run = "soldr" [dependencies] anyhow = "1.0" -axum = "0.6.18" +axum = "0.7" +axum-server = { version = "0.6", features = ["tls-rustls"] } clap = { version = "4.3.8", features = ["derive"] } hyper = { version = "0.14", features = ["full"] } lettre = { version = "0.10.4", default-features = false, features = ["smtp-transport", "tokio1", "tokio1-rustls-tls", "builder"] } @@ -21,7 +22,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] } tokio = { version = "1.0", features = ["full"] } toml = "0.7.5" tower = { version = "0.4", features = ["util"] } -tower-http = { version = "0.4.0", features = ["trace", "cors"] } +tower-http = { version = "0.5", features = ["trace", "cors"] } [dev-dependencies] criterion = {version = "0.4", features = ["async_tokio"]} diff --git a/crates/proxy/examples/origin.rs b/crates/proxy/examples/origin.rs index 0c6cdec..26392ec 100644 --- a/crates/proxy/examples/origin.rs +++ b/crates/proxy/examples/origin.rs @@ -1,6 +1,7 @@ use anyhow::Result; use axum::http::StatusCode; use axum::{routing::any, Router}; +use tokio::net::TcpListener; use tokio::time::{sleep, Duration}; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; @@ -20,10 +21,9 @@ async fn main() -> Result<()> { .route("/timeout", any(timeout_handler)); let addr = "0.0.0.0:8080"; + let listener = TcpListener::bind(addr).await?; tracing::info!("origin listening on {}", addr); - axum::Server::bind(&addr.parse()?) - .serve(origin.into_make_service()) - .await?; + axum::serve(listener, origin).await?; Ok(()) } diff --git a/crates/proxy/src/lib.rs b/crates/proxy/src/lib.rs index 43c61f7..ed775de 100644 --- a/crates/proxy/src/lib.rs +++ b/crates/proxy/src/lib.rs @@ -15,11 +15,9 @@ use std::result::Result as StdResult; use anyhow::Result; use axum::body::Body; use axum::extract::{Extension, State}; -use axum::http::Request; -use axum::http::StatusCode; +use axum::http::{HeaderMap, Request, StatusCode}; use axum::response::IntoResponse; use axum::{routing::any, Router}; -use hyper::HeaderMap; use queue::RetryQueue; use serde::Deserialize; use sqlx::sqlite::SqlitePool; @@ -32,12 +30,21 @@ use crate::proxy::{proxy, Client}; use crate::request::HttpRequest; use crate::request::State as RequestState; +#[derive(Debug, Default, Deserialize)] +#[serde(default)] +pub struct Tls { + pub enable: bool, + pub cert_path: Option, + pub key_path: Option, +} + #[derive(Debug, Deserialize)] #[serde(default)] pub struct Config { pub database_url: String, pub management_listener: String, pub ingest_listener: String, + pub tls: Tls, } impl Default for Config { @@ -48,6 +55,11 @@ impl Default for Config { database_url: "sqlite::memory:".to_string(), management_listener: "0.0.0.0:3443".to_string(), ingest_listener: "0.0.0.0:3000".to_string(), + tls: Tls { + enable: false, + cert_path: None, + key_path: None, + }, } } } @@ -85,7 +97,7 @@ async fn handler( let uri = req.uri().to_string(); let headers = transform_headers(req.headers()); let body = req.into_body(); - let body = hyper::body::to_bytes(body).await?; + let body = axum::body::to_bytes(body, 1_000_000).await?; let r = HttpRequest { method, uri, diff --git a/crates/proxy/src/main.rs b/crates/proxy/src/main.rs index 18d4b43..a0cc8ea 100644 --- a/crates/proxy/src/main.rs +++ b/crates/proxy/src/main.rs @@ -1,4 +1,5 @@ use anyhow::Result; +use axum_server::tls_rustls::RustlsConfig; use clap::Parser; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; @@ -32,7 +33,7 @@ async fn main() -> Result<()> { tokio::spawn(async move { tracing::info!("management API listening on {}", mgmt_listener); - if let Err(err) = axum::Server::bind(&mgmt_listener) + if let Err(err) = axum_server::bind(mgmt_listener) .serve(mgmt.into_make_service()) .await { @@ -45,10 +46,25 @@ async fn main() -> Result<()> { retry_queue.start().await; }); + let tls_config = if config.tls.enable { + let cert_path = config.tls.cert_path.unwrap(); + let key_path = config.tls.key_path.unwrap(); + Some(RustlsConfig::from_pem_file(cert_path, key_path).await?) + } else { + None + }; + tracing::info!("ingest listening on {}", ingest_listener); - axum::Server::bind(&ingest_listener) - .serve(ingest.into_make_service()) - .await?; + if let Some(tls_config) = tls_config { + tracing::info!("tls configured for {}", ingest_listener); + axum_server::bind_rustls(ingest_listener, tls_config) + .serve(ingest.into_make_service()) + .await?; + } else { + axum_server::bind(ingest_listener) + .serve(ingest.into_make_service()) + .await?; + } Ok(()) } diff --git a/crates/proxy/src/origin.rs b/crates/proxy/src/origin.rs index 8d09347..b1bf4e3 100644 --- a/crates/proxy/src/origin.rs +++ b/crates/proxy/src/origin.rs @@ -1,4 +1,4 @@ -use axum::http::Uri; +use hyper::Uri; pub struct Origin { pub uri: Uri, diff --git a/crates/proxy/src/proxy.rs b/crates/proxy/src/proxy.rs index 81f6d74..69d6fac 100644 --- a/crates/proxy/src/proxy.rs +++ b/crates/proxy/src/proxy.rs @@ -1,9 +1,6 @@ use anyhow::{anyhow, Result}; -use axum::http::Request; -use axum::http::Uri; use hyper::client::HttpConnector; -use hyper::Body; -use hyper::Response; +use hyper::{Body, Request, Response, Uri}; use sqlx::SqlitePool; use tokio::time::{timeout, Duration}; diff --git a/crates/proxy/tests/integration/common.rs b/crates/proxy/tests/integration/common.rs index 1b66e0d..6941f4f 100644 --- a/crates/proxy/tests/integration/common.rs +++ b/crates/proxy/tests/integration/common.rs @@ -27,5 +27,6 @@ pub fn config() -> Config { database_url: "sqlite::memory:".to_string(), management_listener: "0.0.0.0:3443".to_string(), ingest_listener: "0.0.0.0:3000".to_string(), + tls: Default::default(), } } diff --git a/crates/proxy/tests/integration/ingest.rs b/crates/proxy/tests/integration/ingest.rs index 2281e2d..cda9530 100644 --- a/crates/proxy/tests/integration/ingest.rs +++ b/crates/proxy/tests/integration/ingest.rs @@ -1,6 +1,5 @@ use crate::common; -use std::net::{SocketAddr, TcpListener}; use std::sync::Arc; use axum::body::Body; @@ -9,6 +8,7 @@ use axum::http::Request; use axum::http::StatusCode; use axum::{routing::post, Router}; use soldr::db::RequestState; +use tokio::net::TcpListener; use tokio::sync::Mutex; use tokio::time::{sleep, Duration}; use tower::util::ServiceExt; @@ -42,18 +42,14 @@ async fn timeout_handler() -> impl axum::response::IntoResponse { #[tokio::test] async fn ingest_save_and_proxy() { // set up origin server - let listener = TcpListener::bind("0.0.0.0:0".parse::().unwrap()).unwrap(); + let listener = TcpListener::bind("0.0.0.0:0").await.unwrap(); let port = listener.local_addr().unwrap().port(); let sentinel: Sentinel = Arc::new(Mutex::new(None)); let s2 = sentinel.clone(); let client_app = Router::new().route("/", post(success_handler).with_state(s2)); tokio::spawn(async move { - axum::Server::from_tcp(listener) - .unwrap() - .serve(client_app.into_make_service()) - .await - .unwrap(); + axum::serve(listener, client_app).await.unwrap(); }); let (ingest, mgmt, _) = app(&common::config()).await.unwrap(); @@ -74,7 +70,7 @@ async fn ingest_save_and_proxy() { .method("POST") .uri("/origins") .header("Content-Type", "application/json") - .body(body.into()) + .body(body) .unwrap(), ) .await @@ -117,7 +113,9 @@ async fn ingest_save_and_proxy() { assert_eq!(response.status(), StatusCode::OK); - let body = hyper::body::to_bytes(response.into_body()).await.unwrap(); + let body = axum::body::to_bytes(response.into_body(), 1_000_000) + .await + .unwrap(); let reqs: Vec = serde_json::from_slice(&body).unwrap(); assert_eq!(reqs[0].state, RequestState::Completed); @@ -137,7 +135,9 @@ async fn ingest_save_and_proxy() { assert_eq!(response.status(), StatusCode::OK); - let body = hyper::body::to_bytes(response.into_body()).await.unwrap(); + let body = axum::body::to_bytes(response.into_body(), 1_000_000) + .await + .unwrap(); let attempts: Vec = serde_json::from_slice(&body).unwrap(); assert_eq!(attempts[0].id, 1); @@ -154,16 +154,12 @@ async fn ingest_proxy_failure() { common::enable_tracing(); // set up origin server - let listener = TcpListener::bind("0.0.0.0:0".parse::().unwrap()).unwrap(); + let listener = TcpListener::bind("0.0.0.0:0").await.unwrap(); let port = listener.local_addr().unwrap().port(); let client_app = Router::new().route("/failure", post(failure_handler)); tokio::spawn(async move { - axum::Server::from_tcp(listener) - .unwrap() - .serve(client_app.into_make_service()) - .await - .unwrap(); + axum::serve(listener, client_app).await.unwrap(); }); let (ingest, mgmt, _) = app(&common::config()).await.unwrap(); @@ -190,7 +186,7 @@ async fn ingest_proxy_failure() { .method("POST") .uri("/origins") .header("Content-Type", "application/json") - .body(body.into()) + .body(body) .unwrap(), ) .await @@ -231,7 +227,9 @@ async fn ingest_proxy_failure() { assert_eq!(response.status(), StatusCode::OK); - let body = hyper::body::to_bytes(response.into_body()).await.unwrap(); + let body = axum::body::to_bytes(response.into_body(), 1_000_000) + .await + .unwrap(); let reqs: Vec = serde_json::from_slice(&body).unwrap(); assert_eq!(reqs[0].state, RequestState::Failed); @@ -251,7 +249,9 @@ async fn ingest_proxy_failure() { assert_eq!(response.status(), StatusCode::OK); - let body = hyper::body::to_bytes(response.into_body()).await.unwrap(); + let body = axum::body::to_bytes(response.into_body(), 1_000_000) + .await + .unwrap(); let attempts: Vec = serde_json::from_slice(&body).unwrap(); assert_eq!(attempts[0].id, 1); @@ -265,16 +265,12 @@ async fn ingest_proxy_timeout() { common::enable_tracing(); // set up origin server - let listener = TcpListener::bind("0.0.0.0:0".parse::().unwrap()).unwrap(); + let listener = TcpListener::bind("0.0.0.0:0").await.unwrap(); let port = listener.local_addr().unwrap().port(); let client_app = Router::new().route("/timeout", post(timeout_handler)); tokio::spawn(async move { - axum::Server::from_tcp(listener) - .unwrap() - .serve(client_app.into_make_service()) - .await - .unwrap(); + axum::serve(listener, client_app).await.unwrap(); }); let (ingest, mgmt, _) = app(&common::config()).await.unwrap(); @@ -295,7 +291,7 @@ async fn ingest_proxy_timeout() { .method("POST") .uri("/origins") .header("Content-Type", "application/json") - .body(body.into()) + .body(body) .unwrap(), ) .await @@ -336,7 +332,9 @@ async fn ingest_proxy_timeout() { assert_eq!(response.status(), StatusCode::OK); - let body = hyper::body::to_bytes(response.into_body()).await.unwrap(); + let body = axum::body::to_bytes(response.into_body(), 1_000_000) + .await + .unwrap(); let reqs: Vec = serde_json::from_slice(&body).unwrap(); assert_eq!(reqs[0].state, RequestState::Timeout); @@ -356,7 +354,9 @@ async fn ingest_proxy_timeout() { assert_eq!(response.status(), StatusCode::OK); - let body = hyper::body::to_bytes(response.into_body()).await.unwrap(); + let body = axum::body::to_bytes(response.into_body(), 1_000_000) + .await + .unwrap(); let attempts: Vec = serde_json::from_slice(&body).unwrap(); assert_eq!(attempts[0].id, 1); diff --git a/crates/proxy/tests/integration/mgmt.rs b/crates/proxy/tests/integration/mgmt.rs index ad964db..f694693 100644 --- a/crates/proxy/tests/integration/mgmt.rs +++ b/crates/proxy/tests/integration/mgmt.rs @@ -26,7 +26,9 @@ async fn mgmt_list_requests() { assert_eq!(response.status(), StatusCode::OK); - let body = hyper::body::to_bytes(response.into_body()).await.unwrap(); + let body = axum::body::to_bytes(response.into_body(), 1_000_000) + .await + .unwrap(); assert_eq!(&body[..], b"[]"); } @@ -47,7 +49,7 @@ async fn mgmt_create_origin() { .method("POST") .uri("/origins") .header("Content-Type", "application/json") - .body(body.into()) + .body(body) .unwrap(), ) .await @@ -55,7 +57,9 @@ async fn mgmt_create_origin() { assert_eq!(response.status(), StatusCode::OK); - let body = hyper::body::to_bytes(response.into_body()).await.unwrap(); + let body = axum::body::to_bytes(response.into_body(), 1_000_000) + .await + .unwrap(); let origin: Origin = serde_json::from_slice(&body).unwrap(); assert_eq!(origin.id, 1); assert_eq!(origin.domain, create_origin.domain); diff --git a/crates/proxy/tests/integration/queue.rs b/crates/proxy/tests/integration/queue.rs index 9879c6f..abe4787 100644 --- a/crates/proxy/tests/integration/queue.rs +++ b/crates/proxy/tests/integration/queue.rs @@ -1,16 +1,16 @@ use crate::common; -use std::net::{SocketAddr, TcpListener}; use std::time::{SystemTime, UNIX_EPOCH}; use axum::body::Body; use axum::http::Request; use axum::http::StatusCode; use axum::{routing::post, Router}; -use soldr::db::RequestState; +use tokio::net::TcpListener; use tower::util::ServiceExt; use shared_types::NewOrigin; +use soldr::db::RequestState; use soldr::mgmt::NewQueueRequest; use soldr::{app, db}; @@ -26,16 +26,12 @@ async fn queue_retry_request() { common::enable_tracing(); // set up origin server - let listener = TcpListener::bind("0.0.0.0:0".parse::().unwrap()).unwrap(); + let listener = TcpListener::bind("0.0.0.0:0").await.unwrap(); let port = listener.local_addr().unwrap().port(); let client_app = Router::new().route("/failure", post(failure_handler)); tokio::spawn(async move { - axum::Server::from_tcp(listener) - .unwrap() - .serve(client_app.into_make_service()) - .await - .unwrap(); + axum::serve(listener, client_app).await.unwrap(); }); let (ingest, mgmt, retry_queue) = app(&common::config()).await.unwrap(); @@ -56,7 +52,7 @@ async fn queue_retry_request() { .method("POST") .uri("/origins") .header("Content-Type", "application/json") - .body(body.into()) + .body(body) .unwrap(), ) .await @@ -97,7 +93,9 @@ async fn queue_retry_request() { assert_eq!(response.status(), StatusCode::OK); - let body = hyper::body::to_bytes(response.into_body()).await.unwrap(); + let body = axum::body::to_bytes(response.into_body(), 1_000_000) + .await + .unwrap(); let reqs: Vec = serde_json::from_slice(&body).unwrap(); assert_eq!(reqs[0].state, RequestState::Failed); @@ -118,7 +116,9 @@ async fn queue_retry_request() { assert_eq!(response.status(), StatusCode::OK); - let body = hyper::body::to_bytes(response.into_body()).await.unwrap(); + let body = axum::body::to_bytes(response.into_body(), 1_000_000) + .await + .unwrap(); let attempts: Vec = serde_json::from_slice(&body).unwrap(); assert_eq!(attempts[0].id, 1); @@ -139,7 +139,7 @@ async fn queue_retry_request() { .method("POST") .uri("/queue") .header("Content-Type", "application/json") - .body(body.into()) + .body(body) .unwrap(), ) .await @@ -164,7 +164,9 @@ async fn queue_retry_request() { assert_eq!(response.status(), StatusCode::OK); - let body = hyper::body::to_bytes(response.into_body()).await.unwrap(); + let body = axum::body::to_bytes(response.into_body(), 1_000_000) + .await + .unwrap(); let attempts: Vec = serde_json::from_slice(&body).unwrap(); assert_eq!(attempts[1].id, 2); @@ -186,7 +188,9 @@ async fn queue_retry_request() { assert_eq!(response.status(), StatusCode::OK); - let body = hyper::body::to_bytes(response.into_body()).await.unwrap(); + let body = axum::body::to_bytes(response.into_body(), 1_000_000) + .await + .unwrap(); let requests: Vec = serde_json::from_slice(&body).unwrap(); diff --git a/soldr.example.toml b/soldr.example.toml index a13d233..967a5b7 100644 --- a/soldr.example.toml +++ b/soldr.example.toml @@ -1,3 +1,9 @@ database_url = "sqlite:soldr.db?mode=rwc" management_listener = "0.0.0.0:3443" ingest_listener = "0.0.0.0:3000" + +[tls] +enable = false +cert_path = "certs/localhost.crt" +key_path = "certs/localhost.key" +