3
0

Make JWT secret gen more stable by using other ENV variables

This commit is contained in:
Denis Arh
2020-12-09 12:50:20 +01:00
parent 4c29350486
commit f3cc8b4990
2 changed files with 11 additions and 5 deletions

View File

@@ -1,12 +1,18 @@
package options
import (
"github.com/cortezaproject/corteza-server/pkg/rand"
"crypto/md5"
"fmt"
)
func (o *AuthOpt) Defaults() {
if o.Secret == "" {
o.Secret = string(rand.Bytes(32))
// if JWT secret is empty generate it from virtualhost/hostname and DB_DSN value.
// this will keep the secret the same through restarts
o.Secret = EnvString("DB_DSN", "memory")
// pick one of the env that holds hostname
o.Secret += EnvString("HOSTNAME", "localhost")
o.Secret = fmt.Sprintf("%x", md5.Sum([]byte(o.Secret)))
}
}

View File

@@ -12,8 +12,8 @@ props:
[IMPORTANT]
====
Make sure to provide a secret.
If you don't, a random value is assigned -- this causes all of the tokens to become invalid after a server restart.
If JWT secret is not set, system auto-generates one from DB_DSN and HOSTNAME environment variables.
Generated secret will change if you change any of variables.
====
- name: expiry