Skip to content

Commit c2f0889

Browse files
authored
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 <[email protected]>
1 parent 4a8ec21 commit c2f0889

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

pkg/auth/token/config.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,25 @@
1717
package token
1818

1919
import (
20-
"strconv"
20+
"time"
2121

2222
"github.com/minio/console/pkg/auth/utils"
2323
"github.com/minio/pkg/env"
2424
)
2525

26-
// ConsoleSTSDurationSeconds returns the default session duration for the STS requested tokens.
27-
func GetConsoleSTSDurationInSeconds() int {
28-
duration, err := strconv.Atoi(env.Get(ConsoleSTSDurationSeconds, "3600"))
26+
// GetConsoleSTSDuration returns the default session duration for the STS requested tokens (defaults to 1h)
27+
func GetConsoleSTSDuration() time.Duration {
28+
durationSeconds := env.Get(ConsoleSTSDurationSeconds, "")
29+
if durationSeconds != "" {
30+
duration, err := time.ParseDuration(durationSeconds + "s")
31+
if err != nil {
32+
duration = 1 * time.Hour
33+
}
34+
return duration
35+
}
36+
duration, err := time.ParseDuration(env.Get(ConsoleSTSDuration, "1h"))
2937
if err != nil {
30-
duration = 3600
38+
duration = 1 * time.Hour
3139
}
3240
return duration
3341
}

pkg/auth/token/const.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
package token
1818

1919
const (
20-
ConsoleSTSDurationSeconds = "CONSOLE_STS_DURATION_SECONDS"
20+
ConsoleSTSDurationSeconds = "CONSOLE_STS_DURATION_SECONDS" // (deprecated), set value in seconds for sts session, ie: 3600
21+
ConsoleSTSDuration = "CONSOLE_STS_DURATION" // time.Duration format, ie: 3600s, 2h45m, 1h, etc
2122
ConsolePBKDFPassphrase = "CONSOLE_PBKDF_PASSPHRASE"
2223
ConsolePBKDFSalt = "CONSOLE_PBKDF_SALT"
2324
)

restapi/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ func NewConsoleCredentials(accessKey, secretKey, location string) (*credentials.
326326
AccessKey: accessKey,
327327
SecretKey: secretKey,
328328
Location: location,
329-
DurationSeconds: xjwt.GetConsoleSTSDurationInSeconds(),
329+
DurationSeconds: int(xjwt.GetConsoleSTSDuration()),
330330
}
331331
stsAssumeRole := &credentials.STSAssumeRole{
332332
Client: GetConsoleHTTPClient(),

restapi/config.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"net/url"
2424
"strconv"
2525
"strings"
26-
"time"
2726

2827
miniov2 "github.com/minio/operator/pkg/apis/minio.min.io/v2"
2928

@@ -46,9 +45,6 @@ var (
4645

4746
// TLSRedirect console tls redirect rule
4847
TLSRedirect = "on"
49-
50-
// SessionDuration cookie validity duration
51-
SessionDuration = 45 * time.Minute
5248
)
5349

5450
func getMinIOServer() string {

restapi/utils.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"os"
2424
"strings"
2525
"time"
26+
27+
xjwt "github.com/minio/console/pkg/auth/token"
2628
)
2729

2830
// Do not use:
@@ -106,12 +108,13 @@ func FileExists(filename string) bool {
106108
}
107109

108110
func NewSessionCookieForConsole(token string) http.Cookie {
111+
sessionDuration := xjwt.GetConsoleSTSDuration()
109112
return http.Cookie{
110113
Path: "/",
111114
Name: "token",
112115
Value: token,
113-
MaxAge: int(SessionDuration.Seconds()), // 45 minutes
114-
Expires: time.Now().Add(SessionDuration),
116+
MaxAge: int(sessionDuration.Seconds()), // default 1 hr
117+
Expires: time.Now().Add(sessionDuration),
115118
HttpOnly: true,
116119
// if len(GlobalPublicCerts) > 0 is true, that means Console is running with TLS enable and the browser
117120
// should not leak any cookie if we access the site using HTTP

0 commit comments

Comments
 (0)