mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-26 06:07:13 +01:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a322059031 | ||
|
|
aac486d6e5 | ||
|
|
42cb8b91f4 |
No files matched your search
@@ -1291,9 +1291,9 @@ func (e *EmbeddedIamApi) GetUserPolicy(s3cfg *iam_pb.S3ApiConfiguration, values
|
||||
ctx := context.Background()
|
||||
storedDoc, storeErr := e.credentialManager.GetUserInlinePolicy(ctx, userName, policyName)
|
||||
if storeErr != nil {
|
||||
glog.Warningf("GetUserPolicy: failed to read stored inline policy %q for user %s: %v; falling back to reconstruction", policyName, userName, storeErr)
|
||||
return resp, &iamError{Code: iam.ErrCodeServiceFailureException, Error: fmt.Errorf("read inline policy %s for %s: %w", policyName, userName, storeErr)}
|
||||
}
|
||||
if storeErr == nil && storedDoc != nil {
|
||||
if storedDoc != nil {
|
||||
policyDocumentJSON, err := json.Marshal(storedDoc)
|
||||
if err != nil {
|
||||
return resp, &iamError{Code: iam.ErrCodeServiceFailureException, Error: err}
|
||||
@@ -1301,6 +1301,14 @@ 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
|
||||
policyNames, err := e.credentialManager.ListUserInlinePolicies(ctx, userName)
|
||||
if err != nil {
|
||||
return resp, &iamError{Code: iam.ErrCodeServiceFailureException, Error: fmt.Errorf("list inline policies for %s: %w", userName, err)}
|
||||
}
|
||||
if len(policyNames) > 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,48 @@ 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)
|
||||
}
|
||||
|
||||
// TestEmbeddedIamGetUserPolicyStoreFailure checks that a store error is a
|
||||
// service failure, not a policy rebuilt from the user's actions.
|
||||
func TestEmbeddedIamGetUserPolicyStoreFailure(t *testing.T) {
|
||||
api := NewEmbeddedIamApiForTest()
|
||||
s3cfg := &iam_pb.S3ApiConfiguration{
|
||||
Identities: []*iam_pb.Identity{{Name: "steward", Actions: []string{"Read:b"}}},
|
||||
}
|
||||
api.mockConfig = s3cfg
|
||||
api.credentialManager.Store = &memory.MemoryStore{}
|
||||
|
||||
_, iamErr := api.GetUserPolicy(s3cfg, url.Values{
|
||||
"UserName": []string{"steward"},
|
||||
"PolicyName": []string{"read"},
|
||||
})
|
||||
require.NotNil(t, iamErr)
|
||||
assert.Equal(t, iam.ErrCodeServiceFailureException, iamErr.Code)
|
||||
}
|
||||
|
||||
// TestEmbeddedIamGetUserPolicyUserNotFound tests GetUserPolicy with non-existent user
|
||||
func TestEmbeddedIamGetUserPolicyUserNotFound(t *testing.T) {
|
||||
api := NewEmbeddedIamApiForTest()
|
||||
|
||||
Reference in new issue
Block a user