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

nsqd: add --tls-min-version config option #513

Merged
merged 3 commits into from
Dec 10, 2014
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: 1 addition & 1 deletion apps/nsq_to_nsq/nsq_to_nsq.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func init() {

type PublishHandler struct {
// 64bit atomic vars need to be first for proper alignment on 32bit platforms
counter uint64
counter uint64

addresses util.StringArray
producers map[string]*nsq.Producer
Expand Down
34 changes: 27 additions & 7 deletions apps/nsqd/nsqd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"crypto/tls"
"flag"
"fmt"
"log"
Expand Down Expand Up @@ -72,6 +73,7 @@ var (
tlsClientAuthPolicy = flagSet.String("tls-client-auth-policy", "", "client certificate auth policy ('require' or 'require-verify')")
tlsRootCAFile = flagSet.String("tls-root-ca-file", "", "path to private certificate authority pem")
tlsRequired tlsRequiredOption
tlsMinVersion tlsVersionOption

// compression
deflateEnabled = flagSet.Bool("deflate", true, "enable deflate feature negotiation (client compression)")
Expand Down Expand Up @@ -99,22 +101,40 @@ func (t *tlsRequiredOption) Set(s string) error {
func (t *tlsRequiredOption) Get() interface{} { return *t }

func (t *tlsRequiredOption) String() string {
switch *t {
case nsqd.TLSRequiredExceptHTTP:
return "1"
case nsqd.TLSRequired:
return "2"
}
return "0"
return strconv.FormatInt(int64(*t), 10)
}

func (t *tlsRequiredOption) IsBoolFlag() bool { return true }

type tlsVersionOption uint16

func (t *tlsVersionOption) Set(s string) error {
s = strings.ToLower(s)
switch s {
case "tls10":
*t = tls.VersionTLS10
case "tls11":
*t = tls.VersionTLS11
case "tls12":
*t = tls.VersionTLS12
default:
*t = tls.VersionSSL30
}
return nil
}

func (t *tlsVersionOption) Get() interface{} { return *t }

func (t *tlsVersionOption) String() string {
return strconv.FormatInt(int64(*t), 10)
}

func init() {
flagSet.Var(&lookupdTCPAddrs, "lookupd-tcp-address", "lookupd TCP address (may be given multiple times)")
flagSet.Var(&e2eProcessingLatencyPercentiles, "e2e-processing-latency-percentile", "message processing time percentiles to keep track of (can be specified multiple times or comma separated, default none)")
flagSet.Var(&authHttpAddresses, "auth-http-address", "<addr>:<port> to query auth server (may be given multiple times)")
flagSet.Var(&tlsRequired, "tls-required", "require TLS for client connections (true, false, tcp-https)")
flagSet.Var(&tlsMinVersion, "tls-min-version", "minimum SSL/TLS version acceptable ('ssl30', 'tls10', 'tls11', or 'tls12')")
}

func main() {
Expand Down
1 change: 1 addition & 0 deletions nsqd/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func TestHTTPSRequire(t *testing.T) {
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{cert},
InsecureSkipVerify: true,
MinVersion: 0,
}
transport := &http.Transport{
TLSClientConfig: tlsConfig,
Expand Down
1 change: 1 addition & 0 deletions nsqd/nsqd.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ func buildTLSConfig(opts *nsqdOptions) (*tls.Config, error) {
tlsConfig = &tls.Config{
Certificates: []tls.Certificate{cert},
ClientAuth: tlsClientAuthPolicy,
MinVersion: uint16(opts.TLSMinVersion),
}

if opts.TLSRootCAFile != "" {
Expand Down
1 change: 1 addition & 0 deletions nsqd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type nsqdOptions struct {
TLSClientAuthPolicy string `flag:"tls-client-auth-policy"`
TLSRootCAFile string `flag:"tls-root-ca-file"`
TLSRequired int `flag:"tls-required"`
TLSMinVersion int `flag:"tls-min-version"`

// compression
DeflateEnabled bool `flag:"deflate"`
Expand Down
4 changes: 2 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LOOKUPD_PID=$!

# build and run nsqd configured to use our lookupd above
NSQD_LOGFILE=$(mktemp -t nsqd.XXXXXXX)
cmd="apps/nsqd/nsqd --data-path=/tmp --lookupd-tcp-address=127.0.0.1:4160 --tls-cert=nsqd/test/certs/cert.pem --tls-key=nsqd/test/certs/key.pem"
cmd="apps/nsqd/nsqd --data-path=/tmp --lookupd-tcp-address=127.0.0.1:4160 --tls-cert=nsqd/test/certs/cert.pem --tls-key=nsqd/test/certs/key.pem --tls-min-version=ssl30"
echo "building and starting $cmd"
echo " logging to $NSQD_LOGFILE"
go build -o apps/nsqd/nsqd ./apps/nsqd
Expand Down Expand Up @@ -39,4 +39,4 @@ for dir in nsqadmin apps/* bench/*; do
else
echo "WARNING: skipping go build in $dir"
fi
done
done