From 0888d1fcb49a124e4aa9c4ce529c70f501d27d35 Mon Sep 17 00:00:00 2001 From: Michel Laterman <82832767+michel-laterman@users.noreply.github.com> Date: Fri, 3 Jan 2025 13:48:32 -0300 Subject: [PATCH 1/3] Update elastic-agent-libs to v0.18.0 (#42202) Co-authored-by: Julien Lind (cherry picked from commit ef2900565005a9e8f796acb99a4010f17cb1ac65) # Conflicts: # go.mod # go.sum --- NOTICE.txt | 4 ++-- go.mod | 5 +++++ go.sum | 7 +++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/NOTICE.txt b/NOTICE.txt index 9e686597987..b776c32389c 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -13406,11 +13406,11 @@ SOFTWARE -------------------------------------------------------------------------------- Dependency : github.com/elastic/elastic-agent-libs -Version: v0.17.5 +Version: v0.18.0 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.17.5/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.18.0/LICENSE: Apache License Version 2.0, January 2004 diff --git a/go.mod b/go.mod index c9f70c8e366..0ae1b8de769 100644 --- a/go.mod +++ b/go.mod @@ -184,8 +184,13 @@ require ( github.com/elastic/bayeux v1.0.5 github.com/elastic/ebpfevents v0.6.0 github.com/elastic/elastic-agent-autodiscover v0.9.0 +<<<<<<< HEAD github.com/elastic/elastic-agent-libs v0.17.5 github.com/elastic/elastic-agent-system-metrics v0.11.6 +======= + github.com/elastic/elastic-agent-libs v0.18.0 + github.com/elastic/elastic-agent-system-metrics v0.11.7 +>>>>>>> ef2900565 (Update elastic-agent-libs to v0.18.0 (#42202)) github.com/elastic/go-elasticsearch/v8 v8.14.0 github.com/elastic/go-quark v0.2.0 github.com/elastic/go-sfdc v0.0.0-20241010131323-8e176480d727 diff --git a/go.sum b/go.sum index 9d07f9f032a..7530dd9e931 100644 --- a/go.sum +++ b/go.sum @@ -338,10 +338,17 @@ github.com/elastic/elastic-agent-autodiscover v0.9.0 h1:+iWIKh0u3e8I+CJa3FfWe9h0 github.com/elastic/elastic-agent-autodiscover v0.9.0/go.mod h1:5iUxLHhVdaGSWYTveSwfJEY4RqPXTG13LPiFoxcpFd4= github.com/elastic/elastic-agent-client/v7 v7.15.0 h1:nDB7v8TBoNuD6IIzC3z7Q0y+7bMgXoT2DsHfolO2CHE= github.com/elastic/elastic-agent-client/v7 v7.15.0/go.mod h1:6h+f9QdIr3GO2ODC0Y8+aEXRwzbA5W4eV4dd/67z7nI= +<<<<<<< HEAD github.com/elastic/elastic-agent-libs v0.17.5 h1:oyv5BohMia+49tZnsOmTyRWp5LoZbH8iOmGa7c4TqTs= github.com/elastic/elastic-agent-libs v0.17.5/go.mod h1:5CR02awPrBr+tfmjBBK+JI+dMmHNQjpVY24J0wjbC7M= github.com/elastic/elastic-agent-system-metrics v0.11.6 h1:yAR9N1MMyf6rzVEuk+SZcuTzYnf5mM7Xlja9pwZlJzg= github.com/elastic/elastic-agent-system-metrics v0.11.6/go.mod h1:nzkrGajQA29YNcfP62gfzhxX9an3/xdQ3RmfQNw9YTI= +======= +github.com/elastic/elastic-agent-libs v0.18.0 h1:PKG1StgHu2MfOwOryGuAVgNZlZXyvVSDw3SvLUfel+w= +github.com/elastic/elastic-agent-libs v0.18.0/go.mod h1:5CR02awPrBr+tfmjBBK+JI+dMmHNQjpVY24J0wjbC7M= +github.com/elastic/elastic-agent-system-metrics v0.11.7 h1:1xm2okCM0eQZ4jivZgUFSlt6HAn/nPgKB/Fj8eLG6mY= +github.com/elastic/elastic-agent-system-metrics v0.11.7/go.mod h1:nzkrGajQA29YNcfP62gfzhxX9an3/xdQ3RmfQNw9YTI= +>>>>>>> ef2900565 (Update elastic-agent-libs to v0.18.0 (#42202)) github.com/elastic/elastic-transport-go/v8 v8.6.0 h1:Y2S/FBjx1LlCv5m6pWAF2kDJAHoSjSRSJCApolgfthA= github.com/elastic/elastic-transport-go/v8 v8.6.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= github.com/elastic/fsevents v0.0.0-20181029231046-e1d381a4d270 h1:cWPqxlPtir4RoQVCpGSRXmLqjEHpJKbR60rxh1nQZY4= From 1b1d1d0b3e74bf838b7f5511794f18062f74d880 Mon Sep 17 00:00:00 2001 From: michel-laterman Date: Fri, 3 Jan 2025 09:11:10 -0800 Subject: [PATCH 2/3] Fix backport --- go.mod | 7 +------ go.sum | 11 ++--------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 0ae1b8de769..d5ca2634c39 100644 --- a/go.mod +++ b/go.mod @@ -184,13 +184,8 @@ require ( github.com/elastic/bayeux v1.0.5 github.com/elastic/ebpfevents v0.6.0 github.com/elastic/elastic-agent-autodiscover v0.9.0 -<<<<<<< HEAD - github.com/elastic/elastic-agent-libs v0.17.5 - github.com/elastic/elastic-agent-system-metrics v0.11.6 -======= github.com/elastic/elastic-agent-libs v0.18.0 - github.com/elastic/elastic-agent-system-metrics v0.11.7 ->>>>>>> ef2900565 (Update elastic-agent-libs to v0.18.0 (#42202)) + github.com/elastic/elastic-agent-system-metrics v0.11.6 github.com/elastic/go-elasticsearch/v8 v8.14.0 github.com/elastic/go-quark v0.2.0 github.com/elastic/go-sfdc v0.0.0-20241010131323-8e176480d727 diff --git a/go.sum b/go.sum index 7530dd9e931..7eafbc038ce 100644 --- a/go.sum +++ b/go.sum @@ -338,17 +338,10 @@ github.com/elastic/elastic-agent-autodiscover v0.9.0 h1:+iWIKh0u3e8I+CJa3FfWe9h0 github.com/elastic/elastic-agent-autodiscover v0.9.0/go.mod h1:5iUxLHhVdaGSWYTveSwfJEY4RqPXTG13LPiFoxcpFd4= github.com/elastic/elastic-agent-client/v7 v7.15.0 h1:nDB7v8TBoNuD6IIzC3z7Q0y+7bMgXoT2DsHfolO2CHE= github.com/elastic/elastic-agent-client/v7 v7.15.0/go.mod h1:6h+f9QdIr3GO2ODC0Y8+aEXRwzbA5W4eV4dd/67z7nI= -<<<<<<< HEAD -github.com/elastic/elastic-agent-libs v0.17.5 h1:oyv5BohMia+49tZnsOmTyRWp5LoZbH8iOmGa7c4TqTs= -github.com/elastic/elastic-agent-libs v0.17.5/go.mod h1:5CR02awPrBr+tfmjBBK+JI+dMmHNQjpVY24J0wjbC7M= -github.com/elastic/elastic-agent-system-metrics v0.11.6 h1:yAR9N1MMyf6rzVEuk+SZcuTzYnf5mM7Xlja9pwZlJzg= -github.com/elastic/elastic-agent-system-metrics v0.11.6/go.mod h1:nzkrGajQA29YNcfP62gfzhxX9an3/xdQ3RmfQNw9YTI= -======= github.com/elastic/elastic-agent-libs v0.18.0 h1:PKG1StgHu2MfOwOryGuAVgNZlZXyvVSDw3SvLUfel+w= github.com/elastic/elastic-agent-libs v0.18.0/go.mod h1:5CR02awPrBr+tfmjBBK+JI+dMmHNQjpVY24J0wjbC7M= -github.com/elastic/elastic-agent-system-metrics v0.11.7 h1:1xm2okCM0eQZ4jivZgUFSlt6HAn/nPgKB/Fj8eLG6mY= -github.com/elastic/elastic-agent-system-metrics v0.11.7/go.mod h1:nzkrGajQA29YNcfP62gfzhxX9an3/xdQ3RmfQNw9YTI= ->>>>>>> ef2900565 (Update elastic-agent-libs to v0.18.0 (#42202)) +github.com/elastic/elastic-agent-system-metrics v0.11.6 h1:yAR9N1MMyf6rzVEuk+SZcuTzYnf5mM7Xlja9pwZlJzg= +github.com/elastic/elastic-agent-system-metrics v0.11.6/go.mod h1:nzkrGajQA29YNcfP62gfzhxX9an3/xdQ3RmfQNw9YTI= github.com/elastic/elastic-transport-go/v8 v8.6.0 h1:Y2S/FBjx1LlCv5m6pWAF2kDJAHoSjSRSJCApolgfthA= github.com/elastic/elastic-transport-go/v8 v8.6.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= github.com/elastic/fsevents v0.0.0-20181029231046-e1d381a4d270 h1:cWPqxlPtir4RoQVCpGSRXmLqjEHpJKbR60rxh1nQZY4= From bd456e4848831925012645d48a0d63524865865c Mon Sep 17 00:00:00 2001 From: michel-laterman Date: Wed, 8 Jan 2025 14:45:46 -0800 Subject: [PATCH 3/3] Move TLS version tests --- libbeat/cmd/instance/beat_test.go | 47 -------------- libbeat/cmd/root_test.go | 104 ++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 47 deletions(-) create mode 100644 libbeat/cmd/root_test.go diff --git a/libbeat/cmd/instance/beat_test.go b/libbeat/cmd/instance/beat_test.go index 0f26e3bb6f0..ebfecf191c7 100644 --- a/libbeat/cmd/instance/beat_test.go +++ b/libbeat/cmd/instance/beat_test.go @@ -21,10 +21,8 @@ package instance import ( "bytes" - "crypto/tls" "io/ioutil" "os" - "path/filepath" "testing" "github.com/elastic/beats/v7/libbeat/cfgfile" @@ -35,7 +33,6 @@ import ( "github.com/elastic/elastic-agent-client/v7/pkg/client" "github.com/elastic/elastic-agent-libs/config" "github.com/elastic/elastic-agent-libs/logp" - "github.com/elastic/elastic-agent-libs/transport/tlscommon" "github.com/elastic/go-ucfg/yaml" "github.com/gofrs/uuid/v5" @@ -479,50 +476,6 @@ func TestLogSystemInfo(t *testing.T) { } } -func TestTLSDefaultVersions(t *testing.T) { - b, err := NewBeat("mockbeat", "testidx", "0.9", false, nil) - require.NoError(t, err) - - cfg, err := cfgfile.Load(filepath.Join("testdata", "tls.yml"), nil) - require.NoError(t, err) - err = cfg.Unpack(&b.Config) - require.NoError(t, err) - assert.True(t, b.Config.Output.IsSet()) - sslCfg, err := b.Config.Output.Config().Child("ssl", -1) - require.NoError(t, err) - var common tlscommon.Config - err = sslCfg.Unpack(&common) - require.NoError(t, err) - tlsCfg, err := tlscommon.LoadTLSConfig(&common) - require.NoError(t, err) - - c := tlsCfg.ToConfig() - assert.Equal(t, uint16(tls.VersionTLS11), c.MinVersion) - assert.Equal(t, uint16(tls.VersionTLS13), c.MaxVersion) -} - -func TestTLSVersion10(t *testing.T) { - b, err := NewBeat("mockbeat", "testidx", "0.9", false, nil) - require.NoError(t, err) - - cfg, err := cfgfile.Load(filepath.Join("testdata", "tls10.yml"), nil) - require.NoError(t, err) - err = cfg.Unpack(&b.Config) - require.NoError(t, err) - assert.True(t, b.Config.Output.IsSet()) - sslCfg, err := b.Config.Output.Config().Child("ssl", -1) - require.NoError(t, err) - var common tlscommon.Config - err = sslCfg.Unpack(&common) - require.NoError(t, err) - tlsCfg, err := tlscommon.LoadTLSConfig(&common) - require.NoError(t, err) - - c := tlsCfg.ToConfig() - assert.Equal(t, uint16(tls.VersionTLS10), c.MinVersion) - assert.Equal(t, uint16(tls.VersionTLS10), c.MaxVersion) -} - type mockManager struct { enabled bool } diff --git a/libbeat/cmd/root_test.go b/libbeat/cmd/root_test.go new file mode 100644 index 00000000000..72612c98ef5 --- /dev/null +++ b/libbeat/cmd/root_test.go @@ -0,0 +1,104 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//go:build !integration + +package cmd + +import ( + "crypto/tls" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + + "github.com/elastic/beats/v7/libbeat/beat" + "github.com/elastic/beats/v7/libbeat/cfgfile" + "github.com/elastic/beats/v7/libbeat/cmd/instance" + "github.com/elastic/elastic-agent-libs/config" + "github.com/elastic/elastic-agent-libs/transport/tlscommon" +) + +type MockBeater struct { + mock.Mock +} + +func (m *MockBeater) Run(b *beat.Beat) error { + args := m.Called(b) + return args.Error(0) +} + +func (m *MockBeater) Stop() { + m.Called() +} + +func genMockCreator(m *MockBeater) beat.Creator { + return func(b *beat.Beat, c *config.C) (beat.Beater, error) { + return m, nil + } +} + +func TestGenRootCmdWithSettings_TLSDefaults(t *testing.T) { + mb := &MockBeater{} + settings := instance.Settings{} + _ = GenRootCmdWithSettings(genMockCreator(mb), settings) + + t.Run("Test defaults", func(t *testing.T) { + b, err := instance.NewBeat("mockbeat", "testidx", "0.9", false, nil) + require.NoError(t, err) + cfg, err := cfgfile.Load(filepath.Join("instance", "testdata", "tls.yml"), nil) + require.NoError(t, err) + err = cfg.Unpack(&b.Config) + require.NoError(t, err) + assert.True(t, b.Config.Output.IsSet()) + sslCfg, err := b.Config.Output.Config().Child("ssl", -1) + require.NoError(t, err) + var common tlscommon.Config + err = sslCfg.Unpack(&common) + require.NoError(t, err) + tlsCfg, err := tlscommon.LoadTLSConfig(&common) + require.NoError(t, err) + + c := tlsCfg.ToConfig() + assert.Equal(t, uint16(tls.VersionTLS11), c.MinVersion) + assert.Equal(t, uint16(tls.VersionTLS13), c.MaxVersion) + }) + + t.Run("Set min TLSv1.0", func(t *testing.T) { + b, err := instance.NewBeat("mockbeat", "testidx", "0.9", false, nil) + require.NoError(t, err) + + cfg, err := cfgfile.Load(filepath.Join("instance", "testdata", "tls10.yml"), nil) + require.NoError(t, err) + err = cfg.Unpack(&b.Config) + require.NoError(t, err) + assert.True(t, b.Config.Output.IsSet()) + sslCfg, err := b.Config.Output.Config().Child("ssl", -1) + require.NoError(t, err) + var common tlscommon.Config + err = sslCfg.Unpack(&common) + require.NoError(t, err) + tlsCfg, err := tlscommon.LoadTLSConfig(&common) + require.NoError(t, err) + + c := tlsCfg.ToConfig() + assert.Equal(t, uint16(tls.VersionTLS10), c.MinVersion) + assert.Equal(t, uint16(tls.VersionTLS10), c.MaxVersion) + }) +}