Skip to content
Snippets Groups Projects
Commit 775db71e authored by ale's avatar ale
Browse files

Ensure secret tokens are deserialized as strings

Otherwise gopkg.in/yaml.v2 won't decode strings to []bytes.
parent 715507b5
Branches
No related tags found
No related merge requests found
...@@ -30,8 +30,8 @@ type Config struct { ...@@ -30,8 +30,8 @@ type Config struct {
rx *regexp.Regexp rx *regexp.Regexp
} `yaml:"service_ttls"` } `yaml:"service_ttls"`
AuthSessionLifetimeSeconds int `yaml:"auth_session_lifetime"` AuthSessionLifetimeSeconds int `yaml:"auth_session_lifetime"`
SessionSecrets [][]byte `yaml:"session_secrets"` SessionSecrets []string `yaml:"session_secrets"`
CSRFSecret []byte `yaml:"csrf_secret"` CSRFSecret string `yaml:"csrf_secret"`
AuthService string `yaml:"auth_service"` AuthService string `yaml:"auth_service"`
DeviceManager *device.Config `yaml:"device_manager"` DeviceManager *device.Config `yaml:"device_manager"`
...@@ -79,9 +79,9 @@ func (c *Config) valid() error { ...@@ -79,9 +79,9 @@ func (c *Config) valid() error {
// only. Print a warning. // only. Print a warning.
if len(c.SessionSecrets) == 0 { if len(c.SessionSecrets) == 0 {
log.Printf("Warning: session_secrets unset, generating temporary random session secrets") log.Printf("Warning: session_secrets unset, generating temporary random session secrets")
c.SessionSecrets = [][]byte{ c.SessionSecrets = []string{
securecookie.GenerateRandomKey(64), string(securecookie.GenerateRandomKey(64)),
securecookie.GenerateRandomKey(32), string(securecookie.GenerateRandomKey(32)),
} }
} }
......
...@@ -28,7 +28,7 @@ type Manager struct { ...@@ -28,7 +28,7 @@ type Manager struct {
// Config stores options for the device info manager. // Config stores options for the device info manager.
type Config struct { type Config struct {
AuthKey []byte `yaml:"auth_key"` AuthKey string `yaml:"auth_key"`
GeoIPDataFile string `yaml:"geo_ip_data"` GeoIPDataFile string `yaml:"geo_ip_data"`
TrustedForwarders []string `yaml:"trusted_forwarders"` TrustedForwarders []string `yaml:"trusted_forwarders"`
RemoteAddrHeader string `yaml:"remote_addr_header"` RemoteAddrHeader string `yaml:"remote_addr_header"`
...@@ -60,7 +60,7 @@ func New(config *Config) (*Manager, error) { ...@@ -60,7 +60,7 @@ func New(config *Config) (*Manager, error) {
return &Manager{ return &Manager{
geodb: geodb, geodb: geodb,
store: newStore(config.AuthKey), store: newStore([]byte(config.AuthKey)),
trustedForwarders: tf, trustedForwarders: tf,
remoteAddrHeader: hdr, remoteAddrHeader: hdr,
}, nil }, nil
......
...@@ -76,9 +76,18 @@ type Server struct { ...@@ -76,9 +76,18 @@ type Server struct {
csrfSecret []byte csrfSecret []byte
} }
func sl2bl(sl []string) [][]byte {
var out [][]byte
for _, s := range sl {
out = append(out, []byte(s))
}
return out
}
// New returns a new Server. // New returns a new Server.
func New(loginService *LoginService, authClient authclient.Client, config *Config) (*Server, error) { func New(loginService *LoginService, authClient authclient.Client, config *Config) (*Server, error) {
store := sessions.NewCookieStore(config.SessionSecrets...) sessionSecrets := sl2bl(config.SessionSecrets)
store := sessions.NewCookieStore(sessionSecrets...)
store.Options = &sessions.Options{ store.Options = &sessions.Options{
HttpOnly: true, HttpOnly: true,
Secure: true, Secure: true,
...@@ -89,7 +98,9 @@ func New(loginService *LoginService, authClient authclient.Client, config *Confi ...@@ -89,7 +98,9 @@ func New(loginService *LoginService, authClient authclient.Client, config *Confi
authSessionLifetime: defaultAuthSessionLifetime, authSessionLifetime: defaultAuthSessionLifetime,
authSessionStore: store, authSessionStore: store,
loginService: loginService, loginService: loginService,
csrfSecret: config.CSRFSecret, }
if config.CSRFSecret != "" {
s.csrfSecret = []byte(config.CSRFSecret)
} }
if config.AuthSessionLifetimeSeconds > 0 { if config.AuthSessionLifetimeSeconds > 0 {
s.authSessionLifetime = time.Duration(config.AuthSessionLifetimeSeconds) * time.Second s.authSessionLifetime = time.Duration(config.AuthSessionLifetimeSeconds) * time.Second
...@@ -99,7 +110,7 @@ func New(loginService *LoginService, authClient authclient.Client, config *Confi ...@@ -99,7 +110,7 @@ func New(loginService *LoginService, authClient authclient.Client, config *Confi
if err != nil { if err != nil {
return nil, err return nil, err
} }
s.loginHandler = newLoginHandler(s.loginCallback, devMgr, authClient, config.AuthService, config.SessionSecrets...) s.loginHandler = newLoginHandler(s.loginCallback, devMgr, authClient, config.AuthService, sessionSecrets...)
return s, nil return s, nil
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment