Skip to main content

Bucket Policy

Arvancloud Object Storage's bucket policy lets you share your buckets with others. With this feature, you can set the necessary access level and let users you've invited to your workspace work with your buckets. If you're a large organization or have many buckets in your account, this feature helps you manage your files and buckets securely and efficiently.

Managing Policies​

To enable this feature, log in to the Arvancloud Object Storage panel and open Policy Management in the Bucket Policy section.

Then click Add Bucket Policy to define a rule for sharing the bucket based on your needs.

On this page, enter the following:

  • Bucket: In this section, select the bucket you want to define a policy for.

    Note that you can't define a new rule for buckets that already have a policy; you need to edit the previous rule.

  • Policy name: Define a name for your rule. This name must contain uppercase and lowercase English letters and/or numbers.

  • Effect: Specify whether you want to allow or deny access to resources.

  • Users: In this section, you can select the users you want from the list of invited users or machine users created in your workspace.

    You can manage the list of users in the User Management section of Object Storage.

  • Permissions: You can assign the necessary permissions to users from the following options and control their access to resources.

    PermissionDescription
    Full accessFull access to the bucket
    AbortMultipartUploadAccess to abort a multipart upload
    CreateBucketAccess to create a new bucket
    DeleteBucketPolicyAccess to delete the bucket policy
    DeleteBucketAccess to delete the bucket defined in the rule
    DeleteObjectAccess to delete the null version of an object
    DeleteObjectVersionAccess to delete a specific version of an object
    GetBucketAclAccess to get the bucket's ACL (access level) settings
    GetBucketCORSAccess to get the bucket's CORS settings
    GetBucketNotificationAccess to get the bucket's notification settings
    GetBucketPolicyAccess to get the bucket's policy rules
    GetBucketTaggingAccess to get the bucket's tags
    GetBucketVersioningAccess to get the bucket's versioning status
    GetBucketWebsiteAccess to get the bucket's static website settings
    GetLifecycleConfigurationAccess to get the bucket's lifecycle settings
    GetObjectAclAccess to get the object's ACL (access level) settings
    GetObjectAccess to get an object
    GetObjectTaggingAccess to get an object's tags
    PutObjectTaggingAccess to add tags to objects
    GetObjectVersionAclAccess to get the ACL (access level) of a specific object version
    GetObjectVersionAccess to get a specific version of objects
    ListAllMyBucketsAccess to get the list of all buckets in the account
    ListBucketMultipartUploadsAccess to get the list of in-progress multipart uploads
    ListBucketAccess to get the list of all or some of the bucket's objects (up to 1000 objects)
    ListBucketVersionsAccess to get the metadata list of all versions of the bucket's objects
    ListMultipartUploadPartsAccess to get the list of parts uploaded in a multipart upload
    PutBucketAclSetting the access level to a bucket with an ACL
    PutBucketCORSAccess to set CORS settings for the bucket
    PutBucketNotificationAccess to receive notifications when specific events occur
    PutBucketPolicyAccess to add or replace the bucket policy
    PutBucketTaggingAccess to add tags to the bucket
    PutBucketVersioningAccess to set the bucket's versioning status
    PutBucketWebsiteAccess to set the bucket's website settings
    PutLifecycleConfigurationAccess to add or replace the bucket's lifecycle rules
    PutObjectAclAccess to set the ACL (access level) status of objects
    PutObjectAccess to add objects to the bucket
    PutObjectVersionAclAccess to set the ACL (access level) status of existing objects
  • Object filter: By entering an object name or prefix, specify which objects in the bucket are shared.

    If you leave this field empty, the policy applies to all objects in the bucket.

On the same page, you can also click Add Another Policy to define more rules for the bucket.

Finally, click Save to confirm the rule.

Managing Policies with the SDK​

Besides the Arvancloud panel, you can also manage your bucket's policies with the Object Storage SDK. For example, you can use the following Go code snippet:

package main

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/aws/credentials"
"encoding/json"
"fmt"
"os"
"path/filepath"
)
func main() {
if len(os.Args) != 2 {
exitErrorf("bucket name required\nUsage: %s bucket_name",
filepath.Base(os.Args[0]))
}
bucket := os.Args[1]

sess, err := session.NewSession(&aws.Config{
Credentials: credentials.NewStaticCredentials("access_key_owner", "secret_key", ""),
})
svc := s3.New(sess, &aws.Config{
Region: aws.String("ir-thr-at1"),
Endpoint: aws.String("s3.ir-thr-at1.arvanstorage.ir"),
})

// Create a policy using map interface. Filling in the bucket as the
// resource.
readOnlyAnonUserPolicy := map[string]interface{}{
"Version": "2012-10-17",
"Statement": []map[string]interface{}{
{
"Sid": "AddPermDef",
"Effect": "Allow",
"Principal": map[string]interface{}{
"AWS": []string{
"arn:aws:iam:::user/Accesskey_invited_user",
},
},
"Action": []string{
"s3:GetObject",
"s3:GetObjectTagging",
},
"Resource": []string{
fmt.Sprintf("arn:aws:s3:::%s/*", bucket),
},
},
},
}

// Marshal the policy into a JSON value so that it can be sent to S3.
policy, err := json.Marshal(readOnlyAnonUserPolicy)
if err != nil {
exitErrorf("Failed to marshal policy, %v", err)
}

// Call S3 to put the policy for the bucket.
_, err = svc.PutBucketPolicy(&s3.PutBucketPolicyInput{
Bucket: aws.String(bucket),
Policy: aws.String(string(policy)),
})
if err != nil {
if aerr, ok := err.(awserr.Error); ok && aerr.Code() == s3.ErrCodeNoSuchBucket {
// Special error handling for the when the bucket doesn't
// exists so we can give a more direct error message from the CLI.
exitErrorf("Bucket %q does not exist", bucket)
}
exitErrorf("Unable to set bucket %q policy, %v", bucket, err)
}

fmt.Printf("Successfully set bucket %q's policy\n", bucket)
}

func exitErrorf(msg string, args ...interface{}) {
fmt.Fprintf(os.Stderr, msg+"\n", args...)
os.Exit(1)
}

Managing Policies with S3 Browser​

If you use S3 Browser to manage your objects and buckets, you can define the rule you want in Buckets > Edit Bucket Policy and click Apply.

Note that you need to put the Access Key of the user you want in principal, as in the following settings.

{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam:::user/ACCESS-KEY"
},
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::my-brand-new-bucket/*"
]
}
]
}

Managing Users​

In the User Management section of the bucket policy menu, you can see the list of users you can share resources with. These users are the members of your workspace whom you've invited earlier.

You can also create access for machine users you've created. Users created in Object Storage this way can't create resources for themselves and can only use the resources shared with them.

These users can access shared resources through S3 tools or the SDK.

Shared Buckets​

By clicking Buckets in the Arvancloud Object Storage panel and opening the Shared tab, you can see the buckets shared with you and perform the operations you need on them.

If a bucket has been shared with you and isn't in this list, you can use Add Bucket.

You can also add these buckets in S3 Browser. To do this, in the Buckets menu, select Add External Bucket, enter the name of the bucket you want, and click Add External Bucket.

After that, you can manage this bucket in S3 Browser according to its access levels.