diff --git a/pkg/http/api.go b/pkg/http/api.go index c2be673926a..5b31c6915f5 100644 --- a/pkg/http/api.go +++ b/pkg/http/api.go @@ -2376,7 +2376,13 @@ func (a *api) onGetHealthz(reqCtx *fasthttp.RequestCtx) { respond(reqCtx, withError(fasthttp.StatusInternalServerError, msg)) log.Debug(msg) } else { - respond(reqCtx, withEmpty()) + matchAppID := string(reqCtx.QueryArgs().Peek("app-id")) + if matchAppID != "" && matchAppID != a.id { + msg := NewErrorResponse("ERR_HEALTH_APPID_NOT_MATCH", messages.ErrHealthAppIDNotMatch) + respond(reqCtx, withError(fasthttp.StatusInternalServerError, msg)) + } else { + respond(reqCtx, withEmpty()) + } } } diff --git a/pkg/http/api_test.go b/pkg/http/api_test.go index 58bdaa7c87f..6227dd54150 100644 --- a/pkg/http/api_test.go +++ b/pkg/http/api_test.go @@ -4751,8 +4751,10 @@ func (l *fakeWorkflowComponent) GetComponentMetadata() map[string]string { func TestV1HealthzEndpoint(t *testing.T) { fakeServer := newFakeHTTPServer() + appId := "test" testAPI := &api{ actor: nil, + id: appId, } fakeServer.StartServer(testAPI.constructHealthzEndpoints()) @@ -4772,6 +4774,20 @@ func TestV1HealthzEndpoint(t *testing.T) { assert.Equal(t, 204, resp.StatusCode) }) + t.Run("Healthz - 500 No AppId Match", func(t *testing.T) { + apiPath := "v1.0/healthz" + testAPI.MarkStatusAsReady() + resp := fakeServer.DoRequest("GET", apiPath, nil, map[string]string{"app-id": "not-test"}) + assert.Equal(t, 500, resp.StatusCode) + }) + + t.Run("Healthz - 204 AppId Match", func(t *testing.T) { + apiPath := "v1.0/healthz" + testAPI.MarkStatusAsReady() + resp := fakeServer.DoRequest("GET", apiPath, nil, map[string]string{"app-id": appId}) + assert.Equal(t, 204, resp.StatusCode) + }) + fakeServer.Shutdown() } diff --git a/pkg/messages/predefined.go b/pkg/messages/predefined.go index a01c9f86212..59e6b2ffc10 100644 --- a/pkg/messages/predefined.go +++ b/pkg/messages/predefined.go @@ -84,6 +84,7 @@ const ( // Healthz. ErrHealthNotReady = "dapr is not ready" ErrOutboundHealthNotReady = "dapr outbound is not ready" + ErrHealthAppIDNotMatch = "dapr appId is not match" // Configuration. ErrConfigurationStoresNotConfigured = "configuration stores not configured"