From 58b46f47f01152bdbe98197d20a6a06064728aec Mon Sep 17 00:00:00 2001 From: clover caruso Date: Tue, 20 Oct 2026 16:08:43 -0700 Subject: [PATCH] Restrict m3-devbox to the Snow account Rename the dashboard registration while keeping the running Tart VM intact. Apply owner-only authorization to inventory, metrics, history, console, clipboard, and lifecycle access, including other infrastructure admins. Assisted-by: gpt-6-astra --- dashboard/src/apps.rs | 4 ++-- dashboard/src/core.rs | 2 +- dashboard/src/vms.rs | 19 +++++++++++-------- nixos/mac-vm.nix | 2 +- tools/mac-agent-vm.md | 5 +++-- tools/mac-vm-test.py | 2 ++ tools/mac-vms.py | 8 ++++++-- tools/vms.py | 2 +- 8 files changed, 27 insertions(+), 17 deletions(-) diff --git a/dashboard/src/apps.rs b/dashboard/src/apps.rs index 2ba9e755d8234f9dad4b0e833d763d159df6bd07..3e8bfd27e46791523e3f11617826ace89a5de309 100644 --- a/dashboard/src/apps.rs +++ b/dashboard/src/apps.rs @@ -307,7 +307,7 @@ pub async fn route( values[1] .as_array_mut() .unwrap() - .retain(|domain| vms::visible(me, &domain["owner"])); + .retain(|domain| vms::visible(me, domain)); for domain in values[1].as_array_mut().unwrap() { domain["usage"] = app .vm_usage @@ -338,7 +338,7 @@ pub async fn route( for (values, key) in [(&cpu.value, "cpu"), (&memory.value, "memory")] { for series in array(values) { if !array(&owned).iter().any(|domain| { - domain["name"] == series["name"] && vms::visible(me, &domain["owner"]) + domain["name"] == series["name"] && vms::visible(me, domain) }) { continue; } diff --git a/dashboard/src/core.rs b/dashboard/src/core.rs index 827bab13abf52929ba57fcc406dbbd697ec723a4..bbd84d30fe2f4567ad50c015dfd988965f4c030a 100644 --- a/dashboard/src/core.rs +++ b/dashboard/src/core.rs @@ -715,7 +715,7 @@ pub async fn route( .clone(); series.as_array_mut().unwrap().retain(|series| { array(&owners).iter().any(|domain| { - domain["name"] == series["name"] && vms::visible(me, &domain["owner"]) + domain["name"] == series["name"] && vms::visible(me, domain) }) }); return Ok(Document::new(series).response()); diff --git a/dashboard/src/vms.rs b/dashboard/src/vms.rs index df237b28e34decaa9107dfe6793afa6b9380acf4..9de90a335bd565ea86730a4442a0359b9af3e5e7 100644 --- a/dashboard/src/vms.rs +++ b/dashboard/src/vms.rs @@ -6,11 +6,10 @@ use axum::extract::{ use futures::{SinkExt, StreamExt}; use tokio::io::{AsyncReadExt, AsyncWriteExt}; -pub fn visible(me: &Value, owner: &Value) -> bool { - array(&me["groups"]) - .iter() - .any(|group| group == "infra-admin") - || (owner.as_str().is_some_and(|id| !id.is_empty()) && owner == &me["id"]) +pub fn visible(me: &Value, domain: &Value) -> bool { + let owner = &domain["owner"]; + (owner.as_str().is_some_and(|id| !id.is_empty()) && owner == &me["id"]) + || (domain["ownerOnly"] != true && array(&me["groups"]).iter().any(|group| group == "infra-admin")) } pub async fn authorize(me: &Value, name: &str) -> Result<()> { @@ -198,17 +197,21 @@ mod tests { #[test] fn ownership_follows_account_id_and_effective_admin_role() { let user = json!({"id":"account-1","name":"renamed","groups":["vm"]}); - assert!(visible(&user, &json!("account-1"))); - assert!(!visible(&user, &json!("account-2"))); + assert!(visible(&user, &json!({"owner":"account-1"}))); + assert!(!visible(&user, &json!({"owner":"account-2"}))); assert!(!visible(&user, &Value::Null)); assert!(!visible( &json!({"id":"snow","groups":["vm"]}), - &json!("other") + &json!({"owner":"other"}) )); assert!(visible( &json!({"id":"snow","groups":["infra-admin"]}), &Value::Null )); + let private = json!({"owner":"account-1","ownerOnly":true}); + assert!(visible(&user, &private)); + assert!(!visible(&json!({"id":"admin","groups":["infra-admin"]}), &private)); + assert!(!visible(&json!({"id":"admin","groups":["infra-admin"]}), &json!({"ownerOnly":true}))); } #[test] diff --git a/nixos/mac-vm.nix b/nixos/mac-vm.nix index 506bd21f7c79ea3202057ac3569fabe9cf3695da..144c8a0bfb67d96ba0b11524774d2b12804d093b 100644 --- a/nixos/mac-vm.nix +++ b/nixos/mac-vm.nix @@ -4,7 +4,7 @@ let in { systemd.services.snowglobe-host = { environment.SNOWGLOBE_MAC_VM = builtins.toJSON { - name = "mac-studio-gui-agent"; + name = "m3-devbox"; owner = "8c909fab-98b0-4472-9171-9606ccebe9d5"; address = workspace.clientAddress; port = 22; diff --git a/tools/mac-agent-vm.md b/tools/mac-agent-vm.md index 96fd8437faed52567e8afe68bcbfcebb0f63817c..022b4dbe743eae19b3bddb5dd10bf1a40ebe4553 100644 --- a/tools/mac-agent-vm.md +++ b/tools/mac-agent-vm.md @@ -67,8 +67,9 @@ old installation was removed. ## Dashboard access -The existing `gui-agent` is registered as `mac-studio-gui-agent` in Snow Globe's -VM dashboard. Its owner is the Snow account declared in `nixos/mac-vm.nix`. +The existing `gui-agent` is registered as `m3-devbox` in Snow Globe's +VM dashboard. Only the Snow account declared in `nixos/mac-vm.nix` can see or +operate it; other infrastructure administrators are excluded too. The dashboard retains its row when Mac Studio is unreachable; hardware in that state is the last successful observation, not live telemetry. Mac resources do not count against Snow Globe's Linux VM capacity. diff --git a/tools/mac-vm-test.py b/tools/mac-vm-test.py index ae138a4badc43aa7edd59dc09ce9b93b8b40b823..309bc951cee21a6de4bccc69d854d5db175d38ce 100644 --- a/tools/mac-vm-test.py +++ b/tools/mac-vm-test.py @@ -65,6 +65,8 @@ class MacVMTests(unittest.TestCase): offline = backend.domain()[0] self.assertEqual(offline["name"], "mac-fixture") self.assertEqual(offline["owner"], "fixture-owner") + self.assertTrue(offline["ownerOnly"]) + self.assertEqual(backend.handle("owner", {}), {"owner": "fixture-owner", "ownerOnly": True}) self.assertEqual(offline["memory"], live["memory"]) self.assertEqual(offline["state"], "unreachable") self.assertIsNone(offline["agent"]) diff --git a/tools/mac-vms.py b/tools/mac-vms.py index 6e6a753197fa75b2bae2c2553f5d5fc4f0b709d2..076b9897bbcb89f9ba41f40083441481c57f2a56 100644 --- a/tools/mac-vms.py +++ b/tools/mac-vms.py @@ -64,10 +64,14 @@ def connect(request, timeout=10): process.wait() +def ownership(): + return {"owner": CONFIG["owner"], "ownerOnly": True} + + def domain(): if not CONFIG: return [] - value = {"name": CONFIG["name"], "owner": CONFIG["owner"], "host": "Mac Studio", "arch": "aarch64", + value = {"name": CONFIG["name"], **ownership(), "host": "Mac Studio", "arch": "aarch64", "description": "macOS development", "state": "unreachable", "reason": None, "os": "macOS", "vcpus": None, "memory": None, "balloon": None, "pinned": None, "autostart": False, "startedAt": None, "agent": None, "setup": None, "pendingAction": None, @@ -104,7 +108,7 @@ def domain(): def handle(action, payload): if action == "owner": - return CONFIG["owner"] + return ownership() if action == "access": return None if action == "console": diff --git a/tools/vms.py b/tools/vms.py index f93369ee1f06ec23f237a24f181fd0027c458c23..a152654cb8c972d32f2e32cb843bb29b8102b5fc 100644 --- a/tools/vms.py +++ b/tools/vms.py @@ -985,7 +985,7 @@ def main(): raise ValueError("This VM has no serial console. Add one in its hardware settings.") return {"path": path} if action == "owner": - return transition.normalize_vm(ET.fromstring(virsh("dumpxml", payload["name"]))).findtext(f"metadata/{NS}vm/{NS}owner") + return {"owner": transition.normalize_vm(ET.fromstring(virsh("dumpxml", payload["name"]))).findtext(f"metadata/{NS}vm/{NS}owner")} if action == "access": try: with os.fdopen(open_regular(DISKS / payload["name"] / "access.json")) as incoming: -- 2.54.1