Browse Source

refactor: automatically generate jwt signing key

main
ning 2 years ago
parent
commit
638c62da2f
7 changed files with 23 additions and 10 deletions
  1. +2
    -0
      center/center.go
  2. +0
    -2
      docker/compose-bridge/etc-nightingale/config.toml
  3. +0
    -2
      docker/compose-host-network-metric-log/etc-nightingale/config.toml
  4. +0
    -2
      docker/compose-host-network/etc-nightingale/config.toml
  5. +0
    -2
      docker/compose-postgres/n9eetc_pg/config.toml
  6. +0
    -2
      etc/config.toml
  7. +21
    -0
      models/configs.go

+ 2
- 0
center/center.go View File

@@ -64,6 +64,8 @@ func Initialize(configDir string, cryptoKey string) (func(), error) {
migrate.Migrate(db)
models.InitRoot(ctx)

config.HTTP.JWTAuth.SigningKey = models.InitJWTSigningKey(ctx)

err = rsa.InitRSAConfig(ctx, &config.HTTP.RSA)
if err != nil {
return nil, err


+ 0
- 2
docker/compose-bridge/etc-nightingale/config.toml View File

@@ -55,8 +55,6 @@ Enable = true
user001 = "ccc26da7b9aba533cbb263a36c07dcc5"

[HTTP.JWTAuth]
# signing key
SigningKey = "5b94a0fd640fe2765af826acfe42d151"
# unit: min
AccessExpired = 1500
# unit: min


+ 0
- 2
docker/compose-host-network-metric-log/etc-nightingale/config.toml View File

@@ -55,8 +55,6 @@ Enable = true
user001 = "ccc26da7b9aba533cbb263a36c07dcc5"

[HTTP.JWTAuth]
# signing key
SigningKey = "5b94a0fd640fe2765af826acfe42d151"
# unit: min
AccessExpired = 1500
# unit: min


+ 0
- 2
docker/compose-host-network/etc-nightingale/config.toml View File

@@ -55,8 +55,6 @@ Enable = true
user001 = "ccc26da7b9aba533cbb263a36c07dcc5"

[HTTP.JWTAuth]
# signing key
SigningKey = "5b94a0fd640fe2765af826acfe42d151"
# unit: min
AccessExpired = 1500
# unit: min


+ 0
- 2
docker/compose-postgres/n9eetc_pg/config.toml View File

@@ -55,8 +55,6 @@ Enable = true
user001 = "ccc26da7b9aba533cbb263a36c07dcc5"

[HTTP.JWTAuth]
# signing key
SigningKey = "5b94a0fd640fe2765af826acfe42d151"
# unit: min
AccessExpired = 1500
# unit: min


+ 0
- 2
etc/config.toml View File

@@ -55,8 +55,6 @@ Enable = true
user001 = "ccc26da7b9aba533cbb263a36c07dcc5"

[HTTP.JWTAuth]
# signing key
SigningKey = "5b94a0fd640fe2765af826acfe42d151"
# unit: min
AccessExpired = 1500
# unit: min


+ 21
- 0
models/configs.go View File

@@ -44,8 +44,29 @@ const (
RSA_PRIVATE_KEY = "rsa_private_key"
RSA_PUBLIC_KEY = "rsa_public_key"
RSA_PASSWORD = "rsa_password"
JWT_SIGNING_KEY = "jwt_signing_key"
)

func InitJWTSigningKey(ctx *ctx.Context) string {
val, err := ConfigsGet(ctx, JWT_SIGNING_KEY)
if err != nil {
log.Fatalln("init jwt signing key in mysql", err)
}

if val != "" {
return val
}

content := fmt.Sprintf("%s%d%d%s", runner.Hostname, os.Getpid(), time.Now().UnixNano(), str.RandLetters(6))
key := str.MD5(content)
err = ConfigsSet(ctx, JWT_SIGNING_KEY, key)
if err != nil {
log.Fatalln("init jwt signing key in mysql", err)
}

return key
}

// InitSalt generate random salt
func InitSalt(ctx *ctx.Context) {
val, err := ConfigsGet(ctx, SALT)


Loading…
Cancel
Save