Skip to content

Commit

Permalink
Call tlscommon.SetInsecureDefaults (#4238)
Browse files Browse the repository at this point in the history
  • Loading branch information
michel-laterman authored Dec 26, 2024
1 parent 026481c commit 18c2932
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ import (
"github.com/gofrs/uuid"
"github.com/rs/zerolog"

"github.com/elastic/elastic-agent-libs/transport/tlscommon"
"github.com/elastic/fleet-server/v7/version"
"github.com/elastic/go-ucfg"
"github.com/elastic/go-ucfg/flag"
"github.com/elastic/go-ucfg/yaml"
)

func init() {
tlscommon.SetInsecureDefaults()
}

// DefaultOptions defaults options used to read the configuration
var DefaultOptions = []ucfg.Option{
ucfg.PathSep("."),
Expand Down
26 changes: 26 additions & 0 deletions internal/pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
package config

import (
"crypto/tls"
"path/filepath"
"sync/atomic"
"testing"
"time"

"github.com/elastic/elastic-agent-libs/transport/tlscommon"
testlog "github.com/elastic/fleet-server/v7/internal/pkg/testing/log"

"github.com/gofrs/uuid"
Expand Down Expand Up @@ -621,3 +623,27 @@ func TestDeprecationWarnings(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, uint64(3), logCount.Load(), "Expected 3 log messages")
}

func TestTLSDefaults(t *testing.T) {
c, err := LoadFile(filepath.Join("testdata", "tls.yml"))
require.NoError(t, err)
require.NotNil(t, c.Output.Elasticsearch.TLS)

common, err := tlscommon.LoadTLSConfig(c.Output.Elasticsearch.TLS)
require.NoError(t, err)
cfg := common.ToConfig()
assert.Equal(t, uint16(tls.VersionTLS11), cfg.MinVersion)
assert.Equal(t, uint16(tls.VersionTLS13), cfg.MaxVersion)
}

func TestTLS10(t *testing.T) {
c, err := LoadFile(filepath.Join("testdata", "tls10.yml"))
require.NoError(t, err)
require.NotNil(t, c.Output.Elasticsearch.TLS)

common, err := tlscommon.LoadTLSConfig(c.Output.Elasticsearch.TLS)
require.NoError(t, err)
cfg := common.ToConfig()
assert.Equal(t, uint16(tls.VersionTLS10), cfg.MinVersion)
assert.Equal(t, uint16(tls.VersionTLS10), cfg.MaxVersion)
}
10 changes: 10 additions & 0 deletions internal/pkg/config/testdata/tls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
output:
elasticsearch:
hosts: ["localhost:9200"]
service_token: "test-token"
ssl:
enabled: true
fleet:
agent:
id: 1e4954ce-af37-4731-9f4a-407b08e69e42

11 changes: 11 additions & 0 deletions internal/pkg/config/testdata/tls10.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
output:
elasticsearch:
hosts: ["localhost:9200"]
service_token: "test-token"
ssl:
enabled: true
supported_protocols:
- TLSv1.0
fleet:
agent:
id: 1e4954ce-af37-4731-9f4a-407b08e69e42

0 comments on commit 18c2932

Please sign in to comment.