Skip to content

Commit

Permalink
Set client.authentication to required by default. (elastic#12333)
Browse files Browse the repository at this point in the history
* Set client.authentication to `required` by default.
  • Loading branch information
simitt authored and ph committed May 29, 2019
1 parent e56375f commit 2807784
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- 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]
- Skipping unparsable log entries from docker json reader {pull}12268[12268]
- Require client_auth by default when ssl is enabled for tcp input {pull}12333[12333]

*Heartbeat*

Expand Down Expand Up @@ -134,6 +135,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Validate that kibana/status metricset cannot be used when xpack is enabled. {pull}12264[12264]
- Ignore prometheus metrics when their values are NaN or Inf. {pull}12084[12084] {issue}10849[10849]
- In the kibana/stats metricset, only log error (don't also index it) if xpack is enabled. {pull}12265[12265]
- 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 2807784

Please sign in to comment.