Browse Source
STS: add GetCallerIdentity support (#8893)
STS: add GetCallerIdentity support (#8893)
* STS: add GetCallerIdentity support Implement the AWS STS GetCallerIdentity action, which returns the ARN, account ID, and user ID of the caller based on SigV4 authentication. This is commonly used by AWS SDKs and CLI tools (e.g. `aws sts get-caller-identity`) to verify credentials and determine the authenticated identity. * test: remove trivial GetCallerIdentity tests Remove the XML unmarshal test (we don't consume this response as input) and the routing constant test (just asserts a literal equals itself). * fix: route GetCallerIdentity through STS in UnifiedPostHandler and use stable UserId - UnifiedPostHandler only dispatched actions starting with "AssumeRole" to STS, so GetCallerIdentity in a POST body would fall through to the IAM path and get AccessDenied for non-admin users. Add explicit check for GetCallerIdentity. - Use identity.Name as UserId instead of credential.AccessKey, which is a transient value and incorrect for STS assumed-role callers.pull/8891/head
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 105 additions and 3 deletions
-
10weed/s3api/s3api_server.go
-
65weed/s3api/s3api_sts.go
-
33weed/s3api/s3api_sts_get_caller_identity_test.go
@ -0,0 +1,33 @@ |
|||
package s3api |
|||
|
|||
import ( |
|||
"encoding/xml" |
|||
"fmt" |
|||
"testing" |
|||
|
|||
"github.com/stretchr/testify/assert" |
|||
"github.com/stretchr/testify/require" |
|||
) |
|||
|
|||
func TestGetCallerIdentityResponse_XMLMarshal(t *testing.T) { |
|||
response := &GetCallerIdentityResponse{ |
|||
Result: GetCallerIdentityResult{ |
|||
Arn: fmt.Sprintf("arn:aws:iam::%s:user/alice", defaultAccountID), |
|||
UserId: "alice", |
|||
Account: defaultAccountID, |
|||
}, |
|||
} |
|||
response.ResponseMetadata.RequestId = "test-request-id" |
|||
|
|||
data, err := xml.MarshalIndent(response, "", " ") |
|||
require.NoError(t, err) |
|||
|
|||
xmlStr := string(data) |
|||
assert.Contains(t, xmlStr, "GetCallerIdentityResponse") |
|||
assert.Contains(t, xmlStr, "GetCallerIdentityResult") |
|||
assert.Contains(t, xmlStr, "<Arn>arn:aws:iam::000000000000:user/alice</Arn>") |
|||
assert.Contains(t, xmlStr, "<UserId>alice</UserId>") |
|||
assert.Contains(t, xmlStr, "<Account>000000000000</Account>") |
|||
assert.Contains(t, xmlStr, "<RequestId>test-request-id</RequestId>") |
|||
assert.Contains(t, xmlStr, "https://sts.amazonaws.com/doc/2011-06-15/") |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue