aboutsummaryrefslogtreecommitdiff
path: root/weed/s3api/auth_credentials.go
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2022-01-03 15:39:36 -0800
committerchrislu <chris.lu@gmail.com>2022-01-03 15:39:36 -0800
commita7887166cfad779b693731dbf4fc1d678a2c81d0 (patch)
tree2fdee8c395e55e3ec3df7bf5727f5a00664e2dc9 /weed/s3api/auth_credentials.go
parent5799a20f7149e8fe8e74ce0a03f138df297e0b9c (diff)
downloadseaweedfs-a7887166cfad779b693731dbf4fc1d678a2c81d0.tar.xz
seaweedfs-a7887166cfad779b693731dbf4fc1d678a2c81d0.zip
wildcard prefix to restrict access to directories in s3 bucket
https://github.com/chrislusf/seaweedfs/discussions/2551
Diffstat (limited to 'weed/s3api/auth_credentials.go')
-rw-r--r--weed/s3api/auth_credentials.go12
1 files changed, 5 insertions, 7 deletions
diff --git a/weed/s3api/auth_credentials.go b/weed/s3api/auth_credentials.go
index 87d478136..3c27b7d35 100644
--- a/weed/s3api/auth_credentials.go
+++ b/weed/s3api/auth_credentials.go
@@ -247,9 +247,9 @@ func (iam *IdentityAccessManagement) authRequest(r *http.Request, action Action)
glog.V(3).Infof("user name: %v actions: %v, action: %v", identity.Name, identity.Actions, action)
- bucket, _ := xhttp.GetBucketAndObject(r)
+ bucket, object := xhttp.GetBucketAndObject(r)
- if !identity.canDo(action, bucket) {
+ if !identity.canDo(action, bucket, object) {
return identity, s3err.ErrAccessDenied
}
@@ -307,7 +307,7 @@ func (iam *IdentityAccessManagement) authUser(r *http.Request) (*Identity, s3err
return identity, s3err.ErrNone
}
-func (identity *Identity) canDo(action Action, bucket string) bool {
+func (identity *Identity) canDo(action Action, bucket string, objectKey string) bool {
if identity.isAdmin() {
return true
}
@@ -319,15 +319,13 @@ func (identity *Identity) canDo(action Action, bucket string) bool {
if bucket == "" {
return false
}
+ target := string(action) + ":" + bucket + "/" + objectKey
limitedByBucket := string(action) + ":" + bucket
adminLimitedByBucket := s3_constants.ACTION_ADMIN + ":" + bucket
for _, a := range identity.Actions {
act := string(a)
if strings.HasSuffix(act, "*") {
- if strings.HasPrefix(limitedByBucket, act[:len(act)-1]) {
- return true
- }
- if strings.HasPrefix(adminLimitedByBucket, act[:len(act)-1]) {
+ if strings.HasPrefix(target, act[:len(act)-1]) {
return true
}
} else {