Skip to content

Commit

Permalink
make jwt signing algorithm configurable
Browse files Browse the repository at this point in the history
Signed-off-by: mornyx <[email protected]>
  • Loading branch information
mornyx committed Sep 19, 2024
1 parent 3305937 commit fd91e5e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions cmd/tidb-dashboard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func NewCLIConfig() *DashboardCLIConfig {
flag.IntVar(&cfg.CoreConfig.NgmTimeout, "ngm-timeout", cfg.CoreConfig.NgmTimeout, "timeout secs for accessing the ngm API")
flag.BoolVar(&cfg.CoreConfig.EnableKeyVisualizer, "keyviz", true, "enable/disable key visualizer(default: true)")
flag.BoolVar(&cfg.CoreConfig.DisableCustomPromAddr, "disable-custom-prom-addr", false, "do not allow custom prometheus address")
flag.StringVar(&cfg.CoreConfig.SigningAlgorithm, "signing-algorithm", cfg.CoreConfig.SigningAlgorithm, "signing algorithm for jwt (HS256, HS384, HS512, RS256, RS384, RS512)")
flag.Float64Var(&cfg.CoreConfig.UnauthedAPIQpsLimit, "unauthed-api-qps-limit", cfg.CoreConfig.UnauthedAPIQpsLimit, "unauthed API qps limit")
flag.IntVar(&cfg.CoreConfig.UnauthedAPIBurstLimit, "unauthed-api-burst-limit", cfg.CoreConfig.UnauthedAPIBurstLimit, "unauthed API burst limit")

Expand Down
13 changes: 7 additions & 6 deletions pkg/apiserver/user/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (a BaseAuthenticator) SignOutInfo(_ *utils.SessionUser, _ string) (*SignOut
return &SignOutInfo{}, nil
}

func NewAuthService(featureFlags *featureflag.Registry) *AuthService {
func NewAuthService(featureFlags *featureflag.Registry, config *config.Config) *AuthService {
var secret *[32]byte

secretStr := os.Getenv("DASHBOARD_SESSION_SECRET")
Expand Down Expand Up @@ -110,11 +110,12 @@ func NewAuthService(featureFlags *featureflag.Registry) *AuthService {
}

middleware, err := jwt.New(&jwt.GinJWTMiddleware{
IdentityKey: utils.SessionUserKey,
Realm: "dashboard",
Key: secret[:],
Timeout: time.Hour * 24,
MaxRefresh: time.Hour * 24,
IdentityKey: utils.SessionUserKey,
Realm: "dashboard",
Key: secret[:],
Timeout: time.Hour * 24,
MaxRefresh: time.Hour * 24,
SigningAlgorithm: config.SigningAlgorithm,
Authenticator: func(c *gin.Context) (interface{}, error) {
var form AuthenticateForm
if err := c.ShouldBindJSON(&form); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Config struct {

NgmTimeout int // in seconds

SigningAlgorithm string
UnauthedAPIQpsLimit float64
UnauthedAPIBurstLimit int
}
Expand All @@ -57,6 +58,7 @@ func Default() *Config {
DisableCustomPromAddr: false,
FeatureVersion: version.PDVersion,
NgmTimeout: 30, // s
SigningAlgorithm: "",
UnauthedAPIQpsLimit: 0,
UnauthedAPIBurstLimit: 0,
}
Expand Down

0 comments on commit fd91e5e

Please sign in to comment.