Movatterモバイル変換


[0]ホーム

URL:


Configuring ACLs - Amazon Simple Storage Service
DocumentationAmazon Simple Storage Service (S3)User Guide

Configuring ACLs

This section explains how to manage access permissions for S3 buckets and objects usingaccess control lists (ACLs). You can add grants to your resource ACL using the AWS Management Console,AWS Command Line Interface (CLI), REST API, or AWS SDKs.

Bucket and object permissions are independent of each other. An object does not inheritthe permissions from its bucket. For example, if you create a bucket and grant write accessto a user, you can't access that user’s objects unless the user explicitly grants youaccess.

You can grant permissions to other AWS account users or to predefined groups. The useror group that you are granting permissions to is called thegrantee. Bydefault, the owner, which is the AWS account that created the bucket, has fullpermissions.

Each permission you grant for a user or group adds an entry in the ACL that is associatedwith the bucket. The ACL lists grants, which identify the grantee and the permissiongranted.

S3 Object Ownership is an Amazon S3 bucket-level setting that you can use to both control ownership of the objects that are uploaded to your bucket and to disable or enable ACLs. By default, Object Ownership is set to the Bucket owner enforced setting, and all ACLs are disabled. When ACLs are disabled, the bucket owner owns all the objects in the bucket and manages access to them exclusively by using access-management policies.

A majority of modern use cases in Amazon S3 no longer require the use of ACLs. We recommend that you keep ACLs disabled, except in circumstances where you need to control access for each object individually. With ACLs disabled, you can use policies to control access to all objects in your bucket, regardless of who uploaded the objects to your bucket. For more information, seeControlling ownership of objects and disabling ACLsfor your bucket.

The console displays combined access grants for duplicate grantees. To see thefull list of ACLs, use the Amazon S3 REST API, AWS CLI, or AWS SDKs.

The following table shows the ACL permissions that you can configure for bucketsin the Amazon S3 console.

Amazon S3 console ACL permissions for buckets
Console permissionACL permissionAccess
Objects - ListREADAllows grantee to list the objects in the bucket.
Objects - WriteWRITEAllows grantee to create new objects in the bucket. For thebucket and object owners of existing objects, also allows deletionsand overwrites of those objects.
Bucket ACL - ReadREAD_ACPAllows grantee to read the bucket ACL.
Bucket ACL - WriteWRITE_ACPAllows grantee to write the ACL for the applicablebucket.
Everyone (public access): Objects - ListREADGrants public read access for the objects in the bucket. When yougrant list access toEveryone (public access),anyone in the world can access the objects in the bucket.
Everyone (public access): Bucket ACL - ReadREAD_ACPGrants public read access for the bucket ACL. When you grant readaccess toEveryone (public access), anyone inthe world can access the bucket ACL.

For more information about ACL permissions, seeAccess control list (ACL) overview.

To set ACL permissions for a bucket
  1. Sign in to the AWS Management Console and open the Amazon S3 console athttps://console.aws.amazon.com/s3/.

  2. In the left navigation pane, chooseGeneral purpose buckets.

  3. In theBuckets list, choose the name of the bucketthat you want to set permissions for.

  4. ChoosePermissions.

  5. UnderAccess control list, chooseEdit.

    You can edit the following ACL permissions for the bucket:

    Objects
    • List – Allows a grantee to list theobjects in the bucket.

    • Write – Allows grantee to create newobjects in the bucket. For the bucket and object owners of existingobjects, also allows deletions and overwrites of those objects.

      In the S3 console, you can only grant write access to the S3 logdelivery group and the bucket owner (your AWS account). We highlyrecommend that you do not grant write access for other grantees.However, if you need to grant write access, you can use the AWS CLI,AWS SDKs, or the REST API.

    Bucket ACL
    • Read – Allows grantee to read thebucket ACL.

    • Write – Allows grantee to write theACL for the applicable bucket.

  6. To change the bucket owner's permissions, besideBucket owner(your AWS account), clear or select from the following ACLpermissions:

    • ObjectsList orWrite

    • Bucket ACLReadorWrite

    Theowner refers to the AWS account root user, not an AWS Identity and Access ManagementIAM user. For more information about the root user, seeThe AWS account root user in theIAM User Guide.

  7. To grant or undo permissions for the general public (everyone on theinternet), besideEveryone (public access), clear orselect from the following ACL permissions:

    • ObjectsList

    • Bucket ACLRead

  8. To grant or undo permissions for anyone with an AWS account, besideAuthenticated Users group (anyone with anAWS account), clear or select from the following ACLpermissions:

  9. To grant or undo permissions for Amazon S3 to write server access logs to thebucket, underS3 log delivery group, clear or selectfrom the following ACL permissions:

  10. To grant access to another AWS account, do the following:

    1. ChooseAdd grantee.

    2. In theGrantee box, enter the canonical ID ofthe other AWS account.

    3. Select from the following ACL permissions:

      • ObjectsList orWrite

      • Bucket ACLRead orWrite

  11. To remove access to another AWS account, underAccess forother AWS accounts, chooseRemove.

  12. To save your changes, chooseSave changes.

The console displays combined access grants for duplicate grantees. To see thefull list of ACLs, use the Amazon S3 REST API, AWS CLI, or AWS SDKs. The following tableshows the ACL permissions that you can configure for objects in the Amazon S3console.

Amazon S3 console ACL permissions for objects
Console permissionACL permissionAccess
Object - ReadREADAllows grantee to read the object data and its metadata.
Object ACL - ReadREAD_ACPAllows grantee to read the object ACL.
Object ACL - WriteWRITE_ACPAllows grantee to write the ACL for the applicable object

For more information about ACL permissions, seeAccess control list (ACL) overview.

To set ACL permissions for an object
  1. Sign in to the AWS Management Console and open the Amazon S3 console athttps://console.aws.amazon.com/s3/.

  2. In theBuckets list, choose the name of the bucketthat contains the object.

  3. In theobjects list, choose the name of the objectfor which you want to set permissions.

  4. ChoosePermissions.

  5. Under Access control list (ACL), chooseEdit.

    You can edit the following ACL permissions for the object:

    Object
    • Read – Allows grantee to read theobject data and its metadata.

    Object ACL
    • Read – Allows grantee to read theobject ACL.

    • Write – Allows grantee to write theACL for the applicable object. In the S3 console, you can only grantwrite access to the bucket owner (your AWS account). We highlyrecommend that you do not grant write access for other grantees.However, if you need to grant write access, you can use the AWS CLI,AWS SDKs, or the REST API.

  6. You can manage object access permissions for the following:

    1. Access for object owner

      Theowner refers to the AWS account root user, and notan AWS Identity and Access Management IAM user. For more information about the root user, seeTheAWS account root user in theIAM User Guide.

      To change the owner's object access permissions, underAccess for object owner, chooseYour AWS Account (owner).

      Select the check boxes for the permissions that you want tochange, and then chooseSave.

    2. Access for other AWS accounts

      To grant permissions to an AWS user from a differentAWS account, underAccess for otherAWS accounts, chooseAddaccount. In theEnter an IDfield, enter the canonical ID of the AWS user that you want togrant object permissions to. For information about finding acanonical ID, seeYour AWS account identifiers in theAmazon Web Services General Reference. You can add as many as 99users.

      Select the check boxes for the permissions that you want to grantto the user, and then chooseSave. To displayinformation about the permissions, choose the Help icons.

    3. Public access

      To grant access to your object to the general public (everyone inthe world), underPublic access, chooseEveryone. Granting public accesspermissions means that anyone in the world can access theobject.

      Select the check boxes for the permissions that you want to grant,and then chooseSave.

This section provides examples of how to configure access control list (ACL)grants on buckets and objects.

Java

This section provides examples of how to configure access control list(ACL) grants on buckets and objects. The first example creates a bucketwith a canned ACL (seeCanned ACL), creates a list of custom permissiongrants, and then replaces the canned ACL with an ACL containing thecustom grants. The second example shows how to modify an ACL using theAccessControlList.grantPermission() method.

Example Create a bucket and specify a canned ACL that grants permissionto the S3 log delivery group

This example creates a bucket. In the request, the examplespecifies a canned ACL that grants the Log Delivery group permissionto write logs to the bucket.

import com.amazonaws.AmazonServiceException;import com.amazonaws.SdkClientException;import com.amazonaws.regions.Regions;import com.amazonaws.services.s3.AmazonS3;import com.amazonaws.services.s3.AmazonS3ClientBuilder;import com.amazonaws.services.s3.model.*;import java.io.IOException;import java.util.ArrayList;public class CreateBucketWithACL{ public static void main(String[] args) throws IOException{ Regions clientRegion = Regions.DEFAULT_REGION; String bucketName = "*** Bucket name ***"; String userEmailForReadPermission = "*** user@example.com ***"; try{ AmazonS3 s3Client = AmazonS3ClientBuilder.standard() .withRegion(clientRegion) .build(); // Create a bucket with a canned ACL. This ACL will be replaced by the // setBucketAcl() // calls below. It is included here for demonstration purposes. CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName, clientRegion.getName()) .withCannedAcl(CannedAccessControlList.LogDeliveryWrite); s3Client.createBucket(createBucketRequest); // Create a collection of grants to add to the bucket. ArrayList<Grant> grantCollection = new ArrayList<Grant>(); // Grant the account owner full control. Grant grant1 = new Grant(new CanonicalGrantee(s3Client.getS3AccountOwner().getId()), Permission.FullControl); grantCollection.add(grant1); // Grant the LogDelivery group permission to write to the bucket. Grant grant2 = new Grant(GroupGrantee.LogDelivery, Permission.Write); grantCollection.add(grant2); // Save grants by replacing all current ACL grants with the two we just created. AccessControlList bucketAcl = new AccessControlList(); bucketAcl.grantAllPermissions(grantCollection.toArray(new Grant[0])); s3Client.setBucketAcl(bucketName, bucketAcl); // Retrieve the bucket's ACL, add another grant, and then save the new ACL. AccessControlList newBucketAcl = s3Client.getBucketAcl(bucketName); Grant grant3 = new Grant(new EmailAddressGrantee(userEmailForReadPermission), Permission.Read); newBucketAcl.grantAllPermissions(grant3); s3Client.setBucketAcl(bucketName, newBucketAcl); } catch (AmazonServiceException e){ // The call was transmitted successfully, but Amazon S3 couldn't process // it and returned an error response. e.printStackTrace(); } catch (SdkClientException e){ // Amazon S3 couldn't be contacted for a response, or the client // couldn't parse the response from Amazon S3. e.printStackTrace(); } }}
Example Update ACL on an existing object

This example updates the ACL on an object. The example performsthe following tasks:

import com.amazonaws.AmazonServiceException;import com.amazonaws.SdkClientException;import com.amazonaws.auth.profile.ProfileCredentialsProvider;import com.amazonaws.regions.Regions;import com.amazonaws.services.s3.AmazonS3;import com.amazonaws.services.s3.AmazonS3ClientBuilder;import com.amazonaws.services.s3.model.AccessControlList;import com.amazonaws.services.s3.model.CanonicalGrantee;import com.amazonaws.services.s3.model.EmailAddressGrantee;import com.amazonaws.services.s3.model.Permission;import java.io.IOException;public class ModifyACLExistingObject{ public static void main(String[] args) throws IOException{ Regions clientRegion = Regions.DEFAULT_REGION; String bucketName = "*** Bucket name ***"; String keyName = "*** Key name ***"; String emailGrantee = "*** user@example.com ***"; try{ AmazonS3 s3Client = AmazonS3ClientBuilder.standard() .withCredentials(new ProfileCredentialsProvider()) .withRegion(clientRegion) .build(); // Get the existing object ACL that we want to modify. AccessControlList acl = s3Client.getObjectAcl(bucketName, keyName); // Clear the existing list of grants. acl.getGrantsAsList().clear(); // Grant a sample set of permissions, using the existing ACL owner for Full // Control permissions. acl.grantPermission(new CanonicalGrantee(acl.getOwner().getId()), Permission.FullControl); acl.grantPermission(new EmailAddressGrantee(emailGrantee), Permission.WriteAcp); // Save the modified ACL back to the object. s3Client.setObjectAcl(bucketName, keyName, acl); } catch (AmazonServiceException e){ // The call was transmitted successfully, but Amazon S3 couldn't process // it, so it returned an error response. e.printStackTrace(); } catch (SdkClientException e){ // Amazon S3 couldn't be contacted for a response, or the client // couldn't parse the response from Amazon S3. e.printStackTrace(); } }}
.NET
Example Create a bucket and specify a canned ACL that grants permissionto the S3 log delivery group

This C# example creates a bucket. In the request, the code alsospecifies a canned ACL that grants the Log Delivery grouppermissions to write the logs to the bucket.

For information about setting up and running the code examples,seeGetting Started with the AWS SDK for .NET in theAWS SDK for .NET Developer Guide.

using Amazon;using Amazon.S3;using Amazon.S3.Model;using System;using System.Threading.Tasks;namespace Amazon.DocSamples.S3{ class ManagingBucketACLTest{ private const string newBucketName = "*** bucket name ***"; // Specify your bucket region (an example region is shown). private static readonly RegionEndpoint bucketRegion = RegionEndpoint.USWest2; private static IAmazonS3 client; public static void Main(){ client = new AmazonS3Client(bucketRegion); CreateBucketUseCannedACLAsync().Wait(); } private static async Task CreateBucketUseCannedACLAsync(){ try{ // Add bucket (specify canned ACL). PutBucketRequest putBucketRequest = new PutBucketRequest(){ BucketName = newBucketName, BucketRegion = S3Region.EUW1, // S3Region.US, // Add canned ACL. CannedACL = S3CannedACL.LogDeliveryWrite }; PutBucketResponse putBucketResponse = await client.PutBucketAsync(putBucketRequest); // Retrieve bucket ACL. GetACLResponse getACLResponse = await client.GetACLAsync(new GetACLRequest{ BucketName = newBucketName }); } catch (AmazonS3Exception amazonS3Exception){ Console.WriteLine("S3 error occurred. Exception: " + amazonS3Exception.ToString()); } catch (Exception e){ Console.WriteLine("Exception: " + e.ToString()); } } }}
Example Update ACL on an existing object

This C# example updates the ACL on an existing object. The exampleperforms the following tasks:

For information about setting up and running the code examples,seeGetting Started with the AWS SDK for .NET in theAWS SDK for .NET Developer Guide.

using Amazon;using Amazon.S3;using Amazon.S3.Model;using System;using System.Collections.Generic;using System.Threading.Tasks;namespace Amazon.DocSamples.S3{ class ManagingObjectACLTest{ private const string bucketName = "*** bucket name ***"; private const string keyName = "*** object key name ***"; private const string emailAddress = "*** email address ***"; // Specify your bucket region (an example region is shown). private static readonly RegionEndpoint bucketRegion = RegionEndpoint.USWest2; private static IAmazonS3 client; public static void Main(){ client = new AmazonS3Client(bucketRegion); TestObjectACLTestAsync().Wait(); } private static async Task TestObjectACLTestAsync(){ try{ // Retrieve the ACL for the object. GetACLResponse aclResponse = await client.GetACLAsync(new GetACLRequest{ BucketName = bucketName, Key = keyName }); S3AccessControlList acl = aclResponse.AccessControlList; // Retrieve the owner (we use this to re-add permissions after we clear the ACL). Owner owner = acl.Owner; // Clear existing grants. acl.Grants.Clear(); // Add a grant to reset the owner's full permission (the previous clear statement removed all permissions). S3Grant fullControlGrant = new S3Grant{ Grantee = new S3Grantee{ CanonicalUser = owner.Id }, Permission = S3Permission.FULL_CONTROL }; // Describe the grant for the permission using an email address. S3Grant grantUsingEmail = new S3Grant{ Grantee = new S3Grantee{ EmailAddress = emailAddress }, Permission = S3Permission.WRITE_ACP }; acl.Grants.AddRange(new List<S3Grant>{ fullControlGrant, grantUsingEmail }); // Set a new ACL. PutACLResponse response = await client.PutACLAsync(new PutACLRequest{ BucketName = bucketName, Key = keyName, AccessControlList = acl }); } catch (AmazonS3Exception amazonS3Exception){ Console.WriteLine("An AmazonS3Exception was thrown. Exception: " + amazonS3Exception.ToString()); } catch (Exception e){ Console.WriteLine("Exception: " + e.ToString()); } } }}

Amazon S3 APIs enable you to set an ACL when you create a bucket or an object. Amazon S3also provides API to set an ACL on an existing bucket or an object. These APIsprovide the following methods to set an ACL:

  • Set ACL using request headers— Whenyou send a request to create a resource (bucket or object), you set an ACLusing the request headers. Using these headers, you can either specify acanned ACL or specify grants explicitly (identifying grantee and permissionsexplicitly).

  • Set ACL using request body— When yousend a request to set an ACL on an existing resource, you can set the ACLeither in the request header or in the body.

For information on the REST API support for managing ACLs, see the followingsections in theAmazon Simple Storage Service API Reference:

Access Control List (ACL)-SpecificRequest Headers

You can use headers to grant access control list (ACL)-based permissions. Bydefault, all objects are private. Only the owner has full access control. Whenadding a new object, you can grant permissions to individual AWS accounts orto predefined groups defined by Amazon S3. These permissions are then added tothe Access Control List (ACL) on the object. For more information, seeAccess control list (ACL) overview.

With this operation, you can grant access permissions using one these twomethods:

  • Canned ACL (x-amz-acl) —Amazon S3 supports a set of predefined ACLs, known as canned ACLs. Eachcanned ACL has a predefined set of grantees and permissions. For moreinformation, seeCanned ACL.

  • Access Permissions — To explicitlygrant access permissions to specific AWS accounts or groups, use thefollowing headers. Each header maps to specific permissions that AmazonS3 supports in an ACL. For more information, seeAccess control list (ACL) overview. In theheader, you specify a list of grantees who get the specific permission.

    • x-amz-grant-read

    • x-amz-grant-write

    • x-amz-grant-read-acp

    • x-amz-grant-write-acp

    • x-amz-grant-full-control

For more information about managing ACLs using the AWS CLI, seeput-bucket-acl in theAWS CLI Command Reference.

ACL overview
Policy examples

[8]
ページ先頭

©2009-2025 Movatter.jp