Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
controlplane, console: a user's status lists admitted nodes; one status call per refresh
Antonio Ojea6dffdf0fdcb2
diff --git a/internal/console/public/app.js b/internal/console/public/app.jsindex a2b47257..b1bd4178 100644--- a/internal/console/public/app.js+++ b/internal/console/public/app.js@@ -4,6 +4,10 @@ const TOAST_TIMEOUT_MS = 5000;let refreshTimer = null;let refreshInFlight = false;+// The session's role and user ID, learned from the first /user/status of a+// session. An admin's later refreshes read /admin/status alone: /user/status+// would list the same mesh a second time only to be overwritten.+let session = null;// Last policy the server confirmed, so an edit is never silently overwritten by// a background refresh or thrown away by a stray click.let policyBaseline = '';@@ -147,6 +151,7 @@ function showApp() {function showLandingPage() {stopAutoRefresh();resetExpiredNodes();+ session = null;document.getElementById('landing-page').classList.add('active');document.getElementById('app-container').style.display = 'none';}@@ -195,8 +200,10 @@ window.saveAdminToken = function() {async function loadData() {try {- // 1. Fetch user-scoped status- const response = await fetch('api/user/status');+ // One status call per refresh: the user's own until the role is known,+ // then the one that matches the role.+ const endpoint = session !== null && session.role === 'admin' ? 'api/admin/status' : 'api/user/status';+ const response = await fetch(endpoint);if (response.status === 401 || response.status === 403) {showLandingPage();throw new Error('Unauthorized. Please login again.');@@ -205,15 +212,19 @@ async function loadData() {throw new Error(`HTTP error! status: ${response.status}`);}let data = await response.json();-- const role = data.user ? data.user.role : 'user';- const userId = data.user ? data.user.id : '';++ if (data.user) {+ session = { role: data.user.role || 'user', id: data.user.id || '' };+ }+ const role = session !== null ? session.role : 'user';+ const userId = session !== null ? session.id : '';// Update UI components depending on RoleupdateUIForRole(role, userId);- // 2. If user is admin, fetch full unfiltered admin status- if (role === 'admin') {+ // The first call of an admin's session answered with the user's view;+ // the mesh-wide one is what the admin console renders.+ if (role === 'admin' && endpoint !== 'api/admin/status') {const adminResp = await fetch('api/admin/status');if (adminResp.ok) {data = await adminResp.json();diff --git a/internal/controlplane/server.go b/internal/controlplane/server.goindex 0e1df95b..e04a2895 100644--- a/internal/controlplane/server.go+++ b/internal/controlplane/server.go@@ -3105,8 +3105,12 @@ func (s *Server) HandleUserStatus(w http.ResponseWriter, r *http.Request) {ctx := r.Context()isAdmin := user.Role == "admin"+ // A banned node is out of the mesh and only an administrator can restore+ // it, so only the administrators' list carries banned rows: a user's+ // list would otherwise keep every node they ever revoked, forever.filter := storage.NodeFilter{States: statusNodeStates, Now: time.Now()}if !isAdmin {+ filter.States = []storage.NodeState{storage.NodeAdmitted}filter.OwnerID = &user.ID}allNodes, err := s.store.ListNodes(ctx, filter)diff --git a/internal/controlplane/server_test.go b/internal/controlplane/server_test.goindex 22d18c1b..d6461645 100644--- a/internal/controlplane/server_test.go+++ b/internal/controlplane/server_test.go@@ -2620,6 +2620,24 @@ func TestUserStatusAndTenancy(t *testing.T) {if !nodeAUpdated.Banned {t.Error("expected node A to be banned/revoked in DB")}++ // A revoked node is out of the user's list from then on: banned rows are+ // never garbage-collected, and only an administrator can restore one.+ req, _ = http.NewRequest("GET", baseURL+"/user/status", nil)+ req.Header.Set("Authorization", "Bearer "+tokenA)+ resp, err = client.Do(req)+ if err != nil {+ t.Fatalf("GET /user/status after revoke failed: %v", err)+ }+ statusBody, _ = io.ReadAll(resp.Body)+ _ = resp.Body.Close()+ data = &api.UserStatusResponse{}+ if err := protojson.Unmarshal(statusBody, data); err != nil {+ t.Fatalf("decode /user/status after revoke: %v", err)+ }+ if nodes := data.GetEnrolledNodes(); len(nodes) != 0 {+ t.Errorf("after revoking its only node the user's status lists %d node(s), want none: %v", len(nodes), nodes)+ }}func TestResolveRolesAndRoleImpersonationProtection(t *testing.T) {