Skip to content

Commit 7484861

Browse files
FIX: Use STS env variable to increase the IDP token expiration (#3132)
Share link duration is based on the token expiration, this increases the IDP token expiration so the share link is able to last longer, by using an env variable called MINIO_STS_DURATION
1 parent 2c0a0b2 commit 7484861

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

pkg/auth/idp/oauth2/config.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ package oauth2
2020

2121
import (
2222
"crypto/sha1"
23-
"strconv"
2423
"strings"
25-
"time"
2624

2725
"github.com/minio/console/pkg/auth/token"
2826
"github.com/minio/pkg/v2/env"
@@ -106,15 +104,3 @@ func getSaltForIDPHmac() string {
106104
func getIDPScopes() string {
107105
return env.Get(ConsoleIDPScopes, "openid,profile,email")
108106
}
109-
110-
// getIDPTokenExpiration return default token expiration for access token
111-
func getIDPTokenExpiration() time.Duration {
112-
expiration := 12 * 3600
113-
if expStr := env.Get(ConsoleIDPTokenExpiration, ""); expStr != "" {
114-
if exp, err := strconv.Atoi(expStr); err == nil {
115-
expiration = exp
116-
}
117-
}
118-
119-
return time.Duration(expiration) * time.Second
120-
}

pkg/auth/idp/oauth2/provider.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ import (
2828
"strings"
2929
"time"
3030

31-
"github.com/minio/minio-go/v7/pkg/credentials"
32-
"github.com/minio/minio-go/v7/pkg/set"
33-
3431
"github.com/minio/console/pkg/auth/token"
3532
"github.com/minio/console/pkg/auth/utils"
33+
"github.com/minio/minio-go/v7/pkg/credentials"
34+
"github.com/minio/minio-go/v7/pkg/set"
35+
"github.com/minio/pkg/v2/env"
3636
"golang.org/x/crypto/pbkdf2"
3737
"golang.org/x/oauth2"
3838
xoauth2 "golang.org/x/oauth2"
@@ -331,14 +331,18 @@ func (client *Provider) VerifyIdentity(ctx context.Context, code, state, roleARN
331331
}
332332
client.RefreshToken = oauth2Token.RefreshToken
333333

334-
expiration := token.GetConsoleSTSDuration()
335-
if exp := getIDPTokenExpiration(); exp > 0 {
336-
expiration = exp
337-
}
334+
envStsDuration := env.Get(token.ConsoleSTSDuration, "")
335+
stsDuration, err := time.ParseDuration(envStsDuration)
336+
337+
expiration := 12 * time.Hour
338338

339-
// Use the expiration configured in the token itself if it is closer than the configured value
340-
if exp := oauth2Token.Expiry.Sub(time.Now().UTC()); exp < expiration {
341-
expiration = exp
339+
if err == nil && stsDuration > 0 {
340+
expiration = stsDuration
341+
} else {
342+
// Use the expiration configured in the token itself if it is closer than the configured value
343+
if exp := oauth2Token.Expiry.Sub(time.Now().UTC()); exp < expiration {
344+
expiration = exp
345+
}
342346
}
343347

344348
// Minimum duration in S3 spec is 15 minutes, do not bother returning

0 commit comments

Comments
 (0)