From 498727e5e3d70eae826ffd2395523a13d76c4a0c Mon Sep 17 00:00:00 2001 From: "HomePC\\Kevin" Date: Sat, 28 Nov 2026 20:56:45 +0100 Subject: [PATCH 1/4] feat(apps): negotiate protocol versions per app and route the handoff abort Advertise protocol 1.1.0 and give every app the lower bound of its declared requires ranges, through the shared contract rule (negotiate_versions of rentnerproxy-app-contracts 1.4.1). Apps built for 1.0.0 keep seeing 1.0.0. - Send the negotiated versions in the launch frame and the registration, and check them against the manifest ranges before the bootstrap. - Readiness must report exactly the negotiated appProtocol of the app. - Keep provider registrations at the provider version 1.0.0. - Forward abortLegacyHandoff through the broker. Co-Authored-By: Claude Opus 5.5 --- core/Cargo.lock | 4 +- core/Cargo.toml | 2 +- core/src/app_install.rs | 30 ++++- core/src/app_ipc.rs | 106 ++++++++++++---- core/src/app_ipc/gateway.rs | 10 +- core/src/app_manager.rs | 6 + core/src/app_manager/runtime.rs | 5 +- core/tests/private/app_install.rs | 57 +++++++++ core/tests/private/app_ipc.rs | 194 ++++++++++++++++++++++++++++-- 9 files changed, 372 insertions(+), 42 deletions(-) diff --git a/core/Cargo.lock b/core/Cargo.lock index ee47aa9c7..d353aa0af 100644 --- a/core/Cargo.lock +++ b/core/Cargo.lock @@ -1998,9 +1998,9 @@ dependencies = [ [[package]] name = "rentnerproxy-app-contracts" -version = "1.2.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2eaa9d69dba6a6e32870f46f349586c7e549fa68ed71c10e177754bc6cff18ee" +checksum = "992fefcd901855c854b488cddce81a06bcb6ad2242b55dc426572608135cadc5" dependencies = [ "jsonschema", "serde_json", diff --git a/core/Cargo.toml b/core/Cargo.toml index a510ab618..8863f05f3 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -7,7 +7,7 @@ license = "MIT" [dependencies] rentnerproxy-app-catalog = "1.0.0" -rentnerproxy-app-contracts = "1.2.0" +rentnerproxy-app-contracts = "1.4.1" rentnerproxy-app-pipeline = "1.0.0" rentnerproxy-artifacts = "1.0.0" aws-lc-rs = "1.19.0" diff --git a/core/src/app_install.rs b/core/src/app_install.rs index 26e09e588..1365db021 100644 --- a/core/src/app_install.rs +++ b/core/src/app_install.rs @@ -49,7 +49,9 @@ pub(crate) use browse::CatalogEntry; any(target_arch = "x86_64", target_arch = "aarch64") ))] pub(crate) use package::{UI_ASSET_LIMIT, UI_DOCUMENT_LIMIT, parse_ui_api}; -use rentnerproxy_app_contracts::{ContractError, Contracts, ManifestEnvironment}; +use rentnerproxy_app_contracts::{ + ContractError, Contracts, ManifestEnvironment, NegotiatedVersions, +}; use rentnerproxy_artifacts::{invalid, parse_json, read_file}; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -81,7 +83,7 @@ pub(crate) use transport::{Source, unreachable_source}; /// same values (`web/src/config/app-requirements.config.ts`), so an older platform can check /// installed apps against a newer release before its image changes. pub(crate) const RUNTIME_PROFILE: &str = "rentnerproxy-linux-v1"; -pub(crate) const PROTOCOL_VERSION: &str = "1.0.0"; +pub(crate) const PROTOCOL_VERSION: &str = "1.1.0"; #[derive(Deserialize)] #[serde(rename_all = "camelCase", deny_unknown_fields)] @@ -374,6 +376,30 @@ fn catalog_outage(error: io::Error, package_answers: impl FnOnce() -> Option io::Result { + static CONTRACTS: std::sync::LazyLock> = + std::sync::LazyLock::new(Contracts::new); + let contracts = CONTRACTS + .as_ref() + .map_err(|_| invalid("Contracts unavailable"))?; + contracts + .negotiate_versions( + manifest, + &ManifestEnvironment { + // Target, profile and engine capabilities are not part of the negotiation. + target: "", + runtime_profile: RUNTIME_PROFILE, + platform_api: PROTOCOL_VERSION, + app_protocol: PROTOCOL_VERSION, + ui_bridge: Some(PROTOCOL_VERSION), + engine_capabilities: &[], + }, + ) + .map_err(invalid_contract) +} + fn invalid_contract(error: rentnerproxy_app_contracts::ContractError) -> io::Error { invalid(error.code()) } diff --git a/core/src/app_ipc.rs b/core/src/app_ipc.rs index 872b28171..f916f4ed6 100644 --- a/core/src/app_ipc.rs +++ b/core/src/app_ipc.rs @@ -28,7 +28,12 @@ pub(crate) const APP_ROOT: &str = "/run/rentnerproxy/apps"; const GATEWAY_SOCKET: &str = "/run/rentnerproxy/app-api/web.sock"; pub(crate) const WEB_UID: u32 = 10002; const PROFILE: &str = "rentnerproxy-linux-v1"; -const VERSION: &str = "1.0.0"; +/// The protocol version this platform advertises in the bootstrap descriptor and the platform +/// context. Apps may report any `1.x.y` version up to it that their manifest range admits. +const VERSION: &str = rentnerproxy_app_contracts::PROTOCOL_VERSION; +/// The provider API version of registrations. It is a wire version of its own and does not +/// move with the protocol version. +const PROVIDER_VERSION: &str = "1.0.0"; const LAUNCH_TIMEOUT: Duration = Duration::from_secs(10); const STARTUP_TIMEOUT: Duration = Duration::from_secs(30); const PROVIDER_PROFILES: [&str; 6] = [ @@ -40,6 +45,14 @@ const PROVIDER_PROFILES: [&str; 6] = [ "crowdsec", ]; +#[derive(Clone, Deserialize, Serialize)] +#[serde(deny_unknown_fields, rename_all = "camelCase")] +struct NegotiatedVersions { + app_protocol: String, + platform_api: String, + ui_bridge: Option, +} + #[derive(Deserialize, Serialize)] #[serde(deny_unknown_fields, rename_all = "camelCase")] struct LaunchConfig { @@ -57,6 +70,8 @@ struct LaunchConfig { ui_bridge: Option, startup_timeout_ms: Option, process_limit: Option, + /// The versions the manager negotiated for this app, which must lie inside its ranges. + negotiated: NegotiatedVersions, /// Provider profiles the signed manifest declares; absent means none. #[serde(default)] providers: Vec, @@ -71,6 +86,14 @@ impl LaunchConfig { .ui_bridge .as_deref() .is_some_and(|range| !supports_version(range)) + || !admitted_by(&self.negotiated.app_protocol, &self.app_protocol) + || !admitted_by(&self.negotiated.platform_api, &self.platform_api) + || match (&self.negotiated.ui_bridge, &self.ui_bridge) { + (Some(version), Some(range)) => !admitted_by(version, range), + (Some(_), None) => true, + // A manifest range without a UI negotiates no bridge version. + (None, _) => false, + } { return Err(io::Error::other( "Unsupported app runtime profile or protocol range", @@ -131,32 +154,73 @@ fn record_id(value: &str) -> bool { }) } +type Version = (u32, u32, u32); + +/// A canonical `major.minor.patch` version: numbers without leading zeros and of at most six +/// digits, the form the manifest contract admits. +fn parse_version(text: &str) -> Option { + fn number(part: &str) -> Option { + let canonical = part.len() <= 6 + && !part.is_empty() + && part.bytes().all(|byte| byte.is_ascii_digit()) + && (part.len() == 1 || !part.starts_with('0')); + if canonical { part.parse().ok() } else { None } + } + let mut parts = text.split('.'); + let version = ( + number(parts.next()?)?, + number(parts.next()?)?, + number(parts.next()?)?, + ); + parts.next().is_none().then_some(version) +} + +/// Split a manifest range of the form `>=MIN Option<(Version, Version)> { + let (min, max) = range.strip_prefix(">=")?.split_once(" <")?; + Some((parse_version(min)?, parse_version(max)?)) +} + +/// Whether a manifest range may run on this platform: it names major 1, starts at or below the +/// advertised version and ends above its own start. fn supports_version(range: &str) -> bool { - let Some(max) = range.strip_prefix(">=1.0.0 <") else { + let (Some((min, max)), Some(advertised)) = (parse_range(range), parse_version(VERSION)) else { return false; }; - if max == "2.0.0" { - return true; - } - max.strip_prefix("1.") - .and_then(|max| max.split_once('.')) - .is_some_and(|(minor, patch)| { - [minor, patch].iter().all(|part| { - part.len() <= 6 - && !part.is_empty() - && part.bytes().all(|byte| byte.is_ascii_digit()) - && (part.len() == 1 || !part.starts_with('0')) - }) && (minor != "0" || patch != "0") - }) + min.0 == 1 && min <= advertised && min < max && (max.0 == 1 || max == (2, 0, 0)) +} + +/// Whether `version`, which the manager negotiated, is one this platform serves and the manifest +/// `range` admits: major 1, at most the advertised version and inside the range. +fn admitted_by(version: &str, range: &str) -> bool { + let (Some(version), Some(advertised), Some((min, max))) = ( + parse_version(version), + parse_version(VERSION), + parse_range(range), + ) else { + return false; + }; + version.0 == 1 && version <= advertised && min <= version && version < max } #[derive(Serialize)] #[serde(rename_all = "camelCase")] struct Versions { - app_protocol: &'static str, - platform_api: &'static str, + app_protocol: String, + platform_api: String, #[serde(skip_serializing_if = "Option::is_none")] - ui_bridge: Option<&'static str>, + ui_bridge: Option, +} + +/// The versions the bootstrap descriptor tells this app: what the manager negotiated from the +/// manifest with the shared contract rule, which validation checked against the ranges. +fn versions(config: &LaunchConfig) -> Versions { + let negotiated = &config.negotiated; + Versions { + app_protocol: negotiated.app_protocol.clone(), + platform_api: negotiated.platform_api.clone(), + ui_bridge: negotiated.ui_bridge.clone(), + } } #[derive(Serialize)] @@ -261,11 +325,7 @@ async fn run_generation( installation_id: &config.installation_id, generation: config.generation, runtime_profile: PROFILE, - versions: Versions { - app_protocol: VERSION, - platform_api: VERSION, - ui_bridge: config.ui_bridge.as_ref().map(|_| VERSION), - }, + versions: versions(&config), app_socket: &sockets.app_socket, core_socket: &sockets.core_socket, app_credential: &app_credential, diff --git a/core/src/app_ipc/gateway.rs b/core/src/app_ipc/gateway.rs index 27ef3b8c5..3690b4e17 100644 --- a/core/src/app_ipc/gateway.rs +++ b/core/src/app_ipc/gateway.rs @@ -34,7 +34,7 @@ use tokio::{ }; use super::{ - Bootstrap, LaunchConfig, PROVIDER_PROFILES, VERSION, filesystem::connect_peer, lease, + Bootstrap, LaunchConfig, PROVIDER_PROFILES, PROVIDER_VERSION, filesystem::connect_peer, lease, record_id, wire_json, }; @@ -512,7 +512,7 @@ struct Operation { events: bool, } -static APP_OPERATIONS: LazyLock<[HttpDescriptor; 18]> = LazyLock::new(|| { +static APP_OPERATIONS: LazyLock<[HttpDescriptor; 19]> = LazyLock::new(|| { [ HttpOperation::GetPlatformContext, HttpOperation::SubscribeToEvents, @@ -532,6 +532,7 @@ static APP_OPERATIONS: LazyLock<[HttpDescriptor; 18]> = LazyLock::new(|| { HttpOperation::BeginLegacyHandoff, HttpOperation::ReadLegacyHandoffPart, HttpOperation::CommitLegacyHandoff, + HttpOperation::AbortLegacyHandoff, ] .map(HttpOperation::descriptor) }); @@ -812,7 +813,8 @@ async fn check_app_ready( ) -> Result, Failure> { let healthy: AppHealth = probe_app(bootstrap, uid, "/app/v1/health").await?; let ready: AppReady = probe_app(bootstrap, uid, "/app/v1/ready").await?; - if !healthy.healthy || !ready.ready || ready.protocol_version != VERSION { + if !healthy.healthy || !ready.ready || ready.protocol_version != bootstrap.versions.app_protocol + { return Err(Failure::Retry); } registrations(ready.providers, declared).map_err(Failure::Fatal) @@ -833,7 +835,7 @@ fn registrations(value: Value, declared: &[String]) -> io::Result>>()?; for (index, provider) in providers.iter().enumerate() { if !record_id(&provider.id) - || provider.version != VERSION + || provider.version != PROVIDER_VERSION || !declared.contains(&provider.profile) || providers[..index] .iter() diff --git a/core/src/app_manager.rs b/core/src/app_manager.rs index 522d7e741..c29188d8b 100644 --- a/core/src/app_manager.rs +++ b/core/src/app_manager.rs @@ -480,6 +480,12 @@ impl Manager { .get("incidentCategories") .cloned() .unwrap_or_else(|| json!([])); + let negotiated = crate::app_install::negotiate_manifest_versions(&package.manifest)?; + registration["versions"] = + json!({"appProtocol": negotiated.app_protocol, "platformApi": negotiated.platform_api}); + if let Some(bridge) = negotiated.ui_bridge { + registration["versions"]["uiBridge"] = bridge.into(); + } self.gateway.post("register", registration).await?; let renewal = runtime::Renewal::start(self.gateway.clone(), who.clone(), deadline); slot.authority_recorded = Some(true); diff --git a/core/src/app_manager/runtime.rs b/core/src/app_manager/runtime.rs index 3512c1586..408f1f08e 100644 --- a/core/src/app_manager/runtime.rs +++ b/core/src/app_manager/runtime.rs @@ -303,6 +303,8 @@ impl Running { let m = &package.manifest; let data = Path::new(USERS).join(slot.uid.to_string()).join("data"); let requirements = &m["requires"]; + let negotiated = crate::app_install::negotiate_manifest_versions(m)?; + let negotiated = json!({"appProtocol":negotiated.app_protocol,"platformApi":negotiated.platform_api,"uiBridge":negotiated.ui_bridge}); let mut frame = serde_json::to_vec(&json!({ "appId":slot.app_id,"installationId":id,"generation":slot.generation,"uid":slot.uid,"gid":slot.uid, "executable":package.directory.join("bin/app"), "dataDirectory":data, @@ -311,7 +313,8 @@ impl Running { "platformApi":requirements["platformApi"],"uiBridge":requirements.get("uiBridge"), "startupTimeoutMs":m["resources"]["startupTimeoutMs"].as_f64().map(|v|v as u64), "processLimit":m["resources"]["processLimit"].as_f64().map(|v|v as u64), - "providers":m.get("providers").cloned().unwrap_or_else(|| json!([])) + "providers":m.get("providers").cloned().unwrap_or_else(|| json!([])), + "negotiated":negotiated }))?; frame.push(b'\n'); let mut command = Command::new(std::env::current_exe()?); diff --git a/core/tests/private/app_install.rs b/core/tests/private/app_install.rs index 22234d9f3..5f1569175 100644 --- a/core/tests/private/app_install.rs +++ b/core/tests/private/app_install.rs @@ -512,6 +512,63 @@ fn target_check_reads_installed_manifests_from_the_accepted_catalog() { assert_eq!(checks[0].providers, None); } +#[test] +fn install_advertises_protocol_1_1_0_to_apps_that_require_it() { + assert_eq!(super::PROTOCOL_VERSION, "1.1.0"); + // The web release config and this constant mirror the protocol of the contracts crate. + assert_eq!( + super::PROTOCOL_VERSION, + rentnerproxy_app_contracts::PROTOCOL_VERSION + ); + let installer = manager(Path::new("unused")); + let engine = ["caddy.load-balancing.v1"]; + for (platform_api, app_protocol, compatible) in [ + (">=1.0.0 <2.0.0", ">=1.0.0 <2.0.0", true), + (">=1.1.0 <2.0.0", ">=1.1.0 <2.0.0", true), + (">=1.2.0 <2.0.0", ">=1.0.0 <2.0.0", false), + (">=1.0.0 <2.0.0", ">=1.2.0 <2.0.0", false), + ] { + let mut manifest = manifest(); + manifest["requires"]["platformApi"] = json!(platform_api); + manifest["requires"]["appProtocol"] = json!(app_protocol); + let result = installer.check_environment( + &manifest, + &rentnerproxy_app_contracts::ManifestEnvironment { + target: TARGET, + runtime_profile: super::RUNTIME_PROFILE, + platform_api: super::PROTOCOL_VERSION, + app_protocol: super::PROTOCOL_VERSION, + ui_bridge: None, + engine_capabilities: &engine, + }, + ); + assert_eq!(result.is_ok(), compatible, "{platform_api} {app_protocol}"); + } +} + +#[test] +fn apps_negotiate_the_lower_bound_of_each_manifest_range() { + for (range, negotiated) in [ + (">=1.0.0 <2.0.0", Some("1.0.0")), + (">=1.1.0 <2.0.0", Some("1.1.0")), + (">=1.2.0 <2.0.0", None), + ] { + let mut manifest = manifest(); + manifest["requires"]["platformApi"] = json!(range); + manifest["requires"]["appProtocol"] = json!(range); + let result = super::negotiate_manifest_versions(&manifest); + match negotiated { + Some(version) => { + let versions = result.unwrap(); + assert_eq!(versions.app_protocol, version); + assert_eq!(versions.platform_api, version); + assert_eq!(versions.ui_bridge, None); + } + None => assert!(result.is_err(), "{range}"), + } + } +} + #[test] fn engine_providers_require_the_engine_capability_that_applies_them() { let installer = manager(Path::new("unused")); diff --git a/core/tests/private/app_ipc.rs b/core/tests/private/app_ipc.rs index b5902500d..77c39f21a 100644 --- a/core/tests/private/app_ipc.rs +++ b/core/tests/private/app_ipc.rs @@ -73,6 +73,11 @@ fn launch(uid: u32, executable: PathBuf, data_directory: PathBuf) -> LaunchConfi app_protocol: ">=1.0.0 <2.0.0".into(), platform_api: ">=1.0.0 <1.1.0".into(), ui_bridge: None, + negotiated: NegotiatedVersions { + app_protocol: "1.0.0".into(), + platform_api: "1.0.0".into(), + ui_bridge: None, + }, startup_timeout_ms: None, process_limit: None, providers: Vec::new(), @@ -678,14 +683,16 @@ async fn legacy_handoff_routes_reach_the_platform_bridge_with_their_keys_and_bod )); let mut sender = open(&socket).await; - // Only the four contract routes exist, and the domain must be a provider profile. + // Only the five contract routes exist, and the domain must be a provider profile. for (method, route) in [ (Method::GET, "monitoring/begin"), (Method::GET, "proxy-hosts"), (Method::GET, "Monitoring"), (Method::GET, ""), (Method::POST, "monitoring"), - (Method::POST, "monitoring/abort"), + (Method::GET, "monitoring/abort"), + (Method::POST, "monitoring/abort/parts"), + (Method::POST, "crowdsec-bouncer/abort"), (Method::POST, "monitoring/begin/parts"), (Method::POST, "crowdsec-bouncer/commit"), ] { @@ -697,11 +704,15 @@ async fn legacy_handoff_routes_reach_the_platform_bridge_with_their_keys_and_bod ) .await; } - // Begin carries no body, while parts and commit need bounded JSON. + // Begin carries no body, while parts, commit and abort need bounded JSON. for (route, body) in [ ("monitoring/begin", &br"{}"[..]), ("monitoring/parts", &br#"{"sequence":9007199254740992}"#[..]), ("monitoring/commit", &br#"{"digest":"a","digest":"b"}"#[..]), + ( + "monitoring/abort", + &br#"{"reason":"other","reason":"other"}"#[..], + ), ] { assert_problem( &mut sender, @@ -727,6 +738,7 @@ async fn legacy_handoff_routes_reach_the_platform_bridge_with_their_keys_and_bod let commit = br#"{"digest":"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"}"#; let part = br#"{"digest":"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08","sequence":0}"#; + let abort = br#"{"digest":"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08","reason":"invalidExport"}"#; for (method, route, key, body, status) in [ (Method::GET, "monitoring", None, None, StatusCode::OK), ( @@ -750,6 +762,13 @@ async fn legacy_handoff_routes_reach_the_platform_bridge_with_their_keys_and_bod Some(&commit[..]), StatusCode::OK, ), + ( + Method::POST, + "monitoring/abort", + Some("abort-1"), + Some(&abort[..]), + StatusCode::OK, + ), ] { let response = sender .send_request(handoff_request(method.clone(), route, key, body)) @@ -1081,6 +1100,7 @@ fn launch_frames_default_to_no_declared_providers_and_reject_unknown_members() { "uid": TEST_UID, "gid": TEST_UID, "executable": "/bin/app", "dataDirectory": "/data", "databaseUrlFile": null, "runtimeProfile": PROFILE, "appProtocol": ">=1.0.0 <2.0.0", "platformApi": ">=1.0.0 <2.0.0", "uiBridge": null, + "negotiated": {"appProtocol": "1.0.0", "platformApi": "1.0.0", "uiBridge": null}, "startupTimeoutMs": null, "processLimit": null, }); let absent: LaunchConfig = serde_json::from_value(frame.clone()).unwrap(); @@ -1283,6 +1303,26 @@ async fn exercise_readiness( statuses: &[u16], authority_delay: Duration, patience: Duration, +) -> Readiness { + exercise_readiness_in( + VERSION, + ready, + declared, + statuses, + authority_delay, + patience, + ) + .await +} + +/// Like [`exercise_readiness`] for an app that negotiated the protocol version `negotiated`. +async fn exercise_readiness_in( + negotiated: &str, + ready: Vec, + declared: &[&str], + statuses: &[u16], + authority_delay: Duration, + patience: Duration, ) -> Readiness { use std::sync::atomic::{AtomicUsize, Ordering}; @@ -1365,8 +1405,8 @@ async fn exercise_readiness( generation: 9, runtime_profile: PROFILE, versions: Versions { - app_protocol: VERSION, - platform_api: VERSION, + app_protocol: negotiated.into(), + platform_api: negotiated.into(), ui_bridge: None, }, app_socket: &app_socket, @@ -1608,6 +1648,10 @@ async fn an_app_that_is_not_ready_keeps_retrying_without_registration() { for ready in [ json!({"ready": false, "protocolVersion": VERSION, "providers": []}), json!({"ready": true, "protocolVersion": "9.9.9", "providers": []}), + json!({"ready": true, "protocolVersion": "1.2.0", "providers": []}), + json!({"ready": true, "protocolVersion": "2.0.0", "providers": []}), + json!({"ready": true, "protocolVersion": "1.1", "providers": []}), + json!({"ready": true, "protocolVersion": "1.01.0", "providers": []}), json!({"ready": false, "protocolVersion": VERSION}), ] { let outcome = exercise_readiness( @@ -1796,6 +1840,7 @@ async fn privileged_controller_validates_launch_pipe_and_bootstrap_paths() { "uid": TEST_UID, "gid": TEST_UID, "executable": executable, "dataDirectory": data, "databaseUrlFile": database, "runtimeProfile": PROFILE, "appProtocol": ">=1.0.0 <2.0.0", "platformApi": ">=1.0.0 <1.0.1", "uiBridge": ">=1.0.0 <2.0.0", + "negotiated": {"appProtocol": "1.0.0", "platformApi": "1.0.0", "uiBridge": "1.0.0"}, }); let start = async |input: String| { let mut child = Command::new(&controller) @@ -1929,7 +1974,7 @@ async fn privileged_controller_validates_launch_pipe_and_bootstrap_paths() { serde_json::from_slice(&fs::read(data.join("descriptor.json")).unwrap()).unwrap(); assert_eq!(descriptor["appId"], "test.native"); assert_eq!(descriptor["generation"], 10); - assert_eq!(descriptor["versions"]["uiBridge"], VERSION); + assert_eq!(descriptor["versions"]["uiBridge"], "1.0.0"); let expected_socket = Path::new(APP_ROOT) .join(TEST_UID.to_string()) .join("10/core.sock"); @@ -2042,8 +2087,8 @@ async fn restricted_child_fixture() { let descriptor: Value = serde_json::from_str(&descriptor).unwrap(); assert_eq!(uid(), TEST_UID); assert_eq!(descriptor["appId"], "test.native"); - assert_eq!(descriptor["versions"]["appProtocol"], VERSION); - assert_eq!(descriptor["versions"]["platformApi"], VERSION); + assert_eq!(descriptor["versions"]["appProtocol"], "1.0.0"); + assert_eq!(descriptor["versions"]["platformApi"], "1.0.0"); assert_ne!(descriptor["appCredential"], descriptor["coreCredential"]); assert!(!descriptor["coreCredential"].as_str().unwrap().is_empty()); assert_eq!( @@ -2101,7 +2146,7 @@ async fn restricted_child_fixture() { "/app/v1/health" => json!({"healthy": true}), "/app/v1/ready" => { fs::write("ready", []).unwrap(); - json!({"ready": true, "protocolVersion": VERSION, "providers": []}) + json!({"ready": true, "protocolVersion": "1.0.0", "providers": []}) } _ => panic!("Unexpected fixture RPC path"), }; @@ -2114,3 +2159,134 @@ async fn restricted_child_fixture() { } std::future::pending::<()>().await; } + +#[test] +fn the_platform_advertises_protocol_1_1_0_and_keeps_provider_registrations_at_1_0_0() { + assert_eq!(VERSION, "1.1.0"); + assert_eq!(VERSION, rentnerproxy_app_contracts::PROTOCOL_VERSION); + assert_eq!(PROVIDER_VERSION, "1.0.0"); +} + +#[test] +fn launch_ranges_admit_apps_that_require_the_advertised_protocol() { + for (range, supported) in [ + (">=1.0.0 <2.0.0", true), + (">=1.1.0 <2.0.0", true), + (">=1.0.0 <1.1.0", true), + (">=1.1.1 <2.0.0", false), + (">=1.2.0 <2.0.0", false), + (">=2.0.0 <3.0.0", false), + (">=1.1.0 <1.1.0", false), + (">=1.0.0 <3.0.0", false), + (">=1.01.0 <2.0.0", false), + (">=1.0.0 <2.0", false), + (">1.0.0 <2.0.0", false), + ("1.0.0", false), + ] { + assert_eq!(supports_version(range), supported, "{range}"); + } +} + +#[test] +fn launch_validation_admits_only_negotiated_versions_inside_the_manifest_ranges() { + for (version, range, admitted) in [ + ("1.0.0", ">=1.0.0 <2.0.0", true), + ("1.1.0", ">=1.0.0 <2.0.0", true), + ("1.1.0", ">=1.1.0 <2.0.0", true), + ("1.0.0", ">=1.1.0 <2.0.0", false), + ("1.2.0", ">=1.0.0 <2.0.0", false), + ("2.0.0", ">=1.0.0 <3.0.0", false), + ("1.1.0", ">=1.0.0 <1.1.0", false), + ("1.1", ">=1.0.0 <2.0.0", false), + ("1.1.0", "not a range", false), + ] { + assert_eq!( + admitted_by(version, range), + admitted, + "{version} in {range}" + ); + } + let mut config = launch(uid(), PathBuf::new(), PathBuf::new()); + assert!(config.negotiated.app_protocol == "1.0.0"); + config.negotiated.app_protocol = "1.1.0".into(); + config.app_protocol = ">=1.1.0 <2.0.0".into(); + assert!(admitted_by( + &config.negotiated.app_protocol, + &config.app_protocol + )); +} + +#[test] +fn the_bootstrap_carries_the_version_each_app_negotiated() { + let mut config = launch(uid(), PathBuf::new(), PathBuf::new()); + let sent = |config: &LaunchConfig| serde_json::to_value(versions(config)).unwrap(); + assert_eq!( + sent(&config), + json!({"appProtocol": "1.0.0", "platformApi": "1.0.0"}) + ); + config.negotiated = NegotiatedVersions { + app_protocol: "1.1.0".into(), + platform_api: "1.1.0".into(), + ui_bridge: Some("1.0.0".into()), + }; + assert_eq!( + sent(&config), + json!({"appProtocol": "1.1.0", "platformApi": "1.1.0", "uiBridge": "1.0.0"}) + ); +} + +#[tokio::test] +async fn readiness_expects_exactly_the_negotiated_protocol() { + let report = + |version: &str| json!({"ready": true, "protocolVersion": version, "providers": []}); + for (negotiated, reported, accepted) in [ + ("1.0.0", "1.0.0", true), + ("1.1.0", "1.1.0", true), + // An app negotiated 1.0.0 must not claim more, nor an app of 1.1.0 less. + ("1.0.0", "1.1.0", false), + ("1.1.0", "1.0.0", false), + ("1.1.0", "1.2.0", false), + ("1.1.0", "2.0.0", false), + ] { + let outcome = exercise_readiness_in( + negotiated, + vec![report(reported)], + &[], + &[204], + Duration::ZERO, + Duration::from_millis(if accepted { 5_000 } else { 700 }), + ) + .await; + assert_eq!( + outcome.result.is_some_and(|result| result.is_ok()), + accepted, + "negotiated {negotiated}, reported {reported}" + ); + } +} + +#[tokio::test] +async fn provider_registrations_stay_at_provider_version_1_0_0_on_a_1_1_0_platform() { + let mut registrations = registration("monitor", "monitoring"); + registrations["version"] = json!(VERSION); + let outcome = readiness(json!([registrations]), &["monitoring"], &[204]).await; + let error = outcome + .result + .expect("an invalid registration must not be retried") + .expect_err("a registration at the protocol version is invalid"); + assert_eq!( + error.to_string(), + "App advertised invalid provider registrations" + ); + assert!(outcome.posted.is_empty()); + let outcome = readiness( + json!([registration("monitor", "monitoring")]), + &["monitoring"], + &[204], + ) + .await; + outcome + .result + .expect("a 1.0.0 registration is valid") + .unwrap(); +} From 0a0659e5e386378e132c6c85245e9bfdff3ffb66 Mon Sep 17 00:00:00 2001 From: "HomePC\\Kevin" Date: Sat, 28 Nov 2026 20:56:45 +0100 Subject: [PATCH 2/4] feat(apps): let apps abort a legacy handoff and see its availability Add abortLegacyHandoff (POST /platform/v1/legacy-handoffs/{domain}/abort): only the installation that began an exported handoff may abort it, the source restore runs, the refusal (reason, time, detail) is recorded per installation and domain and cleared by a commit, and an audit event names the refusal without the app's detail or any export value. A committed handoff answers handoffCommitted, another installation or digest conflict. Report offered and refused in the handoff status only to installations that negotiated platform API 1.1.0, store the negotiated versions per generation and report them in the platform context, and show refusals in the upgrade preview with locale strings. Cover the empty monitoring export. Co-Authored-By: Claude Opus 5.5 --- web/drizzle/0041_early_sage.sql | 19 + web/drizzle/meta/0041_snapshot.json | 5539 +++++++++++++++++ web/drizzle/meta/_journal.json | 7 + web/src/config/app-requirements.config.ts | 6 +- web/src/config/audit.config.ts | 2 + web/src/config/legacy-handoff.config.ts | 14 +- web/src/db/Schema/appRuntime.ts | 9 + web/src/db/Schema/auditEvents.ts | 2 + web/src/db/Schema/legacyFeatureHandoffs.ts | 42 +- .../features/Admin/AuditLogs/validation.ts | 5 +- .../Components/UpgradePreviewSection.tsx | 32 +- .../Types/application-update.types.ts | 12 + .../AuditLogs/Types/audit-events.types.ts | 4 + web/src/lib/Admin/AuditLogs/auditLogs.ts | 2 + .../lib/ApplicationVersion/upgradePreview.ts | 2 + web/src/lib/Language/Locales/de.json | 17 +- web/src/lib/Language/Locales/en.json | 17 +- web/src/lib/Language/Locales/es.json | 17 +- web/src/lib/Language/Locales/fr.json | 17 +- web/src/lib/Language/Locales/it.json | 17 +- web/src/lib/Language/Locales/nl.json | 17 +- web/src/lib/Language/Locales/pl.json | 17 +- web/src/lib/Language/Locales/pt.json | 17 +- .../AppRuntime/Types/authority.types.ts | 6 + .../server/AppRuntime/Types/gateway.types.ts | 6 +- web/src/server/AppRuntime/authority.server.ts | 11 +- web/src/server/AppRuntime/contract.ts | 23 +- web/src/server/AppRuntime/gateway.server.ts | 2 + web/src/server/AppRuntime/lifecycle.server.ts | 19 + .../server/AppRuntime/management.server.ts | 4 + web/src/server/AppRuntime/services.server.ts | 6 +- .../Types/legacy-handoff-api.types.ts | 29 +- .../Types/legacy-handoff.types.ts | 18 +- .../server/LegacyHandoff/app-api.server.ts | 126 +- .../server/LegacyHandoff/journal.server.ts | 105 +- .../application-update-dialog.test.tsx | 41 + .../upgrade-preview.test.ts | 24 + .../tests/server/AppRuntime/gateway.test.ts | 24 +- .../host-monitoring-handoff.db.test.ts | 159 +- .../server/LegacyHandoff/app-api.db.test.ts | 344 +- .../github/release-app-requirements.test.ts | 5 +- 41 files changed, 6724 insertions(+), 61 deletions(-) create mode 100644 web/drizzle/0041_early_sage.sql create mode 100644 web/drizzle/meta/0041_snapshot.json diff --git a/web/drizzle/0041_early_sage.sql b/web/drizzle/0041_early_sage.sql new file mode 100644 index 000000000..7384ea51c --- /dev/null +++ b/web/drizzle/0041_early_sage.sql @@ -0,0 +1,19 @@ +ALTER TYPE "rentnerproxy"."audit_action" ADD VALUE 'abort';--> statement-breakpoint +ALTER TYPE "rentnerproxy"."audit_resource" ADD VALUE 'app-legacy-handoff';--> statement-breakpoint +CREATE TABLE "rentnerproxy"."legacy_feature_handoff_refusals" ( + "installation_id" varchar(64) NOT NULL, + "domain" varchar(32) NOT NULL, + "reason" varchar(20) NOT NULL, + "detail" varchar(500), + "refused_at" timestamp with time zone DEFAULT now() NOT NULL, + CONSTRAINT "legacy_feature_handoff_refusals_installation_id_domain_pk" PRIMARY KEY("installation_id","domain"), + CONSTRAINT "legacy_feature_handoff_refusals_domain_check" CHECK ("rentnerproxy"."legacy_feature_handoff_refusals"."domain" in ('monitoring', 'docker-discovery', 'load-balancer', 'dns', 'oidc', 'crowdsec')), + CONSTRAINT "legacy_feature_handoff_refusals_reason_check" CHECK ("rentnerproxy"."legacy_feature_handoff_refusals"."reason" in ('invalidExport', 'unsupportedFormat', 'importFailed', 'other')) +); +--> statement-breakpoint +ALTER TABLE "rentnerproxy"."legacy_feature_handoff_requests" DROP CONSTRAINT "legacy_feature_handoff_requests_operation_check";--> statement-breakpoint +ALTER TABLE "rentnerproxy"."app_runtime_generations" ADD COLUMN "app_protocol_version" varchar(24) DEFAULT '1.0.0' NOT NULL;--> statement-breakpoint +ALTER TABLE "rentnerproxy"."app_runtime_generations" ADD COLUMN "platform_api_version" varchar(24) DEFAULT '1.0.0' NOT NULL;--> statement-breakpoint +ALTER TABLE "rentnerproxy"."app_runtime_generations" ADD COLUMN "ui_bridge_version" varchar(24);--> statement-breakpoint +ALTER TABLE "rentnerproxy"."legacy_feature_handoff_refusals" ADD CONSTRAINT "legacy_feature_handoff_refusals_installation_id_app_runtime_installations_id_fk" FOREIGN KEY ("installation_id") REFERENCES "rentnerproxy"."app_runtime_installations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "rentnerproxy"."legacy_feature_handoff_requests" ADD CONSTRAINT "legacy_feature_handoff_requests_operation_check" CHECK ("rentnerproxy"."legacy_feature_handoff_requests"."operation" in ('begin', 'commit', 'abort')); \ No newline at end of file diff --git a/web/drizzle/meta/0041_snapshot.json b/web/drizzle/meta/0041_snapshot.json new file mode 100644 index 000000000..3798c5f5e --- /dev/null +++ b/web/drizzle/meta/0041_snapshot.json @@ -0,0 +1,5539 @@ +{ + "id": "0270cd54-4853-4b0c-a311-1d27f0f3f71e", + "prevId": "152e9cdb-2342-4bb0-bbb5-e701f0baa011", + "version": "7", + "dialect": "postgresql", + "tables": { + "rentnerproxy.access_policies": { + "name": "access_policies", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "name": { + "name": "name", + "type": "varchar(120)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "mode": { + "name": "mode", + "type": "access_policy_mode", + "typeSchema": "rentnerproxy", + "primaryKey": false, + "notNull": true + }, + "combination": { + "name": "combination", + "type": "access_policy_combination", + "typeSchema": "rentnerproxy", + "primaryKey": false, + "notNull": false + }, + "ip_rules": { + "name": "ip_rules", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "null" + }, + "forward_auth": { + "name": "forward_auth", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "null" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "access_policies_mode_idx": { + "name": "access_policies_mode_idx", + "columns": [ + { + "expression": "mode", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "access_policies_combination_check": { + "name": "access_policies_combination_check", + "value": "(\"rentnerproxy\".\"access_policies\".\"mode\" = 'combined' and \"rentnerproxy\".\"access_policies\".\"combination\" is not null) or (\"rentnerproxy\".\"access_policies\".\"mode\" <> 'combined' and \"rentnerproxy\".\"access_policies\".\"combination\" is null)" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.access_policy_basic_auth_accounts": { + "name": "access_policy_basic_auth_accounts", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "policy_id": { + "name": "policy_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "username": { + "name": "username", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "password_hash": { + "name": "password_hash", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "access_policy_basic_auth_accounts_policy_id_idx": { + "name": "access_policy_basic_auth_accounts_policy_id_idx", + "columns": [ + { + "expression": "policy_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "access_policy_basic_auth_accounts_policy_username_unique": { + "name": "access_policy_basic_auth_accounts_policy_username_unique", + "columns": [ + { + "expression": "policy_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "username", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "access_policy_basic_auth_accounts_policy_id_access_policies_id_fk": { + "name": "access_policy_basic_auth_accounts_policy_id_access_policies_id_fk", + "tableFrom": "access_policy_basic_auth_accounts", + "tableTo": "access_policies", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "policy_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "rentnerproxy.app_runtime_delegations": { + "name": "app_runtime_delegations", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "installation_id": { + "name": "installation_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "generation": { + "name": "generation", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "session_id": { + "name": "session_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "token_hash": { + "name": "token_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "app_runtime_delegations_hash_idx": { + "name": "app_runtime_delegations_hash_idx", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "app_runtime_delegations_session_idx": { + "name": "app_runtime_delegations_session_idx", + "columns": [ + { + "expression": "session_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "app_runtime_delegations_expiry_idx": { + "name": "app_runtime_delegations_expiry_idx", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "app_runtime_delegations_session_id_sessions_id_fk": { + "name": "app_runtime_delegations_session_id_sessions_id_fk", + "tableFrom": "app_runtime_delegations", + "tableTo": "sessions", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "session_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "app_runtime_delegations_installation_id_generation_app_runtime_generations_installation_id_generation_fk": { + "name": "app_runtime_delegations_installation_id_generation_app_runtime_generations_installation_id_generation_fk", + "tableFrom": "app_runtime_delegations", + "tableTo": "app_runtime_generations", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "installation_id", + "generation" + ], + "columnsTo": [ + "installation_id", + "generation" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "rentnerproxy.app_runtime_event_retention": { + "name": "app_runtime_event_retention", + "schema": "rentnerproxy", + "columns": { + "installation_id": { + "name": "installation_id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "floor": { + "name": "floor", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "0" + } + }, + "indexes": {}, + "foreignKeys": { + "app_runtime_event_retention_installation_id_app_runtime_installations_id_fk": { + "name": "app_runtime_event_retention_installation_id_app_runtime_installations_id_fk", + "tableFrom": "app_runtime_event_retention", + "tableTo": "app_runtime_installations", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "installation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "rentnerproxy.app_runtime_events": { + "name": "app_runtime_events", + "schema": "rentnerproxy", + "columns": { + "sequence": { + "name": "sequence", + "type": "bigint", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "app_runtime_events_sequence_seq", + "schema": "rentnerproxy", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "9223372036854775807", + "cache": "1", + "cycle": false + } + }, + "id": { + "name": "id", + "type": "uuid", + "primaryKey": false, + "notNull": true, + "default": "uuidv7()" + }, + "installation_id": { + "name": "installation_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "capability_id": { + "name": "capability_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "scope": { + "name": "scope", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "resource_id": { + "name": "resource_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "revision": { + "name": "revision", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "occurred_at": { + "name": "occurred_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "app_runtime_events_installation_sequence_idx": { + "name": "app_runtime_events_installation_sequence_idx", + "columns": [ + { + "expression": "installation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sequence", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "app_runtime_events_installation_time_idx": { + "name": "app_runtime_events_installation_time_idx", + "columns": [ + { + "expression": "installation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "occurred_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "app_runtime_events_installation_id_app_runtime_installations_id_fk": { + "name": "app_runtime_events_installation_id_app_runtime_installations_id_fk", + "tableFrom": "app_runtime_events", + "tableTo": "app_runtime_installations", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "installation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "app_runtime_events_id_unique": { + "name": "app_runtime_events_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "rentnerproxy.app_runtime_generations": { + "name": "app_runtime_generations", + "schema": "rentnerproxy", + "columns": { + "installation_id": { + "name": "installation_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "generation": { + "name": "generation", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "state": { + "name": "state", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true + }, + "lease_expires_at": { + "name": "lease_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "capabilities": { + "name": "capabilities", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "permission_keys": { + "name": "permission_keys", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "has_ui": { + "name": "has_ui", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "provider_profiles": { + "name": "provider_profiles", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "incident_categories": { + "name": "incident_categories", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "app_protocol_version": { + "name": "app_protocol_version", + "type": "varchar(24)", + "primaryKey": false, + "notNull": true, + "default": "'1.0.0'" + }, + "platform_api_version": { + "name": "platform_api_version", + "type": "varchar(24)", + "primaryKey": false, + "notNull": true, + "default": "'1.0.0'" + }, + "ui_bridge_version": { + "name": "ui_bridge_version", + "type": "varchar(24)", + "primaryKey": false, + "notNull": false + }, + "providers": { + "name": "providers", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "pending_grants": { + "name": "pending_grants", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "app_runtime_generations_one_active_idx": { + "name": "app_runtime_generations_one_active_idx", + "columns": [ + { + "expression": "installation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"rentnerproxy\".\"app_runtime_generations\".\"state\" = 'active'", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "app_runtime_generations_installation_id_app_runtime_installations_id_fk": { + "name": "app_runtime_generations_installation_id_app_runtime_installations_id_fk", + "tableFrom": "app_runtime_generations", + "tableTo": "app_runtime_installations", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "installation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "app_runtime_generations_installation_id_generation_pk": { + "name": "app_runtime_generations_installation_id_generation_pk", + "columns": [ + "installation_id", + "generation" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "app_runtime_generations_number_check": { + "name": "app_runtime_generations_number_check", + "value": "\"rentnerproxy\".\"app_runtime_generations\".\"generation\" between 1 and 9007199254740991" + }, + "app_runtime_generations_state_check": { + "name": "app_runtime_generations_state_check", + "value": "\"rentnerproxy\".\"app_runtime_generations\".\"state\" in ('preparing', 'active', 'revoked')" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.app_runtime_grants": { + "name": "app_runtime_grants", + "schema": "rentnerproxy", + "columns": { + "installation_id": { + "name": "installation_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "capability_id": { + "name": "capability_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "scope": { + "name": "scope", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "resource_id": { + "name": "resource_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "allow_service": { + "name": "allow_service", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "permission_key": { + "name": "permission_key", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "app_runtime_grants_installation_id_app_runtime_installations_id_fk": { + "name": "app_runtime_grants_installation_id_app_runtime_installations_id_fk", + "tableFrom": "app_runtime_grants", + "tableTo": "app_runtime_installations", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "installation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "app_runtime_grants_installation_id_capability_id_scope_resource_id_pk": { + "name": "app_runtime_grants_installation_id_capability_id_scope_resource_id_pk", + "columns": [ + "installation_id", + "capability_id", + "scope", + "resource_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "rentnerproxy.app_runtime_installations": { + "name": "app_runtime_installations", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "app_id": { + "name": "app_id", + "type": "varchar(97)", + "primaryKey": false, + "notNull": true + }, + "uid": { + "name": "uid", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "authorization_epoch": { + "name": "authorization_epoch", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": "0" + } + }, + "indexes": { + "app_runtime_installations_uid_idx": { + "name": "app_runtime_installations_uid_idx", + "columns": [ + { + "expression": "uid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "app_runtime_installations_uid_check": { + "name": "app_runtime_installations_uid_check", + "value": "\"rentnerproxy\".\"app_runtime_installations\".\"uid\" between 20000 and 59999" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.app_runtime_messages": { + "name": "app_runtime_messages", + "schema": "rentnerproxy", + "columns": { + "installation_id": { + "name": "installation_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "actor": { + "name": "actor", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "idempotency_key": { + "name": "idempotency_key", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "fingerprint": { + "name": "fingerprint", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "generation": { + "name": "generation", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "app_runtime_messages_installation_time_idx": { + "name": "app_runtime_messages_installation_time_idx", + "columns": [ + { + "expression": "installation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "app_runtime_messages_installation_id_app_runtime_installations_id_fk": { + "name": "app_runtime_messages_installation_id_app_runtime_installations_id_fk", + "tableFrom": "app_runtime_messages", + "tableTo": "app_runtime_installations", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "installation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "app_runtime_messages_installation_id_actor_kind_idempotency_key_pk": { + "name": "app_runtime_messages_installation_id_actor_kind_idempotency_key_pk", + "columns": [ + "installation_id", + "actor", + "kind", + "idempotency_key" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "rentnerproxy.app_runtime_operation_requests": { + "name": "app_runtime_operation_requests", + "schema": "rentnerproxy", + "columns": { + "installation_id": { + "name": "installation_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "key_hash": { + "name": "key_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "payload_hash": { + "name": "payload_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "operation_id": { + "name": "operation_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "app_runtime_operation_requests_operation_idx": { + "name": "app_runtime_operation_requests_operation_idx", + "columns": [ + { + "expression": "operation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "app_runtime_operation_requests_operation_id_app_runtime_operations_id_fk": { + "name": "app_runtime_operation_requests_operation_id_app_runtime_operations_id_fk", + "tableFrom": "app_runtime_operation_requests", + "tableTo": "app_runtime_operations", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "operation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "app_runtime_operation_requests_installation_id_key_hash_pk": { + "name": "app_runtime_operation_requests_installation_id_key_hash_pk", + "columns": [ + "installation_id", + "key_hash" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "rentnerproxy.app_runtime_operations": { + "name": "app_runtime_operations", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "installation_id": { + "name": "installation_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "generation": { + "name": "generation", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "delegation_id": { + "name": "delegation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "actor_user_id": { + "name": "actor_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "request_id": { + "name": "request_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "input": { + "name": "input", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "result": { + "name": "result", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "failure": { + "name": "failure", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "lease_token": { + "name": "lease_token", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "lease_expires_at": { + "name": "lease_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "app_runtime_operations_pending_idx": { + "name": "app_runtime_operations_pending_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"rentnerproxy\".\"app_runtime_operations\".\"status\" in ('accepted', 'running')", + "concurrently": false, + "method": "btree", + "with": {} + }, + "app_runtime_operations_installation_pending_idx": { + "name": "app_runtime_operations_installation_pending_idx", + "columns": [ + { + "expression": "installation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"rentnerproxy\".\"app_runtime_operations\".\"status\" in ('accepted', 'running')", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "app_runtime_operations_installation_id_app_runtime_installations_id_fk": { + "name": "app_runtime_operations_installation_id_app_runtime_installations_id_fk", + "tableFrom": "app_runtime_operations", + "tableTo": "app_runtime_installations", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "installation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "app_runtime_operations_state_check": { + "name": "app_runtime_operations_state_check", + "value": "\"rentnerproxy\".\"app_runtime_operations\".\"status\" in ('accepted', 'running', 'cancelled', 'succeeded', 'failed') and\n (\"rentnerproxy\".\"app_runtime_operations\".\"status\" = 'failed') = (\"rentnerproxy\".\"app_runtime_operations\".\"failure\" is not null) and\n (\"rentnerproxy\".\"app_runtime_operations\".\"status\" = 'running' or \"rentnerproxy\".\"app_runtime_operations\".\"lease_token\" is null) and\n (\"rentnerproxy\".\"app_runtime_operations\".\"lease_token\" is null) = (\"rentnerproxy\".\"app_runtime_operations\".\"lease_expires_at\" is null)" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.app_runtime_owned_proxy_hosts": { + "name": "app_runtime_owned_proxy_hosts", + "schema": "rentnerproxy", + "columns": { + "installation_id": { + "name": "installation_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "host_id": { + "name": "host_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "proxy_host_id": { + "name": "proxy_host_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "app_runtime_owned_proxy_hosts_installation_id_app_runtime_installations_id_fk": { + "name": "app_runtime_owned_proxy_hosts_installation_id_app_runtime_installations_id_fk", + "tableFrom": "app_runtime_owned_proxy_hosts", + "tableTo": "app_runtime_installations", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "installation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "app_runtime_owned_proxy_hosts_proxy_host_id_proxy_hosts_id_fk": { + "name": "app_runtime_owned_proxy_hosts_proxy_host_id_proxy_hosts_id_fk", + "tableFrom": "app_runtime_owned_proxy_hosts", + "tableTo": "proxy_hosts", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "proxy_host_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "app_runtime_owned_proxy_hosts_installation_id_host_id_pk": { + "name": "app_runtime_owned_proxy_hosts_installation_id_host_id_pk", + "columns": [ + "installation_id", + "host_id" + ] + } + }, + "uniqueConstraints": { + "app_runtime_owned_proxy_hosts_proxy_host_id_unique": { + "name": "app_runtime_owned_proxy_hosts_proxy_host_id_unique", + "nullsNotDistinct": false, + "columns": [ + "proxy_host_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "rentnerproxy.app_runtime_pending_secrets": { + "name": "app_runtime_pending_secrets", + "schema": "rentnerproxy", + "columns": { + "installation_id": { + "name": "installation_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "generation": { + "name": "generation", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "ciphertext": { + "name": "ciphertext", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "iv": { + "name": "iv", + "type": "bytea", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "app_runtime_pending_secrets_generation_fk": { + "name": "app_runtime_pending_secrets_generation_fk", + "tableFrom": "app_runtime_pending_secrets", + "tableTo": "app_runtime_generations", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "installation_id", + "generation" + ], + "columnsTo": [ + "installation_id", + "generation" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "app_runtime_pending_secrets_installation_id_generation_id_pk": { + "name": "app_runtime_pending_secrets_installation_id_generation_id_pk", + "columns": [ + "installation_id", + "generation", + "id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "app_runtime_pending_secrets_envelope_check": { + "name": "app_runtime_pending_secrets_envelope_check", + "value": "(\"rentnerproxy\".\"app_runtime_pending_secrets\".\"ciphertext\" is null and \"rentnerproxy\".\"app_runtime_pending_secrets\".\"iv\" is null) or\n (\"rentnerproxy\".\"app_runtime_pending_secrets\".\"ciphertext\" is not null and \"rentnerproxy\".\"app_runtime_pending_secrets\".\"iv\" is not null and octet_length(\"rentnerproxy\".\"app_runtime_pending_secrets\".\"iv\") = 12)" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.app_runtime_role_permissions": { + "name": "app_runtime_role_permissions", + "schema": "rentnerproxy", + "columns": { + "installation_id": { + "name": "installation_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "role_id": { + "name": "role_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "key": { + "name": "key", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "app_runtime_role_permissions_role_idx": { + "name": "app_runtime_role_permissions_role_idx", + "columns": [ + { + "expression": "role_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "app_runtime_role_permissions_installation_id_app_runtime_installations_id_fk": { + "name": "app_runtime_role_permissions_installation_id_app_runtime_installations_id_fk", + "tableFrom": "app_runtime_role_permissions", + "tableTo": "app_runtime_installations", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "installation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "app_runtime_role_permissions_role_id_roles_id_fk": { + "name": "app_runtime_role_permissions_role_id_roles_id_fk", + "tableFrom": "app_runtime_role_permissions", + "tableTo": "roles", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "role_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "app_runtime_role_permissions_installation_id_role_id_key_pk": { + "name": "app_runtime_role_permissions_installation_id_role_id_key_pk", + "columns": [ + "installation_id", + "role_id", + "key" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "rentnerproxy.app_runtime_secrets": { + "name": "app_runtime_secrets", + "schema": "rentnerproxy", + "columns": { + "installation_id": { + "name": "installation_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "ciphertext": { + "name": "ciphertext", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "iv": { + "name": "iv", + "type": "bytea", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "app_runtime_secrets_installation_id_app_runtime_installations_id_fk": { + "name": "app_runtime_secrets_installation_id_app_runtime_installations_id_fk", + "tableFrom": "app_runtime_secrets", + "tableTo": "app_runtime_installations", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "installation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "app_runtime_secrets_installation_id_id_pk": { + "name": "app_runtime_secrets_installation_id_id_pk", + "columns": [ + "installation_id", + "id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "app_runtime_secrets_iv_check": { + "name": "app_runtime_secrets_iv_check", + "value": "octet_length(\"rentnerproxy\".\"app_runtime_secrets\".\"iv\") = 12" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.audit_events": { + "name": "audit_events", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp (3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "actor_user_id": { + "name": "actor_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "actor_kind": { + "name": "actor_kind", + "type": "audit_actor_kind", + "typeSchema": "rentnerproxy", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "audit_action", + "typeSchema": "rentnerproxy", + "primaryKey": false, + "notNull": true + }, + "resource": { + "name": "resource", + "type": "audit_resource", + "typeSchema": "rentnerproxy", + "primaryKey": false, + "notNull": true + }, + "target_id": { + "name": "target_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "result": { + "name": "result", + "type": "audit_result", + "typeSchema": "rentnerproxy", + "primaryKey": false, + "notNull": true + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + } + }, + "indexes": { + "audit_events_created_at_id_idx": { + "name": "audit_events_created_at_id_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "audit_events_actor_user_id_idx": { + "name": "audit_events_actor_user_id_idx", + "columns": [ + { + "expression": "actor_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "audit_events_action_resource_idx": { + "name": "audit_events_action_resource_idx", + "columns": [ + { + "expression": "action", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "resource", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "audit_events_result_idx": { + "name": "audit_events_result_idx", + "columns": [ + { + "expression": "result", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "audit_events_metadata_size_check": { + "name": "audit_events_metadata_size_check", + "value": "pg_column_size(\"rentnerproxy\".\"audit_events\".\"metadata\") <= 4096" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.audit_retention_state": { + "name": "audit_retention_state", + "schema": "rentnerproxy", + "columns": { + "singleton": { + "name": "singleton", + "type": "boolean", + "primaryKey": true, + "notNull": true, + "default": true + }, + "row_count": { + "name": "row_count", + "type": "bigint", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "audit_retention_state_singleton_check": { + "name": "audit_retention_state_singleton_check", + "value": "\"rentnerproxy\".\"audit_retention_state\".\"singleton\"" + }, + "audit_retention_state_row_count_check": { + "name": "audit_retention_state_row_count_check", + "value": "\"rentnerproxy\".\"audit_retention_state\".\"row_count\" >= 0" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.certificate_domains": { + "name": "certificate_domains", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "certificate_id": { + "name": "certificate_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "varchar(253)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "certificate_domains_certificate_id_idx": { + "name": "certificate_domains_certificate_id_idx", + "columns": [ + { + "expression": "certificate_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "certificate_domains_certificate_id_certificates_id_fk": { + "name": "certificate_domains_certificate_id_certificates_id_fk", + "tableFrom": "certificate_domains", + "tableTo": "certificates", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "certificate_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "certificate_domains_certificate_domain_unique": { + "name": "certificate_domains_certificate_domain_unique", + "nullsNotDistinct": false, + "columns": [ + "certificate_id", + "domain" + ] + } + }, + "policies": {}, + "checkConstraints": { + "certificate_domains_canonical_check": { + "name": "certificate_domains_canonical_check", + "value": "\"rentnerproxy\".\"certificate_domains\".\"domain\" ~ '^([*][.])?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$' and \"rentnerproxy\".\"certificate_domains\".\"domain\" !~ '^[0-9.]+$'" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.certificate_event_cursor": { + "name": "certificate_event_cursor", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "default": 1 + }, + "cursor": { + "name": "cursor", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "certificate_event_cursor_singleton_check": { + "name": "certificate_event_cursor_singleton_check", + "value": "\"rentnerproxy\".\"certificate_event_cursor\".\"id\" = 1" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.certificate_event_receipts": { + "name": "certificate_event_receipts", + "schema": "rentnerproxy", + "columns": { + "event_id": { + "name": "event_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "operation_id": { + "name": "operation_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "certificate_id": { + "name": "certificate_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "stage": { + "name": "stage", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "occurred_at": { + "name": "occurred_at", + "type": "timestamp (3) with time zone", + "primaryKey": false, + "notNull": true + }, + "error_code": { + "name": "error_code", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "received_at": { + "name": "received_at", + "type": "timestamp (3) with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "certificate_event_receipts_received_at_idx": { + "name": "certificate_event_receipts_received_at_idx", + "columns": [ + { + "expression": "received_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "certificate_event_receipts_certificate_id_idx": { + "name": "certificate_event_receipts_certificate_id_idx", + "columns": [ + { + "expression": "certificate_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "certificate_event_receipts_kind_check": { + "name": "certificate_event_receipts_kind_check", + "value": "\"rentnerproxy\".\"certificate_event_receipts\".\"kind\" in ('operator_action_required', 'cancelled', 'expired', 'accepted', 'started', 'issued', 'activated', 'renewed', 'retry_scheduled', 'failed')" + }, + "certificate_event_receipts_stage_check": { + "name": "certificate_event_receipts_stage_check", + "value": "\"rentnerproxy\".\"certificate_event_receipts\".\"stage\" in ('awaiting_dns', 'checking_dns', 'cancelling', 'cancelled', 'expired', 'queued', 'creating_order', 'preparing_challenge', 'waiting_for_validation', 'finalizing', 'certificate_ready', 'applying', 'applied', 'retry_scheduled', 'failed', 'needs_attention')" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.certificate_binding_jobs": { + "name": "certificate_binding_jobs", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "actor_user_id": { + "name": "actor_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "proxy_host_id": { + "name": "proxy_host_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "certificate_id": { + "name": "certificate_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "idempotency_key": { + "name": "idempotency_key", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "request_digest": { + "name": "request_digest", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "domains": { + "name": "domains", + "type": "text[]", + "primaryKey": false, + "notNull": true + }, + "required_permissions": { + "name": "required_permissions", + "type": "text[]", + "primaryKey": false, + "notNull": true + }, + "host_revision": { + "name": "host_revision", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "assigned_revision": { + "name": "assigned_revision", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "desired_enabled": { + "name": "desired_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "desired_force_https": { + "name": "desired_force_https", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "request_ciphertext": { + "name": "request_ciphertext", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "request_iv": { + "name": "request_iv", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "stage": { + "name": "stage", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'preparing'" + }, + "controller_stage": { + "name": "controller_stage", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + }, + "controller_operation_id": { + "name": "controller_operation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "last_error_code": { + "name": "last_error_code", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "attempt_count": { + "name": "attempt_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "retry_requested": { + "name": "retry_requested", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "next_attempt_at": { + "name": "next_attempt_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "lease_token": { + "name": "lease_token", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "lease_expires_at": { + "name": "lease_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "certificate_jobs_due_idx": { + "name": "certificate_jobs_due_idx", + "columns": [ + { + "expression": "stage", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "next_attempt_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "certificate_jobs_host_created_idx": { + "name": "certificate_jobs_host_created_idx", + "columns": [ + { + "expression": "proxy_host_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "certificate_binding_jobs_actor_user_id_users_id_fk": { + "name": "certificate_binding_jobs_actor_user_id_users_id_fk", + "tableFrom": "certificate_binding_jobs", + "tableTo": "users", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "actor_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "certificate_binding_jobs_proxy_host_id_proxy_hosts_id_fk": { + "name": "certificate_binding_jobs_proxy_host_id_proxy_hosts_id_fk", + "tableFrom": "certificate_binding_jobs", + "tableTo": "proxy_hosts", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "proxy_host_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "certificate_binding_jobs_certificate_id_certificates_id_fk": { + "name": "certificate_binding_jobs_certificate_id_certificates_id_fk", + "tableFrom": "certificate_binding_jobs", + "tableTo": "certificates", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "certificate_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "certificate_jobs_actor_idempotency_unique": { + "name": "certificate_jobs_actor_idempotency_unique", + "nullsNotDistinct": false, + "columns": [ + "actor_user_id", + "idempotency_key" + ] + }, + "certificate_jobs_certificate_unique": { + "name": "certificate_jobs_certificate_unique", + "nullsNotDistinct": false, + "columns": [ + "certificate_id" + ] + } + }, + "policies": {}, + "checkConstraints": { + "certificate_jobs_stage_check": { + "name": "certificate_jobs_stage_check", + "value": "\"rentnerproxy\".\"certificate_binding_jobs\".\"stage\" in ('preparing','issuing','applying','applied','failed','needs_attention')" + }, + "certificate_jobs_attempts_check": { + "name": "certificate_jobs_attempts_check", + "value": "\"rentnerproxy\".\"certificate_binding_jobs\".\"attempt_count\" >= 0" + }, + "certificate_jobs_domains_check": { + "name": "certificate_jobs_domains_check", + "value": "cardinality(\"rentnerproxy\".\"certificate_binding_jobs\".\"domains\") between 1 and 100" + }, + "certificate_jobs_permissions_check": { + "name": "certificate_jobs_permissions_check", + "value": "cardinality(\"rentnerproxy\".\"certificate_binding_jobs\".\"required_permissions\") between 1 and 10" + }, + "certificate_jobs_secret_check": { + "name": "certificate_jobs_secret_check", + "value": "(\"rentnerproxy\".\"certificate_binding_jobs\".\"request_ciphertext\" is null and \"rentnerproxy\".\"certificate_binding_jobs\".\"request_iv\" is null) or (\"rentnerproxy\".\"certificate_binding_jobs\".\"request_ciphertext\" is not null and \"rentnerproxy\".\"certificate_binding_jobs\".\"request_iv\" is not null and octet_length(\"rentnerproxy\".\"certificate_binding_jobs\".\"request_ciphertext\") between 17 and 65536 and octet_length(\"rentnerproxy\".\"certificate_binding_jobs\".\"request_iv\") = 12)" + }, + "certificate_jobs_lease_check": { + "name": "certificate_jobs_lease_check", + "value": "(\"rentnerproxy\".\"certificate_binding_jobs\".\"lease_token\" is null) = (\"rentnerproxy\".\"certificate_binding_jobs\".\"lease_expires_at\" is null)" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.certificates": { + "name": "certificates", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "name": { + "name": "name", + "type": "varchar(120)", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true + }, + "environment": { + "name": "environment", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "operation": { + "name": "operation", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true, + "default": "'idle'" + }, + "current_operation": { + "name": "current_operation", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "challenge_type": { + "name": "challenge_type", + "type": "varchar(7)", + "primaryKey": false, + "notNull": false + }, + "issued_at": { + "name": "issued_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "issuer": { + "name": "issuer", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false + }, + "fingerprint": { + "name": "fingerprint", + "type": "varchar(71)", + "primaryKey": false, + "notNull": false + }, + "candidate": { + "name": "candidate", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "dns_cleanup_pending": { + "name": "dns_cleanup_pending", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "last_error_code": { + "name": "last_error_code", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "last_activated_at": { + "name": "last_activated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_error_at": { + "name": "last_error_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "next_attempt_at": { + "name": "next_attempt_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "attempt_count": { + "name": "attempt_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_attempt_at": { + "name": "last_attempt_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_success_at": { + "name": "last_success_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "next_renewal_at": { + "name": "next_renewal_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "controller_updated_at": { + "name": "controller_updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "certificates_expires_at_idx": { + "name": "certificates_expires_at_idx", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "certificates_name_check": { + "name": "certificates_name_check", + "value": "length(btrim(\"rentnerproxy\".\"certificates\".\"name\")) > 0" + }, + "certificates_source_check": { + "name": "certificates_source_check", + "value": "\"rentnerproxy\".\"certificates\".\"source\" in ('manual', 'acme')" + }, + "certificates_environment_check": { + "name": "certificates_environment_check", + "value": "(\"rentnerproxy\".\"certificates\".\"source\" = 'manual' and \"rentnerproxy\".\"certificates\".\"environment\" is null) or (\"rentnerproxy\".\"certificates\".\"source\" = 'acme' and \"rentnerproxy\".\"certificates\".\"environment\" is not null and \"rentnerproxy\".\"certificates\".\"environment\" in ('staging', 'production'))" + }, + "certificates_status_check": { + "name": "certificates_status_check", + "value": "\"rentnerproxy\".\"certificates\".\"status\" in ('pending', 'valid', 'failed')" + }, + "certificates_operation_check": { + "name": "certificates_operation_check", + "value": "\"rentnerproxy\".\"certificates\".\"operation\" in ('idle', 'issuing', 'renewing')" + }, + "certificates_challenge_type_check": { + "name": "certificates_challenge_type_check", + "value": "\"rentnerproxy\".\"certificates\".\"challenge_type\" is null or \"rentnerproxy\".\"certificates\".\"challenge_type\" in ('http-01', 'dns-01')" + }, + "certificates_attempt_count_check": { + "name": "certificates_attempt_count_check", + "value": "\"rentnerproxy\".\"certificates\".\"attempt_count\" >= 0" + }, + "certificates_validity_check": { + "name": "certificates_validity_check", + "value": "\"rentnerproxy\".\"certificates\".\"status\" != 'valid' or (\"rentnerproxy\".\"certificates\".\"issued_at\" is not null and \"rentnerproxy\".\"certificates\".\"expires_at\" is not null and \"rentnerproxy\".\"certificates\".\"issued_at\" < \"rentnerproxy\".\"certificates\".\"expires_at\" and \"rentnerproxy\".\"certificates\".\"fingerprint\" is not null)" + }, + "certificates_fingerprint_check": { + "name": "certificates_fingerprint_check", + "value": "\"rentnerproxy\".\"certificates\".\"fingerprint\" is null or \"rentnerproxy\".\"certificates\".\"fingerprint\" ~ '^sha256:[a-f0-9]{64}$'" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.host_check_incidents": { + "name": "host_check_incidents", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "policy_id": { + "name": "policy_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "detected_at": { + "name": "detected_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "recovery_started_at": { + "name": "recovery_started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "recovered_at": { + "name": "recovered_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "failure_code": { + "name": "failure_code", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "recovery_code": { + "name": "recovery_code", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "closed_reason": { + "name": "closed_reason", + "type": "varchar(24)", + "primaryKey": false, + "notNull": false + }, + "closed_at": { + "name": "closed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "host_check_incidents_one_open_unique": { + "name": "host_check_incidents_one_open_unique", + "columns": [ + { + "expression": "policy_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"rentnerproxy\".\"host_check_incidents\".\"closed_reason\" is null", + "concurrently": false, + "method": "btree", + "with": {} + }, + "host_check_incidents_policy_time_idx": { + "name": "host_check_incidents_policy_time_idx", + "columns": [ + { + "expression": "policy_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "host_check_incidents_closed_time_idx": { + "name": "host_check_incidents_closed_time_idx", + "columns": [ + { + "expression": "closed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"rentnerproxy\".\"host_check_incidents\".\"closed_at\" is not null", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "host_check_incidents_policy_id_host_check_policies_id_fk": { + "name": "host_check_incidents_policy_id_host_check_policies_id_fk", + "tableFrom": "host_check_incidents", + "tableTo": "host_check_policies", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "policy_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "host_check_incidents_closed_reason_check": { + "name": "host_check_incidents_closed_reason_check", + "value": "\"rentnerproxy\".\"host_check_incidents\".\"closed_reason\" is null or \"rentnerproxy\".\"host_check_incidents\".\"closed_reason\" in ('recovered','policy_changed','monitoring_disabled')" + }, + "host_check_incidents_closed_at_check": { + "name": "host_check_incidents_closed_at_check", + "value": "(\"rentnerproxy\".\"host_check_incidents\".\"closed_reason\" is null) = (\"rentnerproxy\".\"host_check_incidents\".\"closed_at\" is null) and (\"rentnerproxy\".\"host_check_incidents\".\"closed_at\" is null or \"rentnerproxy\".\"host_check_incidents\".\"closed_at\" >= \"rentnerproxy\".\"host_check_incidents\".\"detected_at\")" + }, + "host_check_incidents_dates_check": { + "name": "host_check_incidents_dates_check", + "value": "\"rentnerproxy\".\"host_check_incidents\".\"detected_at\" >= \"rentnerproxy\".\"host_check_incidents\".\"started_at\" and (\"rentnerproxy\".\"host_check_incidents\".\"recovery_started_at\" is null or \"rentnerproxy\".\"host_check_incidents\".\"recovery_started_at\" >= \"rentnerproxy\".\"host_check_incidents\".\"started_at\") and (\"rentnerproxy\".\"host_check_incidents\".\"recovered_at\" is null or \"rentnerproxy\".\"host_check_incidents\".\"recovered_at\" >= \"rentnerproxy\".\"host_check_incidents\".\"detected_at\")" + }, + "host_check_incidents_recovery_check": { + "name": "host_check_incidents_recovery_check", + "value": "(\"rentnerproxy\".\"host_check_incidents\".\"closed_reason\" is not distinct from 'recovered' and \"rentnerproxy\".\"host_check_incidents\".\"recovery_started_at\" is not null and \"rentnerproxy\".\"host_check_incidents\".\"recovered_at\" is not null and \"rentnerproxy\".\"host_check_incidents\".\"recovery_code\" is not null) or (\"rentnerproxy\".\"host_check_incidents\".\"closed_reason\" is distinct from 'recovered' and \"rentnerproxy\".\"host_check_incidents\".\"recovered_at\" is null and \"rentnerproxy\".\"host_check_incidents\".\"recovery_code\" is null)" + }, + "host_check_incidents_failure_code_check": { + "name": "host_check_incidents_failure_code_check", + "value": "\"rentnerproxy\".\"host_check_incidents\".\"failure_code\" in ('unexpected_status','upstream_unreachable','upstream_timeout','upstream_dns_failed','tls_failed')" + }, + "host_check_incidents_recovery_code_check": { + "name": "host_check_incidents_recovery_code_check", + "value": "\"rentnerproxy\".\"host_check_incidents\".\"recovery_code\" is null or \"rentnerproxy\".\"host_check_incidents\".\"recovery_code\" = 'expected_status'" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.host_check_observations": { + "name": "host_check_observations", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "policy_id": { + "name": "policy_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "policy_version": { + "name": "policy_version", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "checked_at": { + "name": "checked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "status": { + "name": "status", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "duration_ms": { + "name": "duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "http_status": { + "name": "http_status", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "host_check_observations_policy_time_idx": { + "name": "host_check_observations_policy_time_idx", + "columns": [ + { + "expression": "policy_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "checked_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "host_check_observations_time_idx": { + "name": "host_check_observations_time_idx", + "columns": [ + { + "expression": "checked_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "host_check_observations_policy_id_host_check_policies_id_fk": { + "name": "host_check_observations_policy_id_host_check_policies_id_fk", + "tableFrom": "host_check_observations", + "tableTo": "host_check_policies", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "policy_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "host_check_observations_status_check": { + "name": "host_check_observations_status_check", + "value": "\"rentnerproxy\".\"host_check_observations\".\"status\" in ('unknown','healthy','unhealthy')" + }, + "host_check_observations_code_check": { + "name": "host_check_observations_code_check", + "value": "\"rentnerproxy\".\"host_check_observations\".\"code\" in ('expected_status','unexpected_status','upstream_unreachable','upstream_timeout','upstream_dns_failed','tls_failed','configuration_stale','configuration_changed','host_not_active','runtime_unavailable','busy','invalid_response')" + }, + "host_check_observations_duration_check": { + "name": "host_check_observations_duration_check", + "value": "\"rentnerproxy\".\"host_check_observations\".\"duration_ms\" is null or \"rentnerproxy\".\"host_check_observations\".\"duration_ms\" between 0 and 12000" + }, + "host_check_observations_http_status_check": { + "name": "host_check_observations_http_status_check", + "value": "\"rentnerproxy\".\"host_check_observations\".\"http_status\" is null or \"rentnerproxy\".\"host_check_observations\".\"http_status\" between 100 and 599" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.host_check_policies": { + "name": "host_check_policies", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "proxy_host_id": { + "name": "proxy_host_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "varchar(253)", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "version": { + "name": "version", + "type": "uuid", + "primaryKey": false, + "notNull": true, + "default": "uuidv7()" + }, + "context_proof": { + "name": "context_proof", + "type": "varchar(71)", + "primaryKey": false, + "notNull": false + }, + "context_revision": { + "name": "context_revision", + "type": "varchar(71)", + "primaryKey": false, + "notNull": false + }, + "interval_seconds": { + "name": "interval_seconds", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 60 + }, + "timeout_ms": { + "name": "timeout_ms", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 3000 + }, + "expected_status": { + "name": "expected_status", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 200 + }, + "failure_threshold": { + "name": "failure_threshold", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 3 + }, + "recovery_threshold": { + "name": "recovery_threshold", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 2 + }, + "retention_days": { + "name": "retention_days", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 7 + }, + "sample_limit": { + "name": "sample_limit", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1440 + }, + "incident_limit": { + "name": "incident_limit", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 100 + }, + "state": { + "name": "state", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true, + "default": "'unknown'" + }, + "failure_count": { + "name": "failure_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "recovery_count": { + "name": "recovery_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "failure_started_at": { + "name": "failure_started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "recovery_started_at": { + "name": "recovery_started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "next_check_at": { + "name": "next_check_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "last_checked_at": { + "name": "last_checked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_outcome": { + "name": "last_outcome", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "last_code": { + "name": "last_code", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "last_duration_ms": { + "name": "last_duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "last_http_status": { + "name": "last_http_status", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "lease_token": { + "name": "lease_token", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "lease_expires_at": { + "name": "lease_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "configured_by": { + "name": "configured_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "host_check_policies_host_unique": { + "name": "host_check_policies_host_unique", + "columns": [ + { + "expression": "proxy_host_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "host_check_policies_due_idx": { + "name": "host_check_policies_due_idx", + "columns": [ + { + "expression": "next_check_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"rentnerproxy\".\"host_check_policies\".\"enabled\"", + "concurrently": false, + "method": "btree", + "with": {} + }, + "host_check_policies_lease_idx": { + "name": "host_check_policies_lease_idx", + "columns": [ + { + "expression": "lease_expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"rentnerproxy\".\"host_check_policies\".\"lease_token\" is not null", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "host_check_policies_proxy_host_id_proxy_hosts_id_fk": { + "name": "host_check_policies_proxy_host_id_proxy_hosts_id_fk", + "tableFrom": "host_check_policies", + "tableTo": "proxy_hosts", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "proxy_host_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "host_check_policies_configured_by_users_id_fk": { + "name": "host_check_policies_configured_by_users_id_fk", + "tableFrom": "host_check_policies", + "tableTo": "users", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "configured_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "host_check_policies_domain_check": { + "name": "host_check_policies_domain_check", + "value": "\"rentnerproxy\".\"host_check_policies\".\"domain\" ~ '^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$' and \"rentnerproxy\".\"host_check_policies\".\"domain\" !~ '^[0-9.]+$'" + }, + "host_check_policies_interval_check": { + "name": "host_check_policies_interval_check", + "value": "\"rentnerproxy\".\"host_check_policies\".\"interval_seconds\" between 30 and 86400" + }, + "host_check_policies_timeout_check": { + "name": "host_check_policies_timeout_check", + "value": "\"rentnerproxy\".\"host_check_policies\".\"timeout_ms\" between 1000 and 10000" + }, + "host_check_policies_status_check": { + "name": "host_check_policies_status_check", + "value": "\"rentnerproxy\".\"host_check_policies\".\"expected_status\" between 100 and 599" + }, + "host_check_policies_thresholds_check": { + "name": "host_check_policies_thresholds_check", + "value": "\"rentnerproxy\".\"host_check_policies\".\"failure_threshold\" between 1 and 20 and \"rentnerproxy\".\"host_check_policies\".\"recovery_threshold\" between 1 and 20" + }, + "host_check_policies_retention_check": { + "name": "host_check_policies_retention_check", + "value": "\"rentnerproxy\".\"host_check_policies\".\"retention_days\" between 1 and 30 and \"rentnerproxy\".\"host_check_policies\".\"sample_limit\" between 10 and 10000 and \"rentnerproxy\".\"host_check_policies\".\"incident_limit\" between 1 and 1000" + }, + "host_check_policies_state_check": { + "name": "host_check_policies_state_check", + "value": "\"rentnerproxy\".\"host_check_policies\".\"state\" in ('unknown','healthy','unhealthy')" + }, + "host_check_policies_streaks_check": { + "name": "host_check_policies_streaks_check", + "value": "\"rentnerproxy\".\"host_check_policies\".\"failure_count\" between 0 and \"rentnerproxy\".\"host_check_policies\".\"failure_threshold\" and \"rentnerproxy\".\"host_check_policies\".\"recovery_count\" between 0 and \"rentnerproxy\".\"host_check_policies\".\"recovery_threshold\" and (\"rentnerproxy\".\"host_check_policies\".\"failure_count\" = 0) = (\"rentnerproxy\".\"host_check_policies\".\"failure_started_at\" is null) and (\"rentnerproxy\".\"host_check_policies\".\"recovery_count\" = 0) = (\"rentnerproxy\".\"host_check_policies\".\"recovery_started_at\" is null)" + }, + "host_check_policies_lease_check": { + "name": "host_check_policies_lease_check", + "value": "(\"rentnerproxy\".\"host_check_policies\".\"lease_token\" is null) = (\"rentnerproxy\".\"host_check_policies\".\"lease_expires_at\" is null)" + }, + "host_check_policies_context_check": { + "name": "host_check_policies_context_check", + "value": "(\"rentnerproxy\".\"host_check_policies\".\"context_proof\" is null and \"rentnerproxy\".\"host_check_policies\".\"context_revision\" is null) or (\"rentnerproxy\".\"host_check_policies\".\"context_proof\" is not null and \"rentnerproxy\".\"host_check_policies\".\"context_revision\" is not null and \"rentnerproxy\".\"host_check_policies\".\"context_proof\" ~ '^sha256:[a-f0-9]{64}$' and \"rentnerproxy\".\"host_check_policies\".\"context_revision\" ~ '^sha256:[a-f0-9]{64}$')" + }, + "host_check_policies_last_outcome_check": { + "name": "host_check_policies_last_outcome_check", + "value": "\"rentnerproxy\".\"host_check_policies\".\"last_outcome\" is null or \"rentnerproxy\".\"host_check_policies\".\"last_outcome\" in ('unknown','healthy','unhealthy')" + }, + "host_check_policies_last_duration_check": { + "name": "host_check_policies_last_duration_check", + "value": "\"rentnerproxy\".\"host_check_policies\".\"last_duration_ms\" is null or \"rentnerproxy\".\"host_check_policies\".\"last_duration_ms\" between 0 and 12000" + }, + "host_check_policies_last_http_status_check": { + "name": "host_check_policies_last_http_status_check", + "value": "\"rentnerproxy\".\"host_check_policies\".\"last_http_status\" is null or \"rentnerproxy\".\"host_check_policies\".\"last_http_status\" between 100 and 599" + }, + "host_check_policies_last_code_check": { + "name": "host_check_policies_last_code_check", + "value": "\"rentnerproxy\".\"host_check_policies\".\"last_code\" is null or \"rentnerproxy\".\"host_check_policies\".\"last_code\" in ('expected_status','unexpected_status','upstream_unreachable','upstream_timeout','upstream_dns_failed','tls_failed','configuration_stale','configuration_changed','host_not_active','runtime_unavailable','busy','invalid_response')" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.host_domains": { + "name": "host_domains", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "proxy_host_id": { + "name": "proxy_host_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "redirect_host_id": { + "name": "redirect_host_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "domain": { + "name": "domain", + "type": "varchar(253)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "host_domains_proxy_host_id_idx": { + "name": "host_domains_proxy_host_id_idx", + "columns": [ + { + "expression": "proxy_host_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "host_domains_redirect_host_id_idx": { + "name": "host_domains_redirect_host_id_idx", + "columns": [ + { + "expression": "redirect_host_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "host_domains_proxy_host_id_proxy_hosts_id_fk": { + "name": "host_domains_proxy_host_id_proxy_hosts_id_fk", + "tableFrom": "host_domains", + "tableTo": "proxy_hosts", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "proxy_host_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "host_domains_redirect_host_id_redirect_hosts_id_fk": { + "name": "host_domains_redirect_host_id_redirect_hosts_id_fk", + "tableFrom": "host_domains", + "tableTo": "redirect_hosts", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "redirect_host_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "host_domains_domain_unique": { + "name": "host_domains_domain_unique", + "nullsNotDistinct": false, + "columns": [ + "domain" + ] + } + }, + "policies": {}, + "checkConstraints": { + "host_domains_domain_canonical_check": { + "name": "host_domains_domain_canonical_check", + "value": "\"rentnerproxy\".\"host_domains\".\"domain\" ~ '^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$' and \"rentnerproxy\".\"host_domains\".\"domain\" !~ '^[0-9.]+$'" + }, + "host_domains_exactly_one_owner_check": { + "name": "host_domains_exactly_one_owner_check", + "value": "num_nonnulls(\"rentnerproxy\".\"host_domains\".\"proxy_host_id\", \"rentnerproxy\".\"host_domains\".\"redirect_host_id\") = 1" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.legacy_feature_handoff_parts": { + "name": "legacy_feature_handoff_parts", + "schema": "rentnerproxy", + "columns": { + "domain": { + "name": "domain", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "sequence": { + "name": "sequence", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "sha256": { + "name": "sha256", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "ciphertext": { + "name": "ciphertext", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "iv": { + "name": "iv", + "type": "bytea", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "legacy_feature_handoff_parts_domain_sequence_pk": { + "name": "legacy_feature_handoff_parts_domain_sequence_pk", + "columns": [ + "domain", + "sequence" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "legacy_feature_handoff_parts_sequence_check": { + "name": "legacy_feature_handoff_parts_sequence_check", + "value": "\"rentnerproxy\".\"legacy_feature_handoff_parts\".\"sequence\" between 0 and 1023" + }, + "legacy_feature_handoff_parts_sha256_check": { + "name": "legacy_feature_handoff_parts_sha256_check", + "value": "\"rentnerproxy\".\"legacy_feature_handoff_parts\".\"sha256\" ~ '^[a-f0-9]{64}$'" + }, + "legacy_feature_handoff_parts_iv_check": { + "name": "legacy_feature_handoff_parts_iv_check", + "value": "octet_length(\"rentnerproxy\".\"legacy_feature_handoff_parts\".\"iv\") = 12" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.legacy_feature_handoff_refusals": { + "name": "legacy_feature_handoff_refusals", + "schema": "rentnerproxy", + "columns": { + "installation_id": { + "name": "installation_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "reason": { + "name": "reason", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "detail": { + "name": "detail", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "refused_at": { + "name": "refused_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "legacy_feature_handoff_refusals_installation_id_app_runtime_installations_id_fk": { + "name": "legacy_feature_handoff_refusals_installation_id_app_runtime_installations_id_fk", + "tableFrom": "legacy_feature_handoff_refusals", + "tableTo": "app_runtime_installations", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "installation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "legacy_feature_handoff_refusals_installation_id_domain_pk": { + "name": "legacy_feature_handoff_refusals_installation_id_domain_pk", + "columns": [ + "installation_id", + "domain" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "legacy_feature_handoff_refusals_domain_check": { + "name": "legacy_feature_handoff_refusals_domain_check", + "value": "\"rentnerproxy\".\"legacy_feature_handoff_refusals\".\"domain\" in ('monitoring', 'docker-discovery', 'load-balancer', 'dns', 'oidc', 'crowdsec')" + }, + "legacy_feature_handoff_refusals_reason_check": { + "name": "legacy_feature_handoff_refusals_reason_check", + "value": "\"rentnerproxy\".\"legacy_feature_handoff_refusals\".\"reason\" in ('invalidExport', 'unsupportedFormat', 'importFailed', 'other')" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.legacy_feature_handoff_requests": { + "name": "legacy_feature_handoff_requests", + "schema": "rentnerproxy", + "columns": { + "installation_id": { + "name": "installation_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "actor": { + "name": "actor", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "operation": { + "name": "operation", + "type": "varchar(6)", + "primaryKey": false, + "notNull": true + }, + "idempotency_key": { + "name": "idempotency_key", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "fingerprint": { + "name": "fingerprint", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "legacy_feature_handoff_requests_installation_time_idx": { + "name": "legacy_feature_handoff_requests_installation_time_idx", + "columns": [ + { + "expression": "installation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "legacy_feature_handoff_requests_installation_id_app_runtime_installations_id_fk": { + "name": "legacy_feature_handoff_requests_installation_id_app_runtime_installations_id_fk", + "tableFrom": "legacy_feature_handoff_requests", + "tableTo": "app_runtime_installations", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "installation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "legacy_feature_handoff_requests_installation_id_actor_operation_idempotency_key_pk": { + "name": "legacy_feature_handoff_requests_installation_id_actor_operation_idempotency_key_pk", + "columns": [ + "installation_id", + "actor", + "operation", + "idempotency_key" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "legacy_feature_handoff_requests_operation_check": { + "name": "legacy_feature_handoff_requests_operation_check", + "value": "\"rentnerproxy\".\"legacy_feature_handoff_requests\".\"operation\" in ('begin', 'commit', 'abort')" + }, + "legacy_feature_handoff_requests_fingerprint_check": { + "name": "legacy_feature_handoff_requests_fingerprint_check", + "value": "\"rentnerproxy\".\"legacy_feature_handoff_requests\".\"fingerprint\" ~ '^[a-f0-9]{64}$'" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.legacy_feature_handoffs": { + "name": "legacy_feature_handoffs", + "schema": "rentnerproxy", + "columns": { + "domain": { + "name": "domain", + "type": "varchar(32)", + "primaryKey": true, + "notNull": true + }, + "installation_id": { + "name": "installation_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "state": { + "name": "state", + "type": "varchar(9)", + "primaryKey": false, + "notNull": true + }, + "digest": { + "name": "digest", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "part_count": { + "name": "part_count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "exported_at": { + "name": "exported_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "committed_at": { + "name": "committed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "legacy_feature_handoffs_installation_id_app_runtime_installations_id_fk": { + "name": "legacy_feature_handoffs_installation_id_app_runtime_installations_id_fk", + "tableFrom": "legacy_feature_handoffs", + "tableTo": "app_runtime_installations", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "installation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "legacy_feature_handoffs_domain_check": { + "name": "legacy_feature_handoffs_domain_check", + "value": "\"rentnerproxy\".\"legacy_feature_handoffs\".\"domain\" in ('monitoring', 'docker-discovery', 'load-balancer', 'dns', 'oidc', 'crowdsec')" + }, + "legacy_feature_handoffs_state_check": { + "name": "legacy_feature_handoffs_state_check", + "value": "\"rentnerproxy\".\"legacy_feature_handoffs\".\"state\" in ('exported', 'committed')" + }, + "legacy_feature_handoffs_digest_check": { + "name": "legacy_feature_handoffs_digest_check", + "value": "\"rentnerproxy\".\"legacy_feature_handoffs\".\"digest\" ~ '^[a-f0-9]{64}$'" + }, + "legacy_feature_handoffs_part_count_check": { + "name": "legacy_feature_handoffs_part_count_check", + "value": "\"rentnerproxy\".\"legacy_feature_handoffs\".\"part_count\" between 0 and 1024" + }, + "legacy_feature_handoffs_commit_check": { + "name": "legacy_feature_handoffs_commit_check", + "value": "(\"rentnerproxy\".\"legacy_feature_handoffs\".\"state\" = 'committed') = (\"rentnerproxy\".\"legacy_feature_handoffs\".\"committed_at\" is not null)" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.npm_import_runs": { + "name": "npm_import_runs", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "actor_user_id": { + "name": "actor_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "source_fingerprint": { + "name": "source_fingerprint", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "source_schema": { + "name": "source_schema", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "result": { + "name": "result", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "runtime_status": { + "name": "runtime_status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "npm_import_runs_created_at_idx": { + "name": "npm_import_runs_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "npm_import_runs_fingerprint_idx": { + "name": "npm_import_runs_fingerprint_idx", + "columns": [ + { + "expression": "source_fingerprint", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "npm_import_runs_actor_user_id_users_id_fk": { + "name": "npm_import_runs_actor_user_id_users_id_fk", + "tableFrom": "npm_import_runs", + "tableTo": "users", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "actor_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "npm_import_runs_fingerprint_check": { + "name": "npm_import_runs_fingerprint_check", + "value": "\"rentnerproxy\".\"npm_import_runs\".\"source_fingerprint\" ~ '^[a-f0-9]{64}$'" + }, + "npm_import_runs_runtime_status_check": { + "name": "npm_import_runs_runtime_status_check", + "value": "\"rentnerproxy\".\"npm_import_runs\".\"runtime_status\" in ('applied', 'pending', 'not_applicable')" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.passkeys": { + "name": "passkeys", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "credential_id": { + "name": "credential_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "public_key": { + "name": "public_key", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "counter": { + "name": "counter", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "transports": { + "name": "transports", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "device_type": { + "name": "device_type", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "backed_up": { + "name": "backed_up", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "last_used_at": { + "name": "last_used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "passkeys_credential_id_unique_idx": { + "name": "passkeys_credential_id_unique_idx", + "columns": [ + { + "expression": "credential_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "passkeys_user_id_idx": { + "name": "passkeys_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "passkeys_user_id_users_id_fk": { + "name": "passkeys_user_id_users_id_fk", + "tableFrom": "passkeys", + "tableTo": "users", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "passkeys_counter_check": { + "name": "passkeys_counter_check", + "value": "\"rentnerproxy\".\"passkeys\".\"counter\" >= 0" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.password_reset_tokens": { + "name": "password_reset_tokens", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "token_hash": { + "name": "token_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "consumed_at": { + "name": "consumed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "password_reset_tokens_user_id_idx": { + "name": "password_reset_tokens_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "password_reset_tokens_token_hash_unique_idx": { + "name": "password_reset_tokens_token_hash_unique_idx", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "password_reset_tokens_expires_at_idx": { + "name": "password_reset_tokens_expires_at_idx", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "password_reset_tokens_user_id_users_id_fk": { + "name": "password_reset_tokens_user_id_users_id_fk", + "tableFrom": "password_reset_tokens", + "tableTo": "users", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "rentnerproxy.permissions": { + "name": "permissions", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "key": { + "name": "key", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "permissions_key_unique": { + "name": "permissions_key_unique", + "nullsNotDistinct": false, + "columns": [ + "key" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "rentnerproxy.proxy_host_legacy_settings": { + "name": "proxy_host_legacy_settings", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "proxy_host_id": { + "name": "proxy_host_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "advanced_config": { + "name": "advanced_config", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "unsupported_settings": { + "name": "unsupported_settings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "rentnerproxy.proxy_hosts": { + "name": "proxy_hosts", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "forward_scheme": { + "name": "forward_scheme", + "type": "varchar(5)", + "primaryKey": false, + "notNull": true + }, + "forward_host": { + "name": "forward_host", + "type": "varchar(253)", + "primaryKey": false, + "notNull": true + }, + "forward_port": { + "name": "forward_port", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "upstream_pool": { + "name": "upstream_pool", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "certificate_id": { + "name": "certificate_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "force_https": { + "name": "force_https", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "verify_upstream_tls": { + "name": "verify_upstream_tls", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "upstream_tls_server_name": { + "name": "upstream_tls_server_name", + "type": "varchar(253)", + "primaryKey": false, + "notNull": false + }, + "trusted_ca_id": { + "name": "trusted_ca_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "access_policy_id": { + "name": "access_policy_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "proxy_hosts_enabled_idx": { + "name": "proxy_hosts_enabled_idx", + "columns": [ + { + "expression": "enabled", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "proxy_hosts_certificate_id_idx": { + "name": "proxy_hosts_certificate_id_idx", + "columns": [ + { + "expression": "certificate_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "proxy_hosts_trusted_ca_id_idx": { + "name": "proxy_hosts_trusted_ca_id_idx", + "columns": [ + { + "expression": "trusted_ca_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "proxy_hosts_access_policy_id_idx": { + "name": "proxy_hosts_access_policy_id_idx", + "columns": [ + { + "expression": "access_policy_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "proxy_hosts_certificate_id_certificates_id_fk": { + "name": "proxy_hosts_certificate_id_certificates_id_fk", + "tableFrom": "proxy_hosts", + "tableTo": "certificates", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "certificate_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "proxy_hosts_trusted_ca_id_trusted_cas_id_fk": { + "name": "proxy_hosts_trusted_ca_id_trusted_cas_id_fk", + "tableFrom": "proxy_hosts", + "tableTo": "trusted_cas", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "trusted_ca_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "proxy_hosts_access_policy_id_access_policies_id_fk": { + "name": "proxy_hosts_access_policy_id_access_policies_id_fk", + "tableFrom": "proxy_hosts", + "tableTo": "access_policies", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "access_policy_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "proxy_hosts_forward_scheme_check": { + "name": "proxy_hosts_forward_scheme_check", + "value": "\"rentnerproxy\".\"proxy_hosts\".\"forward_scheme\" in ('http', 'https')" + }, + "proxy_hosts_forward_port_check": { + "name": "proxy_hosts_forward_port_check", + "value": "\"rentnerproxy\".\"proxy_hosts\".\"forward_port\" between 1 and 65535" + }, + "proxy_hosts_forward_host_check": { + "name": "proxy_hosts_forward_host_check", + "value": "length(btrim(\"rentnerproxy\".\"proxy_hosts\".\"forward_host\")) > 0" + }, + "proxy_hosts_upstream_pool_check": { + "name": "proxy_hosts_upstream_pool_check", + "value": "\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\" is null or coalesce((\n jsonb_typeof(\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\") = 'object'\n and \"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\" ?& array['policy', 'members']\n and (\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\" - 'policy' - 'members' - 'failover') = '{}'::jsonb\n and jsonb_typeof(\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'policy') = 'string'\n and \"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->>'policy' in ('round_robin', 'first')\n and jsonb_typeof(\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'members') = 'array'\n and jsonb_array_length(\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'members') between 1 and 16\n and not jsonb_path_exists(\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\", '$.members[*] ? (@.type() != \"object\" || !exists(@.host) || !exists(@.port) || @.host.type() != \"string\" || @.host == \"\" || @.port.type() != \"number\" || @.port < 1 || @.port > 65535 || @.port.floor() != @.port)')\n and not jsonb_path_exists(\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\", '$.members[*].keyvalue() ? (@.key != \"host\" && @.key != \"port\")')\n and \"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'members'->0->>'host' = \"rentnerproxy\".\"proxy_hosts\".\"forward_host\"\n and \"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'members'->0->'port' = to_jsonb(\"rentnerproxy\".\"proxy_hosts\".\"forward_port\")\n and (not (\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\" ? 'failover') or (\n jsonb_typeof((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')) = 'object'\n and (\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover') <> '{}'::jsonb\n and ((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover') - 'active' - 'passive' - 'retries') = '{}'::jsonb\n and (not ((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover') ? 'active') or (\n jsonb_typeof(((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')) = 'object'\n and ((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active') ?& array['path', 'intervalSeconds', 'timeoutSeconds', 'fails', 'passes', 'expectedStatus']\n and (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active') - 'path' - 'intervalSeconds' - 'timeoutSeconds' - 'fails' - 'passes' - 'expectedStatus') = '{}'::jsonb\n and jsonb_typeof(((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->'intervalSeconds') = 'number'\n and (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'intervalSeconds')::numeric between 5 and 300\n and trunc((((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'intervalSeconds')::numeric) = (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'intervalSeconds')::numeric\n and jsonb_typeof(((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->'timeoutSeconds') = 'number'\n and (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'timeoutSeconds')::numeric between 1 and 30\n and trunc((((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'timeoutSeconds')::numeric) = (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'timeoutSeconds')::numeric\n and jsonb_typeof(((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->'fails') = 'number'\n and (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'fails')::numeric between 1 and 10\n and trunc((((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'fails')::numeric) = (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'fails')::numeric\n and jsonb_typeof(((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->'passes') = 'number'\n and (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'passes')::numeric between 1 and 10\n and trunc((((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'passes')::numeric) = (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'passes')::numeric\n and jsonb_typeof(((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->'expectedStatus') = 'number'\n and (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'expectedStatus')::numeric between 200 and 399\n and trunc((((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'expectedStatus')::numeric) = (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'expectedStatus')::numeric\n and jsonb_typeof(((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->'path') = 'string'\n and length((((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'path')) between 1 and 2048\n and left((((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'path'), 1) = '/' and left((((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'path'), 2) <> '//'\n and (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'path') !~ '[^!-~]'\n and position('#' in (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'path')) = 0\n and position(chr(92) in (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'path')) = 0\n and position('{' in (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'path')) = 0 and position('}' in (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'path')) = 0\n and (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'path') !~ '%([^0-9A-Fa-f]|[0-9A-Fa-f]([^0-9A-Fa-f]|$)|$)'\n and (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'timeoutSeconds')::numeric <= (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'active')->>'intervalSeconds')::numeric\n ))\n and (not ((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover') ? 'passive') or (\n jsonb_typeof(((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'passive')) = 'object'\n and ((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'passive') ?& array['failDurationSeconds', 'maxFails']\n and (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'passive') - 'failDurationSeconds' - 'maxFails') = '{}'::jsonb\n and jsonb_typeof(((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'passive')->'failDurationSeconds') = 'number'\n and (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'passive')->>'failDurationSeconds')::numeric between 1 and 300\n and trunc((((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'passive')->>'failDurationSeconds')::numeric) = (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'passive')->>'failDurationSeconds')::numeric\n and jsonb_typeof(((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'passive')->'maxFails') = 'number'\n and (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'passive')->>'maxFails')::numeric between 1 and 10\n and trunc((((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'passive')->>'maxFails')::numeric) = (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'passive')->>'maxFails')::numeric\n ))\n and (not ((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover') ? 'retries') or (\n jsonb_typeof(((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'retries')) = 'object'\n and ((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'retries') ?& array['maxRetries', 'tryDurationSeconds', 'tryIntervalMilliseconds']\n and (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'retries') - 'maxRetries' - 'tryDurationSeconds' - 'tryIntervalMilliseconds') = '{}'::jsonb\n and jsonb_typeof(((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'retries')->'maxRetries') = 'number'\n and (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'retries')->>'maxRetries')::numeric between 1 and 15\n and trunc((((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'retries')->>'maxRetries')::numeric) = (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'retries')->>'maxRetries')::numeric\n and jsonb_typeof(((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'retries')->'tryDurationSeconds') = 'number'\n and (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'retries')->>'tryDurationSeconds')::numeric between 1 and 30\n and trunc((((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'retries')->>'tryDurationSeconds')::numeric) = (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'retries')->>'tryDurationSeconds')::numeric\n and jsonb_typeof(((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'retries')->'tryIntervalMilliseconds') = 'number'\n and (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'retries')->>'tryIntervalMilliseconds')::numeric between 100 and 5000\n and trunc((((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'retries')->>'tryIntervalMilliseconds')::numeric) = (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'retries')->>'tryIntervalMilliseconds')::numeric\n and (\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover') ? 'passive'\n and (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'retries')->>'tryIntervalMilliseconds')::numeric <= (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'retries')->>'tryDurationSeconds')::numeric * 1000\n and (\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->>'policy' <> 'first' or (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'retries')->>'maxRetries')::numeric >= (((\"rentnerproxy\".\"proxy_hosts\".\"upstream_pool\"->'failover')->'passive')->>'maxFails')::numeric)\n ))\n ))\n ), false)" + }, + "proxy_hosts_trusted_ca_verification_check": { + "name": "proxy_hosts_trusted_ca_verification_check", + "value": "\"rentnerproxy\".\"proxy_hosts\".\"trusted_ca_id\" is null or (\"rentnerproxy\".\"proxy_hosts\".\"forward_scheme\" = 'https' and \"rentnerproxy\".\"proxy_hosts\".\"verify_upstream_tls\" = true)" + }, + "proxy_hosts_force_https_check": { + "name": "proxy_hosts_force_https_check", + "value": "\"rentnerproxy\".\"proxy_hosts\".\"force_https\" = false or \"rentnerproxy\".\"proxy_hosts\".\"certificate_id\" is not null" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.redirect_hosts": { + "name": "redirect_hosts", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "destination": { + "name": "destination", + "type": "varchar(2048)", + "primaryKey": false, + "notNull": true + }, + "status_code": { + "name": "status_code", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 302 + }, + "preserve_request_uri": { + "name": "preserve_request_uri", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "certificate_id": { + "name": "certificate_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "redirect_hosts_enabled_idx": { + "name": "redirect_hosts_enabled_idx", + "columns": [ + { + "expression": "enabled", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "redirect_hosts_certificate_id_idx": { + "name": "redirect_hosts_certificate_id_idx", + "columns": [ + { + "expression": "certificate_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "redirect_hosts_certificate_id_certificates_id_fk": { + "name": "redirect_hosts_certificate_id_certificates_id_fk", + "tableFrom": "redirect_hosts", + "tableTo": "certificates", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "certificate_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "redirect_hosts_status_code_check": { + "name": "redirect_hosts_status_code_check", + "value": "\"rentnerproxy\".\"redirect_hosts\".\"status_code\" in (301, 302, 307, 308)" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.role_permissions": { + "name": "role_permissions", + "schema": "rentnerproxy", + "columns": { + "role_id": { + "name": "role_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "permission_id": { + "name": "permission_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "role_permissions_permission_id_idx": { + "name": "role_permissions_permission_id_idx", + "columns": [ + { + "expression": "permission_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "role_permissions_role_id_roles_id_fk": { + "name": "role_permissions_role_id_roles_id_fk", + "tableFrom": "role_permissions", + "tableTo": "roles", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "role_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "role_permissions_permission_id_permissions_id_fk": { + "name": "role_permissions_permission_id_permissions_id_fk", + "tableFrom": "role_permissions", + "tableTo": "permissions", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "permission_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "role_permissions_role_id_permission_id_pk": { + "name": "role_permissions_role_id_permission_id_pk", + "columns": [ + "role_id", + "permission_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "rentnerproxy.roles": { + "name": "roles", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "key": { + "name": "key", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "is_system": { + "name": "is_system", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "roles_is_system_idx": { + "name": "roles_is_system_idx", + "columns": [ + { + "expression": "is_system", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "roles_key_unique": { + "name": "roles_key_unique", + "nullsNotDistinct": false, + "columns": [ + "key" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "rentnerproxy.sessions": { + "name": "sessions", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "token_hash": { + "name": "token_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "oidc_proof": { + "name": "oidc_proof", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "reauthenticated_at": { + "name": "reauthenticated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "sessions_token_hash_unique_idx": { + "name": "sessions_token_hash_unique_idx", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sessions_user_id_idx": { + "name": "sessions_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sessions_expires_at_idx": { + "name": "sessions_expires_at_idx", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "rentnerproxy.system_settings": { + "name": "system_settings", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "system_settings_key_unique": { + "name": "system_settings_key_unique", + "nullsNotDistinct": false, + "columns": [ + "key" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "rentnerproxy.trusted_cas": { + "name": "trusted_cas", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "name": { + "name": "name", + "type": "varchar(120)", + "primaryKey": false, + "notNull": true + }, + "pem": { + "name": "pem", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "fingerprint_sha256": { + "name": "fingerprint_sha256", + "type": "varchar(71)", + "primaryKey": false, + "notNull": true + }, + "subject": { + "name": "subject", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "issuer": { + "name": "issuer", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "not_before": { + "name": "not_before", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "not_after": { + "name": "not_after", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "trusted_cas_created_at_idx": { + "name": "trusted_cas_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "trusted_cas_fingerprint_sha256_unique": { + "name": "trusted_cas_fingerprint_sha256_unique", + "nullsNotDistinct": false, + "columns": [ + "fingerprint_sha256" + ] + } + }, + "policies": {}, + "checkConstraints": { + "trusted_cas_name_check": { + "name": "trusted_cas_name_check", + "value": "length(btrim(\"rentnerproxy\".\"trusted_cas\".\"name\")) > 0" + }, + "trusted_cas_fingerprint_sha256_check": { + "name": "trusted_cas_fingerprint_sha256_check", + "value": "\"rentnerproxy\".\"trusted_cas\".\"fingerprint_sha256\" ~ '^sha256:[a-f0-9]{64}$'" + }, + "trusted_cas_validity_check": { + "name": "trusted_cas_validity_check", + "value": "\"rentnerproxy\".\"trusted_cas\".\"not_before\" < \"rentnerproxy\".\"trusted_cas\".\"not_after\"" + }, + "trusted_cas_pem_limit_check": { + "name": "trusted_cas_pem_limit_check", + "value": "octet_length(\"rentnerproxy\".\"trusted_cas\".\"pem\") between 1 and 262144" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.user_invites": { + "name": "user_invites", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "invited_by_user_id": { + "name": "invited_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "token_hash": { + "name": "token_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "accepted_at": { + "name": "accepted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "user_invites_user_id_unique_idx": { + "name": "user_invites_user_id_unique_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_invites_token_hash_unique_idx": { + "name": "user_invites_token_hash_unique_idx", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_invites_invited_by_user_id_idx": { + "name": "user_invites_invited_by_user_id_idx", + "columns": [ + { + "expression": "invited_by_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_invites_expires_at_idx": { + "name": "user_invites_expires_at_idx", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "user_invites_user_id_users_id_fk": { + "name": "user_invites_user_id_users_id_fk", + "tableFrom": "user_invites", + "tableTo": "users", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_invites_invited_by_user_id_users_id_fk": { + "name": "user_invites_invited_by_user_id_users_id_fk", + "tableFrom": "user_invites", + "tableTo": "users", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "invited_by_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "rentnerproxy.user_recovery_codes": { + "name": "user_recovery_codes", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "code_hash": { + "name": "code_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "used_at": { + "name": "used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "user_recovery_codes_user_id_code_hash_unique_idx": { + "name": "user_recovery_codes_user_id_code_hash_unique_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "code_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_recovery_codes_user_id_idx": { + "name": "user_recovery_codes_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "user_recovery_codes_user_id_users_id_fk": { + "name": "user_recovery_codes_user_id_users_id_fk", + "tableFrom": "user_recovery_codes", + "tableTo": "users", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "rentnerproxy.user_roles": { + "name": "user_roles", + "schema": "rentnerproxy", + "columns": { + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "role_id": { + "name": "role_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "user_roles_role_id_idx": { + "name": "user_roles_role_id_idx", + "columns": [ + { + "expression": "role_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "user_roles_user_id_users_id_fk": { + "name": "user_roles_user_id_users_id_fk", + "tableFrom": "user_roles", + "tableTo": "users", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_roles_role_id_roles_id_fk": { + "name": "user_roles_role_id_roles_id_fk", + "tableFrom": "user_roles", + "tableTo": "roles", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "role_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "user_roles_user_id_role_id_pk": { + "name": "user_roles_user_id_role_id_pk", + "columns": [ + "user_id", + "role_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "rentnerproxy.user_settings": { + "name": "user_settings", + "schema": "rentnerproxy", + "columns": { + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "language": { + "name": "language", + "type": "varchar(2)", + "primaryKey": false, + "notNull": true, + "default": "'en'" + }, + "theme_mode": { + "name": "theme_mode", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'light'" + }, + "navigation_group_preferences": { + "name": "navigation_group_preferences", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + } + }, + "indexes": {}, + "foreignKeys": { + "user_settings_user_id_users_id_fk": { + "name": "user_settings_user_id_users_id_fk", + "tableFrom": "user_settings", + "tableTo": "users", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "user_settings_theme_mode_check": { + "name": "user_settings_theme_mode_check", + "value": "\"rentnerproxy\".\"user_settings\".\"theme_mode\" in ('light', 'dark')" + }, + "user_settings_language_check": { + "name": "user_settings_language_check", + "value": "\"rentnerproxy\".\"user_settings\".\"language\" in ('en', 'de', 'es', 'fr', 'it', 'pt', 'nl', 'pl')" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.user_totp_factors": { + "name": "user_totp_factors", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "secret_ciphertext": { + "name": "secret_ciphertext", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "secret_iv": { + "name": "secret_iv", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "last_used_counter": { + "name": "last_used_counter", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": -1 + }, + "enabled_at": { + "name": "enabled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "user_totp_factors_user_id_unique_idx": { + "name": "user_totp_factors_user_id_unique_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "user_totp_factors_user_id_users_id_fk": { + "name": "user_totp_factors_user_id_users_id_fk", + "tableFrom": "user_totp_factors", + "tableTo": "users", + "schemaTo": "rentnerproxy", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "user_totp_factors_secret_iv_length_check": { + "name": "user_totp_factors_secret_iv_length_check", + "value": "octet_length(\"rentnerproxy\".\"user_totp_factors\".\"secret_iv\") = 12" + }, + "user_totp_factors_last_used_counter_check": { + "name": "user_totp_factors_last_used_counter_check", + "value": "\"rentnerproxy\".\"user_totp_factors\".\"last_used_counter\" >= -1" + } + }, + "isRLSEnabled": false + }, + "rentnerproxy.users": { + "name": "users", + "schema": "rentnerproxy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "display_name": { + "name": "display_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(254)", + "primaryKey": false, + "notNull": true + }, + "email_verified_at": { + "name": "email_verified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "password_hash": { + "name": "password_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "oidc_provider_id": { + "name": "oidc_provider_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "profile_image_version": { + "name": "profile_image_version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "profile_image_webp": { + "name": "profile_image_webp", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "user_status", + "typeSchema": "rentnerproxy", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "users_email_lower_unique_idx": { + "name": "users_email_lower_unique_idx", + "columns": [ + { + "expression": "lower(\"email\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "users_status_idx": { + "name": "users_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "rentnerproxy.access_policy_combination": { + "name": "access_policy_combination", + "schema": "rentnerproxy", + "values": [ + "all", + "any" + ] + }, + "rentnerproxy.access_policy_mode": { + "name": "access_policy_mode", + "schema": "rentnerproxy", + "values": [ + "public", + "authenticated", + "ip-restricted", + "combined" + ] + }, + "rentnerproxy.audit_action": { + "name": "audit_action", + "schema": "rentnerproxy", + "values": [ + "login", + "logout", + "create", + "update", + "delete", + "enable", + "disable", + "rotate", + "reset", + "accept", + "reauthenticate", + "import", + "replace", + "request", + "renew", + "save", + "apply", + "accepted", + "started", + "issued", + "activated", + "renewed", + "retry_scheduled", + "failed", + "abort" + ] + }, + "rentnerproxy.audit_actor_kind": { + "name": "audit_actor_kind", + "schema": "rentnerproxy", + "values": [ + "user", + "anonymous", + "system" + ] + }, + "rentnerproxy.audit_resource": { + "name": "audit_resource", + "schema": "rentnerproxy", + "values": [ + "session", + "password", + "totp", + "recovery-codes", + "passkey", + "invite", + "setup", + "security-settings", + "user", + "role", + "proxy-host", + "redirect-host", + "access-policy", + "basic-auth-account", + "certificate", + "trusted-ca", + "proxy-runtime-settings", + "proxy-host-settings", + "host-monitoring", + "proxy-runtime", + "crowdsec", + "npm-import", + "config-import", + "config-export", + "app-grants", + "app-legacy-handoff" + ] + }, + "rentnerproxy.audit_result": { + "name": "audit_result", + "schema": "rentnerproxy", + "values": [ + "success", + "failure", + "denied" + ] + }, + "rentnerproxy.user_status": { + "name": "user_status", + "schema": "rentnerproxy", + "values": [ + "pending", + "active", + "disabled" + ] + } + }, + "schemas": { + "rentnerproxy": "rentnerproxy" + }, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/web/drizzle/meta/_journal.json b/web/drizzle/meta/_journal.json index d4999441f..4f65ffd7c 100644 --- a/web/drizzle/meta/_journal.json +++ b/web/drizzle/meta/_journal.json @@ -288,6 +288,13 @@ "when": 1795817335941, "tag": "0040_striped_winter_soldier", "breakpoints": true + }, + { + "idx": 41, + "version": "7", + "when": 1795893951662, + "tag": "0041_early_sage", + "breakpoints": true } ] } \ No newline at end of file diff --git a/web/src/config/app-requirements.config.ts b/web/src/config/app-requirements.config.ts index 9a743a0cd..97a016661 100644 --- a/web/src/config/app-requirements.config.ts +++ b/web/src/config/app-requirements.config.ts @@ -14,9 +14,9 @@ export const APP_REQUIREMENTS_MAX_BYTES = 16_384 */ export const APP_RUNTIME_ENVIRONMENT = { runtimeProfile: 'rentnerproxy-linux-v1', - platformApi: '1.0.0', - appProtocol: '1.0.0', - uiBridge: '1.0.0', + platformApi: '1.1.0', + appProtocol: '1.1.0', + uiBridge: '1.1.0', } as const export const BUNDLED_INSTALLER_CONFIG = 'docker/production/apps/catalog/installer.json' diff --git a/web/src/config/audit.config.ts b/web/src/config/audit.config.ts index cd56c372d..5ea54f0a3 100644 --- a/web/src/config/audit.config.ts +++ b/web/src/config/audit.config.ts @@ -26,6 +26,7 @@ export const AUDIT_ACTIONS = [ 'renewed', 'retry_scheduled', 'failed', + 'abort', ] as const export const AUDIT_RESOURCES = [ @@ -54,6 +55,7 @@ export const AUDIT_RESOURCES = [ 'config-import', 'config-export', 'app-grants', + 'app-legacy-handoff', ] as const export const AUDIT_AUTHENTICATION_METHODS = [ diff --git a/web/src/config/legacy-handoff.config.ts b/web/src/config/legacy-handoff.config.ts index 82f812f99..385e2b5d8 100644 --- a/web/src/config/legacy-handoff.config.ts +++ b/web/src/config/legacy-handoff.config.ts @@ -4,7 +4,7 @@ export const LEGACY_HANDOFF_LIMITS = { maximumParts: 1_024, // Two-key advisory locks: this class plus the domain's position in the profile list. advisoryLockClass: 7_421_917, - // Begin and commit are idempotent through the journal, so a forgotten key only loses the + // Begin, commit and abort are idempotent through the journal, so a forgotten key only loses the // conflict check for its reuse. These bounds keep an app from growing the key record. requestKeyRetentionMs: 30 * 24 * 60 * 60 * 1_000, requestKeysPerInstallation: 1_024, @@ -13,4 +13,16 @@ export const LEGACY_HANDOFF_LIMITS = { workerOwnershipPollMs: 15_000, } as const +/** Why an app refuses an export, as the App API contract names it. */ +export const LEGACY_HANDOFF_ABORT_REASONS = [ + 'invalidExport', + 'unsupportedFormat', + 'importFailed', + 'other', +] as const +export const LEGACY_HANDOFF_ABORT_DETAIL_MAX_LENGTH = 500 + +/** The first negotiated platform API version whose status carries `offered` and `refused`. */ +export const LEGACY_HANDOFF_AVAILABILITY_VERSION = '1.1.0' + export const LEGACY_HANDOFF_DIGEST_LABEL = 'rentnerproxy-legacy-feature-handoff-v1' diff --git a/web/src/db/Schema/appRuntime.ts b/web/src/db/Schema/appRuntime.ts index e2c0b82bd..f16ce6250 100644 --- a/web/src/db/Schema/appRuntime.ts +++ b/web/src/db/Schema/appRuntime.ts @@ -68,6 +68,15 @@ export const appRuntimeGenerations = rentnerProxySchema.table( .$type() .notNull() .default(sql`'[]'::jsonb`), + // The versions this installation negotiated: the lower bounds of its manifest ranges. + // They decide what the platform reports and what it may add to closed shapes. + appProtocolVersion: varchar('app_protocol_version', { length: 24 }) + .notNull() + .default('1.0.0'), + platformApiVersion: varchar('platform_api_version', { length: 24 }) + .notNull() + .default('1.0.0'), + uiBridgeVersion: varchar('ui_bridge_version', { length: 24 }), providers: jsonb('providers').$type(), pendingGrants: jsonb('pending_grants').$type(), }, diff --git a/web/src/db/Schema/auditEvents.ts b/web/src/db/Schema/auditEvents.ts index d3df516d2..caaea74b4 100644 --- a/web/src/db/Schema/auditEvents.ts +++ b/web/src/db/Schema/auditEvents.ts @@ -34,6 +34,7 @@ export const auditAction = rentnerProxySchema.enum('audit_action', [ 'renewed', 'retry_scheduled', 'failed', + 'abort', ]) export const auditResource = rentnerProxySchema.enum('audit_resource', [ 'session', @@ -61,6 +62,7 @@ export const auditResource = rentnerProxySchema.enum('audit_resource', [ 'config-import', 'config-export', 'app-grants', + 'app-legacy-handoff', ]) export const auditResult = rentnerProxySchema.enum('audit_result', ['success', 'failure', 'denied']) diff --git a/web/src/db/Schema/legacyFeatureHandoffs.ts b/web/src/db/Schema/legacyFeatureHandoffs.ts index f98e73a32..24d6e6040 100644 --- a/web/src/db/Schema/legacyFeatureHandoffs.ts +++ b/web/src/db/Schema/legacyFeatureHandoffs.ts @@ -4,6 +4,10 @@ import { check, index, integer, primaryKey, timestamp, varchar } from 'drizzle-o import { appRuntimeInstallations } from './appRuntime.ts' import { rentnerProxySchema } from './base.ts' import { bytea } from './columns.ts' +import { + LEGACY_HANDOFF_ABORT_DETAIL_MAX_LENGTH, + LEGACY_HANDOFF_ABORT_REASONS, +} from '../../config/legacy-handoff.config.ts' /** * One row per built-in feature domain that left platform ownership. No row means platform owns @@ -65,7 +69,7 @@ export const legacyFeatureHandoffParts = rentnerProxySchema.table( ) /** - * Accepted idempotency keys of App API begin and commit requests. A key reused with other input is + * Accepted idempotency keys of App API begin, commit and abort requests. A key reused with other input is * a conflict; the journal itself makes a retry with the same input return the recorded state. */ export const legacyFeatureHandoffRequests = rentnerProxySchema.table( @@ -75,7 +79,10 @@ export const legacyFeatureHandoffRequests = rentnerProxySchema.table( .notNull() .references(() => appRuntimeInstallations.id, { onDelete: 'cascade' }), actor: varchar('actor', { length: 64 }).notNull(), - operation: varchar('operation', { enum: ['begin', 'commit'], length: 6 }).notNull(), + operation: varchar('operation', { + enum: ['begin', 'commit', 'abort'], + length: 6, + }).notNull(), key: varchar('idempotency_key', { length: 64 }).notNull(), fingerprint: varchar('fingerprint', { length: 64 }).notNull(), createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(), @@ -88,7 +95,7 @@ export const legacyFeatureHandoffRequests = rentnerProxySchema.table( ), check( 'legacy_feature_handoff_requests_operation_check', - sql`${table.operation} in ('begin', 'commit')`, + sql`${table.operation} in ('begin', 'commit', 'abort')`, ), check( 'legacy_feature_handoff_requests_fingerprint_check', @@ -96,3 +103,32 @@ export const legacyFeatureHandoffRequests = rentnerProxySchema.table( ), ], ) + +/** + * The last abort of an installation for a domain: why the app refused the export and when. It stays + * visible to administrators and to the app after the abort, and a commit clears it. The detail is + * the app's own text for administrators and is shown only as escaped plain text. + */ +export const legacyFeatureHandoffRefusals = rentnerProxySchema.table( + 'legacy_feature_handoff_refusals', + { + installationId: varchar('installation_id', { length: 64 }) + .notNull() + .references(() => appRuntimeInstallations.id, { onDelete: 'cascade' }), + domain: varchar('domain', { length: 32 }).notNull(), + reason: varchar('reason', { enum: LEGACY_HANDOFF_ABORT_REASONS, length: 20 }).notNull(), + detail: varchar('detail', { length: LEGACY_HANDOFF_ABORT_DETAIL_MAX_LENGTH }), + refusedAt: timestamp('refused_at', { withTimezone: true }).notNull().defaultNow(), + }, + (table) => [ + primaryKey({ columns: [table.installationId, table.domain] }), + check( + 'legacy_feature_handoff_refusals_domain_check', + sql`${table.domain} in ('monitoring', 'docker-discovery', 'load-balancer', 'dns', 'oidc', 'crowdsec')`, + ), + check( + 'legacy_feature_handoff_refusals_reason_check', + sql`${table.reason} in ('invalidExport', 'unsupportedFormat', 'importFailed', 'other')`, + ), + ], +) diff --git a/web/src/features/Admin/AuditLogs/validation.ts b/web/src/features/Admin/AuditLogs/validation.ts index 1808f0cae..a62d97c1b 100644 --- a/web/src/features/Admin/AuditLogs/validation.ts +++ b/web/src/features/Admin/AuditLogs/validation.ts @@ -3,7 +3,8 @@ import { CERTIFICATE_ERROR_CODES, CERTIFICATE_OPERATION_STAGES, } from '@/config/certificates.config.ts' -import { appIdSchema, appRecordId } from '@/lib/AppUi/identifiers.ts' +import { LEGACY_HANDOFF_ABORT_REASONS } from '@/config/legacy-handoff.config.ts' +import { appIdSchema, appProviderProfiles, appRecordId } from '@/lib/AppUi/identifiers.ts' import { AUDIT_ACTIONS, @@ -60,6 +61,8 @@ export const auditMetadataSchema = z.strictObject({ certificateErrorCode: z.enum(CERTIFICATE_ERROR_CODES).optional(), appId: appIdSchema.optional(), installationId: appRecordId.optional(), + handoffDomain: z.enum(appProviderProfiles).optional(), + handoffReason: z.enum(LEGACY_HANDOFF_ABORT_REASONS).optional(), }) export const auditEventInputSchema = z diff --git a/web/src/features/ApplicationVersion/Components/UpgradePreviewSection.tsx b/web/src/features/ApplicationVersion/Components/UpgradePreviewSection.tsx index 399310038..5d206c25e 100644 --- a/web/src/features/ApplicationVersion/Components/UpgradePreviewSection.tsx +++ b/web/src/features/ApplicationVersion/Components/UpgradePreviewSection.tsx @@ -18,7 +18,7 @@ export default function UpgradePreviewSection({ preview, loading, }: UpgradePreviewSectionProps) { - const { t } = useTranslationStore() + const { t, locale } = useTranslationStore() const detailed = preview && 'features' in preview ? preview : null const summary = requirements.status !== 'verified' @@ -28,6 +28,21 @@ export default function UpgradePreviewSection({ : `updates.preview.status.${preview.status}` const featureName = (domain: UpgradePreviewFeature['domain']) => t(`updates.preview.features.${domain}`) + const formatTime = (value: string) => { + const date = new Date(value) + return Number.isNaN(date.getTime()) + ? value + : new Intl.DateTimeFormat(locale, { + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + timeZone: 'UTC', + timeZoneName: 'short', + }).format(date) + } const list = (values: readonly string[]) => values.join(', ') || t('updates.preview.none') const issueText = (issue: UpgradePreviewIssue) => issue.kind === 'app-incompatible' @@ -86,6 +101,21 @@ export default function UpgradePreviewSection({ {list(feature.apps)} ) : null} + {feature.refusals?.map((refusal) => ( + + {t('updates.preview.refused', { + app: refusal.appId, + reason: t( + `updates.preview.refusalReasons.${refusal.reason}`, + ), + time: formatTime(refusal.at), + })} + {refusal.detail === null ? null : ` ${refusal.detail}`} + + ))} {feature.providers && feature.providers.length > 0 ? ( {t('updates.preview.providedBy')}:{' '} diff --git a/web/src/features/ApplicationVersion/Types/application-update.types.ts b/web/src/features/ApplicationVersion/Types/application-update.types.ts index bc1c2a30f..cd5bdc241 100644 --- a/web/src/features/ApplicationVersion/Types/application-update.types.ts +++ b/web/src/features/ApplicationVersion/Types/application-update.types.ts @@ -55,6 +55,16 @@ export interface UpgradePreviewApp { readonly target: UpgradeAppSupport } +/** An installed app that gave a built-in feature back after it began taking it over. */ +export interface UpgradePreviewRefusal { + readonly appId: string + readonly reason: 'invalidExport' | 'unsupportedFormat' | 'importFailed' | 'other' + /** UTC time the platform recorded the refusal, as ISO 8601. */ + readonly at: string + /** The app's own text, or `null`. It is untrusted: render it as plain text only. */ + readonly detail: string | null +} + export interface UpgradePreviewFeature { readonly domain: BuiltInFeatureDomain readonly target: BuiltInFeatureTransitionStatus @@ -66,6 +76,8 @@ export interface UpgradePreviewFeature { readonly references: number | null /** Installed apps offering the feature that the target can run; `null` if apps are unknown. */ readonly providers: readonly string[] | null + /** Apps that refused the handoff and did not commit it since; absent when there are none. */ + readonly refusals?: readonly UpgradePreviewRefusal[] } /** Combinations the target cannot run. Each one hides the copyable image reference. */ diff --git a/web/src/lib/Admin/AuditLogs/Types/audit-events.types.ts b/web/src/lib/Admin/AuditLogs/Types/audit-events.types.ts index bbd6073ac..b7f89bd33 100644 --- a/web/src/lib/Admin/AuditLogs/Types/audit-events.types.ts +++ b/web/src/lib/Admin/AuditLogs/Types/audit-events.types.ts @@ -11,6 +11,8 @@ import type { AUDIT_FAILURE_CODES, AUDIT_CHANGED_FIELDS, } from '@/config/audit.config.ts' +import type { LEGACY_HANDOFF_ABORT_REASONS } from '@/config/legacy-handoff.config.ts' +import type { appProviderProfiles } from '@/lib/AppUi/identifiers.ts' type AuditActorKind = (typeof AUDIT_ACTOR_KINDS)[number] @@ -49,6 +51,8 @@ export interface AuditMetadata { readonly certificateErrorCode?: CertificateErrorCode readonly appId?: string readonly installationId?: string + readonly handoffDomain?: (typeof appProviderProfiles)[number] + readonly handoffReason?: (typeof LEGACY_HANDOFF_ABORT_REASONS)[number] } export interface AuditEventInput { diff --git a/web/src/lib/Admin/AuditLogs/auditLogs.ts b/web/src/lib/Admin/AuditLogs/auditLogs.ts index df743ca6a..530dfe743 100644 --- a/web/src/lib/Admin/AuditLogs/auditLogs.ts +++ b/web/src/lib/Admin/AuditLogs/auditLogs.ts @@ -105,6 +105,8 @@ const metadataKeys: readonly (keyof AuditMetadata)[] = [ 'certificateErrorCode', 'appId', 'installationId', + 'handoffDomain', + 'handoffReason', ] export function formatAuditMetadataValue(entry: AuditMetadataEntry, t: Translate): string { diff --git a/web/src/lib/ApplicationVersion/upgradePreview.ts b/web/src/lib/ApplicationVersion/upgradePreview.ts index 59ce33f16..f2089a3df 100644 --- a/web/src/lib/ApplicationVersion/upgradePreview.ts +++ b/web/src/lib/ApplicationVersion/upgradePreview.ts @@ -14,6 +14,7 @@ export interface LocalBuiltInFeature { readonly domain: BuiltInFeatureDomain readonly ownership: { readonly owner: UpgradePreviewFeature['owner'] } readonly inspection?: { readonly configured: boolean; readonly references: number } + readonly refusals?: UpgradePreviewFeature['refusals'] } /** @@ -56,6 +57,7 @@ export function evaluateUpgradePreview( configured: state?.inspection?.configured ?? null, references: state?.inspection?.references ?? null, providers, + ...(state?.refusals && state.refusals.length > 0 && { refusals: state.refusals }), } const unused = feature.configured === false && feature.references === 0 if (transition.status === 'retired' && owner !== 'app' && !unused) { diff --git a/web/src/lib/Language/Locales/de.json b/web/src/lib/Language/Locales/de.json index 4dee93cb9..7afcff761 100644 --- a/web/src/lib/Language/Locales/de.json +++ b/web/src/lib/Language/Locales/de.json @@ -101,6 +101,13 @@ "handoff": "Übergabe läuft", "app": "An eine App übergeben" }, + "refused": "{{app}} hat die Übergabe abgelehnt ({{reason}}), {{time}}.", + "refusalReasons": { + "invalidExport": "der Export war ungültig", + "unsupportedFormat": "das Exportformat wird nicht unterstützt", + "importFailed": "die App konnte den Export nicht speichern", + "other": "anderer Grund" + }, "configured": { "yes": "konfiguriert", "no": "nicht konfiguriert", @@ -2878,7 +2885,8 @@ "activated": "Aktiviert", "renewed": "Erneuert", "retry_scheduled": "Wiederholung geplant", - "failed": "Fehlgeschlagen" + "failed": "Fehlgeschlagen", + "abort": "Abbrechen" }, "resources": { "session": "Sitzung", @@ -2905,7 +2913,8 @@ "npm-import": "NPM-Import", "config-import": "Konfigurationsimport", "config-export": "Konfigurationsexport", - "app-grants": "App-Berechtigungen" + "app-grants": "App-Berechtigungen", + "app-legacy-handoff": "App-Übernahme" } }, "metadata": { @@ -2925,7 +2934,9 @@ "occurredAt": "Aufgetreten am", "certificateErrorCode": "Zertifikat-Fehlercode", "appId": "App-ID", - "installationId": "App-Installation" + "installationId": "App-Installation", + "handoffDomain": "Übergebene Funktion", + "handoffReason": "Ablehnungsgrund" }, "details": { "noMetadata": "Keine weiteren sicheren Metadaten." diff --git a/web/src/lib/Language/Locales/en.json b/web/src/lib/Language/Locales/en.json index 52e02ab23..70bee7a93 100644 --- a/web/src/lib/Language/Locales/en.json +++ b/web/src/lib/Language/Locales/en.json @@ -101,6 +101,13 @@ "handoff": "Handoff in progress", "app": "Handed off to an app" }, + "refused": "{{app}} refused the handoff ({{reason}}) on {{time}}.", + "refusalReasons": { + "invalidExport": "the export was invalid", + "unsupportedFormat": "the export format is not supported", + "importFailed": "the app could not store the export", + "other": "another reason" + }, "configured": { "yes": "configured", "no": "not configured", @@ -2878,7 +2885,8 @@ "activated": "Activated", "renewed": "Renewed", "retry_scheduled": "Retry scheduled", - "failed": "Failed" + "failed": "Failed", + "abort": "Abort" }, "resources": { "session": "Session", @@ -2905,7 +2913,8 @@ "npm-import": "NPM import", "config-import": "Configuration import", "config-export": "Configuration export", - "app-grants": "App grants" + "app-grants": "App grants", + "app-legacy-handoff": "App handoff" } }, "metadata": { @@ -2925,7 +2934,9 @@ "occurredAt": "Occurred at", "certificateErrorCode": "Certificate error code", "appId": "App ID", - "installationId": "App installation" + "installationId": "App installation", + "handoffDomain": "Handoff feature", + "handoffReason": "Refusal reason" }, "details": { "noMetadata": "No additional safe metadata." diff --git a/web/src/lib/Language/Locales/es.json b/web/src/lib/Language/Locales/es.json index 30a3f95c3..ef5585e94 100644 --- a/web/src/lib/Language/Locales/es.json +++ b/web/src/lib/Language/Locales/es.json @@ -103,6 +103,13 @@ "handoff": "Traspaso en curso", "app": "Traspasada a una app" }, + "refused": "{{app}} rechazó el traspaso ({{reason}}) el {{time}}.", + "refusalReasons": { + "invalidExport": "la exportación no era válida", + "unsupportedFormat": "el formato de exportación no es compatible", + "importFailed": "la aplicación no pudo guardar la exportación", + "other": "otro motivo" + }, "configured": { "yes": "configurada", "no": "sin configurar", @@ -2880,7 +2887,8 @@ "activated": "Activado", "renewed": "Renovado", "retry_scheduled": "Reintento programado", - "failed": "Fallido" + "failed": "Fallido", + "abort": "Cancelar" }, "resources": { "session": "Sesión", @@ -2907,7 +2915,8 @@ "npm-import": "Importación de NPM", "config-import": "Importación de configuración", "config-export": "Exportación de configuración", - "app-grants": "Permisos de aplicaciones" + "app-grants": "Permisos de aplicaciones", + "app-legacy-handoff": "Traspaso a aplicación" } }, "metadata": { @@ -2927,7 +2936,9 @@ "occurredAt": "Ocurrió el", "certificateErrorCode": "Código de error del certificado", "appId": "ID de la aplicación", - "installationId": "Instalación de la aplicación" + "installationId": "Instalación de la aplicación", + "handoffDomain": "Función traspasada", + "handoffReason": "Motivo del rechazo" }, "details": { "noMetadata": "No hay más metadatos seguros." diff --git a/web/src/lib/Language/Locales/fr.json b/web/src/lib/Language/Locales/fr.json index 8731efa9b..0faad46a1 100644 --- a/web/src/lib/Language/Locales/fr.json +++ b/web/src/lib/Language/Locales/fr.json @@ -103,6 +103,13 @@ "handoff": "Transfert en cours", "app": "Transférée à une app" }, + "refused": "{{app}} a refusé le transfert ({{reason}}) le {{time}}.", + "refusalReasons": { + "invalidExport": "l'export était invalide", + "unsupportedFormat": "le format d'export n'est pas pris en charge", + "importFailed": "l'application n'a pas pu enregistrer l'export", + "other": "autre motif" + }, "configured": { "yes": "configurée", "no": "non configurée", @@ -2880,7 +2887,8 @@ "activated": "Activé", "renewed": "Renouvelé", "retry_scheduled": "Nouvel essai planifié", - "failed": "Échec" + "failed": "Échec", + "abort": "Abandonner" }, "resources": { "session": "Session", @@ -2907,7 +2915,8 @@ "npm-import": "Import NPM", "config-import": "Import de configuration", "config-export": "Export de configuration", - "app-grants": "Autorisations d’applications" + "app-grants": "Autorisations d’applications", + "app-legacy-handoff": "Transfert vers une application" } }, "metadata": { @@ -2927,7 +2936,9 @@ "occurredAt": "Survenu le", "certificateErrorCode": "Code d’erreur du certificat", "appId": "ID de l’application", - "installationId": "Installation de l’application" + "installationId": "Installation de l’application", + "handoffDomain": "Fonctionnalité transférée", + "handoffReason": "Motif du refus" }, "details": { "noMetadata": "Aucune autre métadonnée sûre." diff --git a/web/src/lib/Language/Locales/it.json b/web/src/lib/Language/Locales/it.json index 374eaa991..3a5418558 100644 --- a/web/src/lib/Language/Locales/it.json +++ b/web/src/lib/Language/Locales/it.json @@ -103,6 +103,13 @@ "handoff": "Trasferimento in corso", "app": "Trasferita a un'app" }, + "refused": "{{app}} ha rifiutato il passaggio ({{reason}}) il {{time}}.", + "refusalReasons": { + "invalidExport": "l'esportazione non era valida", + "unsupportedFormat": "il formato di esportazione non è supportato", + "importFailed": "l'app non ha potuto salvare l'esportazione", + "other": "altro motivo" + }, "configured": { "yes": "configurata", "no": "non configurata", @@ -2892,7 +2899,8 @@ "activated": "Attivato", "renewed": "Rinnovato", "retry_scheduled": "Nuovo tentativo pianificato", - "failed": "Non riuscito" + "failed": "Non riuscito", + "abort": "Interrompi" }, "resources": { "session": "Sessione", @@ -2919,7 +2927,8 @@ "npm-import": "Importazione NPM", "config-import": "Importazione configurazione", "config-export": "Esportazione configurazione", - "app-grants": "Autorizzazioni delle app" + "app-grants": "Autorizzazioni delle app", + "app-legacy-handoff": "Passaggio a un'app" } }, "metadata": { @@ -2939,7 +2948,9 @@ "occurredAt": "Data e ora dell’evento", "certificateErrorCode": "Codice di errore del certificato", "appId": "ID dell’app", - "installationId": "Installazione dell’app" + "installationId": "Installazione dell’app", + "handoffDomain": "Funzione trasferita", + "handoffReason": "Motivo del rifiuto" }, "details": { "noMetadata": "Nessun altro metadato sicuro." diff --git a/web/src/lib/Language/Locales/nl.json b/web/src/lib/Language/Locales/nl.json index ee9c1b160..dfd9ea9ba 100644 --- a/web/src/lib/Language/Locales/nl.json +++ b/web/src/lib/Language/Locales/nl.json @@ -101,6 +101,13 @@ "handoff": "Overdracht bezig", "app": "Overgedragen aan een app" }, + "refused": "{{app}} weigerde de overdracht ({{reason}}) op {{time}}.", + "refusalReasons": { + "invalidExport": "de export was ongeldig", + "unsupportedFormat": "het exportformaat wordt niet ondersteund", + "importFailed": "de app kon de export niet opslaan", + "other": "andere reden" + }, "configured": { "yes": "geconfigureerd", "no": "niet geconfigureerd", @@ -2859,7 +2866,8 @@ "activated": "Geactiveerd", "renewed": "Vernieuwd", "retry_scheduled": "Nieuwe poging gepland", - "failed": "Mislukt" + "failed": "Mislukt", + "abort": "Afbreken" }, "resources": { "session": "Sessie", @@ -2886,7 +2894,8 @@ "npm-import": "NPM-import", "config-import": "Configuratie importeren", "config-export": "Configuratie exporteren", - "app-grants": "App-machtigingen" + "app-grants": "App-machtigingen", + "app-legacy-handoff": "Overdracht aan app" } }, "metadata": { @@ -2906,7 +2915,9 @@ "occurredAt": "Tijdstip", "certificateErrorCode": "Certificaatfoutcode", "appId": "App-ID", - "installationId": "App-installatie" + "installationId": "App-installatie", + "handoffDomain": "Overgedragen functie", + "handoffReason": "Reden van weigering" }, "details": { "noMetadata": "Geen aanvullende veilige metagegevens." diff --git a/web/src/lib/Language/Locales/pl.json b/web/src/lib/Language/Locales/pl.json index 73abd02a1..ebd3db16e 100644 --- a/web/src/lib/Language/Locales/pl.json +++ b/web/src/lib/Language/Locales/pl.json @@ -105,6 +105,13 @@ "handoff": "Trwa przekazanie", "app": "Przekazana aplikacji" }, + "refused": "{{app}} odrzuciła przekazanie ({{reason}}): {{time}}.", + "refusalReasons": { + "invalidExport": "eksport był nieprawidłowy", + "unsupportedFormat": "format eksportu nie jest obsługiwany", + "importFailed": "aplikacja nie mogła zapisać eksportu", + "other": "inny powód" + }, "configured": { "yes": "skonfigurowana", "no": "nieskonfigurowana", @@ -2906,7 +2913,8 @@ "activated": "Aktywowano", "renewed": "Odnowiono", "retry_scheduled": "Zaplanowano ponowną próbę", - "failed": "Niepowodzenie" + "failed": "Niepowodzenie", + "abort": "Przerwij" }, "resources": { "session": "Sesja", @@ -2933,7 +2941,8 @@ "npm-import": "Import NPM", "config-import": "Import konfiguracji", "config-export": "Eksport konfiguracji", - "app-grants": "Uprawnienia aplikacji" + "app-grants": "Uprawnienia aplikacji", + "app-legacy-handoff": "Przekazanie do aplikacji" } }, "metadata": { @@ -2953,7 +2962,9 @@ "occurredAt": "Data zdarzenia", "certificateErrorCode": "Kod błędu certyfikatu", "appId": "ID aplikacji", - "installationId": "Instalacja aplikacji" + "installationId": "Instalacja aplikacji", + "handoffDomain": "Przekazywana funkcja", + "handoffReason": "Powód odrzucenia" }, "details": { "noMetadata": "Brak dodatkowych bezpiecznych metadanych." diff --git a/web/src/lib/Language/Locales/pt.json b/web/src/lib/Language/Locales/pt.json index bbc03bbfe..56beac045 100644 --- a/web/src/lib/Language/Locales/pt.json +++ b/web/src/lib/Language/Locales/pt.json @@ -103,6 +103,13 @@ "handoff": "Transferência em curso", "app": "Transferida para uma app" }, + "refused": "{{app}} recusou a transferência ({{reason}}) em {{time}}.", + "refusalReasons": { + "invalidExport": "a exportação era inválida", + "unsupportedFormat": "o formato de exportação não é suportado", + "importFailed": "a aplicação não conseguiu guardar a exportação", + "other": "outro motivo" + }, "configured": { "yes": "configurada", "no": "não configurada", @@ -2904,7 +2911,8 @@ "activated": "Ativado", "renewed": "Renovado", "retry_scheduled": "Nova tentativa agendada", - "failed": "Falhou" + "failed": "Falhou", + "abort": "Cancelar" }, "resources": { "session": "Sessão", @@ -2931,7 +2939,8 @@ "npm-import": "Importação NPM", "config-import": "Importação de configuração", "config-export": "Exportação de configuração", - "app-grants": "Permissões de aplicações" + "app-grants": "Permissões de aplicações", + "app-legacy-handoff": "Transferência para aplicação" } }, "metadata": { @@ -2951,7 +2960,9 @@ "occurredAt": "Ocorrido em", "certificateErrorCode": "Código de erro do certificado", "appId": "ID da aplicação", - "installationId": "Instalação da aplicação" + "installationId": "Instalação da aplicação", + "handoffDomain": "Funcionalidade transferida", + "handoffReason": "Motivo da recusa" }, "details": { "noMetadata": "Não há metadados seguros adicionais." diff --git a/web/src/server/AppRuntime/Types/authority.types.ts b/web/src/server/AppRuntime/Types/authority.types.ts index 8f07f711d..2e2c35be6 100644 --- a/web/src/server/AppRuntime/Types/authority.types.ts +++ b/web/src/server/AppRuntime/Types/authority.types.ts @@ -45,6 +45,12 @@ export interface AppRuntimeRegistration { readonly permissionKeys?: readonly string[] readonly hasUi?: boolean readonly incidentCategories?: readonly AppIncidentCategory[] + /** The negotiated versions; absent means 1.0.0 for each, as before protocol 1.1.0. */ + readonly versions?: { + readonly appProtocol: string + readonly platformApi: string + readonly uiBridge?: string | undefined + } } interface AppRuntimePrincipalBase { diff --git a/web/src/server/AppRuntime/Types/gateway.types.ts b/web/src/server/AppRuntime/Types/gateway.types.ts index 81d737b0f..f3fcc5b18 100644 --- a/web/src/server/AppRuntime/Types/gateway.types.ts +++ b/web/src/server/AppRuntime/Types/gateway.types.ts @@ -18,7 +18,11 @@ export type AppRuntimeOperation = | LegacyHandoffOperation export type LegacyHandoffOperation = - 'getLegacyHandoff' | 'beginLegacyHandoff' | 'readLegacyHandoffPart' | 'commitLegacyHandoff' + | 'getLegacyHandoff' + | 'beginLegacyHandoff' + | 'readLegacyHandoffPart' + | 'commitLegacyHandoff' + | 'abortLegacyHandoff' export interface AppRuntimeCall { readonly operation: AppRuntimeOperation diff --git a/web/src/server/AppRuntime/authority.server.ts b/web/src/server/AppRuntime/authority.server.ts index 5f100de8e..f80c37df8 100644 --- a/web/src/server/AppRuntime/authority.server.ts +++ b/web/src/server/AppRuntime/authority.server.ts @@ -59,7 +59,6 @@ export { } from './authority-policy.server.ts' const appRuntimeProfile = 'rentnerproxy-linux-v1' -const appRuntimeVersion = '1.0.0' const delegationLifetimeMs = 15 * 60 * 1000 export function isAppRuntimeIdentity(identity: AppRuntimeIdentity): boolean { @@ -242,10 +241,14 @@ export async function readAppRuntimeContextInTransaction( installationId: identity.installationId, generation: identity.generation, runtimeProfile: appRuntimeProfile, + // Each installation sees the versions it negotiated at registration: the lower bounds of + // its manifest ranges, never more than an older SDK of the app can parse. versions: { - appProtocol: appRuntimeVersion, - platformApi: appRuntimeVersion, - ...(generation.hasUi ? { uiBridge: appRuntimeVersion } : {}), + appProtocol: generation.appProtocolVersion, + platformApi: generation.platformApiVersion, + ...(generation.hasUi && generation.uiBridgeVersion !== null + ? { uiBridge: generation.uiBridgeVersion } + : {}), }, capabilities: [...capabilities.values()], } diff --git a/web/src/server/AppRuntime/contract.ts b/web/src/server/AppRuntime/contract.ts index 5139ee170..ffd29a1fb 100644 --- a/web/src/server/AppRuntime/contract.ts +++ b/web/src/server/AppRuntime/contract.ts @@ -1,5 +1,8 @@ import { z } from 'zod' -import { LEGACY_HANDOFF_LIMITS } from '@/config/legacy-handoff.config.ts' +import { + LEGACY_HANDOFF_ABORT_REASONS, + LEGACY_HANDOFF_LIMITS, +} from '@/config/legacy-handoff.config.ts' import { appProviderProfileSchema, appRecordId } from '@/lib/AppUi/identifiers.ts' export { @@ -194,6 +197,24 @@ export const appLegacyHandoffPartRequest = z.strictObject({ .max(LEGACY_HANDOFF_LIMITS.maximumParts - 1), }) export const appLegacyHandoffCommit = z.strictObject({ digest: appLegacyHandoffDigest }) +// A protocol version number as the manifest contract writes it. +const appProtocolVersion = z + .string() + .regex(/^(?:0|[1-9][0-9]{0,5})\.(?:0|[1-9][0-9]{0,5})\.(?:0|[1-9][0-9]{0,5})$/u) +/** The versions an installation negotiated, which the core derives from the manifest ranges. */ +export const appNegotiatedVersions = z.strictObject({ + appProtocol: appProtocolVersion, + platformApi: appProtocolVersion, + uiBridge: appProtocolVersion.optional(), +}) +export const appLegacyHandoffAbort = z.strictObject({ + digest: appLegacyHandoffDigest, + reason: z.enum(LEGACY_HANDOFF_ABORT_REASONS), + detail: z + .string() + .regex(/^[^\p{Cc}\p{Cs}]{1,500}$/u) + .optional(), +}) export const appAuditEvent = z.strictObject({ action: appRecordId, outcome: z.enum(['succeeded', 'rejected', 'failed']), diff --git a/web/src/server/AppRuntime/gateway.server.ts b/web/src/server/AppRuntime/gateway.server.ts index 892557abe..042c3349f 100644 --- a/web/src/server/AppRuntime/gateway.server.ts +++ b/web/src/server/AppRuntime/gateway.server.ts @@ -42,6 +42,7 @@ const resourceRoutes: readonly [RegExp, AppRuntimeOperation][] = [ [/^POST \/platform\/v1\/legacy-handoffs\/([^/]+)\/begin$/u, 'beginLegacyHandoff'], [/^POST \/platform\/v1\/legacy-handoffs\/([^/]+)\/parts$/u, 'readLegacyHandoffPart'], [/^POST \/platform\/v1\/legacy-handoffs\/([^/]+)\/commit$/u, 'commitLegacyHandoff'], + [/^POST \/platform\/v1\/legacy-handoffs\/([^/]+)\/abort$/u, 'abortLegacyHandoff'], ] const keyedOperations: ReadonlySet = new Set([ @@ -52,6 +53,7 @@ const keyedOperations: ReadonlySet = new Set([ 'setIncident', 'beginLegacyHandoff', 'commitLegacyHandoff', + 'abortLegacyHandoff', ]) // These POST operations carry their whole request in the path and the idempotency key. const bodylessPosts: ReadonlySet = new Set([ diff --git a/web/src/server/AppRuntime/lifecycle.server.ts b/web/src/server/AppRuntime/lifecycle.server.ts index 12754336b..5fb94af62 100644 --- a/web/src/server/AppRuntime/lifecycle.server.ts +++ b/web/src/server/AppRuntime/lifecycle.server.ts @@ -14,6 +14,7 @@ import { appRuntimePendingSecrets, appRuntimeRolePermissions, appRuntimeSecrets, + legacyFeatureHandoffRefusals, legacyFeatureHandoffRequests, roles, type AppRuntimeStoredGrant, @@ -32,6 +33,7 @@ import { isAppRuntimeIdentity, lockAppRuntimeInstallation } from './authority.se import { appCapabilitySchema, appIncidentCategoriesSchema, + appNegotiatedVersions, appProviderProfilesSchema, appProviderRegistrationsSchema, } from './contract.ts' @@ -98,6 +100,7 @@ export async function registerAppRuntimeGenerationInTransaction( providerProfiles = [], hasUi = false, incidentCategories = [], + versions, } = registration if ( !isAppRuntimeIdentity(identity) || @@ -109,6 +112,7 @@ export async function registerAppRuntimeGenerationInTransaction( new Set(permissionKeys).size !== permissionKeys.length || !appProviderProfilesSchema.safeParse(providerProfiles).success || !appIncidentCategoriesSchema.safeParse(incidentCategories).success || + (versions !== undefined && !appNegotiatedVersions.safeParse(versions).success) || // An app declares categories exactly when it may raise incidents. incidentCategories.length > 0 !== capabilities.some(({ id }) => id === APP_INCIDENT_CAPABILITY) @@ -130,6 +134,12 @@ export async function registerAppRuntimeGenerationInTransaction( const declaredCategories = incidentCategories .map(({ id, name, resource }) => ({ id, name, resource })) .toSorted((left, right) => (left.id < right.id ? -1 : left.id > right.id ? 1 : 0)) + // Without negotiation the app speaks 1.0.0, and its bridge, if it has a UI, does too. + const declaredVersions = { + appProtocol: versions?.appProtocol ?? '1.0.0', + platformApi: versions?.platformApi ?? '1.0.0', + uiBridge: versions?.uiBridge ?? (hasUi ? '1.0.0' : null), + } const now = Date.now() if (previous && previous.generation >= generation) { if ( @@ -137,6 +147,9 @@ export async function registerAppRuntimeGenerationInTransaction( previous.state !== 'revoked' && previous.leaseExpiresAt.getTime() > now && previous.hasUi === hasUi && + previous.appProtocolVersion === declaredVersions.appProtocol && + previous.platformApiVersion === declaredVersions.platformApi && + previous.uiBridgeVersion === declaredVersions.uiBridge && JSON.stringify(previous.capabilities) === JSON.stringify(declaredCapabilities) && JSON.stringify(previous.permissionKeys) === JSON.stringify(declaredPermissions) && JSON.stringify(previous.providerProfiles) === JSON.stringify(declaredProviders) && @@ -168,6 +181,9 @@ export async function registerAppRuntimeGenerationInTransaction( permissionKeys: sql`${JSON.stringify(declaredPermissions)}::text::jsonb`, providerProfiles: sql`${JSON.stringify(declaredProviders)}::text::jsonb`, incidentCategories: sql`${JSON.stringify(declaredCategories)}::text::jsonb`, + appProtocolVersion: declaredVersions.appProtocol, + platformApiVersion: declaredVersions.platformApi, + uiBridgeVersion: declaredVersions.uiBridge, hasUi, }) } @@ -403,6 +419,9 @@ export async function checkAppRuntimeDependenciesInTransaction( await transaction .delete(legacyFeatureHandoffRequests) .where(eq(legacyFeatureHandoffRequests.installationId, installationId)) + await transaction + .delete(legacyFeatureHandoffRefusals) + .where(eq(legacyFeatureHandoffRefusals.installationId, installationId)) await bumpAuthorizationEpoch(transaction, installationId) } } diff --git a/web/src/server/AppRuntime/management.server.ts b/web/src/server/AppRuntime/management.server.ts index 00f0d8046..637093e34 100644 --- a/web/src/server/AppRuntime/management.server.ts +++ b/web/src/server/AppRuntime/management.server.ts @@ -13,6 +13,7 @@ import { appCapabilitySchema, appGenerationSchema, appIncidentCategoriesSchema, + appNegotiatedVersions, appIdSchema, appProviderProfilesSchema, appProviderRegistrationsSchema, @@ -50,6 +51,7 @@ const registration = lease.extend({ providerProfiles: appProviderProfilesSchema.default([]), hasUi: z.boolean().optional(), incidentCategories: appIncidentCategoriesSchema.optional(), + versions: appNegotiatedVersions.optional(), }) const providerUpdate = z.strictObject({ identity: identitySchema, @@ -103,6 +105,7 @@ export function manageAppRuntime(action: string, body: unknown, signal: AbortSig providerProfiles, hasUi, incidentCategories, + versions, } = parseAppInput(registration, body) return registerAppRuntimeGenerationInTransaction(transaction, { identity, @@ -112,6 +115,7 @@ export function manageAppRuntime(action: string, body: unknown, signal: AbortSig ...(permissionKeys !== undefined && { permissionKeys }), ...(hasUi !== undefined && { hasUi }), ...(incidentCategories !== undefined && { incidentCategories }), + ...(versions !== undefined && { versions }), }) } case 'providers': { diff --git a/web/src/server/AppRuntime/services.server.ts b/web/src/server/AppRuntime/services.server.ts index 6e2a05637..2732ebe1e 100644 --- a/web/src/server/AppRuntime/services.server.ts +++ b/web/src/server/AppRuntime/services.server.ts @@ -326,7 +326,8 @@ export function executeAppRuntimeCall( case 'getLegacyHandoff': case 'beginLegacyHandoff': case 'readLegacyHandoffPart': - case 'commitLegacyHandoff': { + case 'commitLegacyHandoff': + case 'abortLegacyHandoff': { const request = parseLegacyHandoffRequest( call.operation, resourceId, @@ -347,7 +348,8 @@ export function executeAppRuntimeCall( // The journal change is committed: built-in workers of the domain follow it now. if ( request.operation === 'beginLegacyHandoff' || - request.operation === 'commitLegacyHandoff' + request.operation === 'commitLegacyHandoff' || + request.operation === 'abortLegacyHandoff' ) signalLegacyFeatureOwnership([request.domain]) return json(result) diff --git a/web/src/server/LegacyHandoff/Types/legacy-handoff-api.types.ts b/web/src/server/LegacyHandoff/Types/legacy-handoff-api.types.ts index 87c184429..91e932ceb 100644 --- a/web/src/server/LegacyHandoff/Types/legacy-handoff-api.types.ts +++ b/web/src/server/LegacyHandoff/Types/legacy-handoff-api.types.ts @@ -1,13 +1,27 @@ import type { AppRuntimeJsonValue } from '@/server/AppRuntime/Types/authority.types.ts' -import type { LegacyFeatureDomain, LegacyFeatureHandoffSource } from './legacy-handoff.types.ts' +import type { + LegacyFeatureDomain, + LegacyFeatureHandoffSource, + LegacyFeatureRefusalReason, +} from './legacy-handoff.types.ts' /** Handoff sources by domain; a domain without one cannot begin a handoff. */ export type LegacyFeatureHandoffSources = Readonly< Partial> > +export type LegacyHandoffAbortReason = LegacyFeatureRefusalReason + +/** Protocol 1.1.0 members of the status; only apps that require platform API 1.1.0 get them. */ +export interface LegacyHandoffAvailability { + /** Whether begin can answer for the domain without a not-found problem. */ + readonly offered: boolean + /** The last abort of the calling installation for the domain, never its detail. */ + readonly refused: { readonly reason: LegacyHandoffAbortReason; readonly at: string } | null +} + /** App API v1 `LegacyHandoffStatus`: another holder is a conflict, never a state. */ -export type LegacyHandoffStatus = +export type LegacyHandoffStatus = ( | { readonly domain: LegacyFeatureDomain; readonly state: 'platform' } | { readonly domain: LegacyFeatureDomain @@ -16,6 +30,8 @@ export type LegacyHandoffStatus = readonly partCount: number } | { readonly domain: LegacyFeatureDomain; readonly state: 'committed'; readonly digest: string } +) & + Partial /** App API v1 `LegacyHandoffPart`. */ export interface LegacyHandoffPart { @@ -44,3 +60,12 @@ export type LegacyHandoffRequest = /** The idempotency key, bound to the domain and digest once commit succeeds. */ readonly key: string } + | { + readonly operation: 'abortLegacyHandoff' + readonly domain: LegacyFeatureDomain + readonly digest: string + readonly reason: LegacyHandoffAbortReason + readonly detail?: string + /** The idempotency key, bound to the domain, digest, reason and detail. */ + readonly key: string + } diff --git a/web/src/server/LegacyHandoff/Types/legacy-handoff.types.ts b/web/src/server/LegacyHandoff/Types/legacy-handoff.types.ts index 1a926faed..91a305e0b 100644 --- a/web/src/server/LegacyHandoff/Types/legacy-handoff.types.ts +++ b/web/src/server/LegacyHandoff/Types/legacy-handoff.types.ts @@ -1,3 +1,4 @@ +import type { LEGACY_HANDOFF_ABORT_REASONS } from '@/config/legacy-handoff.config.ts' import type { appProviderProfiles } from '@/server/AppRuntime/contract.ts' import type { AppRuntimeJsonValue } from '@/server/AppRuntime/Types/authority.types.ts' import type { AuthTransaction } from '@/server/Auth/Core/Types/database.types.ts' @@ -5,6 +6,8 @@ import type { AuthTransaction } from '@/server/Auth/Core/Types/database.types.ts /** Built-in feature domains that official apps may take over; they match the provider profiles. */ export type LegacyFeatureDomain = (typeof appProviderProfiles)[number] +export type LegacyFeatureRefusalReason = (typeof LEGACY_HANDOFF_ABORT_REASONS)[number] + export interface LegacyFeatureInspection { /** Whether platform still holds state an app would have to take over. */ readonly configured: boolean @@ -48,17 +51,30 @@ export type LegacyFeatureOwner = } | { readonly owner: 'app'; readonly installationId: string; readonly digest: string } +/** An app that gave the domain back after it began a handoff, as administrators see it. */ +export interface LegacyFeatureRefusalEntry { + readonly appId: string + readonly reason: LegacyFeatureRefusalReason + /** UTC time the platform recorded the abort, as ISO 8601. */ + readonly at: string + /** The app's own text; callers must show it as plain text only. */ + readonly detail: string | null +} + export interface LegacyFeatureStatus { readonly domain: LegacyFeatureDomain readonly ownership: LegacyFeatureOwner /** Present while platform owns the domain and a source is registered for it. */ readonly inspection?: LegacyFeatureInspection + /** Present when installed apps refused a handoff of the domain and did not commit it since. */ + readonly refusals?: readonly LegacyFeatureRefusalEntry[] } export type PlatformOwnedResult = { readonly owned: true; readonly value: T } | { readonly owned: false } -type LegacyFeatureHandoffErrorCode = 'not_found' | 'conflict' | 'invalid_export' | 'corrupt' +type LegacyFeatureHandoffErrorCode = + 'not_found' | 'conflict' | 'committed' | 'invalid_export' | 'corrupt' export class LegacyFeatureHandoffError extends Error { constructor(readonly code: LegacyFeatureHandoffErrorCode) { diff --git a/web/src/server/LegacyHandoff/app-api.server.ts b/web/src/server/LegacyHandoff/app-api.server.ts index b1aa94000..4bc5205ce 100644 --- a/web/src/server/LegacyHandoff/app-api.server.ts +++ b/web/src/server/LegacyHandoff/app-api.server.ts @@ -4,7 +4,10 @@ import { createHash } from 'node:crypto' import { and, desc, eq, lt, lte } from 'drizzle-orm' import type { z } from 'zod' -import { LEGACY_HANDOFF_LIMITS } from '@/config/legacy-handoff.config.ts' +import { + LEGACY_HANDOFF_AVAILABILITY_VERSION, + LEGACY_HANDOFF_LIMITS, +} from '@/config/legacy-handoff.config.ts' import { appRuntimeGenerations, legacyFeatureHandoffRequests, @@ -16,6 +19,7 @@ import { resolveAppRuntimePrincipalInTransaction, } from '@/server/AppRuntime/authority.server.ts' import { + appLegacyHandoffAbort, appLegacyHandoffCommit, appLegacyHandoffPartRequest, appProviderProfileSchema, @@ -27,12 +31,15 @@ import { type AppRuntimeCredentials, } from '@/server/AppRuntime/Types/authority.types.ts' import type { LegacyHandoffOperation } from '@/server/AppRuntime/Types/gateway.types.ts' +import { appendAuditEventInTransactionService } from '@/server/Audit/audit.service.ts' import type { AuthTransaction } from '@/server/Auth/Core/Types/database.types.ts' import { abortLegacyFeatureHandoffInTransaction, beginLegacyFeatureHandoffInTransaction, commitLegacyFeatureHandoffInTransaction, readLegacyFeatureHandoffPartInTransaction, + readLegacyFeatureRefusalInTransaction, + refuseLegacyFeatureHandoffInTransaction, } from './journal.server.ts' import { readLegacyFeatureOwnerInTransaction } from './ownership.server.ts' import { legacyFeatureHandoffSources } from './sources.server.ts' @@ -54,6 +61,11 @@ const idempotencyConflict = new AppRuntimeProblem( 'idempotencyConflict', 'Idempotency key was reused.', ) +const handoffCommitted = new AppRuntimeProblem( + 409, + 'handoffCommitted', + 'The legacy handoff is already committed.', +) function parse(schema: z.ZodType, value: unknown): T { const parsed = schema.safeParse(value) @@ -88,11 +100,39 @@ export function parseLegacyHandoffRequest( digest: parse(appLegacyHandoffCommit, body).digest, key: requiredKey(idempotencyKey), } + case 'abortLegacyHandoff': { + const { digest, reason, detail } = parse(appLegacyHandoffAbort, body) + return { + operation, + domain, + digest, + reason, + ...(detail !== undefined && { detail }), + key: requiredKey(idempotencyKey), + } + } } } +/** Whether `negotiated`, a `major.minor.patch` version, is at least `required`. */ +function atLeastVersion(negotiated: string, required: string): boolean { + const left = negotiated.split('.').map(Number) + const right = required.split('.').map(Number) + for (const [index, wanted] of right.entries()) { + const actual = left[index] ?? 0 + if (actual !== wanted) return actual > wanted + } + return true +} + interface DomainAuthority { readonly installationId: string + readonly appId: string + /** + * Whether the installation negotiated a platform API that has `offered` and `refused`. Older + * SDKs reject unknown members of the closed status shape, so they never get them. + */ + readonly reportsAvailability: boolean /** Idempotency keys are scoped like app messages: per service or delegated user. */ readonly actor: string /** The earliest of the lease, delegation and session deadlines. */ @@ -111,7 +151,10 @@ async function authorizeDomain( const principal = await resolveAppRuntimePrincipalInTransaction(transaction, credentials) const { installationId, generation } = principal.identity const [current] = await transaction - .select({ providerProfiles: appRuntimeGenerations.providerProfiles }) + .select({ + providerProfiles: appRuntimeGenerations.providerProfiles, + platformApiVersion: appRuntimeGenerations.platformApiVersion, + }) .from(appRuntimeGenerations) .where( and( @@ -129,20 +172,25 @@ async function authorizeDomain( throw new AppRuntimeAuthorityError('forbidden') return { installationId, + appId: principal.identity.appId, + reportsAvailability: atLeastVersion( + current.platformApiVersion, + LEGACY_HANDOFF_AVAILABILITY_VERSION, + ), actor: principal.user?.id ?? 'service', expiresAt: principal.expiresAt, } } /** - * Bind an accepted begin or commit key to its input before the journal changes. Reuse with other + * Bind an accepted begin, commit or abort key to its input before the journal changes. Reuse with other * input is a conflict; a retry with the same input continues to the journal, which returns the * recorded export or ownership. A failed request rolls the binding back with the transaction. */ async function bindRequestKey( transaction: AuthTransaction, { installationId, actor }: DomainAuthority, - operation: 'begin' | 'commit', + operation: 'begin' | 'commit' | 'abort', key: string, input: readonly string[], ): Promise { @@ -211,6 +259,7 @@ async function journal(run: () => Promise): Promise { return await run() } catch (error) { if (!(error instanceof LegacyFeatureHandoffError)) throw error + if (error.code === 'committed') throw handoffCommitted if (error.code === 'not_found' || error.code === 'conflict') throw new AppRuntimeAuthorityError(error.code) // A corrupt part or an invalid export needs an abort and a fresh export by platform. @@ -249,7 +298,20 @@ export async function executeLegacyHandoffInTransaction( request.domain, request.digest, ]) - const result = await runRequest(transaction, authority.installationId, request, sources) + if (request.operation === 'abortLegacyHandoff') + await bindRequestKey(transaction, authority, 'abort', request.key, [ + request.domain, + request.digest, + request.reason, + request.detail ?? '', + ]) + const result = await withAvailability( + transaction, + authority, + request.domain, + sources, + await runRequest(transaction, authority, request, sources), + ) // The journal work can wait on locks. Never answer, or keep its writes, once the caller's // authority has expired; the throw rolls the transaction back. if (authority.expiresAt.getTime() <= Date.now()) @@ -257,9 +319,30 @@ export async function executeLegacyHandoffInTransaction( return result } +/** + * Add `offered` and `refused` to a status for an app that requires platform API 1.1.0. Both come + * from the journal state the request ended with, so a begin that just exported reports it too. + */ +async function withAvailability( + transaction: AuthTransaction, + { installationId, reportsAvailability }: DomainAuthority, + domain: LegacyFeatureDomain, + sources: LegacyFeatureHandoffSources, + result: LegacyHandoffStatus | LegacyHandoffPart, +): Promise { + if (!reportsAvailability || !('state' in result)) return result + const refusal = await readLegacyFeatureRefusalInTransaction(transaction, domain, installationId) + return { + ...result, + // Recorded handoffs answer begin; without one, only a registered source can export. + offered: result.state !== 'platform' || sources[domain] !== undefined, + refused: refusal && { reason: refusal.reason, at: refusal.at.toISOString() }, + } +} + async function runRequest( transaction: AuthTransaction, - installationId: string, + { installationId, appId }: DomainAuthority, request: LegacyHandoffRequest, sources: LegacyFeatureHandoffSources, ): Promise { @@ -335,6 +418,37 @@ async function runRequest( if (status.state === 'exported') throw unavailable return status } + case 'abortLegacyHandoff': { + const { digest, reason, detail } = request + const aborted = await journal(() => + refuseLegacyFeatureHandoffInTransaction( + transaction, + domain, + installationId, + digest, + { reason, detail }, + source, + ), + ) + // The audit event names the refusal's category only. The app's detail and everything + // the export held stay out of it, because administrators read the audit log. + if (aborted) + await appendAuditEventInTransactionService(transaction, { + actorUserId: null, + actorKind: 'system', + action: 'abort', + resource: 'app-legacy-handoff', + targetId: null, + result: 'success', + metadata: { + appId, + installationId, + handoffDomain: domain, + handoffReason: reason, + }, + }) + return { domain, state: 'platform' } + } } } diff --git a/web/src/server/LegacyHandoff/journal.server.ts b/web/src/server/LegacyHandoff/journal.server.ts index d232953d5..fdc88aff9 100644 --- a/web/src/server/LegacyHandoff/journal.server.ts +++ b/web/src/server/LegacyHandoff/journal.server.ts @@ -10,6 +10,7 @@ import { import { appRuntimeInstallations, legacyFeatureHandoffParts, + legacyFeatureHandoffRefusals, legacyFeatureHandoffs, } from '@/db/schema.ts' import { appProviderProfiles, isAppWireJson } from '@/server/AppRuntime/contract.ts' @@ -26,6 +27,7 @@ import { type LegacyFeatureDomain, type LegacyFeatureHandoffSource, type LegacyFeatureOwner, + type LegacyFeatureRefusalReason, type LegacyFeatureStatus, } from './Types/legacy-handoff.types.ts' @@ -232,6 +234,15 @@ export async function commitLegacyFeatureHandoffInTransaction( .set({ state: 'committed', committedAt: sql`now()` }) .where(eq(legacyFeatureHandoffs.domain, domain)) .returning() + // The app owns the domain now, so an earlier refusal no longer describes it. + await transaction + .delete(legacyFeatureHandoffRefusals) + .where( + and( + eq(legacyFeatureHandoffRefusals.installationId, installationId), + eq(legacyFeatureHandoffRefusals.domain, domain), + ), + ) return toLegacyFeatureOwner(committed!) } @@ -254,6 +265,68 @@ export async function abortLegacyFeatureHandoffInTransaction( await source?.restore?.(transaction) } +/** What an app tells the platform when it refuses an export. */ +export interface LegacyFeatureHandoffRefusal { + readonly reason: LegacyFeatureRefusalReason + /** The app's own one-line text for administrators; never part of an audit event. */ + readonly detail?: string | undefined +} + +/** + * Let the installation that began a handoff give the domain back before it commits, and record why. + * Without a handoff of the domain there is nothing to undo, so it answers false and records + * nothing: a retry after a completed abort is no new refusal. A committed handoff cannot be undone, + * and another installation's handoff or an export with another digest is not the caller's to refuse. + */ +export async function refuseLegacyFeatureHandoffInTransaction( + transaction: AuthTransaction, + domain: LegacyFeatureDomain, + installationId: string, + digest: string, + refusal: LegacyFeatureHandoffRefusal, + source?: LegacyFeatureHandoffSource, +): Promise { + const row = await lockJournalRow(transaction, domain) + if (!row) return false + if (row.installationId !== installationId) throw new LegacyFeatureHandoffError('conflict') + if (row.state === 'committed') throw new LegacyFeatureHandoffError('committed') + if (row.digest !== digest) throw new LegacyFeatureHandoffError('conflict') + await abortLegacyFeatureHandoffInTransaction(transaction, domain, installationId, source) + const detail = refusal.detail ?? null + await transaction + .insert(legacyFeatureHandoffRefusals) + .values({ installationId, domain, reason: refusal.reason, detail }) + .onConflictDoUpdate({ + target: [ + legacyFeatureHandoffRefusals.installationId, + legacyFeatureHandoffRefusals.domain, + ], + set: { reason: refusal.reason, detail, refusedAt: sql`now()` }, + }) + return true +} + +/** The last refusal of the installation for the domain, or null when it never aborted. */ +export async function readLegacyFeatureRefusalInTransaction( + transaction: AuthTransaction, + domain: LegacyFeatureDomain, + installationId: string, +): Promise<{ readonly reason: LegacyFeatureRefusalReason; readonly at: Date } | null> { + const [row] = await transaction + .select({ + reason: legacyFeatureHandoffRefusals.reason, + at: legacyFeatureHandoffRefusals.refusedAt, + }) + .from(legacyFeatureHandoffRefusals) + .where( + and( + eq(legacyFeatureHandoffRefusals.installationId, installationId), + eq(legacyFeatureHandoffRefusals.domain, domain), + ), + ) + return row ?? null +} + /** * Report each domain's owner and, while platform owns it, what an app would take over. Shared * domain locks keep a handoff from committing between the owner read and the inspection. @@ -265,13 +338,39 @@ export async function inspectLegacyFeaturesInTransaction( await shareLegacyFeatureDomains(transaction) const rows = await transaction.select().from(legacyFeatureHandoffs) const owners = new Map(rows.map((row) => [row.domain, toLegacyFeatureOwner(row)])) + const refusals = await transaction + .select({ + domain: legacyFeatureHandoffRefusals.domain, + appId: appRuntimeInstallations.appId, + reason: legacyFeatureHandoffRefusals.reason, + detail: legacyFeatureHandoffRefusals.detail, + at: legacyFeatureHandoffRefusals.refusedAt, + }) + .from(legacyFeatureHandoffRefusals) + .innerJoin( + appRuntimeInstallations, + eq(appRuntimeInstallations.id, legacyFeatureHandoffRefusals.installationId), + ) + .orderBy(legacyFeatureHandoffRefusals.refusedAt) return Promise.all( appProviderProfiles.map(async (domain): Promise => { const ownership: LegacyFeatureOwner = owners.get(domain) ?? { owner: 'platform' } const source = sources[domain] - return ownership.owner === 'platform' && source - ? { domain, ownership, inspection: await source.inspect(transaction) } - : { domain, ownership } + const refused = refusals + .filter((refusal) => refusal.domain === domain) + .map(({ appId, reason, detail, at }) => ({ + appId, + reason, + detail, + at: at.toISOString(), + })) + const status: { + -readonly [Key in keyof LegacyFeatureStatus]: LegacyFeatureStatus[Key] + } = { domain, ownership } + if (ownership.owner === 'platform' && source) + status.inspection = await source.inspect(transaction) + if (refused.length > 0) status.refusals = refused + return status }), ) } diff --git a/web/src/tests/features/ApplicationVersion/application-update-dialog.test.tsx b/web/src/tests/features/ApplicationVersion/application-update-dialog.test.tsx index 5cfaa5d4d..f905e319a 100644 --- a/web/src/tests/features/ApplicationVersion/application-update-dialog.test.tsx +++ b/web/src/tests/features/ApplicationVersion/application-update-dialog.test.tsx @@ -448,3 +448,44 @@ for (const latest of ['success', 'error'] as const) { } }) } + +test('shows which app refused a handoff, why and when, and renders its detail as plain text', async () => { + const latest = { ...result.latest!, appRequirements: verifiedRequirements } + const detail = ' wrong header' + const dialog = await render({ ...result, latest }, true, { + loading: false, + preview: { + status: 'blocked', + features: [ + { + ...feature, + refusals: [ + { + appId: 'rentnerproxy.monitoring', + reason: 'unsupportedFormat', + at: '2026-11-28T18:30:00.000Z', + detail, + }, + ], + }, + { ...feature, domain: 'dns' }, + ], + apps: [], + issues: [{ kind: 'feature-handoff-pending', domain: 'monitoring' }], + }, + }) + const section = dialog.querySelector(`[aria-label="${catalogs.en.updates.preview.title}"]`)! + const items = [...section.querySelectorAll('li')].filter((item) => + item.textContent?.includes(catalogs.en.updates.preview.references), + ) + expect(items).toHaveLength(2) + const text = items[0]!.textContent! + expect(text).toContain('rentnerproxy.monitoring refused the handoff') + expect(text).toContain(catalogs.en.updates.preview.refusalReasons.unsupportedFormat) + expect(text).toContain('2026') + expect(text).toContain('18:30:00') + // The app's text is data: it appears verbatim and creates no element. + expect(text).toContain(detail) + expect(items[0]!.querySelector('img')).toBeNull() + expect(items[1]!.textContent).not.toContain('refused the handoff') +}) diff --git a/web/src/tests/lib/ApplicationVersion/upgrade-preview.test.ts b/web/src/tests/lib/ApplicationVersion/upgrade-preview.test.ts index 9a48f60b5..c3df11e03 100644 --- a/web/src/tests/lib/ApplicationVersion/upgrade-preview.test.ts +++ b/web/src/tests/lib/ApplicationVersion/upgrade-preview.test.ts @@ -66,6 +66,30 @@ describe('upgrade preview evaluation', () => { }) }) + test('refusals of a handoff reach the feature that the app refused', () => { + const refusal = { + appId: 'rentnerproxy.monitoring', + reason: 'invalidExport', + at: '2026-11-28T18:30:00.000Z', + detail: null, + } as const + const preview = evaluateUpgradePreview( + plan(), + [ + { ...platformOwned('monitoring'), refusals: [refusal] }, + { ...platformOwned('dns'), refusals: [] }, + ], + [], + ) + expect(preview.features.find(({ domain }) => domain === 'monitoring')?.refusals).toEqual([ + refusal, + ]) + // A feature nobody refused stays exactly as before. + expect(preview.features.find(({ domain }) => domain === 'dns')).not.toHaveProperty( + 'refusals', + ) + }) + test('an installed app the target would not run blocks the update', () => { const preview = evaluateUpgradePreview( plan(), diff --git a/web/src/tests/server/AppRuntime/gateway.test.ts b/web/src/tests/server/AppRuntime/gateway.test.ts index f5d5aa663..661ed26e2 100644 --- a/web/src/tests/server/AppRuntime/gateway.test.ts +++ b/web/src/tests/server/AppRuntime/gateway.test.ts @@ -148,6 +148,14 @@ describe('private app gateway', () => { }) ).status, ).toBe(204) + expect( + ( + await send('POST', 'monitoring/abort', { + key: 'abort-1', + body: `{"digest":"${digest}","reason":"invalidExport","detail":"Wrong header"}`, + }) + ).status, + ).toBe(204) expect( calls.map(({ operation, resourceId, idempotencyKey, body }) => ({ operation, @@ -180,9 +188,16 @@ describe('private app gateway', () => { idempotencyKey: 'commit-1', body: { digest }, }, + { + operation: 'abortLegacyHandoff', + resourceId: 'monitoring', + idempotencyKey: 'abort-1', + body: { digest, reason: 'invalidExport', detail: 'Wrong header' }, + }, ]) - // Begin and commit need a key, reads refuse one, and only parts and commit carry JSON. + // Begin, commit and abort need a key, reads refuse one, and only parts, commit and abort + // carry JSON. const refused = [ send('GET', 'monitoring', { key: 'read-1' }), send('POST', 'dns/begin'), @@ -194,6 +209,8 @@ describe('private app gateway', () => { send('POST', 'oidc/parts'), send('POST', 'crowdsec/commit', { body: `{"digest":"${digest}"}` }), send('GET', 'Monitoring'), + send('POST', 'monitoring/abort', { body: `{"digest":"${digest}"}` }), + send('POST', 'monitoring/abort', { key: 'abort-1' }), ] expect((await Promise.all(refused)).map((response) => response.status)).toEqual( refused.map(() => 400), @@ -202,12 +219,13 @@ describe('private app gateway', () => { const missing = [ send('GET', 'monitoring/begin'), send('POST', 'monitoring', { body: '{}' }), - send('POST', 'monitoring/abort', { key: 'abort-1' }), + send('GET', 'monitoring/abort'), + send('POST', 'monitoring/abort/parts', { key: 'abort-1', body: '{}' }), send('GET', 'monitoring/parts/0'), ] expect((await Promise.all(missing)).map((response) => response.status)).toEqual( missing.map(() => 404), ) - expect(calls).toHaveLength(4) + expect(calls).toHaveLength(5) }) }) diff --git a/web/src/tests/server/HostMonitoring/host-monitoring-handoff.db.test.ts b/web/src/tests/server/HostMonitoring/host-monitoring-handoff.db.test.ts index a9a33853f..a8d1e5ff1 100644 --- a/web/src/tests/server/HostMonitoring/host-monitoring-handoff.db.test.ts +++ b/web/src/tests/server/HostMonitoring/host-monitoring-handoff.db.test.ts @@ -12,6 +12,7 @@ import { } from '@/config/notifications.config.ts' import { PERMISSIONS } from '@/config/permissions.config.ts' import { + auditEvents, hostCheckPolicies, legacyFeatureHandoffParts, legacyFeatureHandoffs, @@ -117,7 +118,7 @@ const grant = (capability: { id: string; scope: string }, resourceId: string) => const route = (suffix = '') => '/platform/v1/legacy-handoffs/monitoring' + suffix /** Register and activate the monitoring app like the broker does, through the public gateway. */ -async function install() { +async function install(negotiated?: string) { const identity = { appId, installationId: randomUUID(), generation: 1, uid: nextUid++ } installed.push(identity) const gateway = createAppRuntimeGateway( @@ -160,6 +161,9 @@ async function install() { capabilities: [incidentGrant, readHosts], providerProfiles: ['monitoring'], incidentCategories: categories, + ...(negotiated !== undefined && { + versions: { appProtocol: negotiated, platformApi: negotiated }, + }), }) ).status, ).toBe(204) @@ -193,6 +197,13 @@ async function install() { part: (digest: string, sequence: number) => send(route('/parts'), { digest, sequence }), commit: (digest: string, key = 'commit-1') => send(route('/commit'), { digest }, { 'Idempotency-Key': key }), + status: () => send(route()), + abort: (digest: string, body: object = {}, key = 'abort-1') => + send( + route('/abort'), + { digest, reason: 'invalidExport', ...body }, + { 'Idempotency-Key': key }, + ), incident: (key: string, body: unknown, idempotencyKey: string) => send('/platform/v1/incidents/' + key, body, { 'Idempotency-Key': idempotencyKey }), } @@ -539,6 +550,13 @@ describe('monitoring legacy handoff', () => { const { db } = await import('@/db/index.ts') const ids = installed.splice(0) await db.transaction(async (transaction) => { + if (ids.length > 0) + await transaction.delete(auditEvents).where( + inArray( + sql`${auditEvents.metadata}->>'installationId'`, + ids.map(({ installationId }) => installationId), + ), + ) await transaction .delete(legacyFeatureHandoffParts) .where(eq(legacyFeatureHandoffParts.domain, 'monitoring')) @@ -559,6 +577,145 @@ describe('monitoring legacy handoff', () => { else process.env.APP_ENCRYPTION_KEY = encryptionKey }) + integrationTest( + 'an app abort lifts the writer fence, applies skipped resets and keeps the policies', + async () => { + const { db } = await import('@/db/index.ts') + const [renamed, untouched] = await seedHosts(2, { failureThreshold: 1 }) + await recordOutages() + const app = await install('1.1.0') + const first = exported(await app.begin()) + expect(await claimAll()).toEqual([]) + // The fence keeps this host change from resetting monitoring during the handoff. + await db.execute( + sql`delete from rentnerproxy.host_domains where proxy_host_id = ${renamed!.id}`, + ) + await getAuthDatabase().transaction((transaction) => + invalidateHostMonitoringForHostsInTransaction(transaction, [renamed!.id]), + ) + const state = async (hostId: string) => { + const [row] = await db.execute<{ state: string; reason: string | null }>(sql` + select p.state, + (select string_agg(coalesce(i.closed_reason, 'open'), ',') + from rentnerproxy.host_check_incidents i where i.policy_id = p.id) as reason + from ${hostCheckPolicies} p where p.proxy_host_id = ${hostId}`) + return row + } + expect(await state(renamed!.id)).toEqual({ state: 'unhealthy', reason: 'open' }) + + const refused = await app.abort(first.digest, { + reason: 'unsupportedFormat', + detail: 'The manifest version is unknown to this app', + }) + expect(refused).toMatchObject({ + status: 200, + body: { + domain: 'monitoring', + state: 'platform', + offered: true, + refused: { reason: 'unsupportedFormat' }, + }, + }) + // The restore ran inside the abort: the skipped reset is applied, the rest is retained. + expect(await state(renamed!.id)).toEqual({ state: 'unknown', reason: 'policy_changed' }) + expect(await state(untouched!.id)).toEqual({ state: 'unhealthy', reason: 'open' }) + const [journal] = await db + .select({ domain: legacyFeatureHandoffs.domain }) + .from(legacyFeatureHandoffs) + .where(eq(legacyFeatureHandoffs.domain, 'monitoring')) + expect(journal).toBeUndefined() + const [counted] = await db.execute<{ count: number }>(sql` + select count(*)::integer as count from ${hostCheckPolicies} p + join ${proxyHosts} h on h.id = p.proxy_host_id where h.forward_host = ${marker}`) + expect(counted?.count).toBe(2) + + // The fence is lifted: built-in monitoring claims and records again. + await db.execute(sql` + update ${hostCheckPolicies} set next_check_at = statement_timestamp() - interval '1 minute' + where proxy_host_id = ${untouched!.id}`) + const claims = await claimAll() + expect(claims.length).toBeGreaterThan(0) + expect( + await completeHostMonitoringClaim( + claims[0]!, + unhealthy, + async () => true, + fixtureContext, + ), + ).toBe(true) + const actorId = await createUser() + const service = createHostMonitoringService({ + database: getAuthDatabase, + requireActor: async () => ({ id: actorId }), + rateLimit: async () => undefined, + }) + const [policy] = await db + .select() + .from(hostCheckPolicies) + .where(eq(hostCheckPolicies.proxyHostId, untouched!.id)) + await expect( + service.savePolicy({ + proxyHostId: untouched!.id, + expectedVersion: policy!.version, + settings: { + domain: untouched!.domain, + enabled: true, + intervalSeconds: 60, + timeoutMs: 3_000, + expectedStatus: 200, + failureThreshold: 1, + recoveryThreshold: 2, + retentionDays: 7, + sampleLimit: 1_440, + incidentLimit: 100, + }, + }), + ).resolves.toBeDefined() + // The app may begin again and gets a fresh export of the retained state. + expect(exported(await app.begin('begin-2')).partCount).toBeGreaterThan(0) + }, + 30_000, + ) + + integrationTest( + 'a fresh platform without monitoring policies exports an empty state the app can commit', + async () => { + const { db } = await import('@/db/index.ts') + const [counted] = await db.execute<{ count: number }>( + sql`select count(*)::integer as count from ${hostCheckPolicies}`, + ) + expect(counted?.count).toBe(0) + const app = await install('1.1.0') + expect((await app.status()).body).toEqual({ + domain: 'monitoring', + state: 'platform', + offered: true, + refused: null, + }) + const empty = exported(await app.begin()) + // A manifest and an end part, without any row part in between. + expect(empty.partCount).toBe(2) + const { rows, end } = decode(await readParts(app, empty)) + expect(rows).toEqual({ policies: [], observations: [], incidents: [] }) + expect(end.counts).toEqual({ policies: 0, observations: 0, incidents: 0 }) + const committed = await app.commit(empty.digest) + expect(committed).toEqual({ + status: 200, + body: { + domain: 'monitoring', + state: 'committed', + digest: empty.digest, + offered: true, + refused: null, + }, + }) + // Platform workers stay out for good, and the committed state is repeatable. + expect(await claimAll()).toEqual([]) + expect(await app.commit(empty.digest, 'commit-2')).toEqual(committed) + }, + 30_000, + ) + integrationTest( 'one App API begin exports the maximum history completely, deterministically and resumably', async () => { diff --git a/web/src/tests/server/LegacyHandoff/app-api.db.test.ts b/web/src/tests/server/LegacyHandoff/app-api.db.test.ts index 8c4139751..5ed52defd 100644 --- a/web/src/tests/server/LegacyHandoff/app-api.db.test.ts +++ b/web/src/tests/server/LegacyHandoff/app-api.db.test.ts @@ -6,7 +6,9 @@ import { appRuntimeGenerations, appRuntimeGrants, appRuntimeInstallations, + auditEvents, legacyFeatureHandoffParts, + legacyFeatureHandoffRefusals, legacyFeatureHandoffRequests, legacyFeatureHandoffs, } from '@/db/schema.ts' @@ -38,7 +40,7 @@ interface Reply { /** A synthetic built-in feature: its records stay until the committed handoff retires them. */ function featureSource(domain: LegacyFeatureDomain, records: AppRuntimeJsonValue[]) { - const state = { exports: 0, retirements: 0, records } + const state = { exports: 0, retirements: 0, restores: 0, records } const source: LegacyFeatureHandoffSource = { domain, inspect: () => Promise.resolve({ configured: true, references: state.records.length }), @@ -54,6 +56,10 @@ function featureSource(domain: LegacyFeatureDomain, records: AppRuntimeJsonValue state.records = [] return Promise.resolve() }, + restore: () => { + state.restores += 1 + return Promise.resolve() + }, } return { source, state } } @@ -132,12 +138,15 @@ async function createHarness(domains: readonly LegacyFeatureDomain[], encryption const gateway = gatewayFor(sources) return { status: (target: Identity, domain: string) => send(gateway, target, route(domain)), + context: (target: Identity) => send(gateway, target, '/platform/v1/context'), begin: (target: Identity, domain: string, key = 'begin-1') => send(gateway, target, route(domain, '/begin'), { key, method: 'POST' }), part: (target: Identity, domain: string, sequence: unknown, digest?: string) => send(gateway, target, route(domain, '/parts'), { body: { digest, sequence } }), commit: (target: Identity, domain: string, digest: string, key = 'commit-1') => send(gateway, target, route(domain, '/commit'), { body: { digest }, key }), + abort: (target: Identity, domain: string, body: unknown, key = 'abort-1') => + send(gateway, target, route(domain, '/abort'), { body, key }), } } @@ -192,6 +201,7 @@ async function createHarness(domains: readonly LegacyFeatureDomain[], encryption appId: string, providerProfiles: readonly LegacyFeatureDomain[], grants: ReturnType[], + negotiated?: string, ) => { const identity = { appId, @@ -205,6 +215,9 @@ async function createHarness(domains: readonly LegacyFeatureDomain[], encryption leaseExpiresAt: leaseExpiresAt(), capabilities: [], providerProfiles, + ...(negotiated !== undefined && { + versions: { appProtocol: negotiated, platformApi: negotiated }, + }), }), ).toBe(204) expect(await control('grants', identity, { grants })).toBe(204) @@ -238,6 +251,9 @@ async function createHarness(domains: readonly LegacyFeatureDomain[], encryption const installationIds = identities.map(({ installationId }) => installationId) if (installationIds.length === 0) return await db.transaction(async (transaction) => { + await transaction + .delete(auditEvents) + .where(inArray(sql`${auditEvents.metadata}->>'installationId'`, installationIds)) const owned = await transaction .select({ domain: legacyFeatureHandoffs.domain }) .from(legacyFeatureHandoffs) @@ -767,3 +783,329 @@ integrationTest( }, handoffTestTimeoutMs, ) + +const handoffAbort = (digest: string, extra: object = {}) => ({ + digest, + reason: 'invalidExport', + ...extra, +}) + +integrationTest( + 'abort gives the domain back, restores platform state and records the refusal until a commit', + async () => { + const harness = await createHarness(['dns'], 91) + const { db, install, activate, journalRows, partCount } = harness + try { + const secret = 'legacy-dns-' + crypto.randomUUID() + const dns = featureSource('dns', [{ credential: secret }, { zone: 'example.test' }]) + const api = harness.handoffApi({ dns: dns.source }) + const app = await install('test.abort', ['dns'], [providerGrant('dns')], '1.1.0') + await activate(app) + const rival = await install( + 'test.abort-rival', + ['dns'], + [providerGrant('dns')], + '1.1.0', + ) + await activate(rival) + + // Nothing is offered back before a handoff: abort has nothing to undo and records nothing. + const nothing = await api.abort(app, 'dns', handoffAbort('c'.repeat(64)), 'abort-0') + expect(nothing).toEqual({ + status: 200, + body: { domain: 'dns', state: 'platform', offered: true, refused: null }, + }) + expect(dns.state.restores).toBe(0) + + const begun = await api.begin(app, 'dns') + const { digest } = begun.body as { digest: string } + expect(begun.body).toMatchObject({ state: 'exported', offered: true, refused: null }) + + // A malformed refusal is rejected before anything changes. + for (const body of [ + { digest }, + { digest, reason: 'because' }, + handoffAbort(digest, { detail: 'a\nb' }), + handoffAbort(digest, { detail: '' }), + handoffAbort(digest, { detail: 'x'.repeat(501) }), + handoffAbort(digest, { other: true }), + handoffAbort('not-a-digest'), + ]) { + // oxlint-disable-next-line no-await-in-loop -- Each refusal is checked alone. + expect((await api.abort(app, 'dns', body, 'abort-bad')).status).toBe(400) + } + expect(await journalRows()).toHaveLength(1) + + // Another installation, or another digest, cannot refuse this export. + expect(await api.abort(rival, 'dns', handoffAbort(digest), 'abort-r')).toMatchObject({ + status: 409, + body: { code: 'conflict' }, + }) + expect( + await api.abort(app, 'dns', handoffAbort('d'.repeat(64)), 'abort-wrong'), + ).toMatchObject({ status: 409, body: { code: 'conflict' } }) + expect(dns.state.restores).toBe(0) + expect(await journalRows()).toHaveLength(1) + + const detail = 'The header row is not the one this app reads' + const body = handoffAbort(digest, { detail }) + const refused = await api.abort(app, 'dns', body, 'abort-1') + expect(refused.status).toBe(200) + const { refused: seen } = refused.body as { refused: { reason: string; at: string } } + expect(refused.body).toEqual({ + domain: 'dns', + state: 'platform', + offered: true, + refused: { reason: 'invalidExport', at: seen.at }, + }) + expect(new Date(seen.at).toISOString()).toBe(seen.at) + // The source's restore ran once, the export is gone and platform owns the domain again. + expect(dns.state.restores).toBe(1) + expect(await journalRows()).toEqual([]) + expect(await partCount('dns')).toBe(0) + expect(await api.status(app, 'dns')).toEqual(refused) + const [stored] = await db + .select({ + reason: legacyFeatureHandoffRefusals.reason, + detail: legacyFeatureHandoffRefusals.detail, + }) + .from(legacyFeatureHandoffRefusals) + .where(eq(legacyFeatureHandoffRefusals.installationId, app.installationId)) + expect(stored).toEqual({ reason: 'invalidExport', detail }) + // Administrators see the refusal where they see the handoff state. + const { inspectLegacyFeaturesInTransaction } = + await import('@/server/LegacyHandoff/journal.server.ts') + const inspected = async () => + ( + await db.transaction( + (transaction) => + inspectLegacyFeaturesInTransaction(transaction, { dns: dns.source }), + { accessMode: 'read only' }, + ) + ).find(({ domain }) => domain === 'dns') + expect((await inspected())?.refusals).toEqual([ + { appId: 'test.abort', reason: 'invalidExport', detail, at: seen.at }, + ]) + + // A retry with the same key and input repeats the answer; nothing runs twice. + expect(await api.abort(app, 'dns', body, 'abort-1')).toEqual(refused) + expect(dns.state.restores).toBe(1) + // The same key with other input is a conflict, whichever member differs. + for (const other of [ + handoffAbort(digest, { detail: 'another text' }), + handoffAbort(digest), + handoffAbort(digest, { detail, reason: 'other' }), + handoffAbort('e'.repeat(64), { detail }), + ]) { + // oxlint-disable-next-line no-await-in-loop -- Each variant is checked alone. + expect(await api.abort(app, 'dns', other, 'abort-1')).toMatchObject({ + status: 409, + body: { code: 'idempotencyConflict' }, + }) + } + // Without a handoff a later abort is the idempotent platform answer and keeps the record. + expect(await api.abort(app, 'dns', body, 'abort-2')).toEqual(refused) + expect(dns.state.restores).toBe(1) + + // The app begins again and works on a fresh export; the refusal stays visible meanwhile. + const again = await api.begin(app, 'dns', 'begin-2') + expect(again.body).toMatchObject({ + state: 'exported', + offered: true, + refused: { reason: 'invalidExport', at: seen.at }, + }) + expect(dns.state.exports).toBe(2) + const exportedAgain = (again.body as { digest: string }).digest + // A second refusal replaces the record. + const second = await api.abort( + app, + 'dns', + { digest: exportedAgain, reason: 'importFailed' }, + 'abort-3', + ) + expect(second.body).toMatchObject({ refused: { reason: 'importFailed' } }) + expect(dns.state.restores).toBe(2) + const [replaced] = await db + .select({ detail: legacyFeatureHandoffRefusals.detail }) + .from(legacyFeatureHandoffRefusals) + .where(eq(legacyFeatureHandoffRefusals.installationId, app.installationId)) + expect(replaced?.detail).toBeNull() + + // Commit finishes the handoff and clears the refusal; abort is refused from then on. + const third = await api.begin(app, 'dns', 'begin-3') + const final = (third.body as { digest: string }).digest + expect(await api.commit(app, 'dns', final)).toEqual({ + status: 200, + body: { + domain: 'dns', + state: 'committed', + digest: final, + offered: true, + refused: null, + }, + }) + expect( + await db + .select() + .from(legacyFeatureHandoffRefusals) + .where(eq(legacyFeatureHandoffRefusals.installationId, app.installationId)), + ).toEqual([]) + expect(await inspected()).not.toHaveProperty('refusals') + expect(await api.abort(app, 'dns', handoffAbort(final), 'abort-4')).toMatchObject({ + status: 409, + body: { code: 'handoffCommitted' }, + }) + // The refused request left no key behind, and the committed state is untouched. + expect(await journalRows()).toEqual([ + { domain: 'dns', installationId: app.installationId, state: 'committed' }, + ]) + expect(dns.state.restores).toBe(2) + // Another installation sees a conflict, never the committed state of this one. + expect(await api.abort(rival, 'dns', handoffAbort(final), 'abort-r2')).toMatchObject({ + status: 409, + body: { code: 'conflict' }, + }) + } finally { + await harness.release() + } + }, + handoffTestTimeoutMs, +) + +integrationTest( + 'offered and refused reach only apps that negotiated platform API 1.1.0', + async () => { + const harness = await createHarness(['dns', 'oidc'], 92) + const { install, activate, control } = harness + try { + const dns = featureSource('dns', [{ zone: 'example.test' }]) + const api = harness.handoffApi({ dns: dns.source }) + const grants = [providerGrant('dns'), providerGrant('oidc')] + const old = await install('test.availability-old', ['dns', 'oidc'], grants) + const current = await install('test.availability-new', ['dns', 'oidc'], grants, '1.1.0') + const later = await install('test.availability-later', ['dns', 'oidc'], grants, '1.1.0') + await Promise.all([old, current, later].map(activate)) + + // Negotiated versions must be versions, and a registration repeats them unchanged. + const registration = (negotiated: string) => ({ + leaseExpiresAt: leaseExpiresAt(), + capabilities: [], + providerProfiles: ['dns', 'oidc'], + versions: { appProtocol: negotiated, platformApi: negotiated }, + }) + expect(await control('register', current, registration('1.1.0'))).toBe(204) + expect(await control('register', current, registration('1.0.0'))).toBe(409) + const stranger = { ...current, installationId: crypto.randomUUID(), uid: 59_999 } + for (const minimum of ['1.1', '>=1.1.0', '1.1.0 ', '01.1.0', '1.1.0.0']) { + // oxlint-disable-next-line no-await-in-loop -- Each value is checked alone. + expect(await control('register', stranger, registration(minimum))).toBe(400) + } + + // The context reports what each installation negotiated, not one platform version. + for (const [app, version] of [ + [old, '1.0.0'], + [current, '1.1.0'], + [later, '1.1.0'], + ] as const) { + // oxlint-disable-next-line no-await-in-loop -- Each app is checked alone. + expect((await api.context(app)).body).toMatchObject({ + versions: { appProtocol: version, platformApi: version }, + }) + } + + // The status shape is closed for older SDKs: they get exactly the 1.0.0 members. + expect((await api.status(old, 'dns')).body).toStrictEqual({ + domain: 'dns', + state: 'platform', + }) + for (const app of [current, later]) { + // oxlint-disable-next-line no-await-in-loop -- Each app is checked alone. + expect((await api.status(app, 'dns')).body).toStrictEqual({ + domain: 'dns', + state: 'platform', + offered: true, + refused: null, + }) + } + // A domain without a source is not offered; begin answers 404 as documented. + expect((await api.status(old, 'oidc')).body).toStrictEqual({ + domain: 'oidc', + state: 'platform', + }) + expect((await api.status(current, 'oidc')).body).toStrictEqual({ + domain: 'oidc', + state: 'platform', + offered: false, + refused: null, + }) + expect((await api.begin(current, 'oidc')).status).toBe(404) + + const begun = await api.begin(old, 'dns') + expect(begun.body).toStrictEqual({ + domain: 'dns', + state: 'exported', + digest: (begun.body as { digest: string }).digest, + partCount: 1, + }) + // Another installation's handoff is a conflict for the newer apps as well. + expect((await api.status(current, 'dns')).status).toBe(409) + const { digest } = begun.body as { digest: string } + // An old app may refuse too; it never sees the record it leaves behind. + const refused = await api.abort(old, 'dns', handoffAbort(digest), 'abort-1') + expect(refused.body).toStrictEqual({ domain: 'dns', state: 'platform' }) + expect((await api.status(old, 'dns')).body).toStrictEqual({ + domain: 'dns', + state: 'platform', + }) + // Records are per installation: the others never refused. + expect((await api.status(current, 'dns')).body).toMatchObject({ refused: null }) + } finally { + await harness.release() + } + }, + handoffTestTimeoutMs, +) + +integrationTest( + 'the audit event of an abort names the refusal and carries no export or detail text', + async () => { + const harness = await createHarness(['dns'], 93) + const { db, install, activate } = harness + try { + const secret = 'legacy-dns-' + crypto.randomUUID() + const detail = 'SECRET-DETAIL-' + crypto.randomUUID() + const dns = featureSource('dns', [{ credential: secret }]) + const api = harness.handoffApi({ dns: dns.source }) + const app = await install('test.abort-audit', ['dns'], [providerGrant('dns')], '1.1.0') + await activate(app) + const { digest } = (await api.begin(app, 'dns')).body as { digest: string } + const body = handoffAbort(digest, { detail, reason: 'unsupportedFormat' }) + expect((await api.abort(app, 'dns', body, 'abort-1')).status).toBe(200) + // A repeat is no second refusal. + expect((await api.abort(app, 'dns', body, 'abort-1')).status).toBe(200) + const events = await db + .select() + .from(auditEvents) + .where(sql`${auditEvents.metadata}->>'installationId' = ${app.installationId}`) + expect(events).toHaveLength(1) + expect(events[0]).toMatchObject({ + actorKind: 'system', + actorUserId: null, + action: 'abort', + resource: 'app-legacy-handoff', + result: 'success', + metadata: { + appId: 'test.abort-audit', + installationId: app.installationId, + handoffDomain: 'dns', + handoffReason: 'unsupportedFormat', + }, + }) + const text = JSON.stringify(events) + for (const forbidden of [detail, secret, digest]) expect(text).not.toContain(forbidden) + } finally { + await harness.release() + } + }, + handoffTestTimeoutMs, +) diff --git a/web/src/tests/tooling/github/release-app-requirements.test.ts b/web/src/tests/tooling/github/release-app-requirements.test.ts index 3eb93456d..714c5dbf6 100644 --- a/web/src/tests/tooling/github/release-app-requirements.test.ts +++ b/web/src/tests/tooling/github/release-app-requirements.test.ts @@ -149,9 +149,8 @@ describe('release app requirements generation', () => { expect(authority).toContain( `const appRuntimeProfile = '${APP_RUNTIME_ENVIRONMENT.runtimeProfile}'`, ) - expect(authority).toContain( - `const appRuntimeVersion = '${APP_RUNTIME_ENVIRONMENT.platformApi}'`, - ) + // The context reports what each installation negotiated, never one platform-wide version. + expect(authority).not.toContain('appRuntimeVersion') const dockerfile = await readFile(resolve(root, 'docker/production/Dockerfile'), 'utf8') expect(dockerfile).toContain( 'COPY docker/production/apps/catalog/ /usr/share/rentnerproxy/app-catalog/', From 5d35c89bde6b240d99ae6a263f688628947be561 Mon Sep 17 00:00:00 2001 From: "HomePC\\Kevin" Date: Sat, 28 Nov 2026 21:19:35 +0100 Subject: [PATCH 3/4] fix(apps): check compatibility against negotiated versions and keep migrated UI rows valid - Treat an app as compatible when negotiate_versions succeeds and the manifest passes the check against the negotiated versions, at install, staging, recovery, catalog browsing and the upgrade preview target check. A range such as >=1.0.0 <1.1.0 stays compatible and negotiates 1.0.0. - Count a UI generation without a stored bridge version as 1.0.0 when reading the context and when comparing a registration replay. - Answer conflict for another digest even after a commit; only a refusal of the recorded export reports handoffCommitted. - Send the negotiated versions in the launch frame of the CI app runtime fixture. Co-Authored-By: Claude Opus 5.5 --- .../ci/fixtures/production-app-runtime.ts | 2 + core/src/app_install.rs | 17 ++++++- core/tests/private/app_install.rs | 4 ++ web/src/server/AppRuntime/authority.server.ts | 15 ++++++- web/src/server/AppRuntime/lifecycle.server.ts | 8 +++- .../server/LegacyHandoff/journal.server.ts | 4 +- .../server/LegacyHandoff/app-api.db.test.ts | 44 +++++++++++++++++++ 7 files changed, 88 insertions(+), 6 deletions(-) diff --git a/.github/scripts/ci/fixtures/production-app-runtime.ts b/.github/scripts/ci/fixtures/production-app-runtime.ts index 1158f8e4a..bc913f90e 100644 --- a/.github/scripts/ci/fixtures/production-app-runtime.ts +++ b/.github/scripts/ci/fixtures/production-app-runtime.ts @@ -417,6 +417,8 @@ async function verifyManager() { runtimeProfile: 'rentnerproxy-linux-v1', appProtocol: '>=1.0.0 <2.0.0', platformApi: '>=1.0.0 <2.0.0', + // The manager negotiates the lower bound of each range: 1.0.0 for >=1.0.0. + negotiated: { appProtocol: '1.0.0', platformApi: '1.0.0' }, providers: [providerRegistration.profile], }) + '\n', ) diff --git a/core/src/app_install.rs b/core/src/app_install.rs index 1365db021..4828a7838 100644 --- a/core/src/app_install.rs +++ b/core/src/app_install.rs @@ -316,8 +316,23 @@ impl Installer { manifest: &Value, environment: &ManifestEnvironment<'_>, ) -> io::Result<()> { + // An app is compatible when it negotiates versions and the manifest passes the check + // against exactly those versions: a range that ends below the offered version, such as + // `>=1.0.0 <1.1.0`, still runs with the version it negotiates. + let negotiated = self + .contracts + .negotiate_versions(manifest, environment) + .map_err(invalid_contract)?; self.contracts - .check_manifest_compatibility(manifest, environment) + .check_manifest_compatibility( + manifest, + &ManifestEnvironment { + platform_api: &negotiated.platform_api, + app_protocol: &negotiated.app_protocol, + ui_bridge: negotiated.ui_bridge.as_deref(), + ..*environment + }, + ) .map_err(invalid_contract)?; if declares_engine_providers(manifest, environment) { Ok(()) diff --git a/core/tests/private/app_install.rs b/core/tests/private/app_install.rs index 5f1569175..afe38f1f0 100644 --- a/core/tests/private/app_install.rs +++ b/core/tests/private/app_install.rs @@ -527,6 +527,9 @@ fn install_advertises_protocol_1_1_0_to_apps_that_require_it() { (">=1.1.0 <2.0.0", ">=1.1.0 <2.0.0", true), (">=1.2.0 <2.0.0", ">=1.0.0 <2.0.0", false), (">=1.0.0 <2.0.0", ">=1.2.0 <2.0.0", false), + // A capped range ends below the advertised version, yet the app negotiates 1.0.0. + (">=1.0.0 <1.1.0", ">=1.0.0 <1.1.0", true), + (">=1.0.0 <1.1.0", ">=1.2.0 <2.0.0", false), ] { let mut manifest = manifest(); manifest["requires"]["platformApi"] = json!(platform_api); @@ -551,6 +554,7 @@ fn apps_negotiate_the_lower_bound_of_each_manifest_range() { for (range, negotiated) in [ (">=1.0.0 <2.0.0", Some("1.0.0")), (">=1.1.0 <2.0.0", Some("1.1.0")), + (">=1.0.0 <1.1.0", Some("1.0.0")), (">=1.2.0 <2.0.0", None), ] { let mut manifest = manifest(); diff --git a/web/src/server/AppRuntime/authority.server.ts b/web/src/server/AppRuntime/authority.server.ts index f80c37df8..5e0427c86 100644 --- a/web/src/server/AppRuntime/authority.server.ts +++ b/web/src/server/AppRuntime/authority.server.ts @@ -213,6 +213,17 @@ export async function readAppRuntimeLeaseInTransaction( return { expiresAt: generation.leaseExpiresAt.getTime() } } +/** + * The bridge version of a generation. Rows written before negotiated versions existed have none: + * a generation with a UI then speaks 1.0.0, and a headless one has no bridge. + */ +export function effectiveUiBridgeVersion(row: { + readonly hasUi: boolean + readonly uiBridgeVersion: string | null +}): string | null { + return row.uiBridgeVersion ?? (row.hasUi ? '1.0.0' : null) +} + export async function readAppRuntimeContextInTransaction( transaction: AuthTransaction, identity: AppRuntimeIdentity, @@ -246,8 +257,8 @@ export async function readAppRuntimeContextInTransaction( versions: { appProtocol: generation.appProtocolVersion, platformApi: generation.platformApiVersion, - ...(generation.hasUi && generation.uiBridgeVersion !== null - ? { uiBridge: generation.uiBridgeVersion } + ...(generation.hasUi && effectiveUiBridgeVersion(generation) !== null + ? { uiBridge: effectiveUiBridgeVersion(generation) } : {}), }, capabilities: [...capabilities.values()], diff --git a/web/src/server/AppRuntime/lifecycle.server.ts b/web/src/server/AppRuntime/lifecycle.server.ts index 5fb94af62..93d0f8bb4 100644 --- a/web/src/server/AppRuntime/lifecycle.server.ts +++ b/web/src/server/AppRuntime/lifecycle.server.ts @@ -29,7 +29,11 @@ import { isLocalAppRuntimePermissionKey, sameAppRuntimeCapability, } from './authority-policy.server.ts' -import { isAppRuntimeIdentity, lockAppRuntimeInstallation } from './authority.server.ts' +import { + effectiveUiBridgeVersion, + isAppRuntimeIdentity, + lockAppRuntimeInstallation, +} from './authority.server.ts' import { appCapabilitySchema, appIncidentCategoriesSchema, @@ -149,7 +153,7 @@ export async function registerAppRuntimeGenerationInTransaction( previous.hasUi === hasUi && previous.appProtocolVersion === declaredVersions.appProtocol && previous.platformApiVersion === declaredVersions.platformApi && - previous.uiBridgeVersion === declaredVersions.uiBridge && + effectiveUiBridgeVersion(previous) === declaredVersions.uiBridge && JSON.stringify(previous.capabilities) === JSON.stringify(declaredCapabilities) && JSON.stringify(previous.permissionKeys) === JSON.stringify(declaredPermissions) && JSON.stringify(previous.providerProfiles) === JSON.stringify(declaredProviders) && diff --git a/web/src/server/LegacyHandoff/journal.server.ts b/web/src/server/LegacyHandoff/journal.server.ts index fdc88aff9..6b6a7992d 100644 --- a/web/src/server/LegacyHandoff/journal.server.ts +++ b/web/src/server/LegacyHandoff/journal.server.ts @@ -289,8 +289,10 @@ export async function refuseLegacyFeatureHandoffInTransaction( const row = await lockJournalRow(transaction, domain) if (!row) return false if (row.installationId !== installationId) throw new LegacyFeatureHandoffError('conflict') - if (row.state === 'committed') throw new LegacyFeatureHandoffError('committed') + // The digest names the export being refused, so another digest is a conflict even after a + // commit; only a refusal of the recorded export reports that the handoff is committed. if (row.digest !== digest) throw new LegacyFeatureHandoffError('conflict') + if (row.state === 'committed') throw new LegacyFeatureHandoffError('committed') await abortLegacyFeatureHandoffInTransaction(transaction, domain, installationId, source) const detail = refusal.detail ?? null await transaction diff --git a/web/src/tests/server/LegacyHandoff/app-api.db.test.ts b/web/src/tests/server/LegacyHandoff/app-api.db.test.ts index 5ed52defd..3d0bdb286 100644 --- a/web/src/tests/server/LegacyHandoff/app-api.db.test.ts +++ b/web/src/tests/server/LegacyHandoff/app-api.db.test.ts @@ -951,6 +951,10 @@ integrationTest( .where(eq(legacyFeatureHandoffRefusals.installationId, app.installationId)), ).toEqual([]) expect(await inspected()).not.toHaveProperty('refusals') + // Another digest is no refusal of the committed export. + expect( + await api.abort(app, 'dns', handoffAbort('f'.repeat(64)), 'abort-wrong'), + ).toMatchObject({ status: 409, body: { code: 'conflict' } }) expect(await api.abort(app, 'dns', handoffAbort(final), 'abort-4')).toMatchObject({ status: 409, body: { code: 'handoffCommitted' }, @@ -1109,3 +1113,43 @@ integrationTest( }, handoffTestTimeoutMs, ) + +integrationTest( + 'a migrated UI generation without a stored bridge version speaks 1.0.0 and replays its registration', + async () => { + const harness = await createHarness(['dns'], 94) + const { db, install, activate, control } = harness + try { + const api = harness.handoffApi({}) + const ui = await install('test.migrated-ui', ['dns'], [providerGrant('dns')]) + const headless = await install( + 'test.migrated-headless', + ['dns'], + [providerGrant('dns')], + ) + await Promise.all([ui, headless].map(activate)) + // Register the UI app again as a UI generation, as a migrated row would be. + await db + .update(appRuntimeGenerations) + .set({ hasUi: true, uiBridgeVersion: null }) + .where(eq(appRuntimeGenerations.installationId, ui.installationId)) + expect((await api.context(ui)).body).toMatchObject({ + versions: { appProtocol: '1.0.0', platformApi: '1.0.0', uiBridge: '1.0.0' }, + }) + const replay = { + leaseExpiresAt: leaseExpiresAt(), + capabilities: [], + providerProfiles: ['dns'], + hasUi: true, + versions: { appProtocol: '1.0.0', platformApi: '1.0.0', uiBridge: '1.0.0' }, + } + expect(await control('register', ui, replay)).toBe(204) + // A headless row stays without a bridge. + const reply = (await api.context(headless)).body as { versions: object } + expect(reply.versions).toEqual({ appProtocol: '1.0.0', platformApi: '1.0.0' }) + } finally { + await harness.release() + } + }, + handoffTestTimeoutMs, +) From 9d99ca569015bde105ae730fa9d51960cf0fa979 Mon Sep 17 00:00:00 2001 From: "HomePC\\Kevin" Date: Sat, 28 Nov 2026 21:21:32 +0100 Subject: [PATCH 4/4] fix(apps): offer the handoff abort only to apps that negotiated platform API 1.1.0 An installation that negotiated an older platform API gets the answer of an unknown operation (404 notFound) and its handoff stays unchanged. Co-Authored-By: Claude Opus 5.5 --- .../server/LegacyHandoff/app-api.server.ts | 5 +++++ .../server/LegacyHandoff/app-api.db.test.ts | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/web/src/server/LegacyHandoff/app-api.server.ts b/web/src/server/LegacyHandoff/app-api.server.ts index 4bc5205ce..023e7612d 100644 --- a/web/src/server/LegacyHandoff/app-api.server.ts +++ b/web/src/server/LegacyHandoff/app-api.server.ts @@ -61,6 +61,7 @@ const idempotencyConflict = new AppRuntimeProblem( 'idempotencyConflict', 'Idempotency key was reused.', ) +const operationNotFound = new AppRuntimeProblem(404, 'notFound', 'App API operation was not found.') const handoffCommitted = new AppRuntimeProblem( 409, 'handoffCommitted', @@ -291,6 +292,10 @@ export async function executeLegacyHandoffInTransaction( sources: LegacyFeatureHandoffSources, ): Promise { const authority = await authorizeDomain(transaction, credentials, request.domain) + // Abort exists since protocol 1.1.0: for an app that negotiated less it is an unknown + // operation, exactly as the gateway answers a route it does not have. + if (request.operation === 'abortLegacyHandoff' && !authority.reportsAvailability) + throw operationNotFound if (request.operation === 'beginLegacyHandoff') await bindRequestKey(transaction, authority, 'begin', request.key, [request.domain]) if (request.operation === 'commitLegacyHandoff') diff --git a/web/src/tests/server/LegacyHandoff/app-api.db.test.ts b/web/src/tests/server/LegacyHandoff/app-api.db.test.ts index 3d0bdb286..f95e969f0 100644 --- a/web/src/tests/server/LegacyHandoff/app-api.db.test.ts +++ b/web/src/tests/server/LegacyHandoff/app-api.db.test.ts @@ -1054,15 +1054,18 @@ integrationTest( // Another installation's handoff is a conflict for the newer apps as well. expect((await api.status(current, 'dns')).status).toBe(409) const { digest } = begun.body as { digest: string } - // An old app may refuse too; it never sees the record it leaves behind. - const refused = await api.abort(old, 'dns', handoffAbort(digest), 'abort-1') - expect(refused.body).toStrictEqual({ domain: 'dns', state: 'platform' }) - expect((await api.status(old, 'dns')).body).toStrictEqual({ - domain: 'dns', - state: 'platform', + // Abort is a protocol 1.1.0 operation: an app that negotiated 1.0.0 gets the answer of + // an unknown operation and its handoff stays as it was. + expect(await api.abort(old, 'dns', handoffAbort(digest), 'abort-1')).toMatchObject({ + status: 404, + body: { code: 'notFound' }, }) - // Records are per installation: the others never refused. - expect((await api.status(current, 'dns')).body).toMatchObject({ refused: null }) + expect((await api.status(old, 'dns')).body).toMatchObject({ + state: 'exported', + digest, + }) + expect(dns.state.restores).toBe(0) + expect((await api.status(current, 'dns')).status).toBe(409) } finally { await harness.release() }