Skip to content
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

Call tlscommon.SetInsecureDefaults #42128

Merged
merged 3 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions libbeat/cfgfile/cfgfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/elastic/beats/v7/libbeat/common/fleetmode"
"github.com/elastic/elastic-agent-libs/config"
"github.com/elastic/elastic-agent-libs/logp"
"github.com/elastic/elastic-agent-libs/transport/tlscommon"
)

// Evil package level globals
Expand Down Expand Up @@ -68,6 +69,7 @@ func Initialize() {
AddAllowedBackwardsCompatibleFlag("path.data")
_ = config.ConfigOverwriteFlag(nil, overwrites, "path.logs", "path.logs", "", "Logs path")
AddAllowedBackwardsCompatibleFlag("path.logs")
tlscommon.SetInsecureDefaults()
michel-laterman marked this conversation as resolved.
Show resolved Hide resolved
})
}

Expand Down
47 changes: 47 additions & 0 deletions libbeat/cmd/instance/beat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ package instance

import (
"bytes"
"crypto/tls"
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/elastic/beats/v7/libbeat/cfgfile"
Expand All @@ -33,6 +35,7 @@ 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"
Expand Down Expand Up @@ -476,6 +479,50 @@ 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
}
Expand Down
6 changes: 6 additions & 0 deletions libbeat/cmd/instance/testdata/tls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mockbeat:
name: TestTLSVersions
output.elasticsearch:
hosts: ["localhost:9200"]
ssl:
enabled: true
8 changes: 8 additions & 0 deletions libbeat/cmd/instance/testdata/tls10.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mockbeat:
name: TestTLSVersions
output.elasticsearch:
hosts: ["localhost:9200"]
ssl:
enabled: true
supported_protocols:
- TLSv1.0
Loading