From 491bd40dfed947ea61012d4d3afb6c4f5b467b91 Mon Sep 17 00:00:00 2001 From: Alex Harford Date: Fri, 30 Oct 2026 11:27:08 -0700 Subject: [PATCH] fix(pilot): tolerate a nil CredentialsController for remote clusters With PILOT_ENABLE_REMOTE_CREDENTIALS_CONTROLLER=false (istio/istio#59874, new in 1.31) istiod stores a nil *CredentialsController for every remote cluster, and the multicluster component still calls HasSynced and Close on it. The first remote Secret event dereferences the nil pointer and crashes istiod. Carries the open upstream fix istio/istio#62295 (secrets.go and the regression test; the release note is dropped). Drop this patch once a 1.31.x release ships that fix. --- .../pkg/credentials/kube/multicluster_test.go | 36 +++++++++++++++++++ pilot/pkg/credentials/kube/secrets.go | 8 +++++ 2 files changed, 44 insertions(+) diff --git a/pilot/pkg/credentials/kube/multicluster_test.go b/pilot/pkg/credentials/kube/multicluster_test.go index 27a2c1f..14fadb4 100755 --- a/pilot/pkg/credentials/kube/multicluster_test.go +++ b/pilot/pkg/credentials/kube/multicluster_test.go @@ -94,3 +94,39 @@ func TestAuthorizeWithRemoteCredentialsDisabled(t *testing.T) { t.Fatalf("expected Authorize to fail with %v, actually got %v", ErrNoAuthController, err) } } + +func TestRemoteCredentialsDisabledSyncAndClose(t *testing.T) { + test.SetForTest(t, &features.EnableRemoteCredentialsController, false) + + stop := test.NewStop(t) + localClient := kube.NewFakeClient() + localClient.RunAndWait(stop) + remoteClient := kube.NewFakeClient() + remoteClient.RunAndWait(stop) + + mc := multicluster.NewFakeController() + sc := NewMulticluster("local", mc) + mc.Add("local", localClient, stop) + mc.Add("remote", remoteClient, stop) + + // The multicluster component calls HasSynced on every controller it holds, including the nil + // one stored for the remote cluster. This must not panic and must not block the cluster sync. + sawNil := false + for _, c := range sc.component.All() { + if c == nil { + sawNil = true + if !c.HasSynced() { + t.Fatal("expected disabled controller to report synced") + } + } + } + if !sawNil { + t.Fatal("expected a nil controller for the remote cluster") + } + + // Removing the remote cluster calls Close on the nil controller. This must not panic. + mc.Delete("remote") + if _, err := sc.ForCluster("remote"); err == nil { + t.Fatal("expected error for deleted cluster") + } +} diff --git a/pilot/pkg/credentials/kube/secrets.go b/pilot/pkg/credentials/kube/secrets.go index c1bd758..bc6d1d7 100644 --- a/pilot/pkg/credentials/kube/secrets.go +++ b/pilot/pkg/credentials/kube/secrets.go @@ -130,6 +130,10 @@ func NewCredentialsController(kc kube.Client, handlers []func(typ kind.Kind, nam } func (s *CredentialsController) Close() { + // A nil controller is stored for remote clusters when the remote credentials controller is disabled. + if s == nil { + return + } s.secrets.ShutdownHandlers() if s.configMaps != nil { s.configMaps.ShutdownHandlers() @@ -137,6 +141,10 @@ func (s *CredentialsController) Close() { } func (s *CredentialsController) HasSynced() bool { + // A disabled (nil) controller has nothing to sync. + if s == nil { + return true + } synced := s.secrets.HasSynced() if s.configMaps != nil { synced = synced && s.configMaps.HasSynced()