STS session token and console session cookie have same duration (#1202)

- `CONSOLE_STS_DURATION_IN_SECONDS` env renamed to `CONSOLE_STS_DURATION` to support more time formats

Signed-off-by: Lenin Alevski <alevsk.8772@gmail.com>
This commit is contained in:
Lenin Alevski
2021-11-09 21:41:00 -08:00
committed by GitHub
parent 4a8ec219cc
commit c2f0889ff8
5 changed files with 21 additions and 13 deletions

View File

@@ -17,17 +17,25 @@
package token
import (
"strconv"
"time"
"github.com/minio/console/pkg/auth/utils"
"github.com/minio/pkg/env"
)
// ConsoleSTSDurationSeconds returns the default session duration for the STS requested tokens.
func GetConsoleSTSDurationInSeconds() int {
duration, err := strconv.Atoi(env.Get(ConsoleSTSDurationSeconds, "3600"))
// GetConsoleSTSDuration returns the default session duration for the STS requested tokens (defaults to 1h)
func GetConsoleSTSDuration() time.Duration {
durationSeconds := env.Get(ConsoleSTSDurationSeconds, "")
if durationSeconds != "" {
duration, err := time.ParseDuration(durationSeconds + "s")
if err != nil {
duration = 1 * time.Hour
}
return duration
}
duration, err := time.ParseDuration(env.Get(ConsoleSTSDuration, "1h"))
if err != nil {
duration = 3600
duration = 1 * time.Hour
}
return duration
}

View File

@@ -17,7 +17,8 @@
package token
const (
ConsoleSTSDurationSeconds = "CONSOLE_STS_DURATION_SECONDS"
ConsoleSTSDurationSeconds = "CONSOLE_STS_DURATION_SECONDS" // (deprecated), set value in seconds for sts session, ie: 3600
ConsoleSTSDuration = "CONSOLE_STS_DURATION" // time.Duration format, ie: 3600s, 2h45m, 1h, etc
ConsolePBKDFPassphrase = "CONSOLE_PBKDF_PASSPHRASE"
ConsolePBKDFSalt = "CONSOLE_PBKDF_SALT"
)