Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
180471e
Rename crates to trusted-server-core and trusted-server-adapter-fastly
prk-Jr Mar 18, 2026
f63e5b2
Add platform abstraction layer with traits and RuntimeServices
prk-Jr Mar 19, 2026
020e88c
Merge remote-tracking branch 'origin/main' into feature/edgezero-pr1-…
prk-Jr Mar 19, 2026
37c8fbf
Merge branch 'feature/edgezero-pr1-crate-rename' into feature/edgezer…
prk-Jr Mar 19, 2026
7495d96
Merge branch 'main' into feature/edgezero-pr2-platform-traits
prk-Jr Mar 20, 2026
2c40d58
Address platform layer review feedback
prk-Jr Mar 20, 2026
46e3360
Reject host strings containing control characters in BackendConfig
prk-Jr Mar 20, 2026
2f40b4c
Fix clippy error
prk-Jr Mar 20, 2026
8210a85
Validate scheme and host for control characters in BackendConfig
prk-Jr Mar 20, 2026
99d7bee
Address review findings on platform abstraction layer
prk-Jr Mar 22, 2026
a2597e5
Address review findings on platform abstraction layer
prk-Jr Mar 22, 2026
d7a35a1
Merge branch 'main' into feature/edgezero-pr2-platform-traits
prk-Jr Mar 22, 2026
d8b267b
Add config store read path and storage module split
prk-Jr Mar 23, 2026
ce456a9
Merge branch 'main' into feature/edgezero-pr3-config-store
prk-Jr Mar 23, 2026
ed57b14
Merge branch 'main' into feature/edgezero-pr3-config-store
prk-Jr Mar 24, 2026
a8c5648
Harden legacy config-store reads and align Fastly adapter stubs
prk-Jr Mar 24, 2026
14e54c4
Address storage review feedback
prk-Jr Mar 25, 2026
c682c6d
Resolved github-advanced-security bot problems
prk-Jr Mar 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub struct UserId(Uuid);
- Use concrete error types with `Report<E>`.
- Use `ensure!()` / `bail!()` macros for early returns.
- Import `Error` from `core::error::` instead of `std::error::`.
- Use `change_context()` to map error types, `attach()` / `attach_with()` for debug info.
- Use `change_context()` to map error types, `attach()` for debug info.
- Define errors with `derive_more::Display` (not thiserror):

```rust
Expand Down
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion crates/trusted-server-adapter-fastly/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ edition = "2021"
workspace = true

[dependencies]
async-trait = { workspace = true }
bytes = { workspace = true }
chrono = { workspace = true }
edgezero-adapter-fastly = { workspace = true }
edgezero-adapter-fastly = { workspace = true, features = ["fastly"] }
edgezero-core = { workspace = true }
error-stack = { workspace = true }
fastly = { workspace = true }
fern = { workspace = true }
Expand All @@ -19,3 +22,6 @@ serde = { workspace = true }
serde_json = { workspace = true }
trusted-server-core = { path = "../trusted-server-core" }
trusted-server-js = { path = "../js" }

[dev-dependencies]
edgezero-core = { workspace = true, features = ["test-utils"] }
36 changes: 33 additions & 3 deletions crates/trusted-server-adapter-fastly/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use trusted_server_core::error::TrustedServerError;
use trusted_server_core::geo::GeoInfo;
use trusted_server_core::http_util::sanitize_forwarded_headers;
use trusted_server_core::integrations::IntegrationRegistry;
use trusted_server_core::platform::RuntimeServices;
use trusted_server_core::proxy::{
handle_first_party_click, handle_first_party_proxy, handle_first_party_proxy_rebuild,
handle_first_party_proxy_sign,
Expand All @@ -27,7 +28,10 @@ use trusted_server_core::settings::Settings;
use trusted_server_core::settings_data::get_settings;

mod error;
mod platform;

use crate::error::to_error_response;
use crate::platform::{build_runtime_services, open_kv_store, UnavailableKvStore};

#[fastly::main]
fn main(req: Request) -> Result<Response, Error> {
Expand Down Expand Up @@ -59,10 +63,28 @@ fn main(req: Request) -> Result<Response, Error> {
}
};

let kv_store = match open_kv_store(&settings.synthetic.opid_store) {
Ok(s) => s,
Err(e) => {
// Degrade gracefully: routes that do not touch synthetic IDs
// (e.g. /.well-known/, /verify-signature, /admin/keys/*) must
// still succeed even when the KV store is unavailable.
// Handlers that call kv_handle() will receive KvError::Unavailable.
log::warn!(
"KV store '{}' unavailable, synthetic ID routes will return errors: {e}",
settings.synthetic.opid_store
);
std::sync::Arc::new(UnavailableKvStore)
as std::sync::Arc<dyn trusted_server_core::platform::PlatformKvStore>
}
};
let runtime_services = build_runtime_services(&req, kv_store);

futures::executor::block_on(route_request(
&settings,
&orchestrator,
&integration_registry,
&runtime_services,
req,
))
}
Expand All @@ -71,15 +93,23 @@ async fn route_request(
settings: &Settings,
orchestrator: &AuctionOrchestrator,
integration_registry: &IntegrationRegistry,
runtime_services: &RuntimeServices,
mut req: Request,
) -> Result<Response, Error> {
// Strip client-spoofable forwarded headers at the edge.
// On Fastly this service IS the first proxy — these headers from
// clients are untrusted and can hijack URL rewriting (see #409).
sanitize_forwarded_headers(&mut req);

// Extract geo info before auth check or routing consumes the request
let geo_info = GeoInfo::from_request(&req);
// Look up geo info via the platform abstraction using the client IP
// already captured in RuntimeServices at the entry point.
let geo_info = runtime_services
.geo()
.lookup(runtime_services.client_info.client_ip)
.unwrap_or_else(|e| {
log::warn!("geo lookup failed: {e}");
None
});

if let Some(mut response) = enforce_basic_auth(settings, &req) {
finalize_response(settings, geo_info.as_ref(), &mut response);
Expand All @@ -99,7 +129,7 @@ async fn route_request(

// Discovery endpoint for trusted-server capabilities and JWKS
(Method::GET, "/.well-known/trusted-server.json") => {
handle_trusted_server_discovery(settings, req)
handle_trusted_server_discovery(settings, runtime_services, req)
}

// Signature verification endpoint
Expand Down
Loading
Loading