feat(security): harden gateway boundaries and usage policies

Consolidate subscription usage policy enforcement, privacy-safe persistence, and gateway security hardening into one reviewable change.

Includes bounded HTTP and execution envelopes, header and protocol guards, DNS and relay validation, authentication and secret projection hardening, secure backup/install paths, and regression coverage.
This commit is contained in:
elky
2026-09-04 03:45:52 +08:00
parent ddcbeb3ae9
commit 579f2c7cc1
1019 changed files with 190437 additions and 26080 deletions
+4 -1
View File
@@ -35,4 +35,7 @@ pub use gateway::{GatewayHarness, GatewayHarnessConfig, GATEWAY_HARNESS_API_KEY}
#[cfg(feature = "postgres")]
pub use postgres::{prepare_aether_postgres_schema, ManagedPostgresServer};
#[cfg(feature = "gateway")]
pub use tunnel::{TunnelHarness, TunnelHarnessConfig};
pub use tunnel::{
insert_tunnel_harness_auth_headers, TunnelHarness, TunnelHarnessConfig,
TUNNEL_HARNESS_GENERATION, TUNNEL_HARNESS_MANAGEMENT_TOKEN, TUNNEL_HARNESS_NODE_ID,
};
@@ -8,8 +8,13 @@ use aether_runtime_state::RuntimeSemaphore;
use crate::server::SpawnedServer;
pub const TUNNEL_HARNESS_NODE_ID: &str = "node-baseline";
pub const TUNNEL_HARNESS_GENERATION: &str = "tunnel-harness-generation-1";
pub const TUNNEL_HARNESS_MANAGEMENT_TOKEN: &str = "ae-tunnel-harness-management-token";
#[derive(Debug, Clone)]
pub struct TunnelHarnessConfig {
pub node_id: String,
pub max_streams: usize,
pub ping_interval: Duration,
pub outbound_queue_capacity: usize,
@@ -20,6 +25,7 @@ pub struct TunnelHarnessConfig {
impl Default for TunnelHarnessConfig {
fn default() -> Self {
Self {
node_id: TUNNEL_HARNESS_NODE_ID.to_string(),
max_streams: 128,
ping_interval: Duration::from_secs(15),
outbound_queue_capacity: 128,
@@ -62,6 +68,12 @@ impl TunnelHarness {
} else {
state
};
let state = aether_gateway::configure_test_tunnel_runtime_auth(
state,
&config.node_id,
TUNNEL_HARNESS_GENERATION,
TUNNEL_HARNESS_MANAGEMENT_TOKEN,
)?;
let router = build_tunnel_runtime_router_with_state(state);
let server = match port {
Some(port) => SpawnedServer::start_on_port(port, router)
@@ -82,3 +94,19 @@ impl TunnelHarness {
self.server.port()
}
}
pub fn insert_tunnel_harness_auth_headers(
headers: &mut http::HeaderMap,
node_id: &str,
) -> Result<(), http::header::InvalidHeaderValue> {
headers.insert("x-node-id", http::HeaderValue::from_str(node_id)?);
headers.insert(
aether_contracts::tunnel_security::TUNNEL_GENERATION_HEADER,
http::HeaderValue::from_static(TUNNEL_HARNESS_GENERATION),
);
headers.insert(
http::header::AUTHORIZATION,
http::HeaderValue::from_static(concat!("Bearer ", "ae-tunnel-harness-management-token")),
);
Ok(())
}