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