Skip to content

Commit e9da69d

Browse files
committed
feat: add auth config to manager (#2161)
Fix GHSA-hpc8-7wpm-889w. Signed-off-by: Gaius <[email protected]>
1 parent d1d8eb4 commit e9da69d

File tree

9 files changed

+190
-12
lines changed

9 files changed

+190
-12
lines changed

deploy/docker-compose/template/manager.template.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ server:
3232
# In macos(just for testing), default value is /Users/$USER/.dragonfly/plugins.
3333
pluginDir: ''
3434

35+
auth:
36+
jwt:
37+
# Realm name to display to the user, default value is Dragonfly.
38+
realm: "Dragonfly"
39+
# Key is secret key used for signing, default value is
40+
# encoded base64 of dragonfly.
41+
# Please change the key in production.
42+
key: "ZHJhZ29uZmx5Cg=="
43+
# Timeout is duration that a jwt token is valid,
44+
# default duration is two days.
45+
timeout: 48h
46+
# MaxRefresh field allows clients to refresh their token
47+
# until MaxRefresh has passed, default duration is two days.
48+
maxRefresh: 48h
49+
3550
# Database info used for server.
3651
database:
3752
# Database type, supported types include mysql, mariadb and postgres.

manager/config/config.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ type Config struct {
3737
// Server configuration.
3838
Server ServerConfig `yaml:"server" mapstructure:"server"`
3939

40+
// Auth configuration.
41+
Auth AuthConfig `yaml:"auth" mapstructure:"auth"`
42+
4043
// Database configuration.
4144
Database DatabaseConfig `yaml:"database" mapstructure:"database"`
4245

@@ -79,6 +82,25 @@ type ServerConfig struct {
7982
REST RestConfig `yaml:"rest" mapstructure:"rest"`
8083
}
8184

85+
type AuthConfig struct {
86+
// JWT configuration.
87+
JWT JWTConfig `yaml:"jwt" mapstructure:"jwt"`
88+
}
89+
90+
type JWTConfig struct {
91+
// Realm name to display to the user, default value is Dragonfly.
92+
Realm string `yaml:"realm" mapstructure:"realm"`
93+
94+
// Key is secret key used for signing. Please change the key in production
95+
Key string `yaml:"key" mapstructure:"key"`
96+
97+
// Timeout is duration that a jwt token is valid, default duration is two days.
98+
Timeout time.Duration `yaml:"timeout" mapstructure:"timeout"`
99+
100+
// MaxRefresh field allows clients to refresh their token until MaxRefresh has passed, default duration is two days.
101+
MaxRefresh time.Duration `yaml:"maxRefresh" mapstructure:"maxRefresh"`
102+
}
103+
82104
type DatabaseConfig struct {
83105
// Database type.
84106
Type string `yaml:"type" mapstructure:"type"`
@@ -324,6 +346,13 @@ func New() *Config {
324346
Addr: DefaultRESTAddr,
325347
},
326348
},
349+
Auth: AuthConfig{
350+
JWT: JWTConfig{
351+
Realm: DefaultJWTRealm,
352+
Timeout: DefaultJWTTimeout,
353+
MaxRefresh: DefaultJWTMaxRefresh,
354+
},
355+
},
327356
Database: DatabaseConfig{
328357
Type: DatabaseTypeMysql,
329358
Mysql: MysqlConfig{
@@ -391,6 +420,22 @@ func (cfg *Config) Validate() error {
391420
return errors.New("grpc requires parameter listenIP")
392421
}
393422

423+
if cfg.Auth.JWT.Realm == "" {
424+
return errors.New("jwt requires parameter realm")
425+
}
426+
427+
if cfg.Auth.JWT.Key == "" {
428+
return errors.New("jwt requires parameter key")
429+
}
430+
431+
if cfg.Auth.JWT.Timeout == 0 {
432+
return errors.New("jwt requires parameter timeout")
433+
}
434+
435+
if cfg.Auth.JWT.MaxRefresh == 0 {
436+
return errors.New("jwt requires parameter maxRefresh")
437+
}
438+
394439
if cfg.Database.Type == "" {
395440
return errors.New("database requires parameter type")
396441
}

0 commit comments

Comments
 (0)