You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.4 KiB

  1. package s3api
  2. import (
  3. "github.com/aws/aws-sdk-go/service/s3"
  4. "github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
  5. "github.com/seaweedfs/seaweedfs/weed/s3api/s3account"
  6. "github.com/seaweedfs/seaweedfs/weed/s3api/s3acl"
  7. "github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
  8. "net/http"
  9. )
  10. func getAccountId(r *http.Request) string {
  11. id := r.Header.Get(s3_constants.AmzAccountId)
  12. if len(id) == 0 {
  13. return s3account.AccountAnonymous.Id
  14. } else {
  15. return id
  16. }
  17. }
  18. func (s3a *S3ApiServer) checkAccessByOwnership(r *http.Request, bucket string) s3err.ErrorCode {
  19. metadata, errCode := s3a.bucketRegistry.GetBucketMetadata(bucket)
  20. if errCode != s3err.ErrNone {
  21. return errCode
  22. }
  23. accountId := getAccountId(r)
  24. if accountId == s3account.AccountAdmin.Id || accountId == *metadata.Owner.ID {
  25. return s3err.ErrNone
  26. }
  27. return s3err.ErrAccessDenied
  28. }
  29. func (s3a *S3ApiServer) ExtractBucketAcp(r *http.Request) (owner string, grants []*s3.Grant, errCode s3err.ErrorCode) {
  30. accountId := s3acl.GetAccountId(r)
  31. ownership := s3_constants.DefaultOwnershipForCreate
  32. if ownership == s3_constants.OwnershipBucketOwnerEnforced {
  33. return accountId, []*s3.Grant{
  34. {
  35. Permission: &s3_constants.PermissionFullControl,
  36. Grantee: &s3.Grantee{
  37. Type: &s3_constants.GrantTypeCanonicalUser,
  38. ID: &accountId,
  39. },
  40. },
  41. }, s3err.ErrNone
  42. } else {
  43. return s3acl.ParseAndValidateAclHeadersOrElseDefault(r, s3a.accountManager, ownership, accountId, accountId, false)
  44. }
  45. }