Skip to content

Commit

Permalink
Cherry-pick elastic#12333 to 7.2: Set client.authentication to `requi…
Browse files Browse the repository at this point in the history
…red` by default. (elastic#12344)

* Set client.authentication to `required` by default. (elastic#12333)

* Set client.authentication to `required` by default.

(cherry picked from commit 2807784)
  • Loading branch information
ph authored May 29, 2019
1 parent ed2fd7a commit a481572
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix memory leak in Filebeat pipeline acker. {pull}12063[12063]
- Fix goroutine leak caused on initialization failures of log input. {pull}12125[12125]
- Fix goroutine leak on non-explicit finalization of log input. {pull}12164[12164]
- Require client_auth by default when ssl is enabled for tcp input {pull}12333[12333]

*Heartbeat*

Expand All @@ -126,9 +127,10 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Avoid generating hints-based configuration with empty hosts when no exposed port is suitable for the hosts hint. {issue}8264[8264] {pull}12086[12086]
- Fixed a socket leak in the postgresql module under Windows when SSL is disabled on the server. {pull}11393[11393]
- Change some field type from scaled_float to long in aws module. {pull}11982[11982]
- Fixed RabbitMQ `queue` metricset gathering when `consumer_utilisation` is set empty at the metrics source {pull}12089[12089]
- Fixed RabbitMQ `queue` metricset gathering when `consumer_utilisation` is set empty at the metrics source {pull}12089[12089]
- Fix direction of incoming IPv6 sockets. {pull}12248[12248]
- Ignore prometheus metrics when their values are NaN or Inf. {pull}12084[12084] {issue}10849[10849]
- Require client_auth by default when ssl is enabled for module http metricset server{pull}12333[12333]

*Packetbeat*

Expand Down
3 changes: 1 addition & 2 deletions filebeat/tests/system/test_tcp_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_tcp_over_tls_and_verify_invalid_server_without_mutual_auth(self):
@raises(ssl.SSLError)
def test_tcp_over_tls_mutual_auth_fails(self):
"""
Test filebeat TCP with TLS when enforcing client auth with bad client certificates.
Test filebeat TCP with TLS with default setting to enforce client auth, with bad client certificates
"""
input_raw = """
- type: tcp
Expand All @@ -136,7 +136,6 @@ def test_tcp_over_tls_mutual_auth_fails(self):
ssl.certificate_authorities: {cacert}
ssl.certificate: {certificate}
ssl.key: {key}
ssl.client_authentication: required
"""
config = {
"host": "127.0.0.1",
Expand Down
16 changes: 16 additions & 0 deletions libbeat/common/transport/tlscommon/server_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"crypto/tls"

"github.com/joeshaw/multierror"

"github.com/elastic/beats/libbeat/common"
)

// ServerConfig defines the user configurable tls options for any TCP based service.
Expand Down Expand Up @@ -89,6 +91,20 @@ func LoadTLSServerConfig(config *ServerConfig) (*TLSConfig, error) {
}, nil
}

func (c *ServerConfig) Unpack(cfg common.Config) error {
clientAuthKey := "client_authentication"
if !cfg.HasField(clientAuthKey) {
cfg.SetString(clientAuthKey, -1, "required")
}
type serverCfg ServerConfig
var sCfg serverCfg
if err := cfg.Unpack(&sCfg); err != nil {
return err
}
*c = ServerConfig(sCfg)
return nil
}

// Validate values the TLSConfig struct making sure certificate sure we have both a certificate and
// a key.
func (c *ServerConfig) Validate() error {
Expand Down
24 changes: 24 additions & 0 deletions libbeat/common/transport/tlscommon/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"testing"

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

"github.com/elastic/beats/libbeat/common"
)
Expand Down Expand Up @@ -165,6 +166,29 @@ func TestApplyWithConfig(t *testing.T) {
assert.Len(t, cfg.CurvePreferences, 1)
}

func TestServerConfigDefaults(t *testing.T) {
var c ServerConfig
config := common.MustNewConfigFrom([]byte(``))
err := config.Unpack(&c)
require.NoError(t, err)
tmp, err := LoadTLSServerConfig(&c)
require.NoError(t, err)

cfg := tmp.BuildModuleConfig("")

assert.NotNil(t, cfg)
// values not set by default
assert.Len(t, cfg.Certificates, 0)
assert.Nil(t, cfg.ClientCAs)
assert.Len(t, cfg.CipherSuites, 0)
assert.Len(t, cfg.CurvePreferences, 0)
// values set by default
assert.Equal(t, false, cfg.InsecureSkipVerify)
assert.Equal(t, int(tls.VersionTLS11), int(cfg.MinVersion))
assert.Equal(t, int(tls.VersionTLS12), int(cfg.MaxVersion))
assert.Equal(t, tls.RequireAndVerifyClientCert, cfg.ClientAuth)
}

func TestApplyWithServerConfig(t *testing.T) {
yamlStr := `
certificate: ca_test.pem
Expand Down

0 comments on commit a481572

Please sign in to comment.