Skip to content

Commit 69c3588

Browse files
committed
allow provide optional static jwt seed
Signed-off-by: Jeeva Kandasamy <jkandasa@gmail.com>
1 parent 9abbcb5 commit 69c3588

File tree

10 files changed

+31
-18
lines changed

10 files changed

+31
-18
lines changed

cmd/helper/helper.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func setEnvironmentVariables(cfg *cfgTY.Config) error {
6363
types.ENV_LOG_ENCODING: cfg.Logger.Encoding,
6464
types.ENV_LOG_ENABLE_STACK_TRACE: cfg.Logger.EnableStacktrace,
6565
types.ENV_RUNNING_SINCE: time.Now().Format(time.RFC3339),
66+
types.ENV_JWT_SEED: cfg.JwtSeed,
6667
}
6768

6869
for key, value := range envMap {

pkg/http_router/middleware/auth.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,11 @@ func GetUserID(r *http.Request) string {
218218
}
219219

220220
func getJwtSecret() []byte {
221-
return []byte(fmt.Sprintf("%s_%s", types.GetEnvString(types.ENV_JWT_ACCESS_SECRET), version.Get().HostID))
221+
jwtSeed := types.GetEnvString(types.ENV_JWT_SEED)
222+
if jwtSeed == "" {
223+
jwtSeed = version.Get().HostID
224+
}
225+
return []byte(fmt.Sprintf("%s_%s", types.GetEnvString(types.ENV_JWT_ACCESS_SECRET), jwtSeed))
222226
}
223227

224228
// doSignout clears the cookies

pkg/types/config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const (
1212

1313
// Config of the system
1414
type Config struct {
15-
Secret string `yaml:"secret"` // secret used to encrypt sensitive data
15+
Secret string `yaml:"secret"` // secret used to encrypt sensitive data
16+
JwtSeed string `yaml:"jwt_seed"` // optional static seed used when deriving JWT secret, otherwise host-id is used
1617
Telemetry TelemetryConfig `yaml:"telemetry"`
1718
Web WebConfig `yaml:"web"`
1819
Logger LoggerConfig `yaml:"logger"`

pkg/types/environment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const (
2929
ENV_RUNNING_SINCE = "MC_RUNNING_SINCE" // update starting time
3030

3131
ENV_JWT_ACCESS_SECRET = "JWT_ACCESS_SECRET" // environment variable to set secret for JWT token
32+
ENV_JWT_SEED = "JWT_SEED" // environment variable to set seed for JWT token
3233
)
3334

3435
func GetEnvBool(key string) bool {

resources/sample-binary-gateway.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ gateway:
2424
disabled: false
2525
types: []
2626
ids: []
27-
labels:
27+
labels:
2828
location: external_gw1

resources/sample-binary-handler.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ handler:
2424
disabled: false
2525
types: []
2626
ids: []
27-
labels:
27+
labels:
2828
location: external_handler1

resources/sample-binary-server.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ secret: 5a2f6ff25b0025aeae12ae096363b51a # !!! WARNING: CHANGE THIS SECRET !!!
33
# disable telemetry service, if you do not wish to share non-PII data
44
# non-PII - non Personally Identifiable Information
55
telemetry:
6-
enabled: true
6+
enabled: true
7+
8+
# optional static jwt seed used when deriving JWT secret, otherwise host-id is used
9+
jwt_seed:
710

811
web:
912
web_directory: web_console
1013
enable_profiling: false
1114
read_timeout: 60s
1215
http:
13-
enabled: true
16+
enabled: true
1417
bind_address: "0.0.0.0"
1518
port: 8080
1619
https_ssl:
@@ -23,7 +26,7 @@ web:
2326
bind_address: "0.0.0.0"
2427
port: 9443
2528
cache_dir: mc_home/certs/https_acme
26-
acme_directory:
29+
acme_directory:
2730
email: hello@example.com
2831
domains: ["mycontroller.example.com"]
2932

@@ -71,17 +74,17 @@ database:
7174
dump_enabled: true
7275
dump_interval: 10m
7376
dump_dir: "memory_db"
74-
dump_format: ["yaml","json"]
77+
dump_format: ["yaml", "json"]
7578
load_format: "yaml"
7679

7780
metric:
7881
disabled: true
7982
type: influxdb
8083
uri: http://127.0.0.1:8086
81-
token:
84+
token:
8285
username:
8386
password:
84-
organization_name:
87+
organization_name:
8588
bucket_name: mycontroller
8689
batch_size:
8790
flush_interval: 1s

resources/sample-docker-gateway.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ gateway:
2525
types: []
2626
ids: []
2727
labels:
28-
location: external_gw1
28+
location: external_gw1

resources/sample-docker-handler.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ handler:
2525
types: []
2626
ids: []
2727
labels:
28-
location: external_handler1
28+
location: external_handler1

resources/sample-docker-server.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ secret: 5a2f6ff25b0025aeae12ae096363b51a # !!! WARNING: CHANGE THIS SECRET !!!
33
# disable telemetry service, if you do not wish to share non-PII data
44
# non-PII - non Personally Identifiable Information
55
telemetry:
6-
enabled: true
6+
enabled: true
7+
8+
# optional static jwt seed used when deriving JWT secret, otherwise host-id is used
9+
jwt_secret:
710

811
web:
912
web_directory: /ui
1013
enable_profiling: false
1114
read_timeout: 60s
1215
http:
13-
enabled: true
16+
enabled: true
1417
bind_address: "0.0.0.0"
1518
port: 8080
1619
https_ssl:
@@ -23,7 +26,7 @@ web:
2326
bind_address: "0.0.0.0"
2427
port: 9443
2528
cache_dir: /mc_home/certs/https_acme
26-
acme_directory:
29+
acme_directory:
2730
email: hello@example.com
2831
domains: ["mycontroller.example.com"]
2932

@@ -71,17 +74,17 @@ database:
7174
dump_enabled: true
7275
dump_interval: 10m
7376
dump_dir: "memory_db"
74-
dump_format: ["yaml","json"]
77+
dump_format: ["yaml", "json"]
7578
load_format: "yaml"
7679

7780
metric:
7881
disabled: true
7982
type: influxdb
8083
uri: http://192.168.1.21:8086
81-
token:
84+
token:
8285
username:
8386
password:
84-
organization_name:
87+
organization_name:
8588
bucket_name: mycontroller
8689
batch_size:
8790
flush_interval: 1s

0 commit comments

Comments
 (0)