Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Model durable collector teardown in rootless qualification
rcourtman69a300827f7a
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.mdindex 61b03fdefa..0e0d3e1e81 100644--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md@@ -7317,8 +7317,14 @@ or granting an outer default route is invalid qualification. The outer hostuses a private cgroup namespace with no host cgroup bind mount. Each dedicatedruntime identity must have an active delegated systemd user manager before itsdaemon starts, and cleanup must stop that manager and remove its linger state.-The wrapper-exercises each runtime in an isolated state root and emits the+The in-container control-plane fixture must implement the same authenticated+collector-uninstall response contract as the production lifecycle client. A+teardown succeeds only after the fixture records the exact registered binding+as removed, rejects that bearer thereafter, and returns the matching agent ID;+the following legacy-migration phase uses a distinct replacement enrollment+credential rather than resurrecting the removed one. Final cleanup must commit+and verify the replacement binding's removal too.+The wrapper exercises each runtime in an isolated state root and emits thestandalone `secure-runtime-rootless-v1` receipt only after exact socketownership, daemon rootless attestation, installer pinning, direct telemetry,same-family typed-helper fallback, recovery without collector restart,diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.mdindex c408d07812..be2a58a20f 100644--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md@@ -268,6 +268,12 @@ an outer default route invalidates the proof. The disposable host uses aprivate cgroup namespace without a host cgroup bind mount, creates an activedelegated systemd user manager for the dedicated runtime identity, and removesthat manager's linger state during cleanup.+The qualification control plane must honor the installer's fail-closed+teardown contract: it authenticates the exact collector binding, records the+removal before returning the matching agent ID, rejects the removed bearer,+and provisions a distinct replacement credential for the subsequent legacy+migration. The final uninstall must independently remove that replacement+binding before local files or services disappear.Its standalone `secure-runtime-rootless-v1` receipt must bind the exactqualification, collector, helper, installer, source-manifest, socket,fresh-install, legacy-migration, restart, fallback, recovery, ambiguity,diff --git a/scripts/installtests/secure_runtime_rootless_qualification_test.go b/scripts/installtests/secure_runtime_rootless_qualification_test.goindex 5a3c6c788a..26e272105d 100644--- a/scripts/installtests/secure_runtime_rootless_qualification_test.go+++ b/scripts/installtests/secure_runtime_rootless_qualification_test.go@@ -158,6 +158,7 @@ func TestSecureRuntimeRootlessQualification(t *testing.T) {defer fixture.actionServer.Shutdown()server := httptest.NewServer(fixture)defer server.Close()+ collectorCredential := secureRuntimeLabTokendaemon := rootlessQualPrepareDaemons(t, runtimeKind)defer rootlessQualBestEffortStop(daemon.rootlessUnit, daemon.rootfulUnit, rootlessQualOtherUnit(runtimeKind), fmt.Sprintf("user@%d.service", daemon.uid))@@ -207,11 +208,16 @@ func TestSecureRuntimeRootlessQualification(t *testing.T) {daemonIDBefore := rootlessQualDaemonID(t, daemon, true)appendScenario("fresh_install", freshStarted, &freshReport.Report,rootlessQualDirectEvidence(daemon, identity, freshPID, daemonIDBefore, daemonRootlessObserved, freshDigest))- rootlessQualUninstallPulse(t, installerPath, server.URL)+ rootlessQualUninstallPulse(t, installerPath, server.URL, collectorCredential)rootlessQualAssertPulseRemoved(t)+ if registered, revoked, uninstalls := fixture.collectorLifecycleSnapshot(); registered || !revoked || uninstalls != 1 {+ t.Fatalf("fresh collector uninstall was not durably modeled: registered=%t revoked=%t uninstalls=%d", registered, revoked, uninstalls)+ }+ fixture.replaceCollectorCredential(secureRuntimeLabTokenV2, secureRuntimeCollectorBindingV2)+ collectorCredential = secureRuntimeLabTokenV2migrationStarted := time.Now().UTC()- secureRuntimeRunInstaller(t, installerPath, server.URL,+ secureRuntimeRunInstallerWithCollectorCredential(t, installerPath, server.URL, collectorCredential,"--enable-commands", "--command-authority", "command-capable", "--enable-docker")legacyReport := rootlessQualWaitReport(t, fixture, migrationStarted, 75*time.Second, func(report agentsdocker.Report) bool {return rootlessQualComplete(report) && report.Host.CollectionMode == "" && report.Host.Runtime == runtimeKind@@ -223,7 +229,7 @@ func TestSecureRuntimeRootlessQualification(t *testing.T) {t.Fatalf("legacy root report differs from the separate rootful runtime baseline: report=%s baseline=%s", legacyDigest, rootfulBaseline.SemanticDigest)}applyStarted := time.Now().UTC()- secureRuntimeRunInstaller(t, installerPath, server.URL, "--safe-profile-apply")+ secureRuntimeRunInstallerWithCollectorCredential(t, installerPath, server.URL, collectorCredential, "--safe-profile-apply")migratedReport := rootlessQualWaitDirect(t, fixture, applyStarted, runtimeKind, 75*time.Second)secureRuntimeAssertSafeProfile(t)secureRuntimeAssertHelperProtocol(t)@@ -313,7 +319,7 @@ func TestSecureRuntimeRootlessQualification(t *testing.T) {if _, err := os.Lstat(otherSocket); err != nil {t.Fatalf("second live rootless socket missing: %v", err)}- ambiguityOutput := rootlessQualRunUnpinnedCollector(t, server.URL, 6*time.Second)+ ambiguityOutput := rootlessQualRunUnpinnedCollector(t, server.URL, collectorCredential, 6*time.Second)if !strings.Contains(strings.ToLower(ambiguityOutput), "ambiguous collector-owned rootless runtime endpoints") {t.Fatalf("unpinned collector did not fail closed on dual sockets:\n%s", ambiguityOutput)}@@ -334,7 +340,7 @@ func TestSecureRuntimeRootlessQualification(t *testing.T) {})previousUpdateStream, _, _ := agentshost.ParseReportSequenceID(pinFallback.Report.SequenceID)updateStarted := time.Now().UTC()- secureRuntimeRunInstaller(t, installerPath, server.URL, "--update")+ secureRuntimeRunInstallerWithCollectorCredential(t, installerPath, server.URL, collectorCredential, "--update")unitWhileAbsent := rootlessQualServicePin(t, runtimeKind)if unitBefore != daemon.rootlessSock || unitWhileAbsent != unitBefore {t.Fatalf("offline update lost exact rootless pin: before=%q after=%q", unitBefore, unitWhileAbsent)@@ -411,7 +417,10 @@ func TestSecureRuntimeRootlessQualification(t *testing.T) {})cleanupStarted := time.Now().UTC()- rootlessQualUninstallPulse(t, installerPath, server.URL)+ rootlessQualUninstallPulse(t, installerPath, server.URL, collectorCredential)+ if registered, revoked, uninstalls := fixture.collectorLifecycleSnapshot(); registered || !revoked || uninstalls != 2 {+ t.Fatalf("final collector uninstall was not durably modeled: registered=%t revoked=%t uninstalls=%d", registered, revoked, uninstalls)+ }rootlessQualStopUnit(t, daemon.rootlessUnit)rootlessQualStopUnit(t, daemon.rootfulUnit)rootlessQualStopUserManager(t, daemon)@@ -835,7 +844,7 @@ func rootlessQualUnitIdentity(t *testing.T, unit string) (int, string) {return pid, invocation}-func rootlessQualRunUnpinnedCollector(t *testing.T, serverURL string, duration time.Duration) string {+func rootlessQualRunUnpinnedCollector(t *testing.T, serverURL, collectorCredential string, duration time.Duration) string {t.Helper()protectedPID := secureRuntimeCollectorMainPID(t)stateDir, err := os.MkdirTemp("/tmp", "pulse-unpinned-probe-")@@ -854,7 +863,7 @@ func rootlessQualRunUnpinnedCollector(t *testing.T, serverURL string, duration tctx, cancel := context.WithTimeout(context.Background(), duration)defer cancel()cmd := exec.CommandContext(ctx, "runuser", "-u", "pulse-agent", "--", "env", "-u", "DOCKER_HOST", "-u", "PODMAN_HOST", "-u", "CONTAINER_HOST",- "PULSE_URL="+serverURL, "PULSE_TOKEN="+secureRuntimeLabToken, "PULSE_INTERVAL=1s", "PULSE_AGENT_ID="+secureRuntimeLabAgentID,+ "PULSE_URL="+serverURL, "PULSE_TOKEN="+collectorCredential, "PULSE_INTERVAL=1s", "PULSE_AGENT_ID="+secureRuntimeLabAgentID,"PULSE_HOSTNAME="+secureRuntimeLabHostname, "PULSE_ENABLE_HOST=false", "PULSE_ENABLE_DOCKER=true", "PULSE_ENABLE_COMMANDS=false","PULSE_AGENT_ALLOW_PLAINTEXT_HTTP=true", "/usr/local/bin/pulse-agent", "--state-dir", stateDir, "--health-addr", "")out, err := cmd.CombinedOutput()@@ -1016,9 +1025,9 @@ func rootlessQualSourceHashes(t *testing.T) map[string]string {return hashes}-func rootlessQualUninstallPulse(t *testing.T, installerPath, serverURL string) {+func rootlessQualUninstallPulse(t *testing.T, installerPath, serverURL, collectorCredential string) {t.Helper()- secureRuntimeRunInstaller(t, installerPath, serverURL, "--uninstall")+ secureRuntimeRunInstallerWithCollectorCredential(t, installerPath, serverURL, collectorCredential, "--uninstall")}func rootlessQualAssertPulseRemoved(t *testing.T) {diff --git a/scripts/installtests/secure_runtime_systemd_lab_test.go b/scripts/installtests/secure_runtime_systemd_lab_test.goindex 1d73cc1d39..243d29529a 100644--- a/scripts/installtests/secure_runtime_systemd_lab_test.go+++ b/scripts/installtests/secure_runtime_systemd_lab_test.go@@ -90,9 +90,12 @@ const (secureRuntimeLabMarkerPath = "/etc/pulse-secure-runtime-lab"secureRuntimeLabMarkerValue = "PULSE_SECURE_RUNTIME_SYSTEMD_LAB=disposable-v1"secureRuntimeLabToken = "8fa728ed4cbfa7466947e747627b51e2464ed3f69966ed6394e36a82d85d7d31"+ secureRuntimeLabTokenV2 = "c6314d7664a58129f96576673631cad51fb69d83b577dab7ad9178f73c91cdca"secureRuntimeLabAgentID = "secure-runtime-systemd-lab"secureRuntimeLabHostname = "pulse-secure-runtime-lab"secureRuntimeLabOrgID = "secure-runtime-lab-org"+ secureRuntimeCollectorBindingV1 = "secure-runtime-collector-binding-v1"+ secureRuntimeCollectorBindingV2 = "secure-runtime-collector-binding-v2"secureRuntimeRunnerSecretV1 = "3c896fe99e29384a293def92f23c1709fbf429773e0a20ac5d930f2aab62f839"secureRuntimeRunnerSecretV2 = "d7f6f2550788213e0595f276b62b1df290f7e018ba74c03068c4afbe6efd7601"secureRuntimeRunnerBindingV1 = "secure-runtime-runner-binding-v1"@@ -242,6 +245,11 @@ type secureRuntimeLabFixture struct {actionRevokes intactionActivations intauthorityReductions int+ collectorSecret string+ collectorBindingID string+ collectorRegistered bool+ collectorRevoked bool+ collectorUninstalls int}func newSecureRuntimeLabFixture(collector []byte, collectorSignature string, helper, runner []byte, version string) *secureRuntimeLabFixture {@@ -249,6 +257,7 @@ func newSecureRuntimeLabFixture(collector []byte, collectorSignature string, helcollector: collector, collectorSignature: collectorSignature, helper: helper, runner: runner, serverVersion: version,rejectedVersions: make(map[string]bool),actionSecret: secureRuntimeRunnerSecretV1, actionBindingID: secureRuntimeRunnerBindingV1, actionPending: true,+ collectorSecret: secureRuntimeLabToken, collectorBindingID: secureRuntimeCollectorBindingV1,}fixture.actionServer = agentexec.NewServerWithAdmissionValidator(fixture.admitCommandSession, fixture.validateCommandSession)return fixture@@ -260,7 +269,7 @@ func (f *secureRuntimeLabFixture) admitCommandSession(secret, agentID, hostnameif strings.TrimSpace(agentID) != secureRuntimeLabAgentID || !strings.EqualFold(strings.TrimSpace(hostname), secureRuntimeLabHostname) {return agentexec.AgentAdmission{}, false}- if secret == secureRuntimeLabToken {+ if !f.collectorRevoked && secret == f.collectorSecret {return f.collectorAdmissionLocked(), true}if f.actionRevoked || secret != f.actionSecret {@@ -273,7 +282,7 @@ func (f *secureRuntimeLabFixture) validateCommandSession(admission agentexec.Agef.mu.Lock()defer f.mu.Unlock()if admission.RuntimeRole != agentexec.RuntimeRoleActionRunner {- return admission == f.collectorAdmissionLocked()+ return !f.collectorRevoked && admission == f.collectorAdmissionLocked()}expected := f.actionAdmissionLocked()return !f.actionRevoked &&@@ -288,12 +297,29 @@ func (f *secureRuntimeLabFixture) validateCommandSession(admission agentexec.Agefunc (f *secureRuntimeLabFixture) collectorAdmissionLocked() agentexec.AgentAdmission {return agentexec.AgentAdmission{OrganizationID: secureRuntimeLabOrgID,- TokenID: "secure-runtime-collector-binding-v1",+ TokenID: f.collectorBindingID,AgentID: secureRuntimeLabAgentID,Hostname: secureRuntimeLabHostname,}}+func (f *secureRuntimeLabFixture) replaceCollectorCredential(secret, bindingID string) {+ f.mu.Lock()+ defer f.mu.Unlock()+ if !f.collectorRevoked || f.collectorRegistered {+ panic("qualification fixture collector credential replaced before durable uninstall")+ }+ f.collectorSecret = secret+ f.collectorBindingID = bindingID+ f.collectorRevoked = false+}++func (f *secureRuntimeLabFixture) collectorLifecycleSnapshot() (registered, revoked bool, uninstalls int) {+ f.mu.Lock()+ defer f.mu.Unlock()+ return f.collectorRegistered, f.collectorRevoked, f.collectorUninstalls+}+func (f *secureRuntimeLabFixture) actionAdmissionLocked() agentexec.AgentAdmission {return agentexec.AgentAdmission{OrganizationID: secureRuntimeLabOrgID, TokenID: f.actionBindingID,@@ -409,8 +435,18 @@ func (f *secureRuntimeLabFixture) handleDockerReport(w http.ResponseWriter, r *hhttp.Error(w, "incomplete docker report", http.StatusBadRequest)return}+ if strings.TrimSpace(report.Agent.ID) != secureRuntimeLabAgentID || !strings.EqualFold(strings.TrimSpace(report.Host.Hostname), secureRuntimeLabHostname) {+ http.Error(w, "collector identity mismatch", http.StatusForbidden)+ return+ }f.mu.Lock()+ if f.collectorRevoked || r.Header.Get("X-API-Token") != f.collectorSecret {+ f.mu.Unlock()+ http.Error(w, "collector credential was revoked", http.StatusUnauthorized)+ return+ }f.dockerReports = append(f.dockerReports, secureRuntimeDockerReport{ReceivedAt: time.Now().UTC(), Report: report})+ f.collectorRegistered = truef.mu.Unlock()writeSecureRuntimeJSON(w, http.StatusOK, map[string]any{"success": true})}@@ -434,6 +470,8 @@ func (f *secureRuntimeLabFixture) ServeHTTP(w http.ResponseWriter, r *http.Requef.handleActionRunnerCredential(w, r)case r.URL.Path == "/api/agents/collector/reduce-authority":f.handleCollectorAuthorityReduction(w, r)+ case r.URL.Path == "/api/agents/agent/uninstall":+ f.handleCollectorUninstall(w, r)case r.URL.Path == "/api/health":writeSecureRuntimeJSON(w, http.StatusOK, map[string]any{"status": "ok"})case r.URL.Path == "/api/agents/agent/report":@@ -470,7 +508,11 @@ func (f *secureRuntimeLabFixture) handleCollectorAuthorityReduction(w http.Respohttp.Error(w, "invalid request", http.StatusBadRequest)return}- valid := strings.TrimSpace(r.Header.Get("Authorization")) == "Bearer "+secureRuntimeLabToken &&+ f.mu.Lock()+ collectorSecret := f.collectorSecret+ collectorRevoked := f.collectorRevoked+ f.mu.Unlock()+ valid := !collectorRevoked && strings.TrimSpace(r.Header.Get("Authorization")) == "Bearer "+collectorSecret &&strings.TrimSpace(request.AgentID) == secureRuntimeLabAgentID &&strings.EqualFold(strings.TrimSpace(request.Hostname), secureRuntimeLabHostname)if !valid {@@ -483,10 +525,61 @@ func (f *secureRuntimeLabFixture) handleCollectorAuthorityReduction(w http.Respow.WriteHeader(http.StatusNoContent)}+func (f *secureRuntimeLabFixture) handleCollectorUninstall(w http.ResponseWriter, r *http.Request) {+ if r.Method != http.MethodPost {+ http.Error(w, "method not allowed", http.StatusMethodNotAllowed)+ return+ }+ if !f.collectorLifecycleAuthorized(r) {+ http.Error(w, "unauthorized", http.StatusUnauthorized)+ return+ }+ var request struct {+ AgentID string `json:"agentId"`+ }+ decoder := json.NewDecoder(http.MaxBytesReader(w, r.Body, 4096))+ if err := decoder.Decode(&request); err != nil {+ http.Error(w, "invalid request", http.StatusBadRequest)+ return+ }+ var trailing any+ if err := decoder.Decode(&trailing); !errors.Is(err, io.EOF) {+ http.Error(w, "request contains trailing data", http.StatusBadRequest)+ return+ }+ if strings.TrimSpace(request.AgentID) != secureRuntimeLabAgentID {+ http.Error(w, "forbidden", http.StatusForbidden)+ return+ }++ f.mu.Lock()+ if !f.collectorRegistered || f.collectorRevoked {+ f.mu.Unlock()+ http.Error(w, "collector is not registered", http.StatusNotFound)+ return+ }+ admission := f.collectorAdmissionLocked()+ f.collectorRegistered = false+ f.collectorRevoked = true+ f.collectorUninstalls+++ f.lastSeen = time.Time{}+ f.mu.Unlock()+ f.actionServer.InvalidateAgentSession(admission)++ writeSecureRuntimeJSON(w, http.StatusOK, map[string]any{+ "success": true,+ "agentId": secureRuntimeLabAgentID,+ })+}+func (f *secureRuntimeLabFixture) authorized(r *http.Request) bool {+ f.mu.Lock()+ collectorSecret := f.collectorSecret+ collectorRevoked := f.collectorRevoked+ f.mu.Unlock()bearer := r.Header.Get("Authorization")- valid := r.Header.Get("X-API-Token") == secureRuntimeLabToken &&- (bearer == "" || bearer == "Bearer "+secureRuntimeLabToken) &&+ valid := !collectorRevoked && r.Header.Get("X-API-Token") == collectorSecret &&+ (bearer == "" || bearer == "Bearer "+collectorSecret) &&r.URL.Query().Get("token") == ""if !valid {f.mu.Lock()@@ -498,10 +591,14 @@ func (f *secureRuntimeLabFixture) authorized(r *http.Request) bool {}func (f *secureRuntimeLabFixture) collectorLifecycleAuthorized(r *http.Request) bool {+ f.mu.Lock()+ collectorSecret := f.collectorSecret+ collectorRevoked := f.collectorRevoked+ f.mu.Unlock()bearer := strings.TrimSpace(r.Header.Get("Authorization"))legacyHeader := strings.TrimSpace(r.Header.Get("X-API-Token"))- valid := bearer == "Bearer "+secureRuntimeLabToken &&- (legacyHeader == "" || legacyHeader == secureRuntimeLabToken) &&+ valid := !collectorRevoked && bearer == "Bearer "+collectorSecret &&+ (legacyHeader == "" || legacyHeader == collectorSecret) &&r.URL.Query().Get("token") == ""if !valid {f.mu.Lock()@@ -681,7 +778,16 @@ func (f *secureRuntimeLabFixture) handleReport(w http.ResponseWriter, r *http.Rereport.Authority = payload.Agent.Privilege.Authorityreport.TypedHelper = payload.Agent.Privilege.TypedHelper}+ if report.AgentID != secureRuntimeLabAgentID || !strings.EqualFold(report.Hostname, secureRuntimeLabHostname) {+ http.Error(w, "collector identity mismatch", http.StatusForbidden)+ return+ }f.mu.Lock()+ if f.collectorRevoked || r.Header.Get("X-API-Token") != f.collectorSecret {+ f.mu.Unlock()+ http.Error(w, "collector credential was revoked", http.StatusUnauthorized)+ return+ }f.reportAttempts = append(f.reportAttempts, report)rejected := f.rejectedVersions[report.AgentVersion]serverVersion := f.serverVersion@@ -691,6 +797,7 @@ func (f *secureRuntimeLabFixture) handleReport(w http.ResponseWriter, r *http.Rereturn}f.reports = append(f.reports, report)+ f.collectorRegistered = trueif !f.freezeLastSeen {f.lastSeen = report.ReceivedAt}@@ -709,8 +816,19 @@ func (f *secureRuntimeLabFixture) handleLookup(w http.ResponseWriter, r *http.Re}f.mu.Lock()lastSeen := f.lastSeen+ registered := f.collectorRegisteredf.mu.Unlock()- if lastSeen.IsZero() {+ requestedAgentID := strings.TrimSpace(r.URL.Query().Get("agentId"))+ requestedHostname := strings.TrimSpace(r.URL.Query().Get("hostname"))+ if requestedAgentID != "" && requestedAgentID != secureRuntimeLabAgentID {+ writeSecureRuntimeJSON(w, http.StatusNotFound, map[string]any{"success": false})+ return+ }+ if requestedHostname != "" && !strings.EqualFold(requestedHostname, secureRuntimeLabHostname) {+ writeSecureRuntimeJSON(w, http.StatusNotFound, map[string]any{"success": false})+ return+ }+ if !registered || lastSeen.IsZero() {writeSecureRuntimeJSON(w, http.StatusNotFound, map[string]any{"success": false})return}@@ -1151,6 +1269,7 @@ func TestSecureRuntimeFixtureAcceptsBearerOnlyCollectorLifecycleLookup(t *testindefer fixture.actionServer.Shutdown()fixture.mu.Lock()fixture.lastSeen = time.Now().UTC()+ fixture.collectorRegistered = truefixture.mu.Unlock()request := httptest.NewRequest(http.MethodGet, "/api/agents/agent/lookup?agentId="+secureRuntimeLabAgentID, nil)@@ -1169,6 +1288,75 @@ func TestSecureRuntimeFixtureAcceptsBearerOnlyCollectorLifecycleLookup(t *testin}}+func TestSecureRuntimeFixtureDurablyRemovesExactCollectorAndRejectsRevokedBearer(t *testing.T) {+ fixture := newSecureRuntimeLabFixture(nil, "", nil, nil, "fixture")+ defer fixture.actionServer.Shutdown()+ predecessorAdmission, admitted := fixture.admitCommandSession(secureRuntimeLabToken, secureRuntimeLabAgentID, secureRuntimeLabHostname)+ if !admitted {+ t.Fatal("fixture did not admit the predecessor collector credential")+ }+ fixture.mu.Lock()+ fixture.lastSeen = time.Now().UTC()+ fixture.collectorRegistered = true+ fixture.mu.Unlock()++ uninstall := func(token, agentID string) *httptest.ResponseRecorder {+ t.Helper()+ body, err := json.Marshal(map[string]string{"agentId": agentID})+ if err != nil {+ t.Fatal(err)+ }+ request := httptest.NewRequest(http.MethodPost, "/api/agents/agent/uninstall", bytes.NewReader(body))+ request.Header.Set("Authorization", "Bearer "+token)+ recorder := httptest.NewRecorder()+ fixture.ServeHTTP(recorder, request)+ return recorder+ }++ if recorder := uninstall(secureRuntimeLabToken, "another-agent"); recorder.Code != http.StatusForbidden {+ t.Fatalf("wrong-identity uninstall status = %d, want %d", recorder.Code, http.StatusForbidden)+ }+ if registered, revoked, count := fixture.collectorLifecycleSnapshot(); !registered || revoked || count != 0 {+ t.Fatalf("wrong-identity uninstall mutated fixture: registered=%t revoked=%t count=%d", registered, revoked, count)+ }++ recorder := uninstall(secureRuntimeLabToken, secureRuntimeLabAgentID)+ if recorder.Code != http.StatusOK {+ t.Fatalf("exact uninstall status = %d, body=%s", recorder.Code, recorder.Body.String())+ }+ var confirmation struct {+ Success bool `json:"success"`+ AgentID string `json:"agentId"`+ }+ if err := json.Unmarshal(recorder.Body.Bytes(), &confirmation); err != nil || !confirmation.Success || confirmation.AgentID != secureRuntimeLabAgentID {+ t.Fatalf("exact uninstall confirmation = %+v, err=%v", confirmation, err)+ }+ if registered, revoked, count := fixture.collectorLifecycleSnapshot(); registered || !revoked || count != 1 {+ t.Fatalf("exact uninstall state: registered=%t revoked=%t count=%d", registered, revoked, count)+ }+ if fixture.validateCommandSession(predecessorAdmission) {+ t.Fatal("revoked collector admission remained valid after uninstall")+ }+ if recorder := uninstall(secureRuntimeLabToken, secureRuntimeLabAgentID); recorder.Code != http.StatusUnauthorized {+ t.Fatalf("revoked bearer uninstall status = %d, want %d", recorder.Code, http.StatusUnauthorized)+ }++ fixture.replaceCollectorCredential(secureRuntimeLabTokenV2, secureRuntimeCollectorBindingV2)+ fixture.mu.Lock()+ fixture.lastSeen = time.Now().UTC()+ fixture.collectorRegistered = true+ fixture.mu.Unlock()+ if recorder := uninstall(secureRuntimeLabToken, secureRuntimeLabAgentID); recorder.Code != http.StatusUnauthorized {+ t.Fatalf("predecessor bearer after re-enrollment status = %d, want %d", recorder.Code, http.StatusUnauthorized)+ }+ if recorder := uninstall(secureRuntimeLabTokenV2, secureRuntimeLabAgentID); recorder.Code != http.StatusOK {+ t.Fatalf("replacement bearer uninstall status = %d, body=%s", recorder.Code, recorder.Body.String())+ }+ if registered, revoked, count := fixture.collectorLifecycleSnapshot(); registered || !revoked || count != 2 {+ t.Fatalf("replacement uninstall state: registered=%t revoked=%t count=%d", registered, revoked, count)+ }+}+func TestSecureRuntimeFixtureSelfRevokeUsesBodylessNoContentResponse(t *testing.T) {fixture := newSecureRuntimeLabFixture(nil, "", nil, nil, "fixture")defer fixture.actionServer.Shutdown()@@ -2157,12 +2345,26 @@ func secureRuntimeRunInstallerWithActionCredential(t *testing.T, installerPath,return out}+func secureRuntimeRunInstallerWithCollectorCredential(t *testing.T, installerPath, fixtureURL, collectorCredential string, scenarioArgs ...string) string {+ t.Helper()+ out, err := secureRuntimeRunInstallerErrorWithCredentials(t, installerPath, fixtureURL, collectorCredential, "", scenarioArgs...)+ if err != nil {+ t.Fatalf("installer %s failed: %v\n%s", strings.Join(scenarioArgs, " "), err, out)+ }+ return out+}+func secureRuntimeRunInstallerError(t *testing.T, installerPath, fixtureURL string, scenarioArgs ...string) (string, error) {t.Helper()return secureRuntimeRunInstallerErrorWithActionCredential(t, installerPath, fixtureURL, "", scenarioArgs...)}func secureRuntimeRunInstallerErrorWithActionCredential(t *testing.T, installerPath, fixtureURL, actionCredential string, scenarioArgs ...string) (string, error) {+ t.Helper()+ return secureRuntimeRunInstallerErrorWithCredentials(t, installerPath, fixtureURL, secureRuntimeLabToken, actionCredential, scenarioArgs...)+}++func secureRuntimeRunInstallerErrorWithCredentials(t *testing.T, installerPath, fixtureURL, collectorCredential, actionCredential string, scenarioArgs ...string) (string, error) {t.Helper()ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)defer cancel()@@ -2174,7 +2376,7 @@ func secureRuntimeRunInstallerErrorWithActionCredential(t *testing.T, installerPargs = append(args, scenarioArgs...)default:tokenFile := filepath.Join(t.TempDir(), "monitoring-token")- if err := os.WriteFile(tokenFile, []byte(secureRuntimeLabToken+"\n"), 0o600); err != nil {+ if err := os.WriteFile(tokenFile, []byte(collectorCredential+"\n"), 0o600); err != nil {t.Fatalf("write private fixture token: %v", err)}args = append(args,@@ -2227,7 +2429,7 @@ func secureRuntimeRunStandaloneInstaller(t *testing.T, installerPath string, scefunc secureRuntimeAssertNoCredentialExposure(t *testing.T, output []byte) {t.Helper()- for _, credential := range []string{secureRuntimeLabToken, secureRuntimeRunnerSecretV1, secureRuntimeRunnerSecretV2} {+ for _, credential := range []string{secureRuntimeLabToken, secureRuntimeLabTokenV2, secureRuntimeRunnerSecretV1, secureRuntimeRunnerSecretV2} {if bytes.Contains(output, []byte(credential)) {t.Fatal("installer output exposed a runtime credential")}