Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
mobile: re-enroll from the Config tab to change labels
Tomas Tormofe3e74f6185b
diff --git a/mobile/sam-node-app/lib/main.dart b/mobile/sam-node-app/lib/main.dartindex 0bd1edda..47e8cb8a 100644--- a/mobile/sam-node-app/lib/main.dart+++ b/mobile/sam-node-app/lib/main.dart@@ -644,6 +644,14 @@ class _NodeControlPageState extends State<NodeControlPage> {});}+ // The Config tab has no status card, so surface the outcome inline.+ Future<void> _reEnroll() async {+ await _loginAndEnroll();+ if (!mounted) return;+ ScaffoldMessenger.of(context)+ .showSnackBar(SnackBar(content: Text(_status)));+ }+void _startPolling() {_pollingTimer?.cancel();_pollingTimer = Timer.periodic(const Duration(seconds: 3), (timer) {@@ -1024,8 +1032,8 @@ class _NodeControlPageState extends State<NodeControlPage> {TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),const SizedBox(height: 6),const Text(- 'Attested by the control plane at enrollment. Unenroll '- 'from the Dashboard to change.',+ 'Attested by the control plane. Changing them means '+ 'logging in again; the node keeps its identity.',style: TextStyle(fontSize: 12, color: Colors.grey),),const SizedBox(height: 10),@@ -1034,8 +1042,21 @@ class _NodeControlPageState extends State<NodeControlPage> {label: 'Labels (key=value, comma-separated)',hint: 'region=eu-west-1',maxLines: 1,- enabled: !_loggingIn && _isEnrolled != true,+ enabled: !_loggingIn && !isRunning,),+ if (_isEnrolled == true) ...[+ const SizedBox(height: 10),+ ElevatedButton.icon(+ onPressed: _loggingIn || isRunning ? null : _reEnroll,+ icon: _loggingIn+ ? const SizedBox(+ height: 20,+ width: 20,+ child: CircularProgressIndicator(strokeWidth: 2))+ : const Icon(Icons.login),+ label: const Text('Re-enroll to apply'),+ ),+ ],],),),diff --git a/mobile/sam-node-ffi/ffi/ffi.go b/mobile/sam-node-ffi/ffi/ffi.goindex 3ba694d5..4a524ac1 100644--- a/mobile/sam-node-ffi/ffi/ffi.go+++ b/mobile/sam-node-ffi/ffi/ffi.go@@ -351,7 +351,8 @@ func loadEnrolledLabels(dataDir string) (map[string]string, error) {}// EnrollNode enrolls a node. Labels are comma-separated key=value claims,-// minted into the node's Biscuit here — changing them requires re-enrolling.+// minted into the node's Biscuit here; changing them means enrolling again,+// which reuses the stored key so the PeerID survives.func EnrollNode(dataDir string, controlPlaneURL string, jwt string, allowLoopback bool, labels string) error {parsedLabels, err := api.ParseLabels(labels)if err != nil {@@ -359,9 +360,6 @@ func EnrollNode(dataDir string, controlPlaneURL string, jwt string, allowLoopbac}_ = os.MkdirAll(dataDir, 0700)- if err := os.WriteFile(filepath.Join(dataDir, labelsFile), []byte(labels), 0600); err != nil {- return fmt.Errorf("failed to save labels: %w", err)- }logFilePath := filepath.Join(dataDir, "node.log")golog.SetupLogging(golog.Config{File: logFilePath,@@ -420,6 +418,12 @@ func EnrollNode(dataDir string, controlPlaneURL string, jwt string, allowLoopbacreturn fmt.Errorf("enrollment failed: %w", err)}+ // Saved only once the control plane accepted them, so a rejected+ // re-enrollment cannot leave this file ahead of the Biscuit.+ if err := os.WriteFile(filepath.Join(dataDir, labelsFile), []byte(labels), 0600); err != nil {+ return fmt.Errorf("failed to save labels: %w", err)+ }+if err := store.SaveControlPlaneURL(controlPlaneURL); err != nil {return fmt.Errorf("failed to save control plane URL: %w", err)}diff --git a/mobile/sam-node-ffi/ffi/ffi_test.go b/mobile/sam-node-ffi/ffi/ffi_test.goindex 57ea16eb..93f7e433 100644--- a/mobile/sam-node-ffi/ffi/ffi_test.go+++ b/mobile/sam-node-ffi/ffi/ffi_test.go@@ -200,3 +200,19 @@ func TestMobileConfigDecodesAttenuation(t *testing.T) {t.Fatalf("got %+v, want one statement of each kind", config.Attenuation)}}++// A rejected enrollment must not record labels the Biscuit does not carry.+func TestEnrollNodeRejectedLeavesNoLabels(t *testing.T) {+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ http.Error(w, "role grants no labels", http.StatusForbidden)+ }))+ defer srv.Close()++ dir := t.TempDir()+ if err := EnrollNode(dir, srv.URL, "dummy-jwt", true, "region=eu-west-1"); err == nil {+ t.Fatal("expected enrollment to fail")+ }+ if got, err := loadEnrolledLabels(dir); err != nil || got != nil {+ t.Fatalf("labels must not be persisted after a rejected enrollment, got %v, %v", got, err)+ }+}