Skip to content
This repository was archived by the owner on Oct 19, 2026. It is now read-only.

Commit c26d409

Browse files
authored
feat(orion): catalog VM images in RustFS/mono and pick by image_id (#2185)
* feat(orion): catalog VM images in RustFS/mono and pick by image_id Upload built qcow2 blobs to object storage, register metadata for list/delete, resolve image_id to a signed URL on start-runner, and stop needrestart from SIGTERM-killing overnight VMs. * feat(orion): add Image Management tabs and browser qcow2 upload Split catalog UI under Orion Client, add presigned PUT + register flow, and set RustFS CORS for local moon origins. * feat(orion): fan-out image publish and public presign endpoint Allow build-custom-image to upload/register across envs, avoid Start Runner hangs behind the update lock, and sign Orion image URLs with an optional public RustFS host so out-of-cluster schedulers can download. * fix eslint
1 parent c1429d1 commit c26d409

67 files changed

Lines changed: 4249 additions & 578 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Cargo.lock‎

Lines changed: 175 additions & 90 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ orion = { path = "orion" }
3838
orion-client = { path = "clients/orion-client" }
3939
orion-scheduler-client = { path = "clients/orion-scheduler-client" }
4040

41-
git-internal = "0.8.7"
41+
git-internal = "0.9.0"
4242
libvault = "0.3.0"
4343

4444
#====
@@ -63,7 +63,7 @@ futures = "0.3.34"
6363
futures-util = "0.3.34"
6464
axum = { version = "0.8.9", features = ["macros", "json"] }
6565
axum-extra = "0.12.6"
66-
russh = "0.63.2"
66+
russh = "0.63.3"
6767
tower-http = "0.7.1"
6868
tower = "0.5.3"
6969
tower-sessions = { version = "0.15", features = ["memory-store"] }
@@ -93,7 +93,7 @@ hmac = "0.13"
9393

9494
idgenerator = "2.0.0"
9595
config = "0.15.25"
96-
reqwest = "0.13.4"
96+
reqwest = "0.13.5"
9797
uuid = "1.24.1"
9898
regex = "1.13.1"
9999
ctrlc = "3.5.2"

‎ceres/src/application/api_service/mono/admin/bot.rs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,24 @@ impl AdminApplicationService {
122122
})
123123
}
124124

125+
/// Ensure orion-image-publisher bot + fresh catalog-register token
126+
/// (for secret-gated bootstrap-orion-image).
127+
pub async fn ensure_orion_image_publisher_bot_token(
128+
&self,
129+
) -> Result<crate::model::bots::BootstrapInitBotResponse, MegaError> {
130+
let (bot, token_plain) = self
131+
.ctx
132+
.storage()
133+
.bots_storage()
134+
.ensure_orion_image_publisher_bot_token()
135+
.await?;
136+
Ok(crate::model::bots::BootstrapInitBotResponse {
137+
bot_id: bot.id,
138+
bot_name: bot.name,
139+
token: token_plain,
140+
})
141+
}
142+
125143
pub async fn list_bot_tokens(&self, bot_id: i64) -> Result<Vec<ListBotTokenItem>, MegaError> {
126144
Ok(self
127145
.ctx

‎ceres/src/application/api_service/mono/admin/permissions.rs‎

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,17 @@ const ADMIN_CACHE_KEY_SUFFIX: &str = "admin:list";
2929

3030
impl AdminApplicationService {
3131
/// Check if a user is an admin (config `monorepo.admin` or Cedar).
32+
///
33+
/// Config admins are resolved without loading Cedar, so they remain valid
34+
/// when `.mega_cedar.json` is missing or its blob cannot be fetched.
3235
pub async fn check_is_admin(&self, username: &str) -> Result<bool, MegaError> {
3336
let username = username.trim();
3437
if username.is_empty() {
3538
return Ok(false);
3639
}
40+
if self.config_admins().iter().any(|a| a == username) {
41+
return Ok(true);
42+
}
3743
let admins = self.get_effective_admins().await?;
3844
Ok(admins.iter().any(|a| a == username))
3945
}
@@ -69,7 +75,7 @@ impl AdminApplicationService {
6975
///
7076
/// Config admins are always merged after cache/file load so a stale Redis
7177
/// Cedar list cannot drop configured admins. If `.mega_cedar.json` is
72-
/// missing, config admins alone still apply.
78+
/// missing or cannot be fetched/parsed, config admins alone still apply.
7379
async fn get_effective_admins(&self) -> Result<Vec<String>, MegaError> {
7480
let cedar_admins = self.get_cedar_admins().await?;
7581
Ok(self.merge_with_config_admins(cedar_admins))
@@ -199,8 +205,57 @@ impl AdminApplicationService {
199205
}
200206

201207
fn is_admin_config_unavailable(err: &MegaError) -> bool {
202-
let msg = err.to_string();
203-
msg.contains(".mega_cedar.json not found")
204-
|| msg.contains("Root ref not found")
205-
|| msg.contains("Root tree not found")
208+
match err {
209+
MegaError::ObjStorageNotFound(_)
210+
| MegaError::ObjStorageInconsistent(_)
211+
| MegaError::ObjStorage(_)
212+
| MegaError::SerdeJson(_) => true,
213+
MegaError::Other(msg) => {
214+
msg.contains(".mega_cedar.json not found")
215+
|| msg.contains("Root ref not found")
216+
|| msg.contains("Root tree not found")
217+
|| msg.contains("UTF-8 decode failed")
218+
|| msg.contains("JSON parse failed")
219+
}
220+
_ => false,
221+
}
222+
}
223+
224+
#[cfg(test)]
225+
mod tests {
226+
use super::*;
227+
228+
#[test]
229+
fn obj_storage_inconsistent_is_unavailable() {
230+
let err = MegaError::ObjStorageInconsistent(
231+
"[obj_missing_in_s3_but_has_meta] Object missing".into(),
232+
);
233+
assert!(is_admin_config_unavailable(&err));
234+
}
235+
236+
#[test]
237+
fn obj_storage_not_found_is_unavailable() {
238+
let err = MegaError::ObjStorageNotFound("blob missing".into());
239+
assert!(is_admin_config_unavailable(&err));
240+
}
241+
242+
#[test]
243+
fn missing_cedar_file_is_unavailable() {
244+
let err = MegaError::Other(".mega_cedar.json not found in root directory".into());
245+
assert!(is_admin_config_unavailable(&err));
246+
}
247+
248+
#[test]
249+
fn utf8_and_json_parse_failures_are_unavailable() {
250+
let utf8 = MegaError::Other("UTF-8 decode failed: invalid utf-8".into());
251+
let json = MegaError::Other("JSON parse failed: expected value".into());
252+
assert!(is_admin_config_unavailable(&utf8));
253+
assert!(is_admin_config_unavailable(&json));
254+
}
255+
256+
#[test]
257+
fn unrelated_bad_request_is_not_unavailable() {
258+
let err = MegaError::BadRequest("admins must not be empty".into());
259+
assert!(!is_admin_config_unavailable(&err));
260+
}
206261
}

‎ceres/src/model/bots.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,15 @@ impl From<InstallationTargetType> for InstallationTargetTypeEnum {
126126
#[derive(Debug, Clone)]
127127
pub struct BotIdentity {
128128
pub bot_id: i64,
129+
pub bot_name: String,
129130
pub token_id: i64,
130131
}
131132

132133
impl BotIdentity {
133134
pub fn from_models(bot: callisto::bots::Model, token: callisto::bot_tokens::Model) -> Self {
134135
Self {
135136
bot_id: bot.id,
137+
bot_name: bot.name,
136138
token_id: token.id,
137139
}
138140
}
@@ -160,10 +162,11 @@ pub struct CreateBotTokenResponse {
160162
pub token_plain: String,
161163
}
162164

163-
/// Response for mega-init bot bootstrap (`POST /bots/bootstrap-init`).
165+
/// Response for secret-gated bot bootstrap (`POST /bots/bootstrap-init` or
166+
/// `POST /bots/bootstrap-orion-image`).
164167
///
165168
/// Requires header `X-Mega-Init-Secret` matching `MEGA_INIT_BOOTSTRAP_SECRET`.
166-
/// `token` is a `bot_` push token returned once; use as Bearer (or Basic password).
169+
/// `token` is a `bot_` token returned once; use as Bearer (or Basic password).
167170
#[derive(Serialize, ToSchema)]
168171
pub struct BootstrapInitBotResponse {
169172
#[serde(serialize_with = "serialize_i64_as_string")]

‎ceres/src/model/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub mod label;
1515
pub mod merge_queue;
1616
pub mod note;
1717
pub mod notification;
18+
pub mod orion_image;
1819
pub mod orion_runner;
1920
pub mod serde_snowflake;
2021
pub mod tag;

‎ceres/src/model/orion_image.rs‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
use serde::{Deserialize, Serialize};
2+
use utoipa::ToSchema;
3+
4+
#[derive(Serialize, Deserialize, ToSchema, Debug, Clone)]
5+
pub struct OrionVmImageResponse {
6+
pub id: String,
7+
pub digest: String,
8+
pub object_key: String,
9+
#[serde(default, skip_serializing_if = "Option::is_none")]
10+
pub info_object_key: Option<String>,
11+
#[serde(default, skip_serializing_if = "Option::is_none")]
12+
pub image_name: Option<String>,
13+
#[serde(default, skip_serializing_if = "Option::is_none")]
14+
pub built_at: Option<String>,
15+
#[serde(default, skip_serializing_if = "Option::is_none")]
16+
pub rust: Option<String>,
17+
#[serde(default, skip_serializing_if = "Option::is_none")]
18+
pub buck2: Option<String>,
19+
#[serde(default, skip_serializing_if = "Option::is_none")]
20+
pub python: Option<String>,
21+
#[serde(default, skip_serializing_if = "Option::is_none")]
22+
pub kernel: Option<String>,
23+
#[serde(default, skip_serializing_if = "Option::is_none")]
24+
pub size_bytes: Option<i64>,
25+
#[serde(default, skip_serializing_if = "Option::is_none")]
26+
pub label: Option<String>,
27+
pub created_at: String,
28+
}
29+
30+
#[derive(Serialize, Deserialize, ToSchema, Debug, Clone)]
31+
pub struct OrionVmImageListResponse {
32+
pub count: usize,
33+
pub images: Vec<OrionVmImageResponse>,
34+
}
35+
36+
#[derive(Serialize, Deserialize, ToSchema, Debug, Clone)]
37+
pub struct RegisterOrionVmImageRequest {
38+
/// Content digest, e.g. `sha256:<hex>`.
39+
pub digest: String,
40+
/// Key under the `orion-images/` namespace, e.g. `{hex}/debian-13-buck2.qcow2`.
41+
pub object_key: String,
42+
#[serde(default, skip_serializing_if = "Option::is_none")]
43+
pub info_object_key: Option<String>,
44+
#[serde(default, skip_serializing_if = "Option::is_none")]
45+
pub image_name: Option<String>,
46+
#[serde(default, skip_serializing_if = "Option::is_none")]
47+
pub built_at: Option<String>,
48+
#[serde(default, skip_serializing_if = "Option::is_none")]
49+
pub rust: Option<String>,
50+
#[serde(default, skip_serializing_if = "Option::is_none")]
51+
pub buck2: Option<String>,
52+
#[serde(default, skip_serializing_if = "Option::is_none")]
53+
pub python: Option<String>,
54+
#[serde(default, skip_serializing_if = "Option::is_none")]
55+
pub kernel: Option<String>,
56+
#[serde(default, skip_serializing_if = "Option::is_none")]
57+
pub size_bytes: Option<i64>,
58+
#[serde(default, skip_serializing_if = "Option::is_none")]
59+
pub label: Option<String>,
60+
}
61+
62+
#[derive(Serialize, Deserialize, ToSchema, Debug, Clone)]
63+
pub struct PresignOrionVmImageRequest {
64+
/// Content digest, e.g. `sha256:<hex>`.
65+
pub digest: String,
66+
/// Base name used in the object key (default `debian-13-buck2`).
67+
#[serde(default, skip_serializing_if = "Option::is_none")]
68+
pub image_name: Option<String>,
69+
/// When true, also return a PUT URL for `{hex}/image-info.json`.
70+
#[serde(default)]
71+
pub with_info: bool,
72+
}
73+
74+
#[derive(Serialize, Deserialize, ToSchema, Debug, Clone)]
75+
pub struct PresignOrionVmImageResponse {
76+
pub object_key: String,
77+
#[serde(default, skip_serializing_if = "Option::is_none")]
78+
pub info_object_key: Option<String>,
79+
pub qcow2_put_url: String,
80+
#[serde(default, skip_serializing_if = "Option::is_none")]
81+
pub info_put_url: Option<String>,
82+
pub expires_in_secs: u64,
83+
}

‎ceres/src/model/orion_runner.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ pub struct StartRunnerRequest {
1414
pub image_url: Option<String>,
1515
#[serde(default, skip_serializing_if = "Option::is_none")]
1616
pub image_digest: Option<String>,
17+
/// Catalog image id from `GET /api/v1/orion/images`. Mutually exclusive with
18+
/// `image_path` / `image_url`.
19+
#[serde(default, skip_serializing_if = "Option::is_none")]
20+
pub image_id: Option<String>,
1721
#[serde(default, skip_serializing_if = "Option::is_none")]
1822
pub image_disk_gb: Option<u32>,
1923
#[serde(default, skip_serializing_if = "Option::is_none")]

‎clients/orion-scheduler-client/src/http_client.rs‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,24 @@ impl OrionSchedulerHttpClient {
5959
"Starting runner via scheduler: server_ws={}",
6060
payload.server_ws
6161
);
62+
// Conflict checks must not block behind a multi-minute image download;
63+
// scheduler returns 503 quickly when the update lock is busy. Keep a
64+
// modest client budget for network + signing + lock try.
6265
let req = self
6366
.client
6467
.post(&url)
65-
.timeout(Duration::from_secs(10))
68+
.timeout(Duration::from_secs(30))
6669
.json(&payload);
6770
let res = self.auth_headers(req).send().await?;
6871
let status = res.status();
6972
let body: StartRunnerSchedulerResponse = res.json().await?;
70-
// 200 OK (idempotent), 202 Accepted (provisioning), 409 Conflict
71-
if status.is_success() || status.as_u16() == 202 || status.as_u16() == 409 {
73+
// 200 OK (idempotent), 202 Accepted (provisioning), 409 Conflict,
74+
// 503 Busy (another provision holds the update lock).
75+
if status.is_success()
76+
|| status.as_u16() == 202
77+
|| status.as_u16() == 409
78+
|| status.as_u16() == 503
79+
{
7280
Ok(body)
7381
} else {
7482
Err(anyhow::anyhow!(

‎clients/orion-scheduler-client/src/lib.rs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ pub struct StartRunnerPayload {
2828
pub image_cpus: Option<u32>,
2929
#[serde(skip_serializing_if = "Option::is_none")]
3030
pub image_memory_mb: Option<u32>,
31+
/// Catalog metadata (from mono when starting via `image_id`).
32+
#[serde(skip_serializing_if = "Option::is_none")]
33+
pub image_name: Option<String>,
34+
#[serde(skip_serializing_if = "Option::is_none")]
35+
pub image_built_at: Option<String>,
36+
#[serde(skip_serializing_if = "Option::is_none")]
37+
pub toolchain_rust: Option<String>,
38+
#[serde(skip_serializing_if = "Option::is_none")]
39+
pub toolchain_buck2: Option<String>,
40+
#[serde(skip_serializing_if = "Option::is_none")]
41+
pub toolchain_python: Option<String>,
42+
#[serde(skip_serializing_if = "Option::is_none")]
43+
pub kernel: Option<String>,
3144
/// When set, write `ORION_RETAIN_ANTARES_MOUNTS` into the guest `.env`.
3245
#[serde(skip_serializing_if = "Option::is_none")]
3346
pub retain_antares_mounts: Option<bool>,

0 commit comments

Comments
 (0)