acl - Get, set, or change bucket and/or object ACLs

Synopsis

gsutil acl set [-f] [-r] [-a] (<file-path>|<predefined-acl>) url...
gsutil acl get url
gsutil acl ch [-f] [-r] <grant>... url...

where each <grant> is one of the following forms:

  -u <id>|<email>:<permission>
  -g <id>|<email>|<domain>|All|AllAuth:<permission>
  -p (viewers|editors|owners)-<project number>:<permission>
  -d <id>|<email>|<domain>|All|AllAuth|(viewers|editors|owners)-<project number>

Description

The acl command has three sub-commands:

Get

The acl get command gets the ACL text for a bucket or object, which you can save and edit for the acl set command.

Set

The acl set command allows you to set an Access Control List on one or more buckets and objects. As part of the command, you must specify either a predefined ACL or the path to a file that contains ACL text. The simplest way to use the acl set command is to specify one of the predefined ACLs, e.g.,:

gsutil acl set private gs://example-bucket/example-object

If you want to make an object or bucket publicly readable or writable, it is recommended to use acl ch, to avoid accidentally removing OWNER permissions. See the acl ch section for details.

See Predefined ACLs for a list of predefined ACLs.

If you want to define more fine-grained control over your data, you can retrieve an ACL using the acl get command, save the output to a file, edit the file, and then use the acl set command to set that ACL on the buckets and/or objects. For example:

gsutil acl get gs://bucket/file.txt > acl.txt

Make changes to acl.txt such as adding an additional grant, then:

gsutil acl set acl.txt gs://cats/file.txt

Note that you can set an ACL on multiple buckets or objects at once. For example, to set ACLs on all .jpg files found in a bucket:

gsutil acl set acl.txt gs://bucket/**.jpg

If you have a large number of ACLs to update you might want to use the gsutil -m option, to perform a parallel (multi-threaded/multi-processing) update:

gsutil -m acl set acl.txt gs://bucket/**.jpg

Note that multi-threading/multi-processing is only done when the named URLs refer to objects, which happens either if you name specific objects or if you enumerate objects by using an object wildcard or specifying the acl -r flag.

Set Options

The "set" sub-command has the following options

-R, -r

Performs "acl set" request recursively, to all objects under the specified URL.

-a

Performs "acl set" request on all object versions.

-f

Normally gsutil stops at the first error. The -f option causes it to continue when it encounters errors. If some of the ACLs couldn't be set, gsutil's exit status will be non-zero even if this flag is set. This option is implicitly set when running "gsutil -m acl...".

Ch

The "acl ch" (or "acl change") command updates access control lists, similar in spirit to the Linux chmod command. You can specify multiple access grant additions and deletions in a single command run; all changes will be made atomically to each object in turn. For example, if the command requests deleting one grant and adding a different grant, the ACLs being updated will never be left in an intermediate state where one grant has been deleted but the second grant not yet added. Each change specifies a user or group grant to add or delete, and for grant additions, one of R, W, O (for the permission to be granted). A more formal description is provided in a later section; below we provide examples.

Ch Examples

Examples for "ch" sub-command:

Grant anyone on the internet READ access to the object example-object:

gsutil acl ch -u allUsers:R gs://example-bucket/example-object

Grant the user john.doe@example.com READ access to all objects in example-bucket that begin with folder/:

gsutil acl ch -r -u john.doe@example.com:R gs://example-bucket/folder/

Grant the group admins@example.com OWNER access to all jpg files in example-bucket:

gsutil acl ch -g admins@example.com:O gs://example-bucket/**.jpg

Grant the owners of project example-project WRITE access to the bucket example-bucket:

gsutil acl ch -p owners-example-project:W gs://example-bucket

Remove access to the bucket example-bucket for the viewers of project number 12345:

gsutil acl ch -d viewers-12345 gs://example-bucket

Note that removing a project requires you to reference the project by its number (which you can see with the acl get command) as opposed to its project ID string.

Grant the service account foo@developer.gserviceaccount.com WRITE access to the bucket example-bucket:

gsutil acl ch -u foo@developer.gserviceaccount.com:W gs://example-bucket

Grant all users from the G Suite domain my-domain.org READ access to the bucket gcs.my-domain.org:

gsutil acl ch -g my-domain.org:R gs://gcs.my-domain.org

Remove any current access by john.doe@example.com from the bucket example-bucket:

gsutil acl ch -d john.doe@example.com gs://example-bucket

If you have a large number of objects to update, enabling multi-threading with the gsutil -m flag can significantly improve performance. The following command adds OWNER for admin@example.org using multi-threading:

gsutil -m acl ch -r -u admin@example.org:O gs://example-bucket

Grant READ access to everyone from my-domain.org and to all authenticated users, and grant OWNER to admin@mydomain.org, for the buckets my-bucket and my-other-bucket, with multi-threading enabled:

gsutil -m acl ch -r -g my-domain.org:R -g AllAuth:R \
  -u admin@mydomain.org:O gs://my-bucket/ gs://my-other-bucket

Ch Roles

You may specify the following roles with either their shorthand or their full name:

R: READ
W: WRITE
O: OWNER

For more information on these roles and the access they grant, see the permissions section of the Access Control Lists page.

Ch Entities

There are four different entity types: Users, Groups, All Authenticated Users, and All Users.

Users are added with -u and a plain ID or email address, as in "-u john-doe@gmail.com:r". Note: Service Accounts are considered to be users.

Groups are like users, but specified with the -g flag, as in "-g power-users@example.com:O". Groups may also be specified as a full domain, as in "-g my-company.com:r".

allAuthenticatedUsers and allUsers are specified directly, as in "-g allUsers:R" or "-g allAuthenticatedUsers:O". These are case insensitive, and may be shortened to "all" and "allauth", respectively.

Removing roles is specified with the -d flag and an ID, email address, domain, or one of allUsers or allAuthenticatedUsers.

Many entities' roles can be specified on the same command line, allowing bundled changes to be executed in a single run. This will reduce the number of requests made to the server.

Ch Options

The "ch" sub-command has the following options

-d

Remove all roles associated with the matching entity.

-f

Normally gsutil stops at the first error. The -f option causes it to continue when it encounters errors. With this option the gsutil exit status will be 0 even if some ACLs couldn't be changed.

-g

Add or modify a group entity's role.

-p

Add or modify a project viewers/editors/owners role.

-R, -r

Performs acl ch request recursively, to all objects under the specified URL.

-u

Add or modify a user entity's role.