Skip to content

Commit

Permalink
Call tlscommon.SetInsecureDefaults (#6412)
Browse files Browse the repository at this point in the history
  • Loading branch information
michel-laterman authored Dec 26, 2024
1 parent b7e6cef commit 7180562
Show file tree
Hide file tree
Showing 4 changed files with 71 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 @@ -13,10 +13,15 @@ import (
"go.opentelemetry.io/collector/confmap"
"gopkg.in/yaml.v2"

"github.com/elastic/elastic-agent-libs/transport/tlscommon"
"github.com/elastic/go-ucfg"
"github.com/elastic/go-ucfg/cfgutil"
)

func init() {
tlscommon.SetInsecureDefaults()
}

// options hold the specified options
type options struct {
otelKeys []string
Expand Down
56 changes: 56 additions & 0 deletions internal/pkg/config/test/tls_version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License 2.0;
// you may not use this file except in compliance with the Elastic License 2.0.

package main

import (
"crypto/tls"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/elastic/elastic-agent-libs/transport/tlscommon"
"github.com/elastic/elastic-agent/internal/pkg/agent/configuration"
"github.com/elastic/elastic-agent/internal/pkg/config"
"github.com/elastic/elastic-agent/pkg/core/logger"
)

func TestTLSVersionsDefault(t *testing.T) {
l := newLoader(t, filepath.Join("..", "testdata"))
c, err := l.Load([]string{filepath.Join("..", "testdata", "tls.yml")})
require.NoError(t, err)

agentCfg, err := configuration.NewFromConfig(c)
require.NoError(t, err)

common, err := tlscommon.LoadTLSConfig(agentCfg.Fleet.Client.Transport.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 TestTLSVersions10(t *testing.T) {
l := newLoader(t, filepath.Join("..", "testdata"))
c, err := l.Load([]string{filepath.Join("..", "testdata", "tls10.yml")})
require.NoError(t, err)

agentCfg, err := configuration.NewFromConfig(c)
require.NoError(t, err)

common, err := tlscommon.LoadTLSConfig(agentCfg.Fleet.Client.Transport.TLS)
require.NoError(t, err)
cfg := common.ToConfig()
assert.Equal(t, uint16(tls.VersionTLS10), cfg.MinVersion)
assert.Equal(t, uint16(tls.VersionTLS10), cfg.MaxVersion)
}

func newLoader(t *testing.T, folder string) *config.Loader {
t.Helper()
log, err := logger.New("config_test", true)
require.NoError(t, err)
return config.NewLoader(log, folder)
}
4 changes: 4 additions & 0 deletions internal/pkg/config/testdata/tls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fleet:
hosts: [127.0.0.1:9201]
ssl:
enabled: true
6 changes: 6 additions & 0 deletions internal/pkg/config/testdata/tls10.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fleet:
hosts: [127.0.0.1:9201]
ssl:
enabled: true
supported_protocols:
- TLSv1.0

0 comments on commit 7180562

Please sign in to comment.