Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support variable JWT session durations #1839

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ func Init() {
SigningPassphrase: "",
SigningPassphraseFile: "",
TokenValidation: 0,
TokenDuration: 20,
MaxUploadFileSize: 0,
Cors: httpd.CorsConfig{
Enabled: false,
Expand Down Expand Up @@ -2131,6 +2132,7 @@ func setViperDefaults() {
viper.SetDefault("httpd.signing_passphrase", globalConf.HTTPDConfig.SigningPassphrase)
viper.SetDefault("httpd.signing_passphrase_file", globalConf.HTTPDConfig.SigningPassphraseFile)
viper.SetDefault("httpd.token_validation", globalConf.HTTPDConfig.TokenValidation)
viper.SetDefault("httpd.token_duration", globalConf.HTTPDConfig.TokenDuration)
viper.SetDefault("httpd.max_upload_file_size", globalConf.HTTPDConfig.MaxUploadFileSize)
viper.SetDefault("httpd.cors.enabled", globalConf.HTTPDConfig.Cors.Enabled)
viper.SetDefault("httpd.cors.allowed_origins", globalConf.HTTPDConfig.Cors.AllowedOrigins)
Expand Down
3 changes: 3 additions & 0 deletions internal/httpd/httpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,8 @@ type Conf struct {
// By default all the available security checks are enabled. Set to 1 to disable the requirement
// that a token must be used by the same IP for which it was issued.
TokenValidation int `json:"token_validation" mapstructure:"token_validation"`
// TokenDuration sets the duration of JWT tokens in minutes, by default this is set to 20 minutes.
TokenDuration int `json:"token_duration" mapstructure:"token_duration"`
// MaxUploadFileSize Defines the maximum request body size, in bytes, for Web Client/API HTTP upload requests.
// 0 means no limit
MaxUploadFileSize int64 `json:"max_upload_file_size" mapstructure:"max_upload_file_size"`
Expand Down Expand Up @@ -1003,6 +1005,7 @@ func (c *Conf) Initialize(configDir string, isShared int) error {
maxUploadFileSize = c.MaxUploadFileSize
installationCode = c.Setup.InstallationCode
installationCodeHint = c.Setup.InstallationCodeHint
tokenDuration = time.Duration(c.TokenDuration) * time.Minute
startCleanupTicker(tokenDuration / 2)
c.setTokenValidationMode()
return <-exitChannel
Expand Down
1 change: 1 addition & 0 deletions sftpgo.json
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@
"signing_passphrase": "",
"signing_passphrase_file": "",
"token_validation": 0,
"token_duration": 20,
"max_upload_file_size": 0,
"cors": {
"enabled": false,
Expand Down