@@ -21,8 +21,10 @@ import (
2121 "encoding/json"
2222 "net/http"
2323 "net/url"
24+ "strconv"
2425 "time"
2526
27+ jwtgo "github.com/golang-jwt/jwt/v4"
2628 "github.com/minio/pkg/bucket/policy/condition"
2729
2830 minioIAMPolicy "github.com/minio/pkg/iam/policy"
@@ -70,6 +72,20 @@ func registerSessionHandlers(api *operations.ConsoleAPI) {
7072 })
7173}
7274
75+ func getClaimsFromToken (sessionToken string ) (map [string ]interface {}, error ) {
76+ jp := new (jwtgo.Parser )
77+ jp .ValidMethods = []string {
78+ "RS256" , "RS384" , "RS512" , "ES256" , "ES384" , "ES512" ,
79+ "RS3256" , "RS3384" , "RS3512" , "ES3256" , "ES3384" , "ES3512" ,
80+ }
81+ var claims jwtgo.MapClaims
82+ _ , _ , err := jp .ParseUnverified (sessionToken , & claims )
83+ if err != nil {
84+ return nil , err
85+ }
86+ return claims , nil
87+ }
88+
7389// getSessionResponse parse the token of the current session and returns a list of allowed actions to render in the UI
7490func getSessionResponse (session * models.Principal ) (* models.SessionResponse , * models.Error ) {
7591 ctx , cancel := context .WithTimeout (context .Background (), 20 * time .Second )
@@ -104,12 +120,44 @@ func getSessionResponse(session *models.Principal) (*models.SessionResponse, *mo
104120 actions = acl .GetActionsStringFromPolicy (policy )
105121 }
106122
123+ currTime := time .Now ().UTC ()
124+
107125 // This actions will be global, meaning has to be attached to all resources
108126 conditionValues := map [string ][]string {
109127 condition .AWSUsername .Name (): {session .AccountAccessKey },
128+ // All calls to MinIO from console use temporary credentials.
129+ condition .AWSPrincipalType .Name (): {"AssumeRole" },
130+ condition .AWSSecureTransport .Name (): {strconv .FormatBool (getMinIOEndpointIsSecure ())},
131+ condition .AWSCurrentTime .Name (): {currTime .Format (time .RFC3339 )},
132+ condition .AWSEpochTime .Name (): {strconv .FormatInt (currTime .Unix (), 10 )},
133+
134+ // All calls from console are signature v4.
135+ condition .S3SignatureVersion .Name (): {"AWS4-HMAC-SHA256" },
136+ // All calls from console are signature v4.
137+ condition .S3AuthType .Name (): {"REST-HEADER" },
138+ // This is usually empty, may be set some times (rare).
139+ condition .S3LocationConstraint .Name (): {GetMinIORegion ()},
140+ }
141+
142+ claims , err := getClaimsFromToken (session .STSSessionToken )
143+ if err != nil {
144+ return nil , prepareError (err , errorGenericInvalidSession )
145+ }
146+
147+ // Support all LDAP, JWT variables
148+ for k , v := range claims {
149+ vstr , ok := v .(string )
150+ if ! ok {
151+ // skip all non-strings
152+ continue
153+ }
154+ // store all claims from sessionToken
155+ conditionValues [k ] = []string {vstr }
110156 }
157+
111158 defaultActions := policy .IsAllowedActions ("" , "" , conditionValues )
112159 consoleResourceName := "console-ui"
160+
113161 permissions := map [string ]minioIAMPolicy.ActionSet {
114162 consoleResourceName : defaultActions ,
115163 }
0 commit comments