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

Add TLS support to http server #332

Merged
merged 4 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 .defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ vouch:
# whiteList:
# teamWhitelist:

tls:
# cert:
# key:
profile: intermediate

jwt:
# secret:
issuer: Vouch
Expand Down
5 changes: 5 additions & 0 deletions config/config.yml_example
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ vouch:
# - myOrg
# - myOrg/myTeam

tls:
Copy link
Member

Choose a reason for hiding this comment

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

Please include the the env var names in the documentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

# cert: /path/to/signed_cert_plus_intermediates # Path to certificate file
# key: /path/to/private_key # Path to key file
profile: intermediate # TLS configuration profile (modern, intermediate, old, default)

jwt:
# secret - VOUCH_JWT_SECRET
# a random string used to cryptographically sign the jwt
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ func main() {
ErrorLog: log.New(&fwdToZapWriter{fastlog}, "", 0),
}

if cfg.Cfg.TLS.Cert != "" || cfg.Cfg.TLS.Key != "" {
srv.TLSConfig = cfg.TLSConfig(cfg.Cfg.TLS.Profile)
logger.Fatal(srv.ListenAndServeTLS(cfg.Cfg.TLS.Cert, cfg.Cfg.TLS.Key))
}

Copy link
Member

@bnfinet bnfinet Nov 17, 2020

Choose a reason for hiding this comment

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

althought logger.Fatal is an exit event, could you please put the following srv.ListenAndServe (non TLS) in an else block for clarity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

logger.Fatal(srv.ListenAndServe())

}
Expand Down
8 changes: 7 additions & 1 deletion pkg/cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ type Config struct {
TeamWhiteList []string `mapstructure:"teamWhitelist"`
AllowAllUsers bool `mapstructure:"allowAllUsers"`
PublicAccess bool `mapstructure:"publicAccess"`
JWT struct {

TLS struct {
Cert string `mapstructure:"cert"`
Key string `mapstructure:"key"`
Profile string `mapstructure:"profile"`
}
JWT struct {
MaxAge int `mapstructure:"maxAge"` // in minutes
Issuer string `mapstructure:"issuer"`
Secret string `mapstructure:"secret"`
Expand Down
69 changes: 69 additions & 0 deletions pkg/cfg/tls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*

Copyright 2020 The Vouch Proxy Authors.
Use of this source code is governed by The MIT License (MIT) that
can be found in the LICENSE file. Software distributed under The
MIT License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
OR CONDITIONS OF ANY KIND, either express or implied.

*/

package cfg

import (
"crypto/tls"
)

// TLSConfig config returns a *tls.Config with the specified profile (modern, intermediate, old, default) configuration.
func TLSConfig(profile string) *tls.Config {
c := &tls.Config{}

// Source: https://ssl-config.mozilla.org/#server=go&version=1.14&config=modern&hsts=false&guideline=5.6
switch profile {
case "modern":
c = &tls.Config{
MinVersion: tls.VersionTLS13,
}
case "intermediate":
c = &tls.Config{
MinVersion: tls.VersionTLS12,
CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
PreferServerCipherSuites: true,
CipherSuites: []uint16{
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
},
}
case "old":
c = &tls.Config{
MinVersion: tls.VersionTLS10,
PreferServerCipherSuites: true,
CipherSuites: []uint16{
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
tls.TLS_RSA_WITH_AES_128_GCM_SHA256,
tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_RSA_WITH_AES_128_CBC_SHA256,
tls.TLS_RSA_WITH_AES_128_CBC_SHA,
tls.TLS_RSA_WITH_AES_256_CBC_SHA,
tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA,
},
}
}

return c
}