Skip to content

Commit

Permalink
Get tenant configured region and set on STS Options (#1856)
Browse files Browse the repository at this point in the history
Signed-off-by: pjuarezd <pjuarezd@users.noreply.github.com>
  • Loading branch information
pjuarezd committed Nov 15, 2023
1 parent e2b0094 commit 377fa02
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/controller/sts.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func GetPolicy(ctx context.Context, adminClient *madmin.AdminClient, policyName
}

// AssumeRole invokes the AssumeRole method in the Minio Tenant
func AssumeRole(ctx context.Context, c *Controller, tenant *miniov2.Tenant, sessionPolicy string, duration int) (*credentials.Value, error) {
func AssumeRole(ctx context.Context, c *Controller, tenant *miniov2.Tenant, region string, sessionPolicy string, duration int) (*credentials.Value, error) {
client, accessKey, secretKey, err := getTenantClient(ctx, c, tenant)
if err != nil {
return nil, err
Expand All @@ -330,6 +330,7 @@ func AssumeRole(ctx context.Context, c *Controller, tenant *miniov2.Tenant, sess
SecretKey: secretKey,
Policy: sessionPolicy,
DurationSeconds: duration,
Location: region,
}

stsAssumeRole := &credentials.STSAssumeRole{
Expand Down
9 changes: 8 additions & 1 deletion pkg/controller/sts_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ func (c *Controller) AssumeRoleWithWebIdentityHandler(w http.ResponseWriter, r *
return
}

info, err := adminClient.ServerInfo(ctx)
if err != nil {
writeSTSErrorResponse(w, true, ErrSTSInternalError, fmt.Errorf("Error communicating with tenant '%s': %s", tenant.Name, err))
return
}
region := info.Region

// Session Policy
sessionPolicyStr := r.Form.Get(stsPolicy)
var compactedSessionPolicy string
Expand Down Expand Up @@ -252,7 +259,7 @@ func (c *Controller) AssumeRoleWithWebIdentityHandler(w http.ResponseWriter, r *
durationInSeconds = duration
}

stsCredentials, err := AssumeRole(ctx, c, &tenant, bfCompact, durationInSeconds)
stsCredentials, err := AssumeRole(ctx, c, &tenant, region, bfCompact, durationInSeconds)
if err != nil {
writeSTSErrorResponse(w, true, ErrSTSInternalError, err)
return
Expand Down

0 comments on commit 377fa02

Please sign in to comment.