mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 19:17:28 +01:00
iam: GetUserPolicy returns NoSuchEntity for a policy name the user does not have
When the user has stored inline policies, an unknown name fell through to the policy rebuilt from the user's actions, so a deleted policy still read back. The standalone IAM server already returns NoSuchEntity here.
This commit is contained in:
1 parent
ee2718b14c
commit
42cb8b91f4
2 files changed
+30
No files matched your search
@@ -1301,6 +1301,12 @@ func (e *EmbeddedIamApi) GetUserPolicy(s3cfg *iam_pb.S3ApiConfiguration, values
|
||||
resp.GetUserPolicyResult.PolicyDocument = string(policyDocumentJSON)
|
||||
return resp, nil
|
||||
}
|
||||
// The user has stored inline policies, but none by this name
|
||||
if storeErr == nil {
|
||||
if names, err := e.credentialManager.ListUserInlinePolicies(ctx, userName); err == nil && len(names) > 0 {
|
||||
return resp, &iamError{Code: iam.ErrCodeNoSuchEntityException, Error: fmt.Errorf("the user policy with name %s cannot be found", policyName)}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: reconstruct from ident.Actions (lossy - fine-grained actions
|
||||
|
||||
@@ -1979,6 +1979,30 @@ func TestEmbeddedIamGetUserPolicyFallback(t *testing.T) {
|
||||
assert.ElementsMatch(t, []string{"arn:aws:s3:::b-le*", "arn:aws:s3:::b-le*/*"}, stmt.Resource.Strings())
|
||||
}
|
||||
|
||||
// TestEmbeddedIamGetUserPolicyMissingName checks that a policy name the user does not have
|
||||
// is NoSuchEntity, not a policy rebuilt from the user's other inline policies.
|
||||
func TestEmbeddedIamGetUserPolicyMissingName(t *testing.T) {
|
||||
api := NewEmbeddedIamApiForTest()
|
||||
s3cfg := &iam_pb.S3ApiConfiguration{
|
||||
Identities: []*iam_pb.Identity{{Name: "steward"}},
|
||||
}
|
||||
api.mockConfig = s3cfg
|
||||
|
||||
_, iamErr := api.PutUserPolicy(s3cfg, url.Values{
|
||||
"UserName": []string{"steward"},
|
||||
"PolicyName": []string{"read"},
|
||||
"PolicyDocument": []string{`{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":"s3:GetObject","Resource":"arn:aws:s3:::b/*"}]}`},
|
||||
})
|
||||
require.Nil(t, iamErr)
|
||||
|
||||
_, iamErr = api.GetUserPolicy(s3cfg, url.Values{
|
||||
"UserName": []string{"steward"},
|
||||
"PolicyName": []string{"write"},
|
||||
})
|
||||
require.NotNil(t, iamErr)
|
||||
assert.Equal(t, iam.ErrCodeNoSuchEntityException, iamErr.Code)
|
||||
}
|
||||
|
||||
// TestEmbeddedIamGetUserPolicyUserNotFound tests GetUserPolicy with non-existent user
|
||||
func TestEmbeddedIamGetUserPolicyUserNotFound(t *testing.T) {
|
||||
api := NewEmbeddedIamApiForTest()
|
||||
|
||||
Reference in new issue
Block a user