From 6a2a723bd25816e86c9ae92f42b621aaaaa3c3a2 Mon Sep 17 00:00:00 2001 From: justinsb Date: Thu, 29 Aug 2024 05:32:51 -0400 Subject: [PATCH] refactor: give clear error message if challenge endpoint cannot be found We were not handling this particularly clearly before, although it should only happen in development. --- cmd/kops-controller/pkg/server/server.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/kops-controller/pkg/server/server.go b/cmd/kops-controller/pkg/server/server.go index f5579d4d48fa9..a179d304a8527 100644 --- a/cmd/kops-controller/pkg/server/server.go +++ b/cmd/kops-controller/pkg/server/server.go @@ -210,6 +210,12 @@ func (s *Server) bootstrap(w http.ResponseWriter, r *http.Request) { } if model.UseChallengeCallback(kops.CloudProviderID(s.opt.Cloud)) { + if id.ChallengeEndpoint == "" { + klog.Infof("cannot determine endpoint for bootstrap callback challenge from %q", r.RemoteAddr) + w.WriteHeader(http.StatusBadRequest) + _, _ = w.Write([]byte("callback failed")) + return + } if err := s.challengeClient.DoCallbackChallenge(ctx, s.opt.ClusterName, id.ChallengeEndpoint, req); err != nil { klog.Infof("bootstrap %s callback challenge failed: %v", r.RemoteAddr, err) w.WriteHeader(http.StatusBadRequest)