Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick #12333 to 7.1: Set client.authentication to required by default. #12342

Merged
merged 2 commits into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
ph marked this conversation as resolved.
Show resolved Hide resolved
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