mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-12 23:09:33 +01:00
* s3api: record the caller on AssumeRole sessions The session name is the caller's choice; the session now carries the caller itself as the user it was issued to, as the web identity, LDAP and credential paths already do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3api: take a role session's aws:username from its user, not its name An assumed-role ARN ends in the session name the caller picked, so naming a session after another user resolved ${aws:username} and ${aws:userid} to that user in bucket and attached policies. Resolve them from the user the session was issued to instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iam: take a role session's aws:username from its user, not its name IsActionAllowed set aws:username to the last segment of an assumed-role ARN, the caller-chosen session name, for role and bucket policies. Use the user the session was issued to, and drop a forwarded value when the session names none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3api: pass a role session caller's user on to the session it assumes A role session that calls AssumeRole is named by its session ID, so the new session recorded that ID as its user. An STS session caller now passes on its own recorded user, or none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3api: size the session claims map from the request context Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
76 lines
2.0 KiB
Go
76 lines
2.0 KiB
Go
package policy_engine
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
// TestExtractPrincipalVariablesWithPaths tests ARN parsing with IAM path components
|
|
func TestExtractPrincipalVariablesWithPaths(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
principal string
|
|
expected map[string][]string
|
|
}{
|
|
{
|
|
name: "IAM User with path",
|
|
principal: "arn:aws:iam::123456789012:user/division/team/alice",
|
|
expected: map[string][]string{
|
|
"aws:PrincipalAccount": {"123456789012"},
|
|
"aws:principaltype": {"IAMUser"},
|
|
"aws:username": {"alice"},
|
|
"aws:userid": {"alice"},
|
|
},
|
|
},
|
|
{
|
|
name: "IAM Role with path",
|
|
principal: "arn:aws:iam::123456789012:role/service-role/MyRole",
|
|
expected: map[string][]string{
|
|
"aws:PrincipalAccount": {"123456789012"},
|
|
"aws:principaltype": {"IAMRole"},
|
|
"aws:username": {"MyRole"},
|
|
},
|
|
},
|
|
{
|
|
name: "Assumed Role with path",
|
|
principal: "arn:aws:sts::123456789012:assumed-role/service-role/MyRole/session-name",
|
|
expected: map[string][]string{
|
|
"aws:PrincipalAccount": {"123456789012"},
|
|
"aws:principaltype": {"AssumedRole"},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := ExtractPrincipalVariables(tt.principal)
|
|
|
|
// Check that all expected keys are present with correct values
|
|
for key, expectedValues := range tt.expected {
|
|
actualValues, ok := result[key]
|
|
if !ok {
|
|
t.Errorf("Expected key %s not found in result", key)
|
|
continue
|
|
}
|
|
|
|
if len(actualValues) != len(expectedValues) {
|
|
t.Errorf("For key %s: expected %d values, got %d", key, len(expectedValues), len(actualValues))
|
|
continue
|
|
}
|
|
|
|
for i, expectedValue := range expectedValues {
|
|
if actualValues[i] != expectedValue {
|
|
t.Errorf("For key %s[%d]: expected %s, got %s", key, i, expectedValue, actualValues[i])
|
|
}
|
|
}
|
|
}
|
|
|
|
// Check that there are no unexpected keys
|
|
for key := range result {
|
|
if _, ok := tt.expected[key]; !ok {
|
|
t.Errorf("Unexpected key %s in result", key)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|