From 762675c7532f88cdf2066237d67698a277962f70 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 8 Apr 2021 12:33:54 -0400 Subject: [PATCH] [Elastic Agent] Adjust to Fleet Server connection information from Kibana in configuration (#24713) (#24992) * Adjust fleet.kibana.* to just fleet.* * Switch from fleet.kibana.* to fleet.* for connection. * Add changelog entry. * Add check to ensure no possible panic in mapDict. (cherry picked from commit 974f2555477b37c224706bbd0c65538df9875016) Co-authored-by: Blake Rouse --- x-pack/elastic-agent/.gitignore | 3 + x-pack/elastic-agent/CHANGELOG.next.asciidoc | 1 + .../pkg/agent/application/managed_mode.go | 4 +- .../handlers/handler_action_policy_change.go | 43 +++++++------ .../emitter/modifiers/fleet_decorator.go | 43 ++++++++----- .../elastic-agent/pkg/agent/cmd/enroll_cmd.go | 24 +++---- .../pkg/agent/cmd/enroll_cmd_test.go | 18 +++--- .../pkg/agent/configuration/fleet.go | 10 +-- .../pkg/agent/program/program_test.go | 4 ++ .../pkg/agent/program/supported.go | 2 +- .../endpoint_basic-endpoint-security.yml | 10 ++- .../agent/program/testdata/endpoint_basic.yml | 9 ++- .../testdata/fleet_server-fleet-server.yml | 16 +++++ .../agent/program/testdata/fleet_server.yml | 34 ++++++++++ .../single_config-endpoint-security.yml | 13 ++-- .../testdata/single_config-fleet-server.yml | 3 + .../agent/program/testdata/single_config.yml | 12 ++-- .../elastic-agent/pkg/agent/transpiler/ast.go | 24 ++++++- .../pkg/agent/transpiler/rules.go | 47 +++++++++++--- .../pkg/fleetapi/client/client.go | 18 ++---- .../pkg/fleetapi/client/client_test.go | 10 +-- .../pkg/fleetapi/client/round_trippers.go | 4 +- .../pkg/fleetapi/enroll_cmd_test.go | 6 +- .../elastic-agent/pkg/fleetapi/helper_test.go | 4 +- .../pkg/{kibana => remote}/client.go | 50 +++++++-------- .../pkg/{kibana => remote}/client_test.go | 63 ++++--------------- .../pkg/{kibana => remote}/config.go | 16 ++--- .../pkg/{kibana => remote}/config_test.go | 2 +- .../pkg/{kibana => remote}/round_trippers.go | 22 +------ x-pack/elastic-agent/spec/endpoint.yml | 8 --- x-pack/elastic-agent/spec/fleet-server.yml | 14 ++--- 31 files changed, 288 insertions(+), 249 deletions(-) create mode 100644 x-pack/elastic-agent/pkg/agent/program/testdata/fleet_server-fleet-server.yml create mode 100644 x-pack/elastic-agent/pkg/agent/program/testdata/fleet_server.yml rename x-pack/elastic-agent/pkg/{kibana => remote}/client.go (84%) rename x-pack/elastic-agent/pkg/{kibana => remote}/client_test.go (85%) rename x-pack/elastic-agent/pkg/{kibana => remote}/config.go (84%) rename x-pack/elastic-agent/pkg/{kibana => remote}/config_test.go (98%) rename x-pack/elastic-agent/pkg/{kibana => remote}/round_trippers.go (86%) diff --git a/x-pack/elastic-agent/.gitignore b/x-pack/elastic-agent/.gitignore index cd297650b08..1051bbdd747 100644 --- a/x-pack/elastic-agent/.gitignore +++ b/x-pack/elastic-agent/.gitignore @@ -2,6 +2,9 @@ build/ elastic-agent elastic-agent.dev.yml +elastic-agent.yml.* +fleet.yml +fleet.yml.lock pkg/agent/operation/tests/scripts/short--1.0.yml pkg/agent/operation/tests/scripts/configurable-1.0-darwin-x86/configurable pkg/agent/operation/tests/scripts/servicable-1.0-darwin-x86/configurable diff --git a/x-pack/elastic-agent/CHANGELOG.next.asciidoc b/x-pack/elastic-agent/CHANGELOG.next.asciidoc index 46caa04e28d..210a6bcbf2b 100644 --- a/x-pack/elastic-agent/CHANGELOG.next.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.next.asciidoc @@ -8,6 +8,7 @@ ==== Breaking changes - Docker container is not run as root by default. {pull}21213[21213] +- Read Fleet connection information from `fleet.*` instead of `fleet.kibana.*`. {pull}24713[24713] ==== Bugfixes - Fix rename *ConfigChange to *PolicyChange to align on changes in the UI. {pull}20779[20779] diff --git a/x-pack/elastic-agent/pkg/agent/application/managed_mode.go b/x-pack/elastic-agent/pkg/agent/application/managed_mode.go index c0ce285fceb..77917b341a5 100644 --- a/x-pack/elastic-agent/pkg/agent/application/managed_mode.go +++ b/x-pack/elastic-agent/pkg/agent/application/managed_mode.go @@ -84,12 +84,12 @@ func newManaged( return nil, err } - client, err := client.NewAuthWithConfig(log, cfg.Fleet.AccessAPIKey, cfg.Fleet.Kibana) + client, err := client.NewAuthWithConfig(log, cfg.Fleet.AccessAPIKey, cfg.Fleet.Client) if err != nil { return nil, errors.New(err, "fail to create API client", errors.TypeNetwork, - errors.M(errors.MetaKeyURI, cfg.Fleet.Kibana.Host)) + errors.M(errors.MetaKeyURI, cfg.Fleet.Client.Host)) } sysInfo, err := sysinfo.Host() diff --git a/x-pack/elastic-agent/pkg/agent/application/pipeline/actions/handlers/handler_action_policy_change.go b/x-pack/elastic-agent/pkg/agent/application/pipeline/actions/handlers/handler_action_policy_change.go index 71347407768..968af23c9fe 100644 --- a/x-pack/elastic-agent/pkg/agent/application/pipeline/actions/handlers/handler_action_policy_change.go +++ b/x-pack/elastic-agent/pkg/agent/application/pipeline/actions/handlers/handler_action_policy_change.go @@ -12,21 +12,20 @@ import ( "sort" "time" + "gopkg.in/yaml.v2" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/info" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/pipeline" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/pipeline/actions" - "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/storage/store" - "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/fleetapi/client" - - "gopkg.in/yaml.v2" - "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/configuration" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/errors" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/storage" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/storage/store" "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/fleetapi" - "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/kibana" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/fleetapi/client" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/remote" ) const ( @@ -106,33 +105,33 @@ func (h *PolicyChange) handleKibanaHosts(ctx context.Context, c *config.Config) if err != nil { return errors.New(err, "could not parse the configuration from the policy", errors.TypeConfig) } - if kibanaEqual(h.config.Fleet.Kibana, cfg.Fleet.Kibana) { + if clientEqual(h.config.Fleet.Client, cfg.Fleet.Client) { // already the same hosts return nil } // only set protocol/hosts as that is all Fleet currently sends - prevProtocol := h.config.Fleet.Kibana.Protocol - prevPath := h.config.Fleet.Kibana.Path - prevHosts := h.config.Fleet.Kibana.Hosts - h.config.Fleet.Kibana.Protocol = cfg.Fleet.Kibana.Protocol - h.config.Fleet.Kibana.Path = cfg.Fleet.Kibana.Path - h.config.Fleet.Kibana.Hosts = cfg.Fleet.Kibana.Hosts + prevProtocol := h.config.Fleet.Client.Protocol + prevPath := h.config.Fleet.Client.Path + prevHosts := h.config.Fleet.Client.Hosts + h.config.Fleet.Client.Protocol = cfg.Fleet.Client.Protocol + h.config.Fleet.Client.Path = cfg.Fleet.Client.Path + h.config.Fleet.Client.Hosts = cfg.Fleet.Client.Hosts // rollback on failure defer func() { if err != nil { - h.config.Fleet.Kibana.Protocol = prevProtocol - h.config.Fleet.Kibana.Path = prevPath - h.config.Fleet.Kibana.Hosts = prevHosts + h.config.Fleet.Client.Protocol = prevProtocol + h.config.Fleet.Client.Path = prevPath + h.config.Fleet.Client.Hosts = prevHosts } }() - client, err := client.NewAuthWithConfig(h.log, h.config.Fleet.AccessAPIKey, h.config.Fleet.Kibana) + client, err := client.NewAuthWithConfig(h.log, h.config.Fleet.AccessAPIKey, h.config.Fleet.Client) if err != nil { return errors.New( err, "fail to create API client with updated hosts", - errors.TypeNetwork, errors.M("hosts", h.config.Fleet.Kibana.Hosts)) + errors.TypeNetwork, errors.M("hosts", h.config.Fleet.Client.Hosts)) } ctx, cancel := context.WithTimeout(ctx, apiStatusTimeout) defer cancel() @@ -140,19 +139,19 @@ func (h *PolicyChange) handleKibanaHosts(ctx context.Context, c *config.Config) if err != nil { return errors.New( err, "fail to communicate with updated API client hosts", - errors.TypeNetwork, errors.M("hosts", h.config.Fleet.Kibana.Hosts)) + errors.TypeNetwork, errors.M("hosts", h.config.Fleet.Client.Hosts)) } reader, err := fleetToReader(h.agentInfo, h.config) if err != nil { return errors.New( err, "fail to persist updated API client hosts", - errors.TypeUnexpected, errors.M("hosts", h.config.Fleet.Kibana.Hosts)) + errors.TypeUnexpected, errors.M("hosts", h.config.Fleet.Client.Hosts)) } err = h.store.Save(reader) if err != nil { return errors.New( err, "fail to persist updated API client hosts", - errors.TypeFilesystem, errors.M("hosts", h.config.Fleet.Kibana.Hosts)) + errors.TypeFilesystem, errors.M("hosts", h.config.Fleet.Client.Hosts)) } for _, setter := range h.setters { setter.SetClient(client) @@ -160,7 +159,7 @@ func (h *PolicyChange) handleKibanaHosts(ctx context.Context, c *config.Config) return nil } -func kibanaEqual(k1 *kibana.Config, k2 *kibana.Config) bool { +func clientEqual(k1 remote.Config, k2 remote.Config) bool { if k1.Protocol != k2.Protocol { return false } diff --git a/x-pack/elastic-agent/pkg/agent/application/pipeline/emitter/modifiers/fleet_decorator.go b/x-pack/elastic-agent/pkg/agent/application/pipeline/emitter/modifiers/fleet_decorator.go index 688f8423a4f..1d77e5022c5 100644 --- a/x-pack/elastic-agent/pkg/agent/application/pipeline/emitter/modifiers/fleet_decorator.go +++ b/x-pack/elastic-agent/pkg/agent/application/pipeline/emitter/modifiers/fleet_decorator.go @@ -32,37 +32,50 @@ func InjectFleet(cfg *config.Config, hostInfo types.HostInfo, agentInfo *info.Ag if err != nil { return err } - token, ok := transpiler.Lookup(ast, "fleet.access_api_key") + fleet, ok := transpiler.Lookup(ast, "fleet") if !ok { - return fmt.Errorf("failed to get api key from fleet config") - } - - kbn, ok := transpiler.Lookup(ast, "fleet.kibana") - if !ok { - return fmt.Errorf("failed to get kibana config key from fleet config") + return fmt.Errorf("failed to get fleet from config") } + // copy top-level agent.* into fleet.agent.* (this gets sent to Applications in this structure) agent, ok := transpiler.Lookup(ast, "agent") if !ok { - return fmt.Errorf("failed to get agent key from fleet config") + return fmt.Errorf("failed to get agent key from config") + } + if err := transpiler.Insert(ast, agent, "fleet"); err != nil { + return err } + // ensure that the agent.logging.level is present if _, found := transpiler.Lookup(ast, "agent.logging.level"); !found { transpiler.Insert(ast, transpiler.NewKey("level", transpiler.NewStrVal(logLevel)), "agent.logging") } + // fleet.host to Agent can be the host to connect to Fleet Server, but to Applications it should + // be the fleet.host.id. move fleet.host to fleet.hosts if fleet.hosts doesn't exist + if _, ok := transpiler.Lookup(ast, "fleet.hosts"); !ok { + if host, ok := transpiler.Lookup(ast, "fleet.host"); ok { + if key, ok := host.(*transpiler.Key); ok { + if value, ok := key.Value().(*transpiler.StrVal); ok { + hosts := transpiler.NewList([]transpiler.Node{transpiler.NewStrVal(value.String())}) + if err := transpiler.Insert(ast, hosts, "fleet.hosts"); err != nil { + return err + } + } + } + } + } + + // inject host.* into fleet.host.* (this gets sent to Applications in this structure) host := transpiler.NewKey("host", transpiler.NewDict([]transpiler.Node{ transpiler.NewKey("id", transpiler.NewStrVal(hostInfo.UniqueID)), })) - - nodes := []transpiler.Node{agent, token, kbn, host} - server, ok := transpiler.Lookup(ast, "fleet.server") - if ok { - nodes = append(nodes, server) + if err := transpiler.Insert(ast, host, "fleet"); err != nil { + return err } - fleet := transpiler.NewDict(nodes) - err = transpiler.Insert(rootAst, fleet, "fleet") + // inject fleet.* from local AST to the rootAST so its present when sending to Applications. + err = transpiler.Insert(rootAst, fleet.Value().(transpiler.Node), "fleet") if err != nil { return err } diff --git a/x-pack/elastic-agent/pkg/agent/cmd/enroll_cmd.go b/x-pack/elastic-agent/pkg/agent/cmd/enroll_cmd.go index aa81392a628..0ce8f74de76 100644 --- a/x-pack/elastic-agent/pkg/agent/cmd/enroll_cmd.go +++ b/x-pack/elastic-agent/pkg/agent/cmd/enroll_cmd.go @@ -31,8 +31,8 @@ import ( "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/process" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/fleetapi" fleetclient "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/fleetapi/client" - "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/kibana" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/release" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/remote" ) const ( @@ -58,7 +58,7 @@ type enrollCmd struct { options *enrollCmdOption client fleetclient.Sender configStore saver - kibanaConfig *kibana.Config + remoteConfig remote.Config agentProc *process.Info } @@ -88,13 +88,13 @@ type enrollCmdOption struct { FleetServer enrollCmdFleetServerOption } -func (e *enrollCmdOption) kibanaConfig() (*kibana.Config, error) { - cfg, err := kibana.NewConfigFromURL(e.URL) +func (e *enrollCmdOption) remoteConfig() (remote.Config, error) { + cfg, err := remote.NewConfigFromURL(e.URL) if err != nil { - return nil, err + return remote.Config{}, err } - if cfg.Protocol == kibana.ProtocolHTTP && !e.Insecure { - return nil, fmt.Errorf("connection to Kibana is insecure, strongly recommended to use a secure connection (override with --insecure)") + if cfg.Protocol == remote.ProtocolHTTP && !e.Insecure { + return remote.Config{}, fmt.Errorf("connection to Kibana is insecure, strongly recommended to use a secure connection (override with --insecure)") } // Add any SSL options from the CLI. @@ -160,7 +160,7 @@ func (c *enrollCmd) Execute(ctx context.Context) error { } } - c.kibanaConfig, err = c.options.kibanaConfig() + c.remoteConfig, err = c.options.remoteConfig() if err != nil { return errors.New( err, "Error", @@ -168,7 +168,7 @@ func (c *enrollCmd) Execute(ctx context.Context) error { errors.M(errors.MetaKeyURI, c.options.URL)) } - c.client, err = fleetclient.NewWithConfig(c.log, c.kibanaConfig) + c.client, err = fleetclient.NewWithConfig(c.log, c.remoteConfig) if err != nil { return errors.New( err, "Error", @@ -364,7 +364,7 @@ func (c *enrollCmd) enroll(ctx context.Context) error { errors.TypeNetwork) } - fleetConfig, err := createFleetConfigFromEnroll(resp.Item.AccessAPIKey, c.kibanaConfig) + fleetConfig, err := createFleetConfigFromEnroll(resp.Item.AccessAPIKey, c.remoteConfig) if err != nil { return err } @@ -678,11 +678,11 @@ func createFleetServerBootstrapConfig(connStr string, policyID string, host stri return cfg, nil } -func createFleetConfigFromEnroll(accessAPIKey string, kbn *kibana.Config) (*configuration.FleetAgentConfig, error) { +func createFleetConfigFromEnroll(accessAPIKey string, cli remote.Config) (*configuration.FleetAgentConfig, error) { cfg := configuration.DefaultFleetAgentConfig() cfg.Enabled = true cfg.AccessAPIKey = accessAPIKey - cfg.Kibana = kbn + cfg.Client = cli if err := cfg.Valid(); err != nil { return nil, errors.New(err, "invalid enrollment options", errors.TypeConfig) diff --git a/x-pack/elastic-agent/pkg/agent/cmd/enroll_cmd_test.go b/x-pack/elastic-agent/pkg/agent/cmd/enroll_cmd_test.go index 8f5b7c4f8a5..195969ecf58 100644 --- a/x-pack/elastic-agent/pkg/agent/cmd/enroll_cmd_test.go +++ b/x-pack/elastic-agent/pkg/agent/cmd/enroll_cmd_test.go @@ -155,9 +155,9 @@ func TestEnroll(t *testing.T) { require.NoError(t, err) require.Equal(t, "my-access-api-key", config.AccessAPIKey) - require.Equal(t, host, config.Kibana.Host) - require.Equal(t, "", config.Kibana.Username) - require.Equal(t, "", config.Kibana.Password) + require.Equal(t, host, config.Client.Host) + require.Equal(t, "", config.Client.Username) + require.Equal(t, "", config.Client.Password) }, )) @@ -215,9 +215,9 @@ func TestEnroll(t *testing.T) { require.NoError(t, err) require.Equal(t, "my-access-api-key", config.AccessAPIKey) - require.Equal(t, host, config.Kibana.Host) - require.Equal(t, "", config.Kibana.Username) - require.Equal(t, "", config.Kibana.Password) + require.Equal(t, host, config.Client.Host) + require.Equal(t, "", config.Client.Username) + require.Equal(t, "", config.Client.Password) }, )) @@ -275,9 +275,9 @@ func TestEnroll(t *testing.T) { require.NoError(t, err) require.Equal(t, "my-access-api-key", config.AccessAPIKey) - require.Equal(t, host, config.Kibana.Host) - require.Equal(t, "", config.Kibana.Username) - require.Equal(t, "", config.Kibana.Password) + require.Equal(t, host, config.Client.Host) + require.Equal(t, "", config.Client.Username) + require.Equal(t, "", config.Client.Password) }, )) diff --git a/x-pack/elastic-agent/pkg/agent/configuration/fleet.go b/x-pack/elastic-agent/pkg/agent/configuration/fleet.go index 60a6b7ced22..43b7a95e1fa 100644 --- a/x-pack/elastic-agent/pkg/agent/configuration/fleet.go +++ b/x-pack/elastic-agent/pkg/agent/configuration/fleet.go @@ -6,7 +6,7 @@ package configuration import ( "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/errors" - "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/kibana" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/remote" fleetreporterConfig "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/reporter/fleet/config" ) @@ -15,7 +15,7 @@ import ( type FleetAgentConfig struct { Enabled bool `config:"enabled" yaml:"enabled"` AccessAPIKey string `config:"access_api_key" yaml:"access_api_key"` - Kibana *kibana.Config `config:"kibana" yaml:"kibana"` + Client remote.Config `config:",inline" yaml:",inline"` Reporting *fleetreporterConfig.Config `config:"reporting" yaml:"reporting"` Info *AgentInfo `config:"agent" yaml:"agent"` Server *FleetServerConfig `config:"server" yaml:"server,omitempty"` @@ -33,8 +33,8 @@ func (e *FleetAgentConfig) Valid() error { return errors.New("empty access token", errors.TypeConfig) } - if e.Kibana == nil || len(e.Kibana.Host) == 0 { - return errors.New("missing Kibana host configuration", errors.TypeConfig) + if len(e.Client.Host) == 0 { + return errors.New("missing fleet host configuration", errors.TypeConfig) } } @@ -45,7 +45,7 @@ func (e *FleetAgentConfig) Valid() error { func DefaultFleetAgentConfig() *FleetAgentConfig { return &FleetAgentConfig{ Enabled: false, - Kibana: kibana.DefaultClientConfig(), + Client: remote.DefaultClientConfig(), Reporting: fleetreporterConfig.DefaultConfig(), Info: &AgentInfo{}, } diff --git a/x-pack/elastic-agent/pkg/agent/program/program_test.go b/x-pack/elastic-agent/pkg/agent/program/program_test.go index 19eb5499197..2691aae9e41 100644 --- a/x-pack/elastic-agent/pkg/agent/program/program_test.go +++ b/x-pack/elastic-agent/pkg/agent/program/program_test.go @@ -395,6 +395,10 @@ func TestConfiguration(t *testing.T) { // programs: []string{"journalbeat"}, // expected: 1, // }, + "fleet_server": { + programs: []string{"fleet-server"}, + expected: 1, + }, "synthetics_config": { programs: []string{"heartbeat"}, expected: 1, diff --git a/x-pack/elastic-agent/pkg/agent/program/supported.go b/x-pack/elastic-agent/pkg/agent/program/supported.go index 26e4368897e..a893c7858cb 100644 --- a/x-pack/elastic-agent/pkg/agent/program/supported.go +++ b/x-pack/elastic-agent/pkg/agent/program/supported.go @@ -25,7 +25,7 @@ func init() { // spec/metricbeat.yml // spec/osquerybeat.yml // spec/packetbeat.yml - unpacked := packer.MustUnpack("eJzkWll3o7qWfu+fcV5vDwxx7qXXug82OUx2SBlXJKE3JNlgW2BOjLGhV//3XmIyYCdVqTpD9+qHrCRYaNjaw/d92//1yzFd0/8I0vjfjuu3fP3270XMf/nPX0hsZPjrIVyCmbsALqcJ5jRMdwQuH23TOJOVXGLkKBjZcx85UgBx5Kt3P0toeQhhYWfeyj7aupP5cBJhBWQYTqRFDE4+dI4YLjVmOTKuxrw3Vs6x+aqtdfnsQ/dtAfERQyDZ23Nob2Wj+h0P1j9h05B8oJXMcrgP5fJ2PYfpiSMTE5Qv4SG0dSn0Fe28BppEZO0YIFeqn09DW5+lzATZy3YWExNwNu2eS6Q8hAGcnBnySn07rZ+b2gkpbk5ifAygK71sZyeiaGfx+WI1y3w0fezGWrOImeGjbdZnuj7v7615pkshjUFGVMyRkvH118P8+ln9Eyhg8rKdRb7icqq6Gx/N0mrs8ofmKTCa5TTxUhLT/pjMthxOoKZgoL1ht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dsP6Lzg4yL9me5rOSLG189P2vJLQ5r/4m6P2e0etYVUzPF0iJwRwa71qFMAZT7WEVtdfULGOw1f5G8GL3yghcWhAjYBcspgenXY+kifJxQwIjGNr3Q2e3x4NfhtvXTw3o/os119+1M03Smh+ON04YmePaohzVdJdS1JxBmLGiNyRH3n8133LWOMId6d+hZOnWLoC2NdbVQb+jo5iuWONN0lzNJ43OvZTkjqGNTd/yJptJZT5++/5Qslt7bnCvTsBXsPIH4PVvXfR6IwgT2qKYk6HH89rd/Le0hP9S4MgnI9vk0uqGrIGDmz/5c3ylDsunZC7TdlSBUZrLtB1iqKAKfp/vn/2s3yh9RqEAk3VecOxZvSKREdnb/8SKRNvv0b0qffiyb95AcZ10jKQrpf39Mj3oRjKkAaUSZLUJOcM3NKmWjuNyH7Dcok+tz0/ZQy1XyvlI2G930XZaqvDdy3t+b64HPKNO77IWViH1GmWgvB6ENN4g/R/Wl7Vp3W+Y1rpt9DH/hfoQPUJeK//+V/AgAA///YeLmN") SupportedMap = make(map[string]Spec) for f, v := range unpacked { diff --git a/x-pack/elastic-agent/pkg/agent/program/testdata/endpoint_basic-endpoint-security.yml b/x-pack/elastic-agent/pkg/agent/program/testdata/endpoint_basic-endpoint-security.yml index d81d276f368..dfbec8016ba 100644 --- a/x-pack/elastic-agent/pkg/agent/program/testdata/endpoint_basic-endpoint-security.yml +++ b/x-pack/elastic-agent/pkg/agent/program/testdata/endpoint_basic-endpoint-security.yml @@ -1,16 +1,14 @@ revision: 5 fleet: + access_api_key: VuaCfGcBCdbkQm-e5aOx:ui2lp2axTNmsyakw9tvNnw + protocol: https + hosts: [ localhost:5601 ] + timeout: 30s agent: id: fleet-agent-id logging.level: error host: id: host-agent-id - api: - access_api_key: VuaCfGcBCdbkQm-e5aOx:ui2lp2axTNmsyakw9tvNnw - kibana: - protocol: https - host: localhost:5601 - timeout: 30s output: elasticsearch: diff --git a/x-pack/elastic-agent/pkg/agent/program/testdata/endpoint_basic.yml b/x-pack/elastic-agent/pkg/agent/program/testdata/endpoint_basic.yml index 1681926c56e..9f438cd46fd 100644 --- a/x-pack/elastic-agent/pkg/agent/program/testdata/endpoint_basic.yml +++ b/x-pack/elastic-agent/pkg/agent/program/testdata/endpoint_basic.yml @@ -1,16 +1,15 @@ revision: 5 name: Endpoint Host fleet: + access_api_key: VuaCfGcBCdbkQm-e5aOx:ui2lp2axTNmsyakw9tvNnw + protocol: https + hosts: [ localhost:5601 ] + timeout: 30s agent: id: fleet-agent-id logging.level: error host: id: host-agent-id - access_api_key: VuaCfGcBCdbkQm-e5aOx:ui2lp2axTNmsyakw9tvNnw - kibana: - protocol: https - host: localhost:5601 - timeout: 30s outputs: default: diff --git a/x-pack/elastic-agent/pkg/agent/program/testdata/fleet_server-fleet-server.yml b/x-pack/elastic-agent/pkg/agent/program/testdata/fleet_server-fleet-server.yml new file mode 100644 index 00000000000..c03696aff1f --- /dev/null +++ b/x-pack/elastic-agent/pkg/agent/program/testdata/fleet_server-fleet-server.yml @@ -0,0 +1,16 @@ +fleet: + agent: + id: fleet-agent-id + logging.level: error + host: + id: host-agent-id + +output: + elasticsearch: + hosts: [ 127.0.0.1:9200, 127.0.0.1:9300 ] + username: fleet + password: fleetpassword + +inputs: + - id: fleet-server-id + type: fleet-server diff --git a/x-pack/elastic-agent/pkg/agent/program/testdata/fleet_server.yml b/x-pack/elastic-agent/pkg/agent/program/testdata/fleet_server.yml new file mode 100644 index 00000000000..8268f258fb5 --- /dev/null +++ b/x-pack/elastic-agent/pkg/agent/program/testdata/fleet_server.yml @@ -0,0 +1,34 @@ +name: Fleet Server Only +fleet: + enabled: true + access_api_key: VuaCfGcBCdbkQm-e5aOx:ui2lp2axTNmsyakw9tvNnw + protocol: https + hosts: [ localhost:5601 ] + timeout: 30s + agent: + id: fleet-agent-id + logging.level: error + host: + id: host-agent-id + server: + output: + elasticsearch: + hosts: [ 127.0.0.1:9200, 127.0.0.1:9300 ] + username: fleet + password: fleetpassword + +outputs: + default: + type: elasticsearch + hosts: [127.0.0.1:9200, 127.0.0.1:9300] + username: elastic + password: changeme + api_key: TiNAGG4BaaMdaH1tRfuU:KnR6yE41RrSowb0kQ0HWoA + ca_sha256: 7HIpactkIAq2Y49orFOOQKurWxmmSFZhBCoQYcRhJ3Y= + +inputs: + - id: fleet-server-id + type: fleet-server + use_output: default + data_stream: + type: default diff --git a/x-pack/elastic-agent/pkg/agent/program/testdata/single_config-endpoint-security.yml b/x-pack/elastic-agent/pkg/agent/program/testdata/single_config-endpoint-security.yml index 42d78b09ca5..8e4092d6d63 100644 --- a/x-pack/elastic-agent/pkg/agent/program/testdata/single_config-endpoint-security.yml +++ b/x-pack/elastic-agent/pkg/agent/program/testdata/single_config-endpoint-security.yml @@ -1,13 +1,14 @@ fleet: enabled: true + access_api_key: VuaCfGcBCdbkQm-e5aOx:ui2lp2axTNmsyakw9tvNnw + protocol: https + hosts: [ localhost:5601 ] + timeout: 30s agent: id: fleet-agent-id - api: - access_api_key: VuaCfGcBCdbkQm-e5aOx:ui2lp2axTNmsyakw9tvNnw - kibana: - protocol: https - host: localhost:5601 - timeout: 30s + logging.level: error + host: + id: host-agent-id output: elasticsearch: diff --git a/x-pack/elastic-agent/pkg/agent/program/testdata/single_config-fleet-server.yml b/x-pack/elastic-agent/pkg/agent/program/testdata/single_config-fleet-server.yml index cb8a3e10659..c03696aff1f 100644 --- a/x-pack/elastic-agent/pkg/agent/program/testdata/single_config-fleet-server.yml +++ b/x-pack/elastic-agent/pkg/agent/program/testdata/single_config-fleet-server.yml @@ -1,6 +1,9 @@ fleet: agent: id: fleet-agent-id + logging.level: error + host: + id: host-agent-id output: elasticsearch: diff --git a/x-pack/elastic-agent/pkg/agent/program/testdata/single_config.yml b/x-pack/elastic-agent/pkg/agent/program/testdata/single_config.yml index 006db1e9f52..afb0a5b5427 100644 --- a/x-pack/elastic-agent/pkg/agent/program/testdata/single_config.yml +++ b/x-pack/elastic-agent/pkg/agent/program/testdata/single_config.yml @@ -1,13 +1,15 @@ name: Production Website DB Servers fleet: enabled: true + access_api_key: VuaCfGcBCdbkQm-e5aOx:ui2lp2axTNmsyakw9tvNnw + protocol: https + hosts: [ localhost:5601 ] + timeout: 30s agent: id: fleet-agent-id - access_api_key: VuaCfGcBCdbkQm-e5aOx:ui2lp2axTNmsyakw9tvNnw - kibana: - protocol: https - host: localhost:5601 - timeout: 30s + logging.level: error + host: + id: host-agent-id server: output: elasticsearch: diff --git a/x-pack/elastic-agent/pkg/agent/transpiler/ast.go b/x-pack/elastic-agent/pkg/agent/transpiler/ast.go index 13242297c9a..efadf408c71 100644 --- a/x-pack/elastic-agent/pkg/agent/transpiler/ast.go +++ b/x-pack/elastic-agent/pkg/agent/transpiler/ast.go @@ -1067,11 +1067,33 @@ func Insert(a *AST, node Node, to Selector) error { return fmt.Errorf("expecting Key and received %T", current) } - switch node.(type) { + switch nt := node.(type) { case *Dict: d.value = node case *List: d.value = node + case *Key: + // adding key to existing dictionary + // should overwrite the current key if it exists + dValue, ok := d.value.(*Dict) + if !ok { + // not a dictionary (replace it all) + d.value = &Dict{[]Node{node}, nil} + } else { + // remove the duplicate key (if it exists) + for i, key := range dValue.value { + if k, ok := key.(*Key); ok { + if k.name == nt.name { + dValue.value[i] = dValue.value[len(dValue.value)-1] + dValue.value = dValue.value[:len(dValue.value)-1] + break + } + } + } + // add the new key + dValue.value = append(dValue.value, nt) + dValue.sort() + } default: d.value = &Dict{[]Node{node}, nil} } diff --git a/x-pack/elastic-agent/pkg/agent/transpiler/rules.go b/x-pack/elastic-agent/pkg/agent/transpiler/rules.go index 4fec7c78032..d9f4fd9e34d 100644 --- a/x-pack/elastic-agent/pkg/agent/transpiler/rules.go +++ b/x-pack/elastic-agent/pkg/agent/transpiler/rules.go @@ -999,15 +999,35 @@ func (r *MapRule) Apply(agentInfo AgentInfo, ast *AST) error { switch t := n.Value().(type) { case *List: - return mapList(agentInfo, r, t) + l, err := mapList(agentInfo, r, t) + if err != nil { + return err + } + n.value = l + return nil case *Dict: - return mapDict(agentInfo, r, t) + d, err := mapDict(agentInfo, r, t) + if err != nil { + return err + } + n.value = d + return nil case *Key: switch t := n.Value().(type) { case *List: - return mapList(agentInfo, r, t) + l, err := mapList(agentInfo, r, t) + if err != nil { + return err + } + n.value = l + return nil case *Dict: - return mapDict(agentInfo, r, t) + d, err := mapDict(agentInfo, r, t) + if err != nil { + return err + } + n.value = d + return nil default: return fmt.Errorf( "cannot iterate over node, invalid type expected 'List' or 'Dict' received '%T'", @@ -1022,7 +1042,7 @@ func (r *MapRule) Apply(agentInfo AgentInfo, ast *AST) error { ) } -func mapList(agentInfo AgentInfo, r *MapRule, l *List) error { +func mapList(agentInfo AgentInfo, r *MapRule, l *List) (*List, error) { values := l.Value().([]Node) for idx, item := range values { @@ -1030,24 +1050,31 @@ func mapList(agentInfo AgentInfo, r *MapRule, l *List) error { for _, rule := range r.Rules { err := rule.Apply(agentInfo, newAST) if err != nil { - return err + return nil, err } values[idx] = newAST.root } } - return nil + return l, nil } -func mapDict(agentInfo AgentInfo, r *MapRule, l *Dict) error { +func mapDict(agentInfo AgentInfo, r *MapRule, l *Dict) (*Dict, error) { newAST := &AST{root: l} for _, rule := range r.Rules { err := rule.Apply(agentInfo, newAST) if err != nil { - return err + return nil, err } } - return nil + n, ok := newAST.root.(*Dict) + if !ok { + return nil, fmt.Errorf( + "after applying rules from map, root is no longer a 'Dict' it is an invalid type of '%T'", + newAST.root, + ) + } + return n, nil } // MarshalYAML marshal a MapRule into a YAML document. diff --git a/x-pack/elastic-agent/pkg/fleetapi/client/client.go b/x-pack/elastic-agent/pkg/fleetapi/client/client.go index 8f9fcd7bc98..86efb3d2d66 100644 --- a/x-pack/elastic-agent/pkg/fleetapi/client/client.go +++ b/x-pack/elastic-agent/pkg/fleetapi/client/client.go @@ -15,10 +15,9 @@ import ( "os" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/errors" - "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" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/remote" ) // Sender is an sender interface describing client behavior. @@ -55,7 +54,7 @@ func init() { return nil, errors.New(err, "could not create the logger for debugging HTTP request") } - return kibana.NewDebugRoundTripper(rt, l), nil + return remote.NewDebugRoundTripper(rt, l), nil } } } @@ -65,8 +64,8 @@ func init() { // - Send the API Key on every HTTP request. // - Ensure a minimun version of Kibana is required. // - Send the Fleet User Agent on every HTTP request. -func NewAuthWithConfig(log *logger.Logger, apiKey string, cfg *kibana.Config) (*kibana.Client, error) { - return kibana.NewWithConfig(log, cfg, func(rt http.RoundTripper) (http.RoundTripper, error) { +func NewAuthWithConfig(log *logger.Logger, apiKey string, cfg remote.Config) (*remote.Client, error) { + return remote.NewWithConfig(log, cfg, func(rt http.RoundTripper) (http.RoundTripper, error) { rt, err := baseRoundTrippers(rt) if err != nil { return nil, err @@ -81,14 +80,9 @@ func NewAuthWithConfig(log *logger.Logger, apiKey string, cfg *kibana.Config) (* }) } -// NewWithRawConfig create a non authenticated clients. -func NewWithRawConfig(log *logger.Logger, config *config.Config) (*kibana.Client, error) { - return kibana.NewWithRawConfig(log, config, baseRoundTrippers) -} - // NewWithConfig takes a Kibana configuration and create a kibana.client with the appropriate tripper. -func NewWithConfig(log *logger.Logger, cfg *kibana.Config) (*kibana.Client, error) { - return kibana.NewWithConfig(log, cfg, baseRoundTrippers) +func NewWithConfig(log *logger.Logger, cfg remote.Config) (*remote.Client, error) { + return remote.NewWithConfig(log, cfg, baseRoundTrippers) } // ExtractError extracts error from a fleet response diff --git a/x-pack/elastic-agent/pkg/fleetapi/client/client_test.go b/x-pack/elastic-agent/pkg/fleetapi/client/client_test.go index 098a314af2a..db2242ce7a4 100644 --- a/x-pack/elastic-agent/pkg/fleetapi/client/client_test.go +++ b/x-pack/elastic-agent/pkg/fleetapi/client/client_test.go @@ -17,7 +17,7 @@ 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/kibana" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/remote" ) func TestHTTPClient(t *testing.T) { @@ -37,7 +37,7 @@ func TestHTTPClient(t *testing.T) { "host": host, }) - client, err := kibana.NewWithRawConfig(nil, cfg, func(wrapped http.RoundTripper) (http.RoundTripper, error) { + client, err := remote.NewWithRawConfig(nil, cfg, func(wrapped http.RoundTripper) (http.RoundTripper, error) { return NewFleetAuthRoundTripper(wrapped, "abc123") }) @@ -66,7 +66,7 @@ func TestHTTPClient(t *testing.T) { "host": host, }) - client, err := kibana.NewWithRawConfig(nil, cfg, func(wrapped http.RoundTripper) (http.RoundTripper, error) { + client, err := remote.NewWithRawConfig(nil, cfg, func(wrapped http.RoundTripper) (http.RoundTripper, error) { return NewFleetAuthRoundTripper(wrapped, "abc123") }) @@ -91,7 +91,7 @@ func TestHTTPClient(t *testing.T) { "host": host, }) - client, err := kibana.NewWithRawConfig(nil, cfg, func(wrapped http.RoundTripper) (http.RoundTripper, error) { + client, err := remote.NewWithRawConfig(nil, cfg, func(wrapped http.RoundTripper) (http.RoundTripper, error) { return NewFleetUserAgentRoundTripper(wrapped, "8.0.0"), nil }) @@ -113,7 +113,7 @@ func TestHTTPClient(t *testing.T) { timeoutCtx, cancel := context.WithTimeout(ctx, 3*time.Second) defer cancel() - client, err := kibana.NewWithRawConfig(nil, cfg, func(wrapped http.RoundTripper) (http.RoundTripper, error) { + client, err := remote.NewWithRawConfig(nil, cfg, func(wrapped http.RoundTripper) (http.RoundTripper, error) { return NewFleetAuthRoundTripper(wrapped, "abc123") }) require.NoError(t, err) diff --git a/x-pack/elastic-agent/pkg/fleetapi/client/round_trippers.go b/x-pack/elastic-agent/pkg/fleetapi/client/round_trippers.go index a0c4c04e068..4849edf3276 100644 --- a/x-pack/elastic-agent/pkg/fleetapi/client/round_trippers.go +++ b/x-pack/elastic-agent/pkg/fleetapi/client/round_trippers.go @@ -8,7 +8,7 @@ import ( "errors" "net/http" - "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/kibana" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/remote" ) // ErrInvalidAPIKey is returned when authentication fail to fleet. @@ -29,7 +29,7 @@ func (r *FleetUserAgentRoundTripper) RoundTrip(req *http.Request) (*http.Respons func NewFleetUserAgentRoundTripper(wrapped http.RoundTripper, version string) http.RoundTripper { const name = "Elastic Agent" return &FleetUserAgentRoundTripper{ - rt: kibana.NewUserAgentRoundTripper(wrapped, name+" v"+version), + rt: remote.NewUserAgentRoundTripper(wrapped, name+" v"+version), } } diff --git a/x-pack/elastic-agent/pkg/fleetapi/enroll_cmd_test.go b/x-pack/elastic-agent/pkg/fleetapi/enroll_cmd_test.go index 29bbf7e607e..54f98306693 100644 --- a/x-pack/elastic-agent/pkg/fleetapi/enroll_cmd_test.go +++ b/x-pack/elastic-agent/pkg/fleetapi/enroll_cmd_test.go @@ -16,7 +16,7 @@ import ( "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/info" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/config" - "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/kibana" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/remote" ) func TestEnroll(t *testing.T) { @@ -67,7 +67,7 @@ func TestEnroll(t *testing.T) { "host": host, }) - client, err := kibana.NewWithRawConfig(nil, cfg, nil) + client, err := remote.NewWithRawConfig(nil, cfg, nil) require.NoError(t, err) req := &EnrollRequest{ @@ -103,7 +103,7 @@ func TestEnroll(t *testing.T) { "host": host, }) - client, err := kibana.NewWithRawConfig(nil, cfg, nil) + client, err := remote.NewWithRawConfig(nil, cfg, nil) require.NoError(t, err) req := &EnrollRequest{ diff --git a/x-pack/elastic-agent/pkg/fleetapi/helper_test.go b/x-pack/elastic-agent/pkg/fleetapi/helper_test.go index 4650eb5c4ff..7aac16dbf97 100644 --- a/x-pack/elastic-agent/pkg/fleetapi/helper_test.go +++ b/x-pack/elastic-agent/pkg/fleetapi/helper_test.go @@ -14,7 +14,7 @@ import ( "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/logger" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/fleetapi/client" - "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/kibana" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/remote" ) func authHandler(handler http.HandlerFunc, apiKey string) http.HandlerFunc { @@ -47,7 +47,7 @@ func withServerWithAuthClient( return withServer(m, func(t *testing.T, host string) { log, _ := logger.New("", false) - cfg := &kibana.Config{ + cfg := remote.Config{ Host: host, } diff --git a/x-pack/elastic-agent/pkg/kibana/client.go b/x-pack/elastic-agent/pkg/remote/client.go similarity index 84% rename from x-pack/elastic-agent/pkg/kibana/client.go rename to x-pack/elastic-agent/pkg/remote/client.go index 24be2e7f05e..2c7b36063e6 100644 --- a/x-pack/elastic-agent/pkg/kibana/client.go +++ b/x-pack/elastic-agent/pkg/remote/client.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. -package kibana +package remote import ( "context" @@ -23,10 +23,9 @@ import ( ) const ( - kibanaPort = 5601 - kibanaHTTPSPort = 443 + defaultPort = 8220 - kibanaRetryOnBadConnTimeout = 5 * time.Minute + retryOnBadConnTimeout = 5 * time.Minute ) type requestFunc func(string, string, url.Values, io.Reader) (*http.Request, error) @@ -40,7 +39,7 @@ type requestClient struct { lastErrOcc time.Time } -// Client wraps an http.Client and takes care of making the raw calls to kibana, the client should +// Client wraps an http.Client and takes care of making the raw calls, the client should // stay simple and specificals should be implemented in external action instead of adding new methods // to the client. For authenticated calls or sending fields on every request, create customer RoundTripper // implementations that will take care of the boiler plates. @@ -48,14 +47,14 @@ type Client struct { log *logger.Logger lock sync.Mutex clients []*requestClient - config *Config + config Config } -// NewConfigFromURL returns a Kibana Config based on a received host. -func NewConfigFromURL(kURL string) (*Config, error) { +// NewConfigFromURL returns a Config based on a received host. +func NewConfigFromURL(kURL string) (Config, error) { u, err := url.Parse(kURL) if err != nil { - return nil, errors.Wrap(err, "could not parse Kibana url") + return Config{}, errors.Wrap(err, "could not parse url") } var username, password string @@ -75,27 +74,27 @@ func NewConfigFromURL(kURL string) (*Config, error) { return c, nil } -// NewWithRawConfig returns a new Kibana client with a specified configuration. +// NewWithRawConfig returns a new client with a specified configuration. func NewWithRawConfig(log *logger.Logger, config *config.Config, wrapper wrapperFunc) (*Client, error) { l := log if l == nil { - log, err := logger.New("kibana_client", false) + log, err := logger.New("client", false) if err != nil { return nil, err } l = log } - cfg := &Config{} - if err := config.Unpack(cfg); err != nil { + cfg := Config{} + if err := config.Unpack(&cfg); err != nil { return nil, errors.Wrap(err, "invalidate configuration") } return NewWithConfig(l, cfg, wrapper) } -// NewWithConfig takes a Kibana Config and return a client. -func NewWithConfig(log *logger.Logger, cfg *Config, wrapper wrapperFunc) (*Client, error) { +// NewWithConfig takes a Config and return a client. +func NewWithConfig(log *logger.Logger, cfg Config, wrapper wrapperFunc) (*Client, error) { // Normalize the URL with the path any spaces configured. var p string if len(cfg.SpaceID) > 0 { @@ -108,10 +107,7 @@ func NewWithConfig(log *logger.Logger, cfg *Config, wrapper wrapperFunc) (*Clien p = p + "/" } - usedDefaultPort := kibanaPort - if cfg.Protocol == "https" { - usedDefaultPort = kibanaHTTPSPort - } + usedDefaultPort := defaultPort hosts := cfg.GetHosts() clients := make([]*requestClient, len(hosts)) @@ -139,12 +135,12 @@ func NewWithConfig(log *logger.Logger, cfg *Config, wrapper wrapperFunc) (*Clien Timeout: cfg.Timeout, } - kibanaURL, err := common.MakeURL(string(cfg.Protocol), p, host, usedDefaultPort) + url, err := common.MakeURL(string(cfg.Protocol), p, host, usedDefaultPort) if err != nil { return nil, errors.Wrap(err, "invalid Kibana endpoint") } clients[i] = &requestClient{ - request: prefixRequestFactory(kibanaURL), + request: prefixRequestFactory(url), client: httpClient, } } @@ -152,14 +148,14 @@ func NewWithConfig(log *logger.Logger, cfg *Config, wrapper wrapperFunc) (*Clien return new(log, cfg, clients...) } -// Send executes a direct calls against the Kibana API, the method will takes cares of cloning -// also add necessary headers for Kibana likes: "Content-Type", "Accept", and "kbn-xsrf". +// Send executes a direct calls against the API, the method will takes cares of cloning +// also add necessary headers for likes: "Content-Type", "Accept", and "kbn-xsrf". // No assumptions is done on the response concerning the received format, this will be the responsibility // of the implementation to correctly unpack any received data. // // NOTE: // - The caller of this method is free to override any value found in the headers. -// - The magic of unpack kibana errors is not done in the Send method, a helper method is provided. +// - The magic of unpacking of errors is not done in the Send method, a helper method is provided. func (c *Client) Send( ctx context.Context, method, path string, @@ -208,10 +204,10 @@ func (c *Client) URI() string { return string(c.config.Protocol) + "://" + host + "/" + c.config.Path } -// new creates new Kibana API client. +// new creates new API client. func new( log *logger.Logger, - cfg *Config, + cfg Config, httpClients ...*requestClient, ) (*Client, error) { c := &Client{ @@ -230,7 +226,7 @@ func (c *Client) nextRequester() *requestClient { now := time.Now().UTC() for _, requester := range c.clients { - if requester.lastErr != nil && now.Sub(requester.lastErrOcc) > kibanaRetryOnBadConnTimeout { + if requester.lastErr != nil && now.Sub(requester.lastErrOcc) > retryOnBadConnTimeout { requester.lastErr = nil requester.lastErrOcc = time.Time{} } diff --git a/x-pack/elastic-agent/pkg/kibana/client_test.go b/x-pack/elastic-agent/pkg/remote/client_test.go similarity index 85% rename from x-pack/elastic-agent/pkg/kibana/client_test.go rename to x-pack/elastic-agent/pkg/remote/client_test.go index 7dff58ffb6f..ec304573f41 100644 --- a/x-pack/elastic-agent/pkg/kibana/client_test.go +++ b/x-pack/elastic-agent/pkg/remote/client_test.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. -package kibana +package remote import ( "bytes" @@ -44,11 +44,11 @@ func TestPortDefaults(t *testing.T) { ExpectedPort int ExpectedScheme string }{ - {"no scheme uri", "test.url", kibanaPort, "http"}, - {"default kibana port", "http://test.url", kibanaPort, "http"}, - {"specified kibana port", "http://test.url:123", 123, "http"}, - {"default kibana https port", "https://test.url", kibanaHTTPSPort, "https"}, - {"specified kibana https port", "https://test.url:123", 123, "https"}, + {"no scheme uri", "test.url", defaultPort, "http"}, + {"default port", "http://test.url", defaultPort, "http"}, + {"specified port", "http://test.url:123", 123, "http"}, + {"default https port", "https://test.url", defaultPort, "https"}, + {"specified https port", "https://test.url:123", 123, "https"}, } for _, tc := range testCases { t.Run(tc.Name, func(t *testing.T) { @@ -238,35 +238,6 @@ func TestHTTPClient(t *testing.T) { }, )) - t.Run("Enforce Kibana version", withServer( - func(t *testing.T) *http.ServeMux { - msg := `{ message: "hello" }` - mux := http.NewServeMux() - mux.HandleFunc("/echo-hello", enforceKibanaHandler(func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(http.StatusOK) - fmt.Fprint(w, msg) - }, "8.0.0")) - return mux - }, func(t *testing.T, host string) { - cfg := config.MustNewConfigFrom(map[string]interface{}{ - "host": host, - }) - - client, err := NewWithRawConfig(nil, cfg, func(wrapped http.RoundTripper) (http.RoundTripper, error) { - return NewEnforceKibanaVersionRoundTripper(wrapped, "8.0.0"), nil - }) - - 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("Allows to debug HTTP request between a client and a server", withServer( func(t *testing.T) *http.ServeMux { msg := `{ "message": "hello" }` @@ -310,7 +281,7 @@ func TestNextRequester(t *testing.T) { t.Run("Picks first requester on initial call", func(t *testing.T) { one := &requestClient{} two := &requestClient{} - client, err := new(nil, nil, one, two) + client, err := new(nil, Config{}, one, two) require.NoError(t, err) assert.Equal(t, one, client.nextRequester()) }) @@ -321,7 +292,7 @@ func TestNextRequester(t *testing.T) { lastErrOcc: time.Now().UTC(), } two := &requestClient{} - client, err := new(nil, nil, one, two) + client, err := new(nil, Config{}, one, two) require.NoError(t, err) assert.Equal(t, two, client.nextRequester()) }) @@ -331,7 +302,7 @@ func TestNextRequester(t *testing.T) { lastUsed: time.Now().UTC(), } two := &requestClient{} - client, err := new(nil, nil, one, two) + client, err := new(nil, Config{}, one, two) require.NoError(t, err) assert.Equal(t, two, client.nextRequester()) }) @@ -346,7 +317,7 @@ func TestNextRequester(t *testing.T) { three := &requestClient{ lastUsed: time.Now().UTC().Add(-2 * time.Minute), } - client, err := new(nil, nil, one, two, three) + client, err := new(nil, Config{}, one, two, three) require.NoError(t, err) assert.Equal(t, two, client.nextRequester()) }) @@ -363,7 +334,7 @@ func TestNextRequester(t *testing.T) { three := &requestClient{ lastUsed: time.Now().UTC().Add(-2 * time.Minute), } - client, err := new(nil, nil, one, two, three) + client, err := new(nil, Config{}, one, two, three) require.NoError(t, err) assert.Equal(t, three, client.nextRequester()) }) @@ -384,7 +355,7 @@ func TestNextRequester(t *testing.T) { lastErr: fmt.Errorf("fake error"), lastErrOcc: time.Now().Add(-2 * time.Minute), } - client, err := new(nil, nil, one, two, three) + client, err := new(nil, Config{}, one, two, three) require.NoError(t, err) assert.Equal(t, two, client.nextRequester()) }) @@ -411,16 +382,6 @@ func basicAuthHandler(handler http.HandlerFunc, username, password, realm string } } -func enforceKibanaHandler(handler http.HandlerFunc, version string) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - if r.Header.Get("kbn-version") != version { - http.Error(w, "Bad Request", http.StatusBadRequest) - return - } - handler(w, r) - } -} - type debugStack struct { sync.Mutex messages []string diff --git a/x-pack/elastic-agent/pkg/kibana/config.go b/x-pack/elastic-agent/pkg/remote/config.go similarity index 84% rename from x-pack/elastic-agent/pkg/kibana/config.go rename to x-pack/elastic-agent/pkg/remote/config.go index ae2f3850462..48728073803 100644 --- a/x-pack/elastic-agent/pkg/kibana/config.go +++ b/x-pack/elastic-agent/pkg/remote/config.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. -package kibana +package remote import ( "fmt" @@ -11,7 +11,7 @@ import ( "github.com/elastic/beats/v7/libbeat/common/transport/tlscommon" ) -// Config is the configuration for the Kibana client. +// Config is the configuration for the client. type Config struct { Protocol Protocol `config:"protocol" yaml:"protocol"` SpaceID string `config:"space.id" yaml:"space.id,omitempty"` @@ -28,9 +28,9 @@ type Config struct { type Protocol string const ( - // ProtocolHTTP is HTTP protocol connection to Kibana. + // ProtocolHTTP is HTTP protocol connection. ProtocolHTTP Protocol = "http" - // ProtocolHTTPS is HTTPS protocol connection to Kibana. + // ProtocolHTTPS is HTTPS protocol connection. ProtocolHTTPS Protocol = "https" ) @@ -44,9 +44,9 @@ func (p *Protocol) Unpack(from string) error { return nil } -// DefaultClientConfig creates default configuration for kibana client. -func DefaultClientConfig() *Config { - return &Config{ +// DefaultClientConfig creates default configuration for client. +func DefaultClientConfig() Config { + return Config{ Protocol: ProtocolHTTP, Host: "localhost:5601", Path: "", @@ -63,7 +63,7 @@ func (c *Config) IsBasicAuth() bool { return len(c.Username) > 0 && len(c.Password) > 0 } -// GetHosts returns the hosts to connect to kibana. +// GetHosts returns the hosts to connect. // // This looks first at `Hosts` and then at `Host` when `Hosts` is not defined. func (c *Config) GetHosts() []string { diff --git a/x-pack/elastic-agent/pkg/kibana/config_test.go b/x-pack/elastic-agent/pkg/remote/config_test.go similarity index 98% rename from x-pack/elastic-agent/pkg/kibana/config_test.go rename to x-pack/elastic-agent/pkg/remote/config_test.go index 57809e74778..21843a4b047 100644 --- a/x-pack/elastic-agent/pkg/kibana/config_test.go +++ b/x-pack/elastic-agent/pkg/remote/config_test.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. -package kibana +package remote import ( "reflect" diff --git a/x-pack/elastic-agent/pkg/kibana/round_trippers.go b/x-pack/elastic-agent/pkg/remote/round_trippers.go similarity index 86% rename from x-pack/elastic-agent/pkg/kibana/round_trippers.go rename to x-pack/elastic-agent/pkg/remote/round_trippers.go index ded02935671..8c5b86f45ca 100644 --- a/x-pack/elastic-agent/pkg/kibana/round_trippers.go +++ b/x-pack/elastic-agent/pkg/remote/round_trippers.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. -package kibana +package remote import ( "bytes" @@ -123,26 +123,6 @@ func NewDebugRoundTripper(wrapped http.RoundTripper, log debugLogger) http.Round return &DebugRoundTripper{rt: wrapped, log: log} } -// EnforceKibanaVersionRoundTripper sets the kbn-version header on every request. -type EnforceKibanaVersionRoundTripper struct { - rt http.RoundTripper - version string -} - -// RoundTrip adds the kbn-version header, if the remote kibana is not equal or superior the call -/// will fail. -func (r *EnforceKibanaVersionRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { - const key = "kbn-version" - req.Header.Set(key, r.version) - return r.rt.RoundTrip(req) -} - -// NewEnforceKibanaVersionRoundTripper enforce the remove endpoint to be a a certain version, if the -// remote kibana is not equal the call will fail. -func NewEnforceKibanaVersionRoundTripper(wrapped http.RoundTripper, version string) http.RoundTripper { - return &EnforceKibanaVersionRoundTripper{rt: wrapped, version: version} -} - // BasicAuthRoundTripper wraps any request using a basic auth. type BasicAuthRoundTripper struct { rt http.RoundTripper diff --git a/x-pack/elastic-agent/spec/endpoint.yml b/x-pack/elastic-agent/spec/endpoint.yml index b45a3d35648..28529004a2a 100644 --- a/x-pack/elastic-agent/spec/endpoint.yml +++ b/x-pack/elastic-agent/spec/endpoint.yml @@ -48,17 +48,9 @@ rules: values: - true -- select_into: - selectors: [fleet.access_api_key, fleet.kibana] - path: fleet.api - - map: path: fleet rules: - - remove_key: - key: access_api_key - - remove_key: - key: kibana - remove_key: key: server diff --git a/x-pack/elastic-agent/spec/fleet-server.yml b/x-pack/elastic-agent/spec/fleet-server.yml index 50fded6ea55..31cf9446da7 100644 --- a/x-pack/elastic-agent/spec/fleet-server.yml +++ b/x-pack/elastic-agent/spec/fleet-server.yml @@ -38,16 +38,10 @@ rules: - map: path: fleet rules: - - remove_key: - key: enabled - - remove_key: - key: access_api_key - - remove_key: - key: kibana - - remove_key: - key: reporting - - remove_key: - key: server + - filter: + selectors: + - agent + - host - map: path: inputs