| author | |
| committer | |
| log | 58b46f47f01152bdbe98197d20a6a06064728aec |
| tree | 5317e2560b132439a5654668725de1ec6c51bd9b |
| parent | 9083401435daed119d178d7b48c0e452d41da6c1 |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
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-astra8 files changed, 27 insertions(+), 17 deletions(-)
dashboard/src/apps.rs+2-2| ... | @@ -307,7 +307,7 @@ pub async fn route( | ... | @@ -307,7 +307,7 @@ pub async fn route( |
| 307 | values[1] | 307 | values[1] |
| 308 | .as_array_mut() | 308 | .as_array_mut() |
| 309 | .unwrap() | 309 | .unwrap() |
| 310 | .retain(|domain| vms::visible(me, &domain["owner"])); | 310 | .retain(|domain| vms::visible(me, domain)); |
| 311 | for domain in values[1].as_array_mut().unwrap() { | 311 | for domain in values[1].as_array_mut().unwrap() { |
| 312 | domain["usage"] = app | 312 | domain["usage"] = app |
| 313 | .vm_usage | 313 | .vm_usage |
| ... | @@ -338,7 +338,7 @@ pub async fn route( | ... | @@ -338,7 +338,7 @@ pub async fn route( |
| 338 | for (values, key) in [(&cpu.value, "cpu"), (&memory.value, "memory")] { | 338 | for (values, key) in [(&cpu.value, "cpu"), (&memory.value, "memory")] { |
| 339 | for series in array(values) { | 339 | for series in array(values) { |
| 340 | if !array(&owned).iter().any(|domain| { | 340 | if !array(&owned).iter().any(|domain| { |
| 341 | domain["name"] == series["name"] && vms::visible(me, &domain["owner"]) | 341 | domain["name"] == series["name"] && vms::visible(me, domain) |
| 342 | }) { | 342 | }) { |
| 343 | continue; | 343 | continue; |
| 344 | } | 344 | } |
dashboard/src/core.rs+1-1| ... | @@ -715,7 +715,7 @@ pub async fn route( | ... | @@ -715,7 +715,7 @@ pub async fn route( |
| 715 | .clone(); | 715 | .clone(); |
| 716 | series.as_array_mut().unwrap().retain(|series| { | 716 | series.as_array_mut().unwrap().retain(|series| { |
| 717 | array(&owners).iter().any(|domain| { | 717 | array(&owners).iter().any(|domain| { |
| 718 | domain["name"] == series["name"] && vms::visible(me, &domain["owner"]) | 718 | domain["name"] == series["name"] && vms::visible(me, domain) |
| 719 | }) | 719 | }) |
| 720 | }); | 720 | }); |
| 721 | return Ok(Document::new(series).response()); | 721 | return Ok(Document::new(series).response()); |
dashboard/src/vms.rs+11-8| ... | @@ -6,11 +6,10 @@ use axum::extract::{ | ... | @@ -6,11 +6,10 @@ use axum::extract::{ |
| 6 | use futures::{SinkExt, StreamExt}; | 6 | use futures::{SinkExt, StreamExt}; |
| 7 | use tokio::io::{AsyncReadExt, AsyncWriteExt}; | 7 | use tokio::io::{AsyncReadExt, AsyncWriteExt}; |
| 8 | 8 | ||
| 9 | pub fn visible(me: &Value, owner: &Value) -> bool { | 9 | pub fn visible(me: &Value, domain: &Value) -> bool { |
| 10 | array(&me["groups"]) | 10 | let owner = &domain["owner"]; |
| 11 | .iter() | 11 | (owner.as_str().is_some_and(|id| !id.is_empty()) && owner == &me["id"]) |
| 12 | .any(|group| group == "infra-admin") | 12 | || (domain["ownerOnly"] != true && array(&me["groups"]).iter().any(|group| group == "infra-admin")) |
| 13 | || (owner.as_str().is_some_and(|id| !id.is_empty()) && owner == &me["id"]) | ||
| 14 | } | 13 | } |
| 15 | 14 | ||
| 16 | pub async fn authorize(me: &Value, name: &str) -> Result<()> { | 15 | pub async fn authorize(me: &Value, name: &str) -> Result<()> { |
| ... | @@ -198,17 +197,21 @@ mod tests { | ... | @@ -198,17 +197,21 @@ mod tests { |
| 198 | #[test] | 197 | #[test] |
| 199 | fn ownership_follows_account_id_and_effective_admin_role() { | 198 | fn ownership_follows_account_id_and_effective_admin_role() { |
| 200 | let user = json!({"id":"account-1","name":"renamed","groups":["vm"]}); | 199 | let user = json!({"id":"account-1","name":"renamed","groups":["vm"]}); |
| 201 | assert!(visible(&user, &json!("account-1"))); | 200 | assert!(visible(&user, &json!({"owner":"account-1"}))); |
| 202 | assert!(!visible(&user, &json!("account-2"))); | 201 | assert!(!visible(&user, &json!({"owner":"account-2"}))); |
| 203 | assert!(!visible(&user, &Value::Null)); | 202 | assert!(!visible(&user, &Value::Null)); |
| 204 | assert!(!visible( | 203 | assert!(!visible( |
| 205 | &json!({"id":"snow","groups":["vm"]}), | 204 | &json!({"id":"snow","groups":["vm"]}), |
| 206 | &json!("other") | 205 | &json!({"owner":"other"}) |
| 207 | )); | 206 | )); |
| 208 | assert!(visible( | 207 | assert!(visible( |
| 209 | &json!({"id":"snow","groups":["infra-admin"]}), | 208 | &json!({"id":"snow","groups":["infra-admin"]}), |
| 210 | &Value::Null | 209 | &Value::Null |
| 211 | )); | 210 | )); |
| 211 | let private = json!({"owner":"account-1","ownerOnly":true}); | ||
| 212 | assert!(visible(&user, &private)); | ||
| 213 | assert!(!visible(&json!({"id":"admin","groups":["infra-admin"]}), &private)); | ||
| 214 | assert!(!visible(&json!({"id":"admin","groups":["infra-admin"]}), &json!({"ownerOnly":true}))); | ||
| 212 | } | 215 | } |
| 213 | 216 | ||
| 214 | #[test] | 217 | #[test] |
nixos/mac-vm.nix+1-1| ... | @@ -4,7 +4,7 @@ let | ... | @@ -4,7 +4,7 @@ let |
| 4 | in { | 4 | in { |
| 5 | systemd.services.snowglobe-host = { | 5 | systemd.services.snowglobe-host = { |
| 6 | environment.SNOWGLOBE_MAC_VM = builtins.toJSON { | 6 | environment.SNOWGLOBE_MAC_VM = builtins.toJSON { |
| 7 | name = "mac-studio-gui-agent"; | 7 | name = "m3-devbox"; |
| 8 | owner = "8c909fab-98b0-4472-9171-9606ccebe9d5"; | 8 | owner = "8c909fab-98b0-4472-9171-9606ccebe9d5"; |
| 9 | address = workspace.clientAddress; | 9 | address = workspace.clientAddress; |
| 10 | port = 22; | 10 | port = 22; |
tools/mac-agent-vm.md+3-2| ... | @@ -67,8 +67,9 @@ old installation was removed. | ... | @@ -67,8 +67,9 @@ old installation was removed. |
| 67 | 67 | ||
| 68 | ## Dashboard access | 68 | ## Dashboard access |
| 69 | 69 | ||
| 70 | The existing `gui-agent` is registered as `mac-studio-gui-agent` in Snow Globe's | 70 | The existing `gui-agent` is registered as `m3-devbox` in Snow Globe's |
| 71 | VM dashboard. Its owner is the Snow account declared in `nixos/mac-vm.nix`. | 71 | VM dashboard. Only the Snow account declared in `nixos/mac-vm.nix` can see or |
| 72 | operate it; other infrastructure administrators are excluded too. | ||
| 72 | The dashboard retains its row when Mac Studio is unreachable; hardware in that | 73 | The dashboard retains its row when Mac Studio is unreachable; hardware in that |
| 73 | state is the last successful observation, not live telemetry. Mac resources do | 74 | state is the last successful observation, not live telemetry. Mac resources do |
| 74 | not count against Snow Globe's Linux VM capacity. | 75 | not count against Snow Globe's Linux VM capacity. |
tools/mac-vm-test.py+2| ... | @@ -65,6 +65,8 @@ class MacVMTests(unittest.TestCase): | ... | @@ -65,6 +65,8 @@ class MacVMTests(unittest.TestCase): |
| 65 | offline = backend.domain()[0] | 65 | offline = backend.domain()[0] |
| 66 | self.assertEqual(offline["name"], "mac-fixture") | 66 | self.assertEqual(offline["name"], "mac-fixture") |
| 67 | self.assertEqual(offline["owner"], "fixture-owner") | 67 | self.assertEqual(offline["owner"], "fixture-owner") |
| 68 | self.assertTrue(offline["ownerOnly"]) | ||
| 69 | self.assertEqual(backend.handle("owner", {}), {"owner": "fixture-owner", "ownerOnly": True}) | ||
| 68 | self.assertEqual(offline["memory"], live["memory"]) | 70 | self.assertEqual(offline["memory"], live["memory"]) |
| 69 | self.assertEqual(offline["state"], "unreachable") | 71 | self.assertEqual(offline["state"], "unreachable") |
| 70 | self.assertIsNone(offline["agent"]) | 72 | self.assertIsNone(offline["agent"]) |
tools/mac-vms.py+6-2| ... | @@ -64,10 +64,14 @@ def connect(request, timeout=10): | ... | @@ -64,10 +64,14 @@ def connect(request, timeout=10): |
| 64 | process.wait() | 64 | process.wait() |
| 65 | 65 | ||
| 66 | 66 | ||
| 67 | def ownership(): | ||
| 68 | return {"owner": CONFIG["owner"], "ownerOnly": True} | ||
| 69 | |||
| 70 | |||
| 67 | def domain(): | 71 | def domain(): |
| 68 | if not CONFIG: | 72 | if not CONFIG: |
| 69 | return [] | 73 | return [] |
| 70 | value = {"name": CONFIG["name"], "owner": CONFIG["owner"], "host": "Mac Studio", "arch": "aarch64", | 74 | value = {"name": CONFIG["name"], **ownership(), "host": "Mac Studio", "arch": "aarch64", |
| 71 | "description": "macOS development", "state": "unreachable", "reason": None, | 75 | "description": "macOS development", "state": "unreachable", "reason": None, |
| 72 | "os": "macOS", "vcpus": None, "memory": None, "balloon": None, "pinned": None, | 76 | "os": "macOS", "vcpus": None, "memory": None, "balloon": None, "pinned": None, |
| 73 | "autostart": False, "startedAt": None, "agent": None, "setup": None, "pendingAction": None, | 77 | "autostart": False, "startedAt": None, "agent": None, "setup": None, "pendingAction": None, |
| ... | @@ -104,7 +108,7 @@ def domain(): | ... | @@ -104,7 +108,7 @@ def domain(): |
| 104 | 108 | ||
| 105 | def handle(action, payload): | 109 | def handle(action, payload): |
| 106 | if action == "owner": | 110 | if action == "owner": |
| 107 | return CONFIG["owner"] | 111 | return ownership() |
| 108 | if action == "access": | 112 | if action == "access": |
| 109 | return None | 113 | return None |
| 110 | if action == "console": | 114 | if action == "console": |
tools/vms.py+1-1| ... | @@ -985,7 +985,7 @@ def main(): | ... | @@ -985,7 +985,7 @@ def main(): |
| 985 | raise ValueError("This VM has no serial console. Add one in its hardware settings.") | 985 | raise ValueError("This VM has no serial console. Add one in its hardware settings.") |
| 986 | return {"path": path} | 986 | return {"path": path} |
| 987 | if action == "owner": | 987 | if action == "owner": |
| 988 | return transition.normalize_vm(ET.fromstring(virsh("dumpxml", payload["name"]))).findtext(f"metadata/{NS}vm/{NS}owner") | 988 | return {"owner": transition.normalize_vm(ET.fromstring(virsh("dumpxml", payload["name"]))).findtext(f"metadata/{NS}vm/{NS}owner")} |
| 989 | if action == "access": | 989 | if action == "access": |
| 990 | try: | 990 | try: |
| 991 | with os.fdopen(open_regular(DISKS / payload["name"] / "access.json")) as incoming: | 991 | with os.fdopen(open_regular(DISKS / payload["name"] / "access.json")) as incoming: |