Skip to content

Commit

Permalink
Cherry-pick #12333 to 7.1: Set client.authentication to required by…
Browse files Browse the repository at this point in the history
… default. (#12342)

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

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

(cherry picked from commit d1446d4)
  • Loading branch information
ph authored May 29, 2019
1 parent 0e71bc0 commit bd4a48a
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 @@ -46,6 +46,7 @@ https://github.com/elastic/beats/compare/v7.1.1...7.1[Check the HEAD diff]
- Fix goroutine leak caused on initialization failures of log input. {pull}12125[12125]
- Fix memory leak in Filebeat pipeline acker. {pull}12063[12063]
- 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 @@ -59,6 +60,7 @@ https://github.com/elastic/beats/compare/v7.1.1...7.1[Check the HEAD diff]
- Fix direction of incoming IPv6 sockets. {pull}12248[12248]
- 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]
- 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 bd4a48a

Please sign in to comment.