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

Tls min version #400

Merged
merged 4 commits into from
Aug 21, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- github.com/aws/aws-sdk-go [PR395](https://github.com/observIQ/stanza/pull/395)
- golang.org/x/text [PR386](https://github.com/observIQ/stanza/pull/386)
- ARM64 Container Image: [PR381](https://github.com/observIQ/stanza/pull/381)
- TCP Input: Minimum TLS version is now configurable: [PR 400](https://github.com/observIQ/stanza/pull/400)

## 1.1.8 - 2021-08-19

Expand Down
72 changes: 72 additions & 0 deletions docs/operators/tcp_input.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The `tcp_input` operator supports TLS, disabled by default.
| `enable` | `false` | Boolean value to enable or disable TLS |
| `certificate` | | File path for the X509 certificate chain |
| `private_key` | | File path for the X509 private key |
| `min_version` | `1.0` | Minimum TLS version to accept connections from, defaults [TLS 1.0](https://pkg.go.dev/crypto/tls#Config)


### Example Configurations
Expand Down Expand Up @@ -56,3 +57,74 @@ Generated entries:
"record": "message2"
}
```

### Example TLS Configurations

#### Simple TLS

Configuration:
```yaml
pipeline:
- type: tcp_input
listen_address: 0.0.0.0:5000
tls:
enable: true
certificate: ./cert
private_key: ./key
- type: stdout
```

Send a log:
```bash
echo sample message | openssl s_client -connect localhost:5000
```

Generated entry:
```json
{
"timestamp": "2021-08-20T19:53:56.905051345-04:00",
"severity": 0,
"record": "sample message"
}
```

#### TLS 1.3

Configuration:
```yaml
pipeline:
- type: tcp_input
listen_address: 0.0.0.0:5000
tls:
enable: true
certificate: ./cert
private_key: ./key
min_version: 1.3
- type: stdout
```

Send a log with the `-tls1_3` flag:
```bash
echo sample message | openssl s_client -tls1_3 -connect localhost:5000
```

Generated entry:
```json
{
"timestamp": "2021-08-20T19:53:56.905051345-04:00",
"severity": 0,
"record": "sample message"
}
```

Try it a second time using a lower TLS version, such as `-tls1_2`, and it will fail:
```json
{
"level":"error",
"timestamp":"2021-08-20T19:56:38.108-0400",
"message":"Scanner error",
"operator_id":"$.tcp_input",
"operator_type":"tcp_input",
"error":"tls: client offered only unsupported versions: [303 302 301]"
}
```
30 changes: 22 additions & 8 deletions operator/builtin/input/tcp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ type TLSConfig struct {

// PrivateKey is the file path for the private key
PrivateKey string `json:"private_key,omitempty" yaml:"private_key,omitempty"`

// MinVersion is the minimum tls version
MinVersion float32 `json:"min_version,omitempty" yaml:"min_version,omitempty"`
}

// Build will build a tcp input operator.
Expand Down Expand Up @@ -104,13 +107,29 @@ func (c TCPInputConfig) Build(context operator.BuildContext) ([]operator.Operato
cert = c
}

var tlsMinVersion uint16
switch c.TLS.MinVersion {
case 0, 1.0:
// TLS 1.0 is the default version implemented by cypto/tls https://pkg.go.dev/crypto/tls#Config
tlsMinVersion = tls.VersionTLS10
case 1.1:
tlsMinVersion = tls.VersionTLS11
case 1.2:
tlsMinVersion = tls.VersionTLS12
case 1.3:
tlsMinVersion = tls.VersionTLS13
default:
return nil, fmt.Errorf("unsupported tls version: %f", c.TLS.MinVersion)
}

tcpInput := &TCPInput{
InputOperator: inputOperator,
address: c.ListenAddress,
maxBufferSize: int(c.MaxBufferSize),
addLabels: c.AddLabels,
tlsEnable: c.TLS.Enable,
tlsKeyPair: cert,
tlsMinVersion: tlsMinVersion,
backoff: backoff.Backoff{
Min: 100 * time.Millisecond,
Max: 3 * time.Second,
Expand All @@ -129,6 +148,7 @@ type TCPInput struct {
addLabels bool
tlsEnable bool
tlsKeyPair tls.Certificate
tlsMinVersion uint16
backoff backoff.Backoff

listener net.Listener
Expand Down Expand Up @@ -158,16 +178,10 @@ func (t *TCPInput) configureListener() error {
return nil
}

// TLS 1.0 is the package default since Go 1.2
// https://golang.org/pkg/crypto/tls/
// An issue has been filed to support modifyingn the minimum version
// https://github.com/observIQ/stanza/issues/349
var tlsVersion uint16 = tls.VersionTLS10

// #nosec - Go defaults to TLS 1.0, and some users may require it
// #nosec - User to specify tls minimum version
config := tls.Config{
Certificates: []tls.Certificate{t.tlsKeyPair},
MinVersion: tlsVersion,
MinVersion: t.tlsMinVersion,
}
config.Time = func() time.Time { return time.Now() }
config.Rand = rand.Reader
Expand Down
84 changes: 84 additions & 0 deletions operator/builtin/input/tcp/tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,90 @@ func TestBuild(t *testing.T) {
},
false,
},
{
"tls-min-version-default",
TCPInputConfig{
MaxBufferSize: 65536,
ListenAddress: "10.0.0.1:9000",
TLS: TLSConfig{
Enable: false,
Certificate: "/tmp/cert",
PrivateKey: "/tmp/key",
MinVersion: 0,
},
},
false,
},
{
"tls-min-version-1.0",
TCPInputConfig{
MaxBufferSize: 65536,
ListenAddress: "10.0.0.1:9000",
TLS: TLSConfig{
Enable: false,
Certificate: "/tmp/cert",
PrivateKey: "/tmp/key",
MinVersion: 1.0,
},
},
false,
},
{
"tls-min-version-1.1",
TCPInputConfig{
MaxBufferSize: 65536,
ListenAddress: "10.0.0.1:9000",
TLS: TLSConfig{
Enable: false,
Certificate: "/tmp/cert",
PrivateKey: "/tmp/key",
MinVersion: 1.1,
},
},
false,
},
{
"tls-min-version-1.2",
TCPInputConfig{
MaxBufferSize: 65536,
ListenAddress: "10.0.0.1:9000",
TLS: TLSConfig{
Enable: false,
Certificate: "/tmp/cert",
PrivateKey: "/tmp/key",
MinVersion: 1.2,
},
},
false,
},
{
"tls-min-version-1.3",
TCPInputConfig{
MaxBufferSize: 65536,
ListenAddress: "10.0.0.1:9000",
TLS: TLSConfig{
Enable: false,
Certificate: "/tmp/cert",
PrivateKey: "/tmp/key",
MinVersion: 1.3,
},
},
false,
},
{
"tls-invalid-min-version-1.4",
TCPInputConfig{
MaxBufferSize: 65536,
ListenAddress: "10.0.0.1:9000",
TLS: TLSConfig{
Enable: false,
Certificate: "/tmp/cert",
PrivateKey: "/tmp/key",
MinVersion: 1.4,
},
},
true,
},
{
"tls-enabled-with-no-such-file-error",
TCPInputConfig{
Expand Down