Public: anyone can read this; the crew can change it.
OVHcloud US holds a pinned forge: volume, instance and both US regions as places #16636
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16556-ovhcloud-us-holds-a-pinned-forge-volume → main 0 commits fork 3 threads · 3 unresolved
12 files
changed +438
−13
docs/CLOUD.md +4
| @@ -71,3 +71,7 @@ query) is listed at **Settings → Cloud accounts → Every vendor call today**. | ||
| 71 | 71 | Rows are pruned past 90 days on every write; `at` is indexed. Left out: one |
| 72 | 72 | token per vendor is not enforced (several names per vendor stay allowed), and |
| 73 | 73 | an agent's own vendor calls beyond the hand-out are not metered. A forge admin reaches the same accounts in the terminal (`:` → Cloud accounts: each account with what it is used for, verified / last used and today's vendor calls; `a` attach, `v` verify, `r` rotate, `n` rename, `x` remove, `w` flip the write switch, `A` audit into an `owner/repo`, `c` every vendor call today (purpose, host and path, bytes out, allowed or refused), the token typed masked) and over MCP (`cloud_accounts` lists them with today's audit rows; `cloud_account` with `verb` attach, verify, rotate, rename, remove, `allow_writes` (with `allowed`) or `audit` (with `repo`) needs an admin-scope token). Both call `actions/cloud.ts`, neither ever shows a token, and anyone else is refused. A rename is refused when the account or the secret `CLOUD_<PROVIDER>_<NAME>` already exists. |
| 74 | ||
| 75 | ## OVHcloud US as a pinned-forge target (#16556) | |
| 76 | ||
| 77 | `src/cloud/ovh.ts` is a `Driver` like Hetzner's: the stored credential `APPLICATION_KEY:APPLICATION_SECRET:CONSUMER_KEY:PROJECT_ID` signs every call (`Driver.signed`) against `/cloud/project/{id}`. A classic 10 GiB volume and one instance (flavor and `Ubuntu 24.04` looked up by name in the row's region) are made; the volume is attached once the instance is active, and the boot config waits for its block device, formats it only when blank, and mounts it at `/mnt/forge_data`. Places are `US-EAST-VA-1` and `US-WEST-OR-1` with d2-2, d2-4 and d2-8, availability from `GET flavor?region=`, prices from the public catalog with the 2026-11-23 list prices as the dated fallback. Nothing deploys until the owner attaches an OVHcloud US account. |
src/cloud/ceiling.ts +2 −1
| @@ -20,7 +20,7 @@ import type { App } from "../app.ts"; | ||
| 20 | 20 | import { getCloudAccount } from "../core/cloud_account.ts"; |
| 21 | 21 | import { getPinned, listPinned, placeIdOf, type Pinned } from "../core/pinned.ts"; |
| 22 | 22 | import type { Driver } from "./machine.ts"; |
| 23 | import { DO_VOLUME_USD_PER_GIB, VOLUME_GIB } from "./places.ts"; | |
| 23 | import { DO_VOLUME_USD_PER_GIB, OVH_VOLUME_USD_PER_GIB, VOLUME_GIB } from "./places.ts"; | |
| 24 | 24 | import { keptPlaces } from "./places_read.ts"; |
| 25 | 25 | import { dollars, toUsd, type Rate } from "./prices.ts"; |
| 26 | 26 | import { keptRate } from "./rates.ts"; |
| @@ -59,6 +59,7 @@ export interface Priced { | ||
| 59 | 59 | */ |
| 60 | 60 | function keptVolumeCents(db: Database, provider: string, rate: Rate | undefined): number | undefined { |
| 61 | 61 | if (provider === "digitalocean") return toUsd(DO_VOLUME_USD_PER_GIB * VOLUME_GIB, "USD", undefined, "up").usdCents; |
| 62 | if (provider === "ovh") return toUsd(OVH_VOLUME_USD_PER_GIB * VOLUME_GIB, "USD", undefined, "up").usdCents; | |
| 62 | 63 | if (provider !== "hetzner") return undefined; |
| 63 | 64 | try { |
| 64 | 65 | const row = db.query<{ body: string }, [string]>("SELECT body FROM place_read WHERE provider = ?1").get(provider); |
src/cloud/drivers.ts +2 −1
| @@ -5,9 +5,10 @@ | ||
| 5 | 5 | |
| 6 | 6 | import { digitalocean } from "./droplet.ts"; |
| 7 | 7 | import { hetzner } from "./hetzner.ts"; |
| 8 | import { ovh } from "./ovh.ts"; | |
| 8 | 9 | import type { Driver } from "./machine.ts"; |
| 9 | 10 | |
| 10 | const DRIVERS: Readonly<Record<string, Driver>> = { digitalocean, hetzner }; | |
| 11 | const DRIVERS: Readonly<Record<string, Driver>> = { digitalocean, hetzner, ovh }; | |
| 11 | 12 | |
| 12 | 13 | /** The driver of a target, or a plain error when none deploys there. */ |
| 13 | 14 | export function driverOf(id: string): Driver { |
src/cloud/machine.ts +10 −3
| @@ -119,7 +119,7 @@ const proxyCommands = (dataDir: string): string => ` - install -d -m 0700 -o ca | ||
| 119 | 119 | * safe to leave on the internet (an unprivileged user, a firewall, no shell, updates, the sandbox) |
| 120 | 120 | * is `harden.ts`. What the boot sets is written after the config, the data directory last. |
| 121 | 121 | */ |
| 122 | export function bootConfig(p: Booted, dataDir: string): string { | |
| 122 | export function bootConfig(p: Booted, dataDir: string, early: readonly string[] = []): string { | |
| 123 | 123 | // A row from before `checkConfig` refused these names may still hold one: it is dropped, so what |
| 124 | 124 | // the boot sets is said once and in its own place. |
| 125 | 125 | const settings = Object.fromEntries(Object.entries(p.config).filter(([k]) => !BOOT_NAMES.includes(k))); |
| @@ -140,7 +140,7 @@ ${serviceUnit(p.name, p.version, dataDir).replace(/^(?=.)/gm, " ")} | ||
| 140 | 140 | ${hardenFiles()} |
| 141 | 141 | runcmd: |
| 142 | 142 | ${hardenEarly()} |
| 143 | - curl -fsSL https://bun.sh/install | BUN_INSTALL=${BUN_HOME} bash -s "bun-v${BUN_VERSION}" | |
| 143 | ${early.map((c) => ` - ${JSON.stringify(c)}\n`).join("")} - curl -fsSL https://bun.sh/install | BUN_INSTALL=${BUN_HOME} bash -s "bun-v${BUN_VERSION}" | |
| 144 | 144 | - for try in 1 2 3 4 5; do rm -rf ${CHECKOUT} && git init -q ${CHECKOUT} && git -C ${CHECKOUT} fetch -q --depth 1 ${p.source} ${p.version} && break; sleep 15; done |
| 145 | 145 | - git -C ${CHECKOUT} checkout -q --detach FETCH_HEAD |
| 146 | 146 | ${hardenLate()} |
| @@ -161,6 +161,12 @@ export type Call = (method: string, path: string, body?: unknown) => Promise<any | ||
| 161 | 161 | export interface Driver { |
| 162 | 162 | /** The fixed API base, https, no trailing slash. */ |
| 163 | 163 | readonly api: string; |
| 164 | /** | |
| 165 | * The cloud's own way of making a call, where a bearer token is not it (OVHcloud signs each | |
| 166 | * request with several keys): `token` is the stored credential, whatever its shape. Throws | |
| 167 | * before any call when the credential has the wrong shape. | |
| 168 | */ | |
| 169 | signed?(f: Fetch, token: string): Call; | |
| 164 | 170 | /** |
| 165 | 171 | * Refuse a place that may not be ordered, by throwing in words shown as they are: called before |
| 166 | 172 | * the first thing is made or deleted (`ceiling.ts` sets it). |
| @@ -189,6 +195,7 @@ export interface Driver { | ||
| 189 | 195 | export const forgeTag = (name: string) => `forge:${name}`; |
| 190 | 196 | |
| 191 | 197 | function caller(d: Driver, f: Fetch, token: string): Call { |
| 198 | if (d.signed) return d.signed(f, token); | |
| 192 | 199 | const host = new URL(d.api).host; |
| 193 | 200 | return async (method, path, body) => { |
| 194 | 201 | const res = await f(`${d.api}${path}`, { |
| @@ -202,7 +209,7 @@ function caller(d: Driver, f: Fetch, token: string): Call { | ||
| 202 | 209 | }; |
| 203 | 210 | } |
| 204 | 211 | |
| 205 | const ID = /^\d+$/; | |
| 212 | const ID = /^[A-Za-z0-9-]{1,64}$/; | |
| 206 | 213 | |
| 207 | 214 | /** |
| 208 | 215 | * Volume first, then the machine that mounts it. A volume a failed earlier try |
src/cloud/ovh.ts added +105
| @@ -0,0 +1,105 @@ | ||
| 1 | /** | |
| 2 | * OVHcloud US Public Cloud (#16556): its calls only; the sequence they run in is machine.ts. The | |
| 3 | * credential is one stored string, APPLICATION_KEY:APPLICATION_SECRET:CONSUMER_KEY:PROJECT_ID, and | |
| 4 | * every call is signed (`ovh_sign.ts`) against /cloud/project/{PROJECT_ID}, so a consumer key | |
| 5 | * limited to that one project's paths is enough and nothing wider is asked for. | |
| 6 | * | |
| 7 | * Calls: POST volume (classic), GET flavor?region= and GET image?region= (the size and the boot | |
| 8 | * image by name), POST instance (userData = the shared boot config), GET instance/{id} (status, | |
| 9 | * then the public IPv4 read back), POST volume/{id}/attach, DELETE instance/{id}, DELETE | |
| 10 | * volume/{id}, GET volume/{id}. An instance cannot take a volume at creation: it is attached once | |
| 11 | * the instance is active, and an instance whose attach fails is deleted, never left unrecorded. | |
| 12 | */ | |
| 13 | ||
| 14 | import { bootConfig as boot, ipv4, volumeName, type Booted, type Driver } from "./machine.ts"; | |
| 15 | import { OVH_REGIONS } from "./places.ts"; | |
| 16 | import { ovhParts } from "./providers.ts"; | |
| 17 | import { ovhCall } from "./ovh_sign.ts"; | |
| 18 | ||
| 19 | /** The image every forge boots, by the name OVHcloud lists it under. */ | |
| 20 | export const OVH_IMAGE = "Ubuntu 24.04"; | |
| 21 | ||
| 22 | /** How long a create waits for the instance to turn active before it attaches the volume. */ | |
| 23 | export const ACTIVE = { waitMs: 300_000, everyMs: 5_000 }; | |
| 24 | ||
| 25 | const MOUNT = "/mnt/forge_data"; | |
| 26 | const VOLUME = /^[A-Za-z0-9-]{1,64}$/; | |
| 27 | ||
| 28 | /** | |
| 29 | * Wait for the volume's block device (OVHcloud shows it as virtio-<the first 20 characters of its | |
| 30 | * id>), make a filesystem only on a blank one, and mount it by label. The volume is attached after | |
| 31 | * the instance boots, so this runs first and waits. | |
| 32 | */ | |
| 33 | const mountStep = (volume: string): string => { | |
| 34 | if (!VOLUME.test(volume)) throw new Error("this forge's volume has no id the boot can mount"); | |
| 35 | const dev = `/dev/disk/by-id/virtio-${volume.slice(0, 20)}`; | |
| 36 | return `for i in $(seq 1 120); do [ -b ${dev} ] && break; sleep 5; done; [ -b ${dev} ] && { blkid ${dev} >/dev/null 2>&1 || mkfs.ext4 -q -L forge_data ${dev}; mkdir -p ${MOUNT}; grep -q ${MOUNT} /etc/fstab || echo 'LABEL=forge_data ${MOUNT} ext4 defaults,nofail 0 2' >> /etc/fstab; mount ${MOUNT}; }`; | |
| 37 | }; | |
| 38 | ||
| 39 | export function bootConfig(p: Booted, volume: string): string { | |
| 40 | return boot(p, MOUNT, [mountStep(volume)]); | |
| 41 | } | |
| 42 | ||
| 43 | const q = encodeURIComponent; | |
| 44 | ||
| 45 | export const ovh: Driver = { | |
| 46 | api: "https://api.us.ovhcloud.com/1.0", | |
| 47 | signed(f, token) { | |
| 48 | const o = ovhParts(token); | |
| 49 | if (!o) throw new Error("the OVHcloud US credential is not APPLICATION_KEY:APPLICATION_SECRET:CONSUMER_KEY:PROJECT_ID"); | |
| 50 | return (method, path, body) => ovhCall(f, o.keys, method, `/cloud/project/${o.project}${path}`, body); | |
| 51 | }, | |
| 52 | admit(p) { | |
| 53 | if (!(p.datacenter in OVH_REGIONS)) throw new Error(`OVHcloud US has no region ${p.datacenter.slice(0, 40)}: it is US-EAST-VA-1 or US-WEST-OR-1.`); | |
| 54 | }, | |
| 55 | async createVolume(call, p) { | |
| 56 | const v = await call("POST", "/volume", { name: volumeName(p.name), region: p.datacenter, size: 10, type: "classic", description: `forge:${p.name}` }); | |
| 57 | return String(v?.id ?? ""); | |
| 58 | }, | |
| 59 | async createMachine(call, p, volume) { | |
| 60 | const flavors: any[] = (await call("GET", `/flavor?region=${q(p.datacenter)}`)) ?? []; | |
| 61 | const flavor = flavors.find((x) => x?.name === p.size && typeof x.id === "string"); | |
| 62 | if (!flavor) throw new Error(`OVHcloud has no flavor ${p.size} in ${p.datacenter}. Nothing new was made.`); | |
| 63 | const images: any[] = (await call("GET", `/image?region=${q(p.datacenter)}&osType=linux`)) ?? []; | |
| 64 | const image = images.find((x) => x?.name === OVH_IMAGE && typeof x.id === "string"); | |
| 65 | if (!image) throw new Error(`OVHcloud lists no ${OVH_IMAGE} image in ${p.datacenter}. Nothing new was made.`); | |
| 66 | const made = await call("POST", "/instance", { name: `forge-${p.name}`, flavorId: flavor.id, imageId: image.id, region: p.datacenter, userData: bootConfig(p, volume), monthlyBilling: false }); | |
| 67 | const id = String(made?.id ?? ""); | |
| 68 | if (id === "") throw new Error("api.us.ovhcloud.com made no instance"); | |
| 69 | try { | |
| 70 | const until = Date.now() + ACTIVE.waitMs; | |
| 71 | while (String((await call("GET", `/instance/${id}`))?.status).toUpperCase() !== "ACTIVE") { | |
| 72 | if (Date.now() >= until) throw new Error("the instance did not turn active in time"); | |
| 73 | await Bun.sleep(ACTIVE.everyMs); | |
| 74 | } | |
| 75 | await call("POST", `/volume/${volume}/attach`, { instanceId: id }); | |
| 76 | } catch (e) { | |
| 77 | // Never an instance the forge does not record: the attach failed, so the instance goes. | |
| 78 | try { | |
| 79 | await call("DELETE", `/instance/${id}`); | |
| 80 | } catch (c) { | |
| 81 | // The one case an instance can outlive the forge's record: say its id, so a person deletes | |
| 82 | // it. | |
| 83 | throw new Error(`${e instanceof Error ? e.message : String(e)}; and deleting OVHcloud instance ${id} failed (${c instanceof Error ? c.message : String(c)}): delete it in the OVHcloud console, it bills until then.`); | |
| 84 | } | |
| 85 | throw e; | |
| 86 | } | |
| 87 | return id; | |
| 88 | }, | |
| 89 | async deleteMachine(call, remote) { | |
| 90 | await call("DELETE", `/instance/${remote}`); | |
| 91 | }, | |
| 92 | async deleteVolume(call, volume) { | |
| 93 | await call("DELETE", `/volume/${volume}`); | |
| 94 | }, | |
| 95 | async volumeFree(call, volume) { | |
| 96 | const v = await call("GET", `/volume/${volume}`); | |
| 97 | return Array.isArray(v?.attachedTo) ? v.attachedTo.length === 0 : true; | |
| 98 | }, | |
| 99 | async readMachine(call, remote) { | |
| 100 | const i = await call("GET", `/instance/${remote}`); | |
| 101 | const ips: any[] = Array.isArray(i?.ipAddresses) ? i.ipAddresses : []; | |
| 102 | const pub = ips.find((a) => a?.type === "public" && a.version === 4 && ipv4(a.ip) !== ""); | |
| 103 | return { status: String(i?.status ?? "").toLowerCase(), address: pub?.ip ?? "" }; | |
| 104 | }, | |
| 105 | }; |
src/cloud/places.ts +57
| @@ -160,6 +160,63 @@ export function digitaloceanPlaces(body: { sizes: unknown; regions: unknown }, r | ||
| 160 | 160 | return out; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | /** The two US regions and where they are. */ | |
| 164 | export const OVH_REGIONS: Readonly<Record<string, { city: string; country: string }>> = { | |
| 165 | "US-EAST-VA-1": { city: "Vint Hill, Virginia", country: "US" }, | |
| 166 | "US-WEST-OR-1": { city: "Hillsboro, Oregon", country: "US" }, | |
| 167 | }; | |
| 168 | ||
| 169 | /** What OVHcloud's d2 flavors are: the API names them, the page gives their parts. */ | |
| 170 | const OVH_SIZES: Readonly<Record<string, { vcpu: number; memoryMiB: number; diskGiB: number; usd: number }>> = { | |
| 171 | "d2-2": { vcpu: 1, memoryMiB: 2048, diskGiB: 25, usd: 7.08 }, | |
| 172 | "d2-4": { vcpu: 2, memoryMiB: 4096, diskGiB: 50, usd: 14.18 }, | |
| 173 | "d2-8": { vcpu: 4, memoryMiB: 8192, diskGiB: 80, usd: 25.53 }, | |
| 174 | }; | |
| 175 | /** | |
| 176 | * The day those list prices were read from us.ovhcloud.com/public-cloud/prices, the fallback when | |
| 177 | * the catalog gives none. | |
| 178 | */ | |
| 179 | export const OVH_PRICED_ON = "2026-11-23"; | |
| 180 | /** OVHcloud's block storage list price, USD per GiB a month, from the same page. */ | |
| 181 | export const OVH_VOLUME_USD_PER_GIB = 0.048; | |
| 182 | const HOURS_A_MONTH = 730; | |
| 183 | ||
| 184 | /** | |
| 185 | * The catalog's price of a flavor, USD a month: the `<flavor>.consumption` add-on's hourly price | |
| 186 | * (OVHcloud writes prices in 1e-8 of a dollar). Anything outside a sane range is not believed. | |
| 187 | */ | |
| 188 | function ovhCatalogUsd(catalog: unknown, size: string): number | undefined { | |
| 189 | const add = arr((catalog as any)?.addons).find((a) => typeof a?.planCode === "string" && a.planCode.startsWith(`${size}.consumption`)); | |
| 190 | const hourly = num(arr(add?.pricings)[0]?.price) / 1e8; | |
| 191 | const month = hourly * HOURS_A_MONTH; | |
| 192 | return month >= 1 && month <= 500 ? month : undefined; | |
| 193 | } | |
| 194 | ||
| 195 | /** | |
| 196 | * OVHcloud US: the d2 flavors in its two regions. A flavor is orderable where `GET flavor?region=` | |
| 197 | * lists it as available; the price is the public catalog's, else the dated list price above, and | |
| 198 | * says which. The volume's list price is added; the address is free. | |
| 199 | */ | |
| 200 | export function ovhPlaces(body: { flavors: unknown; catalog: unknown }, readAt: string): Place[] { | |
| 201 | const out: Place[] = []; | |
| 202 | for (const [region, here] of Object.entries(OVH_REGIONS)) { | |
| 203 | const listed = arr((body.flavors as any)?.[region]); | |
| 204 | for (const [size, spec] of Object.entries(OVH_SIZES)) { | |
| 205 | const flavor = listed.find((f) => f?.name === size); | |
| 206 | const fromCatalog = ovhCatalogUsd(body.catalog, size); | |
| 207 | const price = toUsd((fromCatalog ?? spec.usd) + OVH_VOLUME_USD_PER_GIB * VOLUME_GIB, "USD", undefined); | |
| 208 | const base = { | |
| 209 | id: `ovh:${region}:${size}`, provider: "ovh", datacenter: region, city: here.city, country: here.country, size, | |
| 210 | vcpu: spec.vcpu, memoryMiB: spec.memoryMiB, diskGiB: spec.diskGiB, trafficGiB: 0, | |
| 211 | costCents: price.usdCents, price, readAt, | |
| 212 | assumed: fromCatalog === undefined ? [`the machine's price is OVHcloud's list price of ${OVH_PRICED_ON}`] : [], | |
| 213 | }; | |
| 214 | out.push(flavor?.available === true ? { ...base, orderable: true, why: "" } : unorderable(base, flavor ? "sold out in this region right now" : "OVHcloud does not list this flavor in this region")); | |
| 215 | } | |
| 216 | } | |
| 217 | return out; | |
| 218 | } | |
| 219 | ||
| 163 | 220 | export const meets = (p: Place, plan: PlanName): boolean => { |
| 164 | 221 | const m = PLAN_MINIMUMS[plan]; |
| 165 | 222 | return p.memoryMiB >= m.memoryMiB && p.vcpu >= m.vcpu && p.diskGiB >= m.diskGiB; |
src/cloud/places_read.ts +40 −4
| @@ -6,15 +6,17 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | import type { Database } from "bun:sqlite"; |
| 9 | import { digitaloceanPlaces, hetznerPlaces, isPlan, type PlanName, type Place } from "./places.ts"; | |
| 9 | import { digitaloceanPlaces, hetznerPlaces, ovhPlaces, isPlan, type PlanName, type Place } from "./places.ts"; | |
| 10 | 10 | import type { Rate } from "./prices.ts"; |
| 11 | 11 | import { readCapped } from "../spawn/bounded_read.ts"; |
| 12 | import type { Fetch } from "./providers.ts"; | |
| 12 | import { ovhParts, type Fetch } from "./providers.ts"; | |
| 13 | import { OVH_REGIONS } from "./places.ts"; | |
| 14 | import { ovhCall, OVH_API } from "./ovh_sign.ts"; | |
| 13 | 15 | |
| 14 | 16 | /** A read older than this is refreshed the next time an admin looks. */ |
| 15 | 17 | export const STALE_MS = 6 * 3_600_000; |
| 16 | 18 | /** Providers whose API lists places. */ |
| 17 | export const LISTED = ["digitalocean", "hetzner"] as const; | |
| 19 | export const LISTED = ["digitalocean", "hetzner", "ovh"] as const; | |
| 18 | 20 | const MAX_BODY = 2_000_000; |
| 19 | 21 | |
| 20 | 22 | /** A failing provider is asked again no sooner than this. */ |
| @@ -45,6 +47,7 @@ const API: Readonly<Record<string, { base: string; paths: Readonly<Record<string | ||
| 45 | 47 | */ |
| 46 | 48 | export async function readPlaces(db: Database, provider: string, f: Fetch, token: string, now = new Date()): Promise<boolean> { |
| 47 | 49 | const api = API[provider]; |
| 50 | if (provider === "ovh") return readOvh(db, f, token, now); | |
| 48 | 51 | if (!api) return false; |
| 49 | 52 | try { |
| 50 | 53 | const body: Record<string, unknown> = {}; |
| @@ -71,6 +74,39 @@ export async function readPlaces(db: Database, provider: string, f: Fetch, token | ||
| 71 | 74 | } |
| 72 | 75 | } |
| 73 | 76 | |
| 77 | /** | |
| 78 | * OVHcloud US: each region's flavors, signed, and the public catalog, unsigned. A catalog that | |
| 79 | * cannot be read leaves the dated list prices in place; flavors that cannot be read fail the read. | |
| 80 | */ | |
| 81 | async function readOvh(db: Database, f: Fetch, token: string, now: Date): Promise<boolean> { | |
| 82 | const o = ovhParts(token); | |
| 83 | if (!o) return false; | |
| 84 | try { | |
| 85 | const flavors: Record<string, unknown> = {}; | |
| 86 | for (const region of Object.keys(OVH_REGIONS)) flavors[region] = await ovhCall(f, o.keys, "GET", `/cloud/project/${o.project}/flavor?region=${encodeURIComponent(region)}`); | |
| 87 | let catalog: unknown = {}; | |
| 88 | try { | |
| 89 | const res = await f(`${OVH_API}/order/catalog/public/cloud?ovhSubsidiary=US`, { signal: AbortSignal.timeout(20_000) }); | |
| 90 | const bytes = res.ok ? await readCapped(res, MAX_BODY) : undefined; | |
| 91 | if (bytes !== undefined) catalog = JSON.parse(new TextDecoder().decode(bytes)); | |
| 92 | } catch { | |
| 93 | catalog = {}; | |
| 94 | } | |
| 95 | // Only the add-ons a flavor price is read from are kept, so the stored read stays small. | |
| 96 | const addons = (Array.isArray((catalog as any)?.addons) ? (catalog as any).addons : []).filter((a: any) => /^d2-\d+\.consumption/.test(String(a?.planCode))); | |
| 97 | const text = JSON.stringify({ flavors, catalog: { addons } }); | |
| 98 | if (text.length > MAX_BODY) return false; | |
| 99 | table(db); | |
| 100 | db.query( | |
| 101 | `INSERT INTO place_read (provider, read_at, body) VALUES (?1, ?2, ?3) | |
| 102 | ON CONFLICT (provider) DO UPDATE SET read_at = excluded.read_at, body = excluded.body`, | |
| 103 | ).run("ovh", now.toISOString(), text); | |
| 104 | return true; | |
| 105 | } catch { | |
| 106 | return false; | |
| 107 | } | |
| 108 | } | |
| 109 | ||
| 74 | 110 | /** Note that a provider was asked now, whether or not the read worked. */ |
| 75 | 111 | export function noteTry(db: Database, provider: string, now = new Date()): void { |
| 76 | 112 | table(db); |
| @@ -95,7 +131,7 @@ export function keptPlaces(db: Database, rate: Rate | undefined): Place[] { | ||
| 95 | 131 | for (const r of db.query<{ provider: string; read_at: string; body: string }, []>("SELECT * FROM place_read ORDER BY provider").all()) { |
| 96 | 132 | try { |
| 97 | 133 | const body = JSON.parse(r.body); |
| 98 | out.push(...(r.provider === "hetzner" ? hetznerPlaces(body, rate, r.read_at) : digitaloceanPlaces(body, r.read_at))); | |
| 134 | out.push(...(r.provider === "hetzner" ? hetznerPlaces(body, rate, r.read_at) : r.provider === "ovh" ? ovhPlaces(body, r.read_at) : digitaloceanPlaces(body, r.read_at))); | |
| 99 | 135 | } catch { |
| 100 | 136 | // an unreadable keep is skipped, not a failure of the catalog |
| 101 | 137 | } |
src/cloud/providers.ts +1 −1
| @@ -230,7 +230,7 @@ function parts(value: string, n: number): string[] | undefined { | ||
| 230 | 230 | |
| 231 | 231 | const OVH_SHAPE = "An OVHcloud US credential is APPLICATION_KEY:APPLICATION_SECRET:CONSUMER_KEY:PROJECT_ID."; |
| 232 | 232 | |
| 233 | function ovhParts(value: string): { keys: OvhKeys; project: string } | undefined { | |
| 233 | export function ovhParts(value: string): { keys: OvhKeys; project: string } | undefined { | |
| 234 | 234 | const p = parts(value, 4); |
| 235 | 235 | if (!p || !/^[0-9a-zA-Z_-]{1,64}$/.test(p[3]!)) return undefined; |
| 236 | 236 | return { keys: { applicationKey: p[0]!, applicationSecret: p[1]!, consumerKey: p[2]! }, project: p[3]! }; |
src/cloud/targets.ts +9 −1
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | * so, and the owner's own bill is the truth. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | export type TargetId = "digitalocean" | "hetzner" | "aws" | "azure" | "cloudflare" | "vercel"; | |
| 9 | export type TargetId = "digitalocean" | "hetzner" | "ovh" | "aws" | "azure" | "cloudflare" | "vercel"; | |
| 10 | 10 | |
| 11 | 11 | export interface Target { |
| 12 | 12 | readonly id: TargetId; |
| @@ -35,6 +35,14 @@ export const TARGETS: readonly Target[] = [ | ||
| 35 | 35 | cost: "read from Hetzner's own pricing and converted to US dollars at the day's reference rate: GET /api/v1/places?provider=hetzner", |
| 36 | 36 | refused: "Nothing the forge needs is refused; the token must be read-write, and Hetzner scopes it to one project and offers nothing narrower.", |
| 37 | 37 | }, |
| 38 | { | |
| 39 | id: "ovh", | |
| 40 | label: "OVHcloud US", | |
| 41 | status: "first", | |
| 42 | runs: "One Public Cloud instance (Ubuntu, Bun from the pinned source) with one classic volume mounted as FORGE_DATA, in Vint Hill, Virginia or Hillsboro, Oregon. Replacing the instance keeps the volume.", | |
| 43 | cost: "read from OVHcloud's public catalog in US dollars, with its own list prices of 2026-11-23 as the fallback: GET /api/v1/places?provider=ovh", | |
| 44 | refused: "Nothing the forge needs is refused; the consumer key needs POST and DELETE on one project. Nothing deploys there until the owner attaches an OVHcloud US account.", | |
| 45 | }, | |
| 38 | 46 | { |
| 39 | 47 | id: "aws", |
| 40 | 48 | label: "AWS", |
src/core/pinned.ts +1
| @@ -54,6 +54,7 @@ export interface Pinned { | ||
| 54 | 54 | const LEGACY_PLACE: Readonly<Record<string, { datacenter: string; size: string }>> = { |
| 55 | 55 | digitalocean: { datacenter: "nyc3", size: "s-1vcpu-2gb" }, |
| 56 | 56 | hetzner: { datacenter: "nbg1", size: "cx23" }, |
| 57 | ovh: { datacenter: "US-EAST-VA-1", size: "d2-2" }, | |
| 57 | 58 | }; |
| 58 | 59 | |
| 59 | 60 | /** The Places id of where a forge is: `provider:datacenter:size`. */ |
test/pinned-forge.test.ts +2 −2
| @@ -186,7 +186,7 @@ describe("pinned forge", () => { | ||
| 186 | 186 | const r = await deployPinned(app, admin(), input({ name: `x-${target}`, target })); |
| 187 | 187 | expect(r.ok).toBe(false); |
| 188 | 188 | } |
| 189 | expect(TARGETS.map((t) => t.id)).toEqual(["digitalocean", "hetzner", "aws", "azure", "cloudflare", "vercel"]); | |
| 189 | expect(TARGETS.map((t) => t.id)).toEqual(["digitalocean", "hetzner", "ovh", "aws", "azure", "cloudflare", "vercel"]); | |
| 190 | 190 | expect(getPinned(app.db, "x-vercel")).toBeUndefined(); |
| 191 | 191 | }); |
| 192 | 192 | |
| @@ -206,7 +206,7 @@ describe("pinned forge", () => { | ||
| 206 | 206 | const list = await fetch(`${servers.url}/api/v1/admin/pinned`, { headers: h(tok) }); |
| 207 | 207 | expect(list.status).toBe(200); |
| 208 | 208 | const body = (await list.json()) as any; |
| 209 | expect(body.targets).toHaveLength(6); | |
| 209 | expect(body.targets).toHaveLength(7); | |
| 210 | 210 | expect(body.items.length).toBeGreaterThan(0); |
| 211 | 211 | expect((await fetch(`${servers.url}/api/v1/admin/pinned`, { headers: h(bob) })).status).toBeGreaterThanOrEqual(403); |
| 212 | 212 | const up = await fetch(`${servers.url}/api/v1/admin/pinned/fresh/update`, { method: "POST", headers: h(tok), body: JSON.stringify({ version: V2 }) }); |
test/pinned-ovh.test.ts added +205
| @@ -0,0 +1,205 @@ | ||
| 1 | /** | |
| 2 | * OVHcloud US as a pinned-forge target (#16556): a recorded fetch stands in for | |
| 3 | * api.us.ovhcloud.com. The shared sequence is proved on DigitalOcean; here are OVHcloud's own | |
| 4 | * calls, signed, at the recorded region, and the same half-way recovery. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { createApp, type App } from "../src/app.ts"; | |
| 11 | import { addAccount, allowWrite, net as cloudNet } from "../src/actions/cloud.ts"; | |
| 12 | import { checkPinned, deployPinned, net, updatePinned } from "../src/actions/pinned.ts"; | |
| 13 | import { ACTIVE } from "../src/cloud/ovh.ts"; | |
| 14 | import { resetOvhClock } from "../src/cloud/ovh_sign.ts"; | |
| 15 | import { DETACH } from "../src/cloud/machine.ts"; | |
| 16 | import { keptPlaces, readPlaces } from "../src/cloud/places_read.ts"; | |
| 17 | import { getPinned } from "../src/core/pinned.ts"; | |
| 18 | import { createUser, getUserByName } from "../src/core/users.ts"; | |
| 19 | import { quietLogs } from "./helpers/globals.ts"; | |
| 20 | import { seedPlaces } from "./helpers/places-fixture.ts"; | |
| 21 | ||
| 22 | quietLogs(); | |
| 23 | ACTIVE.everyMs = 1; | |
| 24 | DETACH.everyMs = 1; | |
| 25 | ||
| 26 | const CRED = "ak:secret:ck:abc123"; | |
| 27 | const V1 = "a".repeat(40); | |
| 28 | const V2 = "b".repeat(40); | |
| 29 | const SOURCE = "https://forge.example.org/trevato/forge"; | |
| 30 | const PLACE = "ovh:US-EAST-VA-1:d2-2"; | |
| 31 | const VOLUME = "11111111-2222-3333-4444-555555555555"; | |
| 32 | const P = "/1.0/cloud/project/abc123"; | |
| 33 | ||
| 34 | type Seen = { method: string; path: string; headers: Headers; body: any }; | |
| 35 | ||
| 36 | function recordOvh() { | |
| 37 | const calls: Seen[] = []; | |
| 38 | let n = 0; | |
| 39 | let faults: { method: string; path: string; status: number }[] = []; | |
| 40 | const json = (o: unknown, status = 200) => new Response(JSON.stringify(o), { status }); | |
| 41 | const available = (names: string[]) => names.map((name) => ({ id: `fl-${name}`, name, available: true })); | |
| 42 | const fetch = async (url: string, init?: RequestInit): Promise<Response> => { | |
| 43 | const u = new URL(url); | |
| 44 | if (u.host !== "api.us.ovhcloud.com") throw new Error(`asked for ${u.host}`); | |
| 45 | const method = init?.method ?? "GET"; | |
| 46 | if (u.pathname === "/1.0/auth/time") return new Response(String(Math.floor(Date.now() / 1000))); | |
| 47 | const path = u.pathname + u.search; | |
| 48 | calls.push({ method, path, headers: new Headers(init?.headers), body: init?.body ? JSON.parse(String(init.body)) : undefined }); | |
| 49 | const f = faults.find((x) => x.method === method && path.startsWith(x.path)); | |
| 50 | if (f) { | |
| 51 | faults = faults.filter((x) => x !== f); | |
| 52 | return json({}, f.status); | |
| 53 | } | |
| 54 | if (u.pathname === "/1.0/auth/currentCredential") return json({ rules: [] }); | |
| 55 | if (u.pathname === "/1.0/order/catalog/public/cloud") return json({ addons: [] }); | |
| 56 | if (u.pathname === `${P}/flavor`) return json(available(["d2-2", "d2-4", "d2-8"])); | |
| 57 | if (u.pathname === `${P}/image`) return json([{ id: "img-1", name: "Ubuntu 24.04" }, { id: "img-0", name: "Debian 12" }]); | |
| 58 | if (method === "POST" && u.pathname === `${P}/volume`) return json({ id: VOLUME }); | |
| 59 | if (method === "POST" && u.pathname === `${P}/instance`) return json({ id: `inst-${++n}` }); | |
| 60 | if (method === "POST" && u.pathname.endsWith("/attach")) return json({}); | |
| 61 | if (method === "DELETE") return new Response(null, { status: 204 }); | |
| 62 | if (u.pathname === `${P}/volume/${VOLUME}`) return json({ id: VOLUME, attachedTo: [] }); | |
| 63 | if (u.pathname.startsWith(`${P}/instance/`)) return json({ status: "ACTIVE", ipAddresses: [{ type: "private", version: 4, ip: "10.0.0.5" }, { type: "public", version: 6, ip: "2001:db8::1" }, { type: "public", version: 4, ip: "203.0.113.9" }] }); | |
| 64 | return json({}, 404); | |
| 65 | }; | |
| 66 | return { fetch, calls, seen: () => calls.map((c) => `${c.method} ${c.path}`), clear: () => void (calls.length = 0), fail: (method: string, path: string, status = 500) => void faults.push({ method, path: `${P}${path}`, status }) }; | |
| 67 | } | |
| 68 | ||
| 69 | describe("ovh target", () => { | |
| 70 | let dataDir = ""; | |
| 71 | let app: App; | |
| 72 | const cloud = recordOvh(); | |
| 73 | const admin = () => getUserByName(app.db, "alice")!; | |
| 74 | const input = (over: { name?: string; version?: string; place?: string } = {}) => ({ | |
| 75 | name: "acme", host: `${over.name ?? "acme"}.forge.test`, target: "ovh", account: "main", app: "alice/shop", source: SOURCE, version: V1, place: PLACE, config: { PUBLIC_NAME: "Acme" }, ...over, | |
| 76 | }); | |
| 77 | ||
| 78 | beforeAll(async () => { | |
| 79 | dataDir = await mkdtemp(join(tmpdir(), "forge-ovh-target-")); | |
| 80 | app = createApp({ dataDir, port: 0 }); | |
| 81 | await seedPlaces(app.db); | |
| 82 | const made = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 83 | if (!made.ok) throw new Error(made.error); | |
| 84 | resetOvhClock(); | |
| 85 | cloudNet.fetch = async (url) => { | |
| 86 | const p = new URL(url).pathname; | |
| 87 | if (p.endsWith("/auth/time")) return new Response(String(Math.floor(Date.now() / 1000))); | |
| 88 | if (p.endsWith("/auth/currentCredential")) return new Response(JSON.stringify({ rules: [{ method: "POST", path: "/cloud/project/abc123/*" }, { method: "DELETE", path: "/cloud/project/abc123/*" }] })); | |
| 89 | return new Response("[]"); | |
| 90 | }; | |
| 91 | const added = await addAccount(app, admin(), "ovh", "main", CRED); | |
| 92 | if (!added.ok) throw new Error(String(added.error)); | |
| 93 | allowWrite(app, admin(), "ovh", "main", true); | |
| 94 | expect(await readPlaces(app.db, "ovh", cloud.fetch, CRED)).toBe(true); | |
| 95 | cloud.clear(); | |
| 96 | net.resolve = async () => []; | |
| 97 | net.fetch = cloud.fetch; | |
| 98 | }, 30_000); | |
| 99 | ||
| 100 | afterAll(async () => { | |
| 101 | app.close(); | |
| 102 | await rm(dataDir, { recursive: true, force: true }); | |
| 103 | }); | |
| 104 | ||
| 105 | test("both US regions are places with the three flavors, priced from the dated list", () => { | |
| 106 | const places = keptPlaces(app.db, undefined).filter((p) => p.provider === "ovh"); | |
| 107 | expect(places.map((p) => p.id).sort()).toEqual(["US-EAST-VA-1", "US-WEST-OR-1"].flatMap((r) => ["d2-2", "d2-4", "d2-8"].map((s) => `ovh:${r}:${s}`)).sort()); | |
| 108 | const small = places.find((p) => p.id === PLACE)!; | |
| 109 | expect(small).toMatchObject({ city: "Vint Hill, Virginia", country: "US", orderable: true, costCents: 756 }); | |
| 110 | expect(small.assumed.join()).toContain("2026-11-23"); | |
| 111 | }); | |
| 112 | ||
| 113 | test("deploy creates the volume, the instance, attaches, and reads the public IPv4", async () => { | |
| 114 | const r = await deployPinned(app, admin(), input()); | |
| 115 | expect(r.ok).toBe(true); | |
| 116 | expect(cloud.seen()).toEqual([ | |
| 117 | `POST ${P}/volume`, `GET ${P}/flavor?region=US-EAST-VA-1`, `GET ${P}/image?region=US-EAST-VA-1&osType=linux`, | |
| 118 | `POST ${P}/instance`, `GET ${P}/instance/inst-1`, `POST ${P}/volume/${VOLUME}/attach`, `GET ${P}/instance/inst-1`, | |
| 119 | ]); | |
| 120 | const [volume, instance, attach] = [cloud.calls[0]!, cloud.calls[3]!, cloud.calls[5]!]; | |
| 121 | expect(volume.body).toMatchObject({ region: "US-EAST-VA-1", size: 10, type: "classic" }); | |
| 122 | expect(instance.body).toMatchObject({ flavorId: "fl-d2-2", imageId: "img-1", region: "US-EAST-VA-1" }); | |
| 123 | expect(instance.body.userData).toContain("FORGE_DATA=/mnt/forge_data"); | |
| 124 | expect(instance.body.userData).toContain(`virtio-${VOLUME.slice(0, 20)}`); | |
| 125 | const ud: string = instance.body.userData; | |
| 126 | expect(ud.indexOf("mkfs.ext4")).toBeGreaterThan(0); | |
| 127 | expect(ud.indexOf("mkfs.ext4")).toBeLessThan(ud.indexOf("curl -fsSL https://bun.sh/install")); | |
| 128 | expect(instance.body.userData).toContain(`--depth 1 ${SOURCE} ${V1}`); | |
| 129 | expect(attach.body).toEqual({ instanceId: "inst-1" }); | |
| 130 | for (const c of cloud.calls) { | |
| 131 | expect(c.headers.get("x-ovh-signature")).toMatch(/^\$1\$[0-9a-f]{40}$/); | |
| 132 | expect(c.headers.get("x-ovh-consumer")).toBe("ck"); | |
| 133 | expect(JSON.stringify(c.body ?? {})).not.toContain("secret"); | |
| 134 | } | |
| 135 | expect(getPinned(app.db, "acme")).toMatchObject({ target: "ovh", state: "running", volume: VOLUME, remote: "inst-1", datacenter: "US-EAST-VA-1", size: "d2-2" }); | |
| 136 | }); | |
| 137 | ||
| 138 | test("the address is the public IPv4, not the private or the IPv6", async () => { | |
| 139 | net.probe = async () => new Response("ok", { status: 200 }); | |
| 140 | const r = await checkPinned(app, admin(), "acme"); | |
| 141 | expect(r.ok && r.value.address).toBe("203.0.113.9"); | |
| 142 | }); | |
| 143 | ||
| 144 | test("Update deletes the instance, waits for the volume, makes a new one on it", async () => { | |
| 145 | cloud.clear(); | |
| 146 | const r = await updatePinned(app, admin(), "acme", { version: V2 }); | |
| 147 | expect(r.ok).toBe(true); | |
| 148 | const seen = cloud.seen(); | |
| 149 | expect(seen).toContain(`DELETE ${P}/instance/inst-1`); | |
| 150 | expect(seen.indexOf(`GET ${P}/volume/${VOLUME}`)).toBeGreaterThan(seen.indexOf(`DELETE ${P}/instance/inst-1`)); | |
| 151 | expect(seen).not.toContain(`POST ${P}/volume`); | |
| 152 | expect(seen).not.toContain(`DELETE ${P}/volume/${VOLUME}`); | |
| 153 | expect(cloud.calls.filter((c) => c.method === "POST" && c.path === `${P}/instance`)).toHaveLength(1); | |
| 154 | expect(getPinned(app.db, "acme")).toMatchObject({ volume: VOLUME, remote: "inst-2", version: V2 }); | |
| 155 | }); | |
| 156 | ||
| 157 | test("a failed attach deletes its instance, and a retry reuses the volume and makes one instance", async () => { | |
| 158 | app.db.run("DELETE FROM pinned_forge"); | |
| 159 | cloud.clear(); | |
| 160 | cloud.fail("POST", `/volume/${VOLUME}/attach`); | |
| 161 | const bad = await deployPinned(app, admin(), input({ name: "again" })); | |
| 162 | expect(bad.ok).toBe(false); | |
| 163 | expect(cloud.seen().filter((s) => s.startsWith("DELETE "))).toEqual([`DELETE ${P}/instance/inst-3`]); | |
| 164 | expect(getPinned(app.db, "again")).toMatchObject({ state: "failed", volume: VOLUME, remote: "" }); | |
| 165 | cloud.clear(); | |
| 166 | const good = await deployPinned(app, admin(), input({ name: "again" })); | |
| 167 | expect(good.ok).toBe(true); | |
| 168 | expect(cloud.seen()).not.toContain(`POST ${P}/volume`); | |
| 169 | expect(cloud.calls.filter((c) => c.method === "POST" && c.path === `${P}/instance`)).toHaveLength(1); | |
| 170 | expect(getPinned(app.db, "again")).toMatchObject({ state: "running", volume: VOLUME }); | |
| 171 | }); | |
| 172 | ||
| 173 | test("a failed attach whose cleanup also fails names the instance that still bills", async () => { | |
| 174 | app.db.run("DELETE FROM pinned_forge"); | |
| 175 | cloud.clear(); | |
| 176 | cloud.fail("POST", `/volume/${VOLUME}/attach`); | |
| 177 | cloud.fail("DELETE", "/instance/"); | |
| 178 | const bad = await deployPinned(app, admin(), input({ name: "leaky" })); | |
| 179 | expect(bad.ok).toBe(false); | |
| 180 | expect(String((bad as any).error)).toMatch(/instance inst-\d+ failed/); | |
| 181 | expect(String((bad as any).error)).toContain("bills until then"); | |
| 182 | }); | |
| 183 | ||
| 184 | test("the spend ceiling counts the held OVHcloud volume", async () => { | |
| 185 | const { priced } = await import("../src/cloud/ceiling.ts"); | |
| 186 | expect(priced(app.db).volume("ovh")).toBe(48); | |
| 187 | }); | |
| 188 | ||
| 189 | test("a refused credential makes nothing", async () => { | |
| 190 | app.db.run("DELETE FROM pinned_forge"); | |
| 191 | cloud.clear(); | |
| 192 | cloud.fail("POST", "/volume", 403); | |
| 193 | const r = await deployPinned(app, admin(), input({ name: "denied" })); | |
| 194 | expect(r).toMatchObject({ ok: false }); | |
| 195 | expect(String((r as any).error)).toContain("api.us.ovhcloud.com answered 403"); | |
| 196 | expect(cloud.seen()).toEqual([`POST ${P}/volume`]); | |
| 197 | expect(getPinned(app.db, "denied")).toMatchObject({ volume: "", remote: "" }); | |
| 198 | }); | |
| 199 | ||
| 200 | test("a region that is not OVHcloud's is refused before any call", async () => { | |
| 201 | const { ovh } = await import("../src/cloud/ovh.ts"); | |
| 202 | expect(() => ovh.admit!({ datacenter: "GRA11" } as any)).toThrow("US-EAST-VA-1 or US-WEST-OR-1"); | |
| 203 | expect(() => ovh.signed!(cloud.fetch, "not-a-credential")).toThrow("APPLICATION_KEY"); | |
| 204 | }); | |
| 205 | }); |
new above
offline
Silent no-op if the marker is missing: throw when
.replacechanges nothing, or add a real hook in machine.ts's bootConfig.