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

Fabio can connect to Consul using TLS for secure communication. #391

Closed
wants to merge 6 commits into from
Closed
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
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,9 @@ type Consul struct {
CheckTLSSkipVerify bool
CheckDeregisterCriticalServiceAfter string
ChecksRequired string
EnableSSL bool
VerifySSL bool
CAFile string
CertFile string
KeyFile string
}
2 changes: 2 additions & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ var defaultConfig = &Config{
CheckScheme: "http",
CheckDeregisterCriticalServiceAfter: "90m",
ChecksRequired: "one",
EnableSSL: false,
VerifySSL: false,
},
Timeout: 10 * time.Second,
Retry: 500 * time.Millisecond,
Expand Down
5 changes: 5 additions & 0 deletions config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ func load(cmdline, environ, envprefix []string, props *properties.Properties) (c
f.StringVar(&cfg.Registry.Consul.KVPath, "registry.consul.kvpath", defaultConfig.Registry.Consul.KVPath, "consul KV path for manual overrides")
f.StringVar(&cfg.Registry.Consul.NoRouteHTMLPath, "registry.consul.noroutehtmlpath", defaultConfig.Registry.Consul.NoRouteHTMLPath, "consul KV path for HTML returned when no route is found")
f.StringVar(&cfg.Registry.Consul.TagPrefix, "registry.consul.tagprefix", defaultConfig.Registry.Consul.TagPrefix, "prefix for consul tags")
f.BoolVar(&cfg.Registry.Consul.EnableSSL, "registry.consul.enableSSL", defaultConfig.Registry.Consul.EnableSSL, "enable HTTPS communication with Consul")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uppercase words are not parsed by flag library. If you change it to lower case flag will parse it correctly. I mean - registry.consul.enableSSL change to registry.consul.enablessl
same for other added parametes

  • change to lowercase if property file

f.BoolVar(&cfg.Registry.Consul.VerifySSL, "registry.consul.verifySSL", defaultConfig.Registry.Consul.VerifySSL, "enable or disable SSL verification with Consul")
f.StringVar(&cfg.Registry.Consul.CAFile, "registry.consul.caFile", defaultConfig.Registry.Consul.CAFile, "the path to the ca certificate used for Consul communication")
f.StringVar(&cfg.Registry.Consul.CertFile, "registry.consul.certFile", defaultConfig.Registry.Consul.CertFile, "the path to the certificate for Consul communication")
f.StringVar(&cfg.Registry.Consul.KeyFile, "registry.consul.keyFile", defaultConfig.Registry.Consul.KeyFile, "the path to the private key for Consul communication")
f.BoolVar(&cfg.Registry.Consul.Register, "registry.consul.register.enabled", defaultConfig.Registry.Consul.Register, "register fabio in consul")
f.StringVar(&cfg.Registry.Consul.ServiceAddr, "registry.consul.register.addr", defaultConfig.Registry.Consul.ServiceAddr, "service registration address")
f.StringVar(&cfg.Registry.Consul.ServiceName, "registry.consul.register.name", defaultConfig.Registry.Consul.ServiceName, "service registration name")
Expand Down
100 changes: 100 additions & 0 deletions fabio.properties
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,106 @@
#
# registry.consul.noroutehtmlpath = /fabio/noroute.html

# registry.consul.enableSSL enables HTTPS communication with Consul.
#
# Consul support TLS client communication and this flag is used to
# enable Fabio to talk to Consul over HTTPS.
#
# The default is
#
# registry.consul.enableSSL = false


# registry.consul.verifySSL enable SSL verification with Consul.
#
# VerifySSL enables or disables SSL verification when the transport scheme
# for the Consul API client is HTTPS
#
# The default is
#
# registry.consul.verifySSL = false


# registry.consul.caFile the path to the ca certificate used for Consul communication.
#
# This is the full path to the CA certificate to use when communicating
# with Consul over HTTPS.
#
# The default is
#
# registry.consul.caFile =


# registry.consul.CertFile the path to the TLS certificate used for Consul communication.
#
# This is the full path to the TLS certificate to use when communicating
# with Consul over HTTPS.
#
# The default is
#
# registry.consul.CertFile =


# registry.consul.KeyFile the path to the TLS certificate key used for Consul communication.
#
# This is the full path to the TLS ckey ertificate to use when communicating
# with Consul over HTTPS.
#
# The default is
#
# registry.consul.KeyFile =


# registry.consul.enableSSL enables HTTPS communication with Consul.
#
# Consul support TLS client communication and this flag is used to
# enable Fabio to talk to Consul over HTTPS.
#
# The default is
#
# registry.consul.enableSSL = false


# registry.consul.verifySSL enable SSL verification with Consul.
#
# VerifySSL enables or disables SSL verification when the transport scheme
# for the Consul API client is HTTPS
#
# The default is
#
# registry.consul.verifySSL = false


# registry.consul.caFile the path to the ca certificate used for Consul communication.
#
# This is the full path to the CA certificate to use when communicating
# with Consul over HTTPS.
#
# The default is
#
# registry.consul.caFile =


# registry.consul.CertFile the path to the TLS certificate used for Consul communication.
#
# This is the full path to the TLS certificate to use when communicating
# with Consul over HTTPS.
#
# The default is
#
# registry.consul.CertFile =


# registry.consul.KeyFile the path to the TLS certificate key used for Consul communication.
#
# This is the full path to the TLS ckey ertificate to use when communicating
# with Consul over HTTPS.
#
# The default is
#
# registry.consul.KeyFile =


# registry.consul.service.status configures the valid service status
# values for services included in the routing table.
#
Expand Down
17 changes: 16 additions & 1 deletion registry/consul/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,23 @@ type be struct {
}

func NewBackend(cfg *config.Consul) (registry.Backend, error) {

var tls api.TLSConfig

if cfg.EnableSSL {
cfg.Scheme = "https"

tls := &api.TLSConfig{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tls variable is shadowed here. Here should be
tls = api.TLSConfig{

Address: cfg.Addr,
CAFile: cfg.CAFile,
CertFile: cfg.CertFile,
KeyFile: cfg.KeyFile,
}
tls.InsecureSkipVerify = !cfg.VerifySSL
}

// create a reusable client
c, err := api.NewClient(&api.Config{Address: cfg.Addr, Scheme: cfg.Scheme, Token: cfg.Token})
c, err := api.NewClient(&api.Config{Address: cfg.Addr, Scheme: cfg.Scheme, Token: cfg.Token, TLSConfig: tls})
if err != nil {
return nil, err
}
Expand Down
35 changes: 35 additions & 0 deletions vendor/github.com/hashicorp/consul/api/acl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 15 additions & 11 deletions vendor/github.com/hashicorp/consul/api/agent.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading