cloud/provider/mod.rs
1//! @yah:relay(R409, "Envoy — providers and internal verb catalog (W144)")
2//! @yah:at(2026-06-02T20:58:35Z)
3//! @yah:status(open)
4//! @arch:see(.yah/docs/working/W144-envoy-providers-and-tiering.md)
5//!
6//!
7//!
8//!
9
10use anyhow::Result;
11use async_trait::async_trait;
12
13// R374-F3: `s3_sign` moved to the `local-driver` crate; yubaba's pond MinIO
14// slot uses the same SigV4 helpers. Cloud's hetzner / r2_publish / pond_publish
15// callers now import from `local_driver::s3_sign`.
16
17pub mod cloudflare;
18pub use cloudflare::{
19 CfAccountInfo, CloudflareClient, CreateR2BucketResult, CreateTokenResult, CreateTunnelResult,
20 GrantScope, R2BucketInfo, R2CustomDomain, TokenGrant, TunnelConnState, TunnelDnsRecord,
21 TunnelDriftRow, TunnelDriftState, WorkerDeployResult, MESOFACT_STATIC_GRANTS,
22};
23
24pub mod hetzner;
25pub use hetzner::HetznerDriver;
26
27pub mod cloudflare_envoy;
28pub use cloudflare_envoy::CloudflareEnvoy;
29
30pub mod hetzner_envoy;
31pub use hetzner_envoy::HetznerEnvoy;
32
33pub mod digitalocean;
34pub use digitalocean::{DigitalOceanClient, DigitalOceanEnvoy, DoCreateDropletSpec};
35
36// R594-F5: `floating_ip.*` envoy verb — raft `ingress_owner` follow-placement
37// for sovereign-tier public ingress (W267 §Tier 1). Three crates now, not one
38// module: `yah-floating-ip` holds the seam + reconcile core + planner,
39// `yah-floating-ip-adapters` holds the three vendor HTTP clients (R859-F3), and
40// what is left here is the credentialed constructor and the envoy verb layer.
41pub mod floating_ip;
42pub use floating_ip::{
43 on_ingress_owner_changed, reconcile_assignment, FloatingIpAssignOutcome, FloatingIpProvider,
44 FloatingIpState, FloatingIpTarget,
45};
46// R859-F2: the registry R594-F5 left out (nothing mapped `machine.provider` to
47// an adapter, so the verbs were described but unreachable), plus the pure
48// planner that decides what an `ingress_owner` transition should command.
49pub use floating_ip::{
50 floating_ip_provider_for, plan_ingress_owner_effect, provider_has_floating_ip_adapter,
51 resolve_ingress_owner, IngressOwnerEffect, OwnerLiveness, QuorumHealth,
52};
53
54// R859-F3: the vendor transports moved to `yah-floating-ip-adapters` so the
55// fleet daemon can link them; re-exported here at their historical paths so
56// `cloud::provider::HetznerFloatingIp` still resolves for every call site.
57// `floating_ip_envoy` is what stayed: the `EnvoyAdapter` impls that make these
58// three dispatchable as `floating_ip.assign` / `floating_ip.status`.
59pub use floating_ip_adapters::{HetznerFloatingIp, OvhFloatingIp, VultrFloatingIp};
60
61pub mod floating_ip_envoy;
62pub use floating_ip_envoy::{dispatch_floating_ip_verb, FloatingIpEnvoy};
63
64#[cfg(feature = "local-docker")]
65pub mod local_docker;
66#[cfg(feature = "local-docker")]
67pub use local_docker::LocalDockerProvider;
68
69#[cfg(feature = "local-docker")]
70pub mod local_docker_envoy;
71#[cfg(feature = "local-docker")]
72pub use local_docker_envoy::LocalDockerEnvoy;
73
74/// Logical project scope. Hetzner Cloud tokens are already project-scoped, so
75/// this is a no-op placeholder there.
76#[derive(Debug, Clone, PartialEq, Eq, Hash)]
77pub struct ProjectId(pub String);
78
79/// Opaque server identifier returned by the provider.
80#[derive(Debug, Clone, PartialEq, Eq, Hash)]
81pub struct ServerId(pub String);
82
83/// Reference to a created object-storage bucket.
84#[derive(Debug, Clone, PartialEq, Eq)]
85pub struct BucketRef {
86 pub name: String,
87 /// S3-compat base endpoint for this bucket's region.
88 pub endpoint: String,
89}
90
91/// Observed server lifecycle status (mirrors Hetzner Cloud's status field).
92#[derive(Debug, Clone, PartialEq, Eq)]
93pub enum ServerStatus {
94 Initializing,
95 Starting,
96 Running,
97 Stopping,
98 Off,
99 Deleting,
100 Unknown(String),
101}
102
103impl ServerStatus {
104 pub fn is_running(&self) -> bool {
105 matches!(self, ServerStatus::Running)
106 }
107}
108
109/// Snapshot of a live server returned by [`MachineProvider::find_server_by_name`].
110#[derive(Debug, Clone, PartialEq, Eq)]
111pub struct ServerSummary {
112 pub id: ServerId,
113 /// `server_type.name` from the Hetzner API (e.g. `"cpx22"`).
114 pub server_type: String,
115 pub status: ServerStatus,
116 /// Primary public IPv4 address, if available (`public_net.ipv4.ip`).
117 pub public_ipv4: Option<String>,
118 /// Provider-native location slug (e.g. Hetzner `"hil"` / `"ash"` / `"fsn1"`).
119 /// Used by the idempotent-provision reconciler (R330-F15) to detect
120 /// declared-vs-reality location drift without a separate API call.
121 pub location: String,
122}
123
124/// Parameters for a new machine.
125#[derive(Debug, Clone)]
126pub struct ServerSpec {
127 pub name: String,
128 pub server_type: String,
129 /// Cloud image slug, e.g. `"debian-12"`.
130 pub image: String,
131 pub location: Location,
132 /// Provider-side SSH-key IDs to authorize for `root` at create time.
133 /// Empty means "no key" — Hetzner then emails a random root password,
134 /// which the cloud-crate currently throws away. For machines that
135 /// expect mesh-only access via yah-yubaba once cloud-init finishes,
136 /// pre-mesh SSH is still useful for bootstrap deploys (the
137 /// `yah-agentd` round-trip in R032-T3) and recovery.
138 pub ssh_keys: Vec<u64>,
139}
140
141/// Phase-1 cloud regions.
142#[derive(Debug, Clone, PartialEq, Eq)]
143pub enum Location {
144 /// Hillsboro, Oregon, USA — Hetzner Cloud: `"hil"`
145 Pdx,
146 /// Ashburn, Virginia, USA — Hetzner Cloud: `"ash"`
147 Iad,
148 /// Falkenstein, Germany — Hetzner Cloud: `"fsn1"`
149 Fsn,
150}
151
152impl Location {
153 /// Hetzner Cloud API location slug.
154 pub fn hetzner_cloud_id(&self) -> &'static str {
155 match self {
156 Location::Pdx => "hil",
157 Location::Iad => "ash",
158 Location::Fsn => "fsn1",
159 }
160 }
161
162 /// Hetzner Object Storage S3-compat base endpoint.
163 ///
164 /// VERIFY before A6 that Hillsboro (PDX) and Ashburn (IAD) Object Storage
165 /// are GA. Falkenstein (FSN) is confirmed GA.
166 pub fn hetzner_storage_endpoint(&self) -> &'static str {
167 match self {
168 Location::Fsn => "https://fsn1.your-objectstorage.com",
169 Location::Pdx => "https://hil.your-objectstorage.com",
170 Location::Iad => "https://ash.your-objectstorage.com",
171 }
172 }
173
174 /// Region label used for AWS Sig V4 signing against Hetzner Object Storage.
175 pub fn hetzner_storage_region(&self) -> &'static str {
176 match self {
177 Location::Fsn => "fsn1",
178 Location::Pdx => "hil",
179 Location::Iad => "ash",
180 }
181 }
182}
183
184impl TryFrom<&str> for Location {
185 type Error = anyhow::Error;
186 fn try_from(s: &str) -> Result<Self> {
187 // Wire codes are the coarse region tags from W144 D5; the
188 // Hetzner-native city codes stay as a one-way internal shorthand for
189 // logs, config files, and bucket endpoints — they are not accepted
190 // from the public verb surface.
191 match s {
192 "na-west" | "pdx" | "hil" => Ok(Location::Pdx),
193 "na-east" | "iad" | "ash" => Ok(Location::Iad),
194 "eu-central" | "fsn" | "fsn1" => Ok(Location::Fsn),
195 other => Err(anyhow::anyhow!("unknown location: {other}")),
196 }
197 }
198}
199
200/// Canned S3 ACL policies for bucket-level access control.
201#[derive(Debug, Clone, PartialEq, Eq)]
202pub enum BucketAcl {
203 /// No public access; presigned URLs still work (signed-only access pattern).
204 Private,
205 /// Anonymous GET/HEAD allowed; objects served publicly.
206 PublicRead,
207}
208
209impl BucketAcl {
210 /// S3 canned ACL string for the `x-amz-acl` header.
211 pub fn as_canned(&self) -> &'static str {
212 match self {
213 BucketAcl::Private => "private",
214 BucketAcl::PublicRead => "public-read",
215 }
216 }
217}
218
219/// Abstracts over cloud providers for the machine + bucket lifecycle.
220#[async_trait]
221pub trait MachineProvider: Send + Sync {
222 /// Return or create a logical project scope.
223 ///
224 /// Hetzner Cloud tokens are already project-scoped — this returns a
225 /// no-op `ProjectId(name)` without calling the API.
226 async fn ensure_project(&self, name: &str) -> Result<ProjectId>;
227
228 /// Provision a new server with the given cloud-init `user_data` string.
229 async fn create_server(
230 &self,
231 project: &ProjectId,
232 spec: &ServerSpec,
233 user_data: &str,
234 ) -> Result<ServerId>;
235
236 /// Create an object-storage bucket in the given location.
237 ///
238 /// Uses Hetzner Object Storage S3-compat API (separate from Cloud API).
239 /// Requires `HETZNER_S3_ACCESS_KEY` + `HETZNER_S3_SECRET_KEY` — run
240 /// `yah cloud secrets` for the canonical contract.
241 async fn create_bucket(&self, name: &str, location: Location) -> Result<BucketRef>;
242
243 /// Fetch the current lifecycle status of a server.
244 async fn server_status(&self, id: &ServerId) -> Result<ServerStatus>;
245
246 /// Look up a server by its declared name. `Ok(None)` means the API
247 /// responded but no server with that name exists; `Err(_)` means the
248 /// API call itself failed.
249 async fn find_server_by_name(&self, name: &str) -> Result<Option<ServerSummary>>;
250
251 /// Probe whether a bucket exists in `location`. `Ok(true)` = HEAD 200,
252 /// `Ok(false)` = HEAD 404. Auth failures (403) propagate as `Err` so
253 /// the caller can distinguish "missing" from "can't tell".
254 async fn bucket_exists(&self, name: &str, location: Location) -> Result<bool>;
255
256 /// Irreversibly destroy a server. Returns `Ok(())` if already deleted.
257 async fn destroy_server(&self, id: &ServerId) -> Result<()>;
258
259 /// Irreversibly delete an object-storage bucket. Lists and deletes every
260 /// object first (S3 won't delete a non-empty bucket), then deletes the
261 /// bucket itself. Returns `Ok(())` if the bucket was already gone (404
262 /// on the final DELETE). Auth/transport failures propagate as `Err`.
263 async fn delete_bucket(&self, name: &str, location: Location) -> Result<()>;
264
265 /// Set the canned ACL on an existing bucket via `PUT /<bucket>?acl`.
266 ///
267 /// [`BucketAcl::Private`] covers both "private" and "signed-only" semantics —
268 /// presigned URLs work regardless of ACL. [`BucketAcl::PublicRead`] enables
269 /// anonymous GET/HEAD. The call is idempotent: applying the same ACL twice
270 /// succeeds without error.
271 async fn set_bucket_acl(&self, name: &str, location: Location, acl: BucketAcl) -> Result<()>;
272}