diff --git a/Cargo.lock b/Cargo.lock index d9c6efe..804a3d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -243,6 +243,12 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5" + [[package]] name = "base64" version = "0.21.2" @@ -1762,7 +1768,7 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" dependencies = [ - "base64", + "base64 0.21.2", ] [[package]] @@ -2255,7 +2261,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ca69bf415b93b60b80dc8fda3cb4ef52b2336614d8da2de5456cc942a110482" dependencies = [ "atoi", - "base64", + "base64 0.21.2", "bigdecimal", "bitflags 2.3.3", "byteorder", @@ -2302,7 +2308,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0db2df1b8731c3651e204629dd55e52adbae0462fa1bdcbed56a2302c18181e" dependencies = [ "atoi", - "base64", + "base64 0.21.2", "bigdecimal", "bitflags 2.3.3", "byteorder", @@ -2616,6 +2622,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8bd22a874a2d0b70452d5597b12c537331d49060824a95f49f108994f94aa4c" dependencies = [ + "base64 0.20.0", "bitflags 2.3.3", "bytes", "futures-core", diff --git a/server/Cargo.toml b/server/Cargo.toml index c147eae..bf4fd7f 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -18,7 +18,7 @@ sha256 = "1.1.4" tokio = { version = "1.29.1", features = ["full"] } tokio-util = { version = "0.7.8", features = ["io"] } tower = { version = "0.4.13", features = ["make"] } -tower-http = { version = "0.4.1", features = ["fs", "trace"] } +tower-http = { version = "0.4.1", features = ["fs", "trace", "auth"] } tracing = "0.1.37" tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } uuid = { version = "1.4.0", features = ["v4"] } diff --git a/server/src/repo/mod.rs b/server/src/repo/mod.rs index 0a28969..aec846b 100644 --- a/server/src/repo/mod.rs +++ b/server/src/repo/mod.rs @@ -17,15 +17,28 @@ use std::sync::Arc; use tokio::{fs, io::AsyncWriteExt}; use tower::util::ServiceExt; use tower_http::services::{ServeDir, ServeFile}; +use tower_http::validate_request::ValidateRequestHeaderLayer; use uuid::Uuid; pub fn router() -> Router { Router::new() - .route("/:repo", post(post_package_archive).delete(delete_repo)) - .route("/:repo/:arch", delete(delete_arch_repo)) + .route( + "/:repo", + post(post_package_archive) + .delete(delete_repo) + .layer(ValidateRequestHeaderLayer::bearer("test")), + ) + .route( + "/:repo/:arch", + delete(delete_arch_repo).layer(ValidateRequestHeaderLayer::bearer("test")), + ) + // Routes added after the layer do not get that layer applied, so the GET requests will not + // be authorized .route( "/:repo/:arch/:filename", - delete(delete_package).get(get_file), + delete(delete_package) + .layer(ValidateRequestHeaderLayer::bearer("test")) + .get(get_file), ) } @@ -57,6 +70,8 @@ async fn post_package_archive( match res { // Insert the newly added package into the database Ok(pkg) => { + tracing::info!("Added '{}' to repository '{}'", pkg.file_name(), repo); + // Query the repo for its ID, or create it if it does not already exist let repo_entity = db_repo::Entity::find() .filter(db_repo::Column::Name.eq(&repo))