Repository navigation
policy: add the aws:SourceIdentity and sts:SourceIdentity condition keys #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
harshavardhana
merged 4 commits into
minio:main
from
harshavardhana:sts-source-identity
Sep 28, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a70a9d4
policy: add the aws:SourceIdentity and sts:SourceIdentity condition keys
harshavardhana 3b04374
test: cover Deny on the source identity condition keys
harshavardhana 00725e7
test: lead the source identity test doc comments with their names
harshavardhana 22fa80f
policy: keep sts:SourceIdentity apart from aws:SourceIdentity
harshavardhana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| // Copyright (c) 2015-2026 MinIO, Inc. | ||
| // | ||
| // This file is part of MinIO Object Storage stack | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| package policy | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/minio/pkg/v3/policy/condition" | ||
| ) | ||
|
|
||
| // TestSourceIdentityConditions verifies that policies can grant S3, admin and | ||
| // STS actions on a source identity: aws:SourceIdentity for the signing | ||
| // session's, sts:SourceIdentity for the one an STS call's new session will | ||
| // carry. | ||
| func TestSourceIdentityConditions(t *testing.T) { | ||
| doc := `{ | ||
| "Version": "2012-10-17", | ||
| "Statement": [ | ||
| {"Effect": "Allow", "Action": ["s3:GetObject"], "Resource": ["arn:aws:s3:::data/*"], | ||
| "Condition": {"StringLike": {"aws:SourceIdentity": ["alice*"]}}}, | ||
| {"Effect": "Allow", "Action": ["admin:ServerInfo"], | ||
| "Condition": {"StringEquals": {"aws:SourceIdentity": ["alice"]}}}, | ||
| {"Effect": "Allow", "Action": ["sts:AssumeRole"], | ||
| "Condition": {"StringEquals": {"sts:SourceIdentity": ["alice"]}}} | ||
| ] | ||
| }` | ||
| p, err := ParseConfig(strings.NewReader(doc)) | ||
| if err != nil { | ||
| t.Fatalf("a policy naming the source identity keys must parse: %v", err) | ||
| } | ||
|
|
||
| cases := []struct { | ||
| action Action | ||
| sourceIdentity []string | ||
| allowed bool | ||
| }{ | ||
| {GetObjectAction, []string{"alice@example.com"}, true}, | ||
| {GetObjectAction, []string{"bob"}, false}, | ||
| {GetObjectAction, nil, false}, | ||
| {Action(ServerInfoAdminAction), []string{"alice"}, true}, | ||
| {Action(ServerInfoAdminAction), []string{"bob"}, false}, | ||
| {Action(AssumeRoleAction), []string{"alice"}, true}, | ||
| {Action(AssumeRoleAction), []string{"bob"}, false}, | ||
| {Action(AssumeRoleAction), nil, false}, | ||
| } | ||
| for _, tc := range cases { | ||
|
harshavardhana marked this conversation as resolved.
|
||
| values := map[string][]string{} | ||
| if tc.sourceIdentity != nil { | ||
| values[condition.AWSSourceIdentity.Name()] = tc.sourceIdentity | ||
| values[condition.STSSourceIdentity.Name()] = tc.sourceIdentity | ||
| } | ||
| got := p.IsAllowed(Args{ | ||
| AccountName: "app", | ||
| Action: tc.action, | ||
| BucketName: "data", | ||
| ObjectName: "report.csv", | ||
| ConditionValues: values, | ||
| }) | ||
| if got != tc.allowed { | ||
| t.Errorf("%s with source identity %v: allowed=%v, want %v", tc.action, tc.sourceIdentity, got, tc.allowed) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // TestSourceIdentityConditionsDeny verifies that a Deny keyed on a source | ||
| // identity overrides a broader Allow, and that a StringNotEquals Deny refuses a | ||
| // request that carries no source identity. | ||
| func TestSourceIdentityConditionsDeny(t *testing.T) { | ||
| doc := `{ | ||
| "Version": "2012-10-17", | ||
| "Statement": [ | ||
| {"Effect": "Allow", "Action": ["s3:GetObject"], "Resource": ["arn:aws:s3:::data/*"]}, | ||
| {"Effect": "Allow", "Action": ["sts:AssumeRole"]}, | ||
| {"Effect": "Deny", "Action": ["s3:GetObject"], "Resource": ["arn:aws:s3:::data/*"], | ||
| "Condition": {"StringEquals": {"aws:SourceIdentity": ["mallory"]}}}, | ||
| {"Effect": "Deny", "Action": ["sts:AssumeRole"], | ||
| "Condition": {"StringNotEquals": {"sts:SourceIdentity": ["alice"]}}} | ||
| ] | ||
| }` | ||
| p, err := ParseConfig(strings.NewReader(doc)) | ||
| if err != nil { | ||
| t.Fatalf("a policy denying on the source identity keys must parse: %v", err) | ||
| } | ||
|
|
||
| cases := []struct { | ||
| action Action | ||
| sourceIdentity []string | ||
| allowed bool | ||
| }{ | ||
| {GetObjectAction, []string{"alice"}, true}, | ||
| {GetObjectAction, []string{"mallory"}, false}, | ||
| {GetObjectAction, nil, true}, | ||
| {Action(AssumeRoleAction), []string{"alice"}, true}, | ||
| {Action(AssumeRoleAction), []string{"bob"}, false}, | ||
| {Action(AssumeRoleAction), nil, false}, | ||
| } | ||
| for _, tc := range cases { | ||
| values := map[string][]string{} | ||
| if tc.sourceIdentity != nil { | ||
| values[condition.AWSSourceIdentity.Name()] = tc.sourceIdentity | ||
| values[condition.STSSourceIdentity.Name()] = tc.sourceIdentity | ||
| } | ||
| got := p.IsAllowed(Args{ | ||
| AccountName: "app", | ||
| Action: tc.action, | ||
| BucketName: "data", | ||
| ObjectName: "report.csv", | ||
| ConditionValues: values, | ||
| }) | ||
| if got != tc.allowed { | ||
| t.Errorf("%s with source identity %v: allowed=%v, want %v", tc.action, tc.sourceIdentity, got, tc.allowed) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // TestSourceIdentityKeysReadSeparateValues verifies that within one STS call | ||
| // aws:SourceIdentity reads the calling session's source identity and | ||
| // sts:SourceIdentity the one the new session will carry, so a policy can tell a | ||
| // session setting its source identity for the first time from one inheriting | ||
| // it. | ||
| func TestSourceIdentityKeysReadSeparateValues(t *testing.T) { | ||
| doc := `{ | ||
| "Version": "2012-10-17", | ||
| "Statement": [ | ||
| {"Effect": "Allow", "Action": ["sts:AssumeRole"], | ||
| "Condition": {"StringEquals": {"sts:SourceIdentity": ["alice"]}}}, | ||
| {"Effect": "Deny", "Action": ["sts:AssumeRole"], | ||
| "Condition": {"Null": {"aws:SourceIdentity": ["true"]}}} | ||
| ] | ||
| }` | ||
| p, err := ParseConfig(strings.NewReader(doc)) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| cases := []struct { | ||
| name string | ||
| caller, session string | ||
| allowed bool | ||
| }{ | ||
| {name: "caller carries alice, session inherits it", caller: "alice", session: "alice", allowed: true}, | ||
| {name: "caller carries none, session sets alice", session: "alice"}, | ||
| {name: "caller carries bob, session inherits it", caller: "bob", session: "bob"}, | ||
| } | ||
| for _, tc := range cases { | ||
| values := map[string][]string{} | ||
| if tc.caller != "" { | ||
| values[condition.AWSSourceIdentity.Name()] = []string{tc.caller} | ||
| } | ||
| if tc.session != "" { | ||
| values[condition.STSSourceIdentity.Name()] = []string{tc.session} | ||
| } | ||
| got := p.IsAllowed(Args{AccountName: "app", Action: Action(AssumeRoleAction), ConditionValues: values}) | ||
| if got != tc.allowed { | ||
| t.Errorf("%s: allowed=%v, want %v", tc.name, got, tc.allowed) | ||
| } | ||
| } | ||
| if condition.AWSSourceIdentity.Name() == condition.STSSourceIdentity.Name() { | ||
| t.Errorf("aws:SourceIdentity and sts:SourceIdentity both read %q", condition.AWSSourceIdentity.Name()) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.