• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (PHP SDK)
  4. Object Management
  5. Managing Object ACLs

Managing Object ACLs

Object ACLs, similar to bucket ACLs, support pre-defined access control policies and direct configuration. For details, see Managing Bucket ACLs.

An object ACL can be configured in three modes:

  1. Specify a pre-defined access control policy during object upload.
  2. Call ObsClient->setObjectAcl to specify a pre-defined access control policy.
  3. Call ObsClient->setObjectAcl to set the ACL directly.

Specifying a Pre-defined Access Control Policy During Object Upload

Sample code:

// Import the third-party open source libraries.
require 'vendor/autoload.php';
// Import the SDK code library.
require 'obs-autoloader.php';
// Declare the namespace.
use Obs\S3\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient ( [
       'key' => '*** Provide your Access Key ***',
       'secret' => '*** Provide your Secret Key ***',
       'endpoint' => 'https://yourdomainname'
] );

$resp = $obsClient -> putObject([
       'Bucket' => 'bucketname',
       'Key' => 'objectkey',
       'Body' => 'Hello OBS',
       // Set the object ACL to public-read.
       'ACL' => ObsClient::AclPublicRead
]);

printf("RequestId:%s\n", $resp['RequestId']);

Setting a Pre-defined Access Control Policy for an Object

Sample code:

// Import the third-party open source libraries.
require 'vendor/autoload.php';
// Import the SDK code library.
require 'obs-autoloader.php';
// Declare the namespace.
use Obs\S3\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient ( [
       'key' => '*** Provide your Access Key ***',
       'secret' => '*** Provide your Secret Key ***',
       'endpoint' => 'https://yourdomainname'
] );

$resp = $obsClient -> setObjectAcl([
       'Bucket' => 'bucketname',
       'Key' => 'objectkey',
       // Set the object ACL to private.
       'ACL' => ObsClient::AclPrivate
]);

printf("RequestId:%s\n", $resp['RequestId']);
NOTE:

Use the ACL parameter to specify the ACL for an object.

Directly Setting an Object ACL

Sample code:

// Import the third-party open source libraries.
require 'vendor/autoload.php';
// Import the SDK code library.
require 'obs-autoloader.php';
// Declare the namespace.
use Obs\S3\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient ( [
       'key' => '*** Provide your Access Key ***',
       'secret' => '*** Provide your Secret Key ***',
       'endpoint' => 'https://yourdomainname'
] );

$resp = $obsClient -> setObjectAcl([
       'Bucket' => 'bucketname',
       'Key' => 'objectkey',
       // Set the object owner.  
       'Owner' => ['ID' => 'ownerid', 'DisplayName' => 'ownername'],
       'Grants' => [
              // Grant all permissions to a specified user.
              ['Grantee' => ['Type' => 'CanonicalUser', 'ID' => 'userid'], 'Permission' => ObsClient::PermissionFullControl],
              // Grant the READ permission to all users.
              ['Grantee' => ['Type' => 'Group', 'URI' => ObsClient::GroupAllUsers], 'Permission' => ObsClient::PermissionRead],
              // Grant the WRITE_ACP permission to authorized users.
              ['Grantee' => ['Type' => 'Group', 'URI' => ObsClient::GroupAuthenticatedUsers], 'Permission' => ObsClient::PermissionWriteAcp]
       ]      
]);

printf("RequestId:%s\n", $resp['RequestId']);
NOTE:
  • Use the Owner parameter to specify the object owner and the Grants parameter to specify information about the authorized users.
  • The owner or grantee ID needed in the ACL indicates the account ID, which can be viewed on the My Credential page of OBS Console.
  • OBS objects support two types of grantee group:
    • Authorized users: ObsClient::GroupAuthenticatedUsers
    • All users: ObsClient::GroupAllUsers

Obtaining an Object ACL

You can call ObsClient->getObjectAcl to obtain an object ACL. Sample code is as follows:

// Import the third-party open source libraries.
require 'vendor/autoload.php';
// Import the SDK code library.
require 'obs-autoloader.php';
// Declare the namespace.
use Obs\S3\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient ( [ 
       'key' => '*** Provide your Access Key ***',
       'secret' => '*** Provide your Secret Key ***',
       'endpoint' => 'https://yourdomainname'
] );

$resp = $obsClient->getObjectAcl ( [ 
       'Bucket' => 'bucketname',
       'Key' => 'objectkey' 
] );

printf ( "RequestId:%s\n", $resp ['RequestId'] );
printf ( "Owner[ID]:%s\n", $resp ['Owner'] ['ID'] );
printf ( "Owner[DisplayName]:%s\n", $resp ['Owner'] ['DisplayName'] );
foreach ( $resp ['Grants'] as $index => $grant ) {
       printf ( "Grants[%d]\n", $index + 1 );
       printf ( "Grantee[ID]:%s\n", $grant ['Grantee'] ['ID'] );
       printf ( "Grantee[URI]:%s\n", $grant ['Grantee'] ['URI'] );
       printf ( "Permission:%s\n", $grant ['Permission'] );
}