Skip to content

fix(cli/server): do not redirect /healthz #12080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1991,6 +1991,13 @@ func redirectToAccessURL(handler http.Handler, accessURL *url.URL, tunnel bool,
http.Redirect(w, r, accessURL.String(), http.StatusTemporaryRedirect)
}

// Exception: /healthz
// Kubernetes doesn't like it if you redirect your healthcheck or liveness check endpoint.
if r.URL.Path == "/healthz" {
handler.ServeHTTP(w, r)
return
}

// Exception: DERP
// We use this endpoint when creating a DERP-mesh in the enterprise version to directly
// dial other Coderd derpers. Redirecting to the access URL breaks direct dial since the
Expand Down
8 changes: 7 additions & 1 deletion cli/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,17 @@ func TestServer(t *testing.T) {
require.Equal(t, c.expectRedirect, resp.Header.Get("Location"))
}

// We should never readirect /healthz
respHealthz, err := client.Request(ctx, http.MethodGet, "/healthz", nil)
require.NoError(t, err)
defer respHealthz.Body.Close()
require.Equal(t, http.StatusOK, respHealthz.StatusCode, "/healthz should never redirect")

// We should never redirect DERP
respDERP, err := client.Request(ctx, http.MethodGet, "/derp", nil)
require.NoError(t, err)
defer respDERP.Body.Close()
require.Equal(t, http.StatusUpgradeRequired, respDERP.StatusCode)
require.Equal(t, http.StatusUpgradeRequired, respDERP.StatusCode, "/derp should never redirect")
}

// Verify TLS
Expand Down