Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Cargo.lock

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

8 changes: 8 additions & 0 deletions crates/edgezero-adapter-axum/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,14 @@ mod tests {
}
}

#[test]
fn client_identities_are_unsupported() {
assert_eq!(
AXUM_ADAPTER.capability(Capability::OutboundClientIdentity),
CapabilitySupport::Unsupported
);
}

#[test]
fn adapter_capability_matrix_matches_contracts() {
let connect = AXUM_ADAPTER.capability(Capability::OutboundConnectTimeout);
Expand Down
37 changes: 33 additions & 4 deletions crates/edgezero-adapter-axum/src/outbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ use edgezero_core::outbound::test_support::{
NativeBodyRecorder, native_body_recorder, observe_sdk_read, own_sdk_operation, own_sdk_source,
};
use edgezero_core::outbound::{
OutboundBatch, OutboundBatchDriverEvent, OutboundDispatchRequest, OutboundExchangeOwner,
OutboundFuture, OutboundHead, OutboundHeaderFidelity, OutboundHeaderInput, OutboundHttpClient,
OutboundPending, OutboundPreparedBatch, OutboundRequest, OutboundRequestParts,
OutboundResponse, OutboundResponseContext, OutboundSendMode, OutboundTask, OutboundTime,
ClientIdentityError, OutboundBatch, OutboundBatchDriverEvent, OutboundDispatchRequest,
OutboundExchangeOwner, OutboundFuture, OutboundHead, OutboundHeaderFidelity,
OutboundHeaderInput, OutboundHttpClient, OutboundPending, OutboundPreparedBatch,
OutboundRequest, OutboundRequestParts, OutboundResponse, OutboundResponseContext,
OutboundSendMode, OutboundTask, OutboundTime,
};
use edgezero_core::time::{Deadline, DispatchBudget, MonotonicClock, MonotonicInstant};
use futures::channel::{mpsc, oneshot};
Expand Down Expand Up @@ -157,6 +158,12 @@ impl AxumOutboundClient {
}

fn validate_options(request: &OutboundRequest) -> Result<(), EdgeError> {
if let Some(name) = request.client_identity_name() {
return Err(EdgeError::client_identity(
name,
ClientIdentityError::Unsupported { adapter: "axum" },
));
}
if request.image_optimizer_options().is_some() {
return Err(EdgeError::bad_request(
"image_optimizer is not supported by axum",
Expand Down Expand Up @@ -1267,6 +1274,28 @@ mod clock_tests {
.expect("zero connect timeout conformance");
}

#[test]
fn client_identity_is_unsupported_without_transport() {
use edgezero_core::outbound::ClientIdentityName;
use futures::FutureExt as _;
let executor_owner = AxumOutboundExecutor::new();
let client = edgezero_core::HttpClient::with_client(
AxumOutboundClient::try_new(executor_owner.handle()).expect("client"),
);
let request = OutboundRequest::get("https://127.0.0.1:9/mtls")
.expect("request")
.client_identity(ClientIdentityName::new("mtls").expect("name"));
let error = client
.send(request)
.now_or_never()
.expect("rejected before any transport")
.expect_err("axum cannot present client identities");
assert_eq!(
error.client_identity_error(),
Some(&ClientIdentityError::Unsupported { adapter: "axum" })
);
}

#[test]
fn unsupported_optimizer_precedes_expiry_without_transport() {
use edgezero_core::outbound::test_support::check_unsupported_image_optimizer_preflight;
Expand Down
4 changes: 4 additions & 0 deletions crates/edgezero-adapter-cloudflare/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,10 @@ mod tests {
CapabilitySupport::Native,
),
(Capability::OutboundCacheBypass, CapabilitySupport::Native),
(
Capability::OutboundClientIdentity,
CapabilitySupport::Unsupported,
),
(
Capability::OutboundImageOptimizer,
CapabilitySupport::Unsupported,
Expand Down
13 changes: 13 additions & 0 deletions crates/edgezero-adapter-cloudflare/src/outbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ use edgezero_core::error::{BadGatewayReason, BudgetSource};
all(feature = "cloudflare", target_arch = "wasm32"),
feature = "test-utils"
))]
use edgezero_core::outbound::ClientIdentityError;
#[cfg(any(
all(feature = "cloudflare", target_arch = "wasm32"),
feature = "test-utils"
))]
use edgezero_core::outbound::OutboundRequest;
#[cfg(feature = "test-utils")]
use edgezero_core::outbound::{OutboundSendMode, validate_for_dispatch};
Expand Down Expand Up @@ -3843,6 +3848,14 @@ fn timeout_error(cause: BudgetSource) -> EdgeError {
feature = "test-utils"
))]
fn validate_supported_options(request: &OutboundRequest) -> Result<(), EdgeError> {
if let Some(name) = request.client_identity_name() {
return Err(EdgeError::client_identity(
name,
ClientIdentityError::Unsupported {
adapter: "cloudflare",
},
));
}
if request.image_optimizer_options().is_some() {
return Err(EdgeError::bad_request(
"image_optimizer is not supported by cloudflare",
Expand Down
16 changes: 16 additions & 0 deletions crates/edgezero-adapter-cloudflare/tests/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1982,6 +1982,22 @@ mod native_tests {
use futures_util::stream;
use std::time::Duration;

#[test]
fn client_identity_is_unsupported_before_other_preflight() {
let request = OutboundRequest::get("https://example.com/mtls")
.unwrap()
.client_identity(edgezero_core::ClientIdentityName::new("mtls").unwrap())
.body(Body::from_stream(stream::pending()))
.timeout(Duration::ZERO);
let error = validate_batch_request_for_test(&request).expect_err("unsupported");
assert_eq!(
error.client_identity_error(),
Some(&edgezero_core::ClientIdentityError::Unsupported {
adapter: "cloudflare"
})
);
}

#[test]
fn image_optimizer_rejection_precedes_other_preflight() {
let request = OutboundRequest::get("https://example.com/image")
Expand Down
85 changes: 85 additions & 0 deletions crates/edgezero-adapter-fastly/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use edgezero_adapter::scaffold::{
ManifestSpec, ReadmeInfo, TemplateRegistration, register_adapter_blueprint,
};
use edgezero_core::env_config::{EnvConfig, merge_env_defaults};
use edgezero_core::manifest::Manifest;
use edgezero_core::{Capability, CapabilitySupport, PlatformMetadata};
use walkdir::WalkDir;

Expand Down Expand Up @@ -2041,6 +2042,7 @@ impl Adapter for FastlyCliAdapter {
Capability::IngressAdmission
| Capability::OutboundAuthorityOverride
| Capability::OutboundCacheBypass
| Capability::OutboundClientIdentity
| Capability::OutboundConnectTimeout
| Capability::OutboundFailureDiagnostics
| Capability::OutboundFlexiblePhaseBudget
Expand Down Expand Up @@ -2227,6 +2229,10 @@ impl Adapter for FastlyCliAdapter {
validate_fastly_config_key(logical_store_id, key, staging, local)
}

fn validate_client_identities(&self, manifest: &Manifest) -> Result<(), String> {
validate_fastly_client_identities(manifest)
}

fn preflight_deploy(
&self,
context: &AdapterDeployContext,
Expand Down Expand Up @@ -5913,6 +5919,36 @@ fn effective_deploy_environment(context: &AdapterDeployContext) -> Result<EnvCon
Ok(environment)
}

/// Fastly reads each client identity's certificate and hosts from a config store
/// and its key from a secret store, so both must resolve from the manifest.
fn validate_fastly_client_identities(manifest: &Manifest) -> Result<(), String> {
let unresolved: Vec<String> = manifest
.capabilities
.outbound
.client_identities
.iter()
.filter_map(|(name, identity)| {
let mut missing = Vec::new();
if identity.resolved_config_store(&manifest.stores).is_none() {
missing.push("config store");
}
if identity.resolved_secret_store(&manifest.stores).is_none() {
missing.push("secret store");
}
(!missing.is_empty()).then(|| format!("`{name}` (no {})", missing.join(" or ")))
})
.collect();
if unresolved.is_empty() {
return Ok(());
}
Err(format!(
"adapter 'fastly' reads client identity bindings from a config store and a secret store, \
and these identities cannot resolve one: {}. Declare [stores.config] and [stores.secrets], \
or name the stores with `config-store` and `secret-store`.",
unresolved.join(", ")
))
}

fn validate_fastly_config_key(
logical_store_id: &str,
key: &str,
Expand Down Expand Up @@ -6979,6 +7015,51 @@ mod tests {
assert!(FASTLY_BLUEPRINT.logging.endpoint.is_none());
}

#[test]
fn client_identities_need_resolvable_config_and_secret_stores() {
use edgezero_core::manifest::ManifestLoader;

let resolvable = ManifestLoader::load_from_str(
"[capabilities.outbound.client-identities.defaulted]\n\
[capabilities.outbound.client-identities.explicit]\n\
config-store = \"app_config\"\nsecret-store = \"keys\"\n\
[stores.config]\nids = [\"app_config\"]\n\
[stores.secrets]\nids = [\"keys\"]\n",
);
assert_eq!(
FastlyCliAdapter.validate_client_identities(resolvable.manifest()),
Ok(())
);

let no_secrets = ManifestLoader::load_from_str(
"[capabilities.outbound.client-identities.mtls]\n\
[stores.config]\nids = [\"app_config\"]\n",
);
let no_secret_error = FastlyCliAdapter
.validate_client_identities(no_secrets.manifest())
.expect_err("missing secret store");
assert!(
no_secret_error.contains("`mtls` (no secret store)"),
"{no_secret_error}"
Comment thread
aram356 marked this conversation as resolved.
Dismissed
);

let no_stores =
ManifestLoader::load_from_str("[capabilities.outbound.client-identities.mtls]\n");
let no_store_error = FastlyCliAdapter
.validate_client_identities(no_stores.manifest())
.expect_err("missing both stores");
assert!(
no_store_error.contains("`mtls` (no config store or secret store)"),
"{no_store_error}"
);

let none = ManifestLoader::load_from_str("[app]\nname = \"plain\"\n");
assert_eq!(
FastlyCliAdapter.validate_client_identities(none.manifest()),
Ok(())
);
}

#[test]
fn adapter_capability_matrix_matches_contracts() {
adapter_capability_matrix_matches_outbound_spec();
Expand Down Expand Up @@ -7079,6 +7160,10 @@ mod tests {
CapabilitySupport::BestEffort,
),
(Capability::OutboundCacheBypass, CapabilitySupport::Native),
(
Capability::OutboundClientIdentity,
CapabilitySupport::Native,
),
(
Capability::OutboundImageOptimizer,
CapabilitySupport::BestEffort,
Expand Down
8 changes: 6 additions & 2 deletions crates/edgezero-adapter-fastly/src/config_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ impl FastlyConfigStore {
unsafe_code,
reason = "the pinned ABI receives a live initialized slice and cannot resize it"
)]
fn read_entry(&self, key: &str, limit: u64) -> Result<Option<String>, ConfigStoreError> {
pub(crate) fn read_entry(
&self,
key: &str,
limit: u64,
) -> Result<Option<String>, ConfigStoreError> {
let read_limit = limit.min(MAX_ENTRY_BYTES);
match &self.inner {
FastlyConfigStoreBackend::Fastly(handle) => {
Expand Down Expand Up @@ -90,7 +94,7 @@ impl FastlyConfigStore {
unsafe_code,
reason = "the pinned host ABI writes only the supplied handle out-parameter"
)]
fn try_open_optional(name: &str) -> Result<Option<Self>, ConfigStoreError> {
pub(crate) fn try_open_optional(name: &str) -> Result<Option<Self>, ConfigStoreError> {
let mut handle = fastly_shared::INVALID_CONFIG_STORE_HANDLE;
// SAFETY: the UTF-8 name slice and initialized out-parameter remain live
// for this synchronous call. Config Store exposes no close operation.
Expand Down
Loading