From c40a841844c2111ad74126ca435242dfbaaf35da Mon Sep 17 00:00:00 2001 From: Pier-Hugues Pellerin Date: Fri, 17 Apr 2020 09:17:54 -0400 Subject: [PATCH] [Agent] Remove the hard version between Fleet and the Elastic Agent. (#17764) * Remove the hard version between Fleet and the Elastic Agent. This remove the check that Kibana was doing to enforce that the remove version match the current version of Kibana. Instead the Fleet API should take the agent header version and ensure we can support it. This allow the Kibana side to control the communication and the upgrade more gracefully. Fixes: #17761 --- x-pack/elastic-agent/CHANGELOG.asciidoc | 2 ++ x-pack/elastic-agent/pkg/fleetapi/client.go | 1 - .../elastic-agent/pkg/fleetapi/client_test.go | 31 ------------------- .../pkg/kibana/round_trippers.go | 2 +- 4 files changed, 3 insertions(+), 33 deletions(-) diff --git a/x-pack/elastic-agent/CHANGELOG.asciidoc b/x-pack/elastic-agent/CHANGELOG.asciidoc index 826f6e2ccb76..9547f2f80ca6 100644 --- a/x-pack/elastic-agent/CHANGELOG.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.asciidoc @@ -18,8 +18,10 @@ - Fixed merge of config {pull}17399[17399] - Handle abs paths on windows correctly {pull}17461[17461] - Improved cancellation of agent {pull}17318[17318] +- Remove the kbn-version on each request to the Kibana API. {pull}17764[17764] - Fixed process spawning on Windows {pull}17751[17751] + ==== New features - Generate index name in a format type-dataset-namespace {pull}16903[16903] diff --git a/x-pack/elastic-agent/pkg/fleetapi/client.go b/x-pack/elastic-agent/pkg/fleetapi/client.go index 648620dcab98..bfdc131ce908 100644 --- a/x-pack/elastic-agent/pkg/fleetapi/client.go +++ b/x-pack/elastic-agent/pkg/fleetapi/client.go @@ -34,7 +34,6 @@ type clienter interface { var baseRoundTrippers = func(rt http.RoundTripper) (http.RoundTripper, error) { rt = NewFleetUserAgentRoundTripper(rt, release.Version()) - rt = kibana.NewEnforceKibanaVersionRoundTripper(rt, release.Version()) return rt, nil } diff --git a/x-pack/elastic-agent/pkg/fleetapi/client_test.go b/x-pack/elastic-agent/pkg/fleetapi/client_test.go index 305bbafc1174..5766fe109a6f 100644 --- a/x-pack/elastic-agent/pkg/fleetapi/client_test.go +++ b/x-pack/elastic-agent/pkg/fleetapi/client_test.go @@ -17,43 +17,12 @@ import ( "github.com/stretchr/testify/require" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/config" - "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/logger" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/kibana" - "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/release" ) func TestHTTPClient(t *testing.T) { ctx := context.Background() - t.Run("Ensure we validate the remote Kibana version is higher or equal", withServer( - func(t *testing.T) *http.ServeMux { - msg := `{ message: "hello" }` - mux := http.NewServeMux() - mux.HandleFunc("/echo-hello", authHandler(func(w http.ResponseWriter, r *http.Request) { - v := r.Header.Get("kbn-version") - assert.Equal(t, release.Version(), v) - w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, msg) - }, "abc123")) - return mux - }, func(t *testing.T, host string) { - cfg := &kibana.Config{ - Host: host, - } - - l, err := logger.New() - client, err := NewAuthWithConfig(l, "abc123", cfg) - require.NoError(t, err) - resp, err := client.Send(ctx, "GET", "/echo-hello", nil, nil, nil) - require.NoError(t, err) - - body, err := ioutil.ReadAll(resp.Body) - require.NoError(t, err) - defer resp.Body.Close() - assert.Equal(t, `{ message: "hello" }`, string(body)) - }, - )) - t.Run("API Key is valid", withServer( func(t *testing.T) *http.ServeMux { msg := `{ message: "hello" }` diff --git a/x-pack/elastic-agent/pkg/kibana/round_trippers.go b/x-pack/elastic-agent/pkg/kibana/round_trippers.go index 4adbee0e476e..ded029356716 100644 --- a/x-pack/elastic-agent/pkg/kibana/round_trippers.go +++ b/x-pack/elastic-agent/pkg/kibana/round_trippers.go @@ -138,7 +138,7 @@ func (r *EnforceKibanaVersionRoundTripper) RoundTrip(req *http.Request) (*http.R } // NewEnforceKibanaVersionRoundTripper enforce the remove endpoint to be a a certain version, if the -// remove kibana is not equal or superior on the requested version the call will fail. +// remote kibana is not equal the call will fail. func NewEnforceKibanaVersionRoundTripper(wrapped http.RoundTripper, version string) http.RoundTripper { return &EnforceKibanaVersionRoundTripper{rt: wrapped, version: version} }