A bucket is a container for objects stored in OSS. Every object is contained in a bucket. This topic describes how to configure and obtain the access control list (ACL) of a bucket.

The following table describes the ACLs for buckets.

ACL Description Value
Private Only the owner or authorized users of this bucket can read and write objects in the bucket. Other users, including anonymous users cannot access objects in the bucket without authorization. Aliyun::OSS::ACL::PRIVATE
Public read Only the owner or authorized users of this bucket can write objects in the bucket. Other users, including anonymous users can only read objects from the bucket. We recommend that you exercise with caution when you set the bucket ACL to public read. Aliyun::OSS::ACL::PUBLIC_READ
Public read/write Any users, including anonymous users can read and write objects in the bucket. We recommend that you exercise caution when you set the bucket ACL to public read/write. Aliyun::OSS::ACL::PUBLIC_READ_WRITE

Configure the ACL of a bucket

The following code provides an example on how to call Bucket#acl= to configure the ACL of a bucket:

require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  endpoint: 'endpoint',
  access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')

bucket = client.get_bucket('my-bucket')
bucket.acl = Aliyun::OSS::ACL::PUBLIC_READ
puts bucket.acl
			

For more information about how to configure the ACL for a bucket, see PutBucketACL.

Query the ACL of a bucket

The following code provides an example on how to call Bucket#acl to query the ACL of a bucket:

require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  endpoint: 'endpoint',
  access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')

bucket = client.get_bucket('my-bucket')
puts bucket.acl
			

For more information about how to obtain the ACL of a bucket, see GetBucketAcl.