diff --git a/Cargo.lock b/Cargo.lock index 0ca4b2df1..f5a47b750 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -169,6 +169,17 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chacha20" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d524456ba66e72eb8b115ff89e01e497f8e6d11d78b70b1aa13c0fbd97540a81" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "rand_core", +] + [[package]] name = "chrono" version = "0.4.38" @@ -254,6 +265,15 @@ dependencies = [ "libc", ] +[[package]] +name = "cpufeatures" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" +dependencies = [ + "libc", +] + [[package]] name = "curl" version = "0.4.47" @@ -394,6 +414,7 @@ name = "fastly-compute-project" version = "0.1.0" dependencies = [ "fastly", + "uuid", ] [[package]] @@ -530,6 +551,18 @@ dependencies = [ "version_check", ] +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "rand_core", +] + [[package]] name = "gimli" version = "0.31.1" @@ -1110,6 +1143,29 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rand" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" +dependencies = [ + "chacha20", + "getrandom", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + [[package]] name = "reqwest" version = "0.11.27" @@ -1301,7 +1357,7 @@ checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" dependencies = [ "block-buffer", "cfg-if", - "cpufeatures", + "cpufeatures 0.2.17", "digest", "opaque-debug", ] @@ -1612,6 +1668,18 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "uuid" +version = "1.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f053576934f05a761a402421fbbe3d425d9366f75f978806a037b3ca481abecc" +dependencies = [ + "getrandom", + "js-sys", + "rand", + "wasm-bindgen", +] + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/terraform/docs-rs/fastly-compute-docs-rs/Cargo.toml b/terraform/docs-rs/fastly-compute-docs-rs/Cargo.toml index 16c95680e..e47f9cf85 100644 --- a/terraform/docs-rs/fastly-compute-docs-rs/Cargo.toml +++ b/terraform/docs-rs/fastly-compute-docs-rs/Cargo.toml @@ -6,3 +6,5 @@ publish = false [dependencies] fastly = "0.12.1" +uuid = { version = "1.25.0", features = ["v4", "fast-rng"] } + diff --git a/terraform/docs-rs/fastly-compute-docs-rs/src/main.rs b/terraform/docs-rs/fastly-compute-docs-rs/src/main.rs index 0f36f3897..266cb1245 100644 --- a/terraform/docs-rs/fastly-compute-docs-rs/src/main.rs +++ b/terraform/docs-rs/fastly-compute-docs-rs/src/main.rs @@ -9,6 +9,7 @@ use fastly::{ header::{CACHE_CONTROL, EXPIRES, STRICT_TRANSPORT_SECURITY}, }, }; +use uuid::Uuid; // Should match the backend name in terraform const DOCS_RS_BACKEND: &str = "docs_rs_origin"; @@ -27,9 +28,10 @@ const NGWAF_WORKSPACE_KEY: &str = "ngwaf_workspace"; const FASTLY_CLIENT_IP: HeaderName = HeaderName::from_static("fastly-client-ip"); const SURROGATE_CONTROL: HeaderName = HeaderName::from_static("surrogate-control"); -const X_ORIGIN_AUTH: HeaderName = HeaderName::from_static("x-origin-auth"); const X_COMPRESS_HINT: HeaderName = HeaderName::from_static("x-compress-hint"); const X_FORWARDED_HOST: HeaderName = HeaderName::from_static("x-forwarded-host"); +const X_ORIGIN_AUTH: HeaderName = HeaderName::from_static("x-origin-auth"); +const X_REQUEST_ID: HeaderName = HeaderName::from_static("x-request-id"); #[fastly::main] fn main(mut req: Request) -> Result { @@ -82,6 +84,14 @@ fn main(mut req: Request) -> Result { } } + // Generate the request ID at the POP receiving the client request. On + // shield POPs, preserve the ID set by the edge POP. + if shield.response_is_for_client() { + req.set_header(X_REQUEST_ID, Uuid::new_v4().to_string()); + } else if !req.contains_header(&X_REQUEST_ID) { + eprintln!("shield POP received request without expected X-Request-ID header from edge POP"); + } + if shield.target_is_origin() { let origin_auth = secrets .get(ORIGIN_AUTH_KEY)