This document describes how to create, list, get, update, and delete managed folders.
Managed folders let you control access to groups of objects in your Cloud Storage buckets by selectively setting IAM policies to objects that have a common prefix in their object name paths. This approach helps you meet data security and compliance requirements.
Managed folders can also be used to enable Rapid Cache caches to ingest data on write selectively by object name prefix. For more information, see Ingest-on-write.
Before you begin
To create and manage managed folders, you must first enable uniform bucket-level access and get the required IAM roles.
Enable uniform bucket-level access
If you haven't already, enable uniform bucket-level access.
Get required roles
To get the permissions that
you need to create and manage managed folders,
ask your administrator to grant you the
Storage Folder Admin (roles/storage.folderAdmin) IAM role on the bucket.
This predefined role contains the permissions required to create and manage managed folders. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to create and manage managed folders:
-
To create managed folders:
storage.managedFolders.create -
To validate newly created managed folders by listing them:
storage.objects.list -
To list managed folders:
storage.managedFolders.list -
To get managed folders:
storage.managedFolders.get -
To move managed folders:
-
storage.managedFolders.delete(on the source bucket) -
storage.managedFolders.create(on the destination bucket)
-
-
To update managed folders:
storage.managedFolders.update -
To delete managed folders:
storage.managedFolders.delete
For information about granting roles on buckets, see Set and manage IAM policies on buckets.
Create a managed folder
Console
When using the Google Cloud console, you create managed folders by enabling management on folders or simulated folders. The following steps describe how to create a folder or a simulated folder and then enable folder management:
- In the Google Cloud console, go to the Cloud Storage Buckets page.
In the list of buckets, click the name of the bucket you want to create managed folders in.
In the Bucket details page, click Create folder to create a new folder. If the folder you want to convert to a managed folder already exists, skip to the step describing how to access the More options menu.
In the Name field, enter a name for your folder. For naming considerations, see Managed folder names.
Click Create.
Your newly created folder appears in the Folder browser pane.
In the Folder browser pane, click the More options menu next to the folder you want to convert to a managed folder and click Edit access.
The Enable folder management? dialog appears.
Click Enable.
Your folder converts to a managed folder. A Permissions for
MANAGED_FOLDER_NAMEpane appears that displays the IAM policies on the folder by principal and role. To create new IAM policies, see Set an IAM policy on a managed folder.
Command line
To create a managed folder, run the
gcloud storage managed-folders create command:
gcloud storage managed-folders create gs://BUCKET_NAME/MANAGED_FOLDER_NAME
Where:
BUCKET_NAMEis the name of the bucket in which you want to create a managed folder. For example,my-bucket.MANAGED_FOLDER_NAMEis the name of the managed folder you want to create. For example,my-managed-folder/.
To confirm that the managed folder was created, run the
gcloud storage managed-folders describe command:
gcloud storage managed-folders describe gs://BUCKET_NAME/MANAGED_FOLDER_NAME
Where:
BUCKET_NAMEis the name of the bucket in which you created a managed folder.MANAGED_FOLDER_NAMEis the name of the managed folder you created.
Client libraries
For more information, see the
Cloud Storage C++ API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage C# API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Go API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Java API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Node.js API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage PHP API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Python API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Ruby API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
C++
C#
Go
Java
Node.js
PHP
Python
Ruby
Rust
REST APIs
JSON API
Have gcloud CLI installed and initialized, which lets you generate an access token for the
Authorizationheader.Use
cURLto call the JSON API with aPOSTManagedFolder request:curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -d '{ "name": "MANAGED_FOLDER_NAME" }' \ "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/managedFolders"Where:
MANAGED_FOLDER_NAMEis the name of the managed folder you want to create. For example,my-managed-folder/.BUCKET_NAMEis the name of the bucket in which you want to create a managed folder. For example,my-bucket.
Create a managed folder to enable Rapid Cache ingest-on-write
This section describes how to create a managed folder with settings that enable the Rapid Cache ingest-on-write feature at the prefix level. If you don't use Rapid Cache or its ingest-on-write feature, skip this section.
If you want to create a managed folder to enable prefix-level ingest on write for caches created with Rapid Cache:
Read Understanding how to enable ingest-on-write to familiarize yourself with how prefix-level ingest-on-write is configured.
Ensure that the cache's
ingestOnWriteproperty is set tofalse. For instructions, see Update a cache.Include a
rapidCacheConfigconfiguration in your request:
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ -d '{ "name": "MANAGED_FOLDER_NAME", "rapidCacheConfig": { "policies": { "RAPID_CACHE_ID": { "rapidCacheId": "RAPID_CACHE_ID", "ingestOnWrite": "enabled" } } } }' \ "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/managedFolders"Where:
MANAGED_FOLDER_NAMEis the name of the managed folder you want to create. The cache uses this managed folder name to selectively ingest objects on write. For example, if you specifymy-managed-folder/as the managed folder's name, the cache will only ingest objects in the bucket whose name includesmy-managed-folder/in its path.RAPID_CACHE_IDis the identifier for the cache, which is the zone of the cache. For example,us-east1-b. The cache you specify must be associated with the bucket in which the managed folder is being created. To find the caches associated with a bucket, list the caches for the bucket.BUCKET_NAMEis the name of the bucket that's associated with the cache. For example,my-cached-bucket. The managed folder will be created in this bucket.
List managed folders
Console
- In the Google Cloud console, go to the Cloud Storage Buckets page.
From the Folder browser pane, use the toggle node to expand the list of folders within your bucket.
A list displays the folders, simulated folders, and managed folders in your bucket.
Command line
To list managed folders, run the
gcloud storage managed-folders list command:
gcloud storage managed-folders list gs://BUCKET_NAME
Where:
BUCKET_NAMEis the name of the bucket that contains the managed folders you want to list. For example,my-bucket.
Note that you can also specify a folder path instead of a bucket name. For example:
gcloud storage managed-folders list gs://my-bucket/folder/
Client libraries
For more information, see the
Cloud Storage C++ API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage C# API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Go API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Java API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Node.js API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage PHP API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Python API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Ruby API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
C++
C#
Go
Java
Node.js
PHP
Python
Ruby
Rust
REST APIs
JSON API
Have gcloud CLI installed and initialized, which lets you generate an access token for the
Authorizationheader.Use
cURLto call the JSON API with a request to list managed folders:curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/managedFolders"
Where
BUCKET_NAMEis the name of the bucket that contains the managed folders you want to list. For example,my-bucket.
Get the metadata of a managed folder
Command line
To get the metadata of a managed folder, run the
gcloud storage managed-folders describe command:
gcloud storage managed-folders describe gs://BUCKET_NAME/MANAGED_FOLDER_NAME
Where:
BUCKET_NAMEis the name of the bucket that contains the managed folders you want to list. For example,my-bucket.MANAGED_FOLDER_NAMEis the name of the managed folder you want to retrieve metadata for.
Client libraries
For more information, see the
Cloud Storage C++ API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage C# API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Go API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Java API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Node.js API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage PHP API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Python API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Ruby API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
C++
C#
Go
Java
Node.js
PHP
Python
Ruby
Rust
REST APIs
JSON API
Have gcloud CLI installed and initialized, which lets you generate an access token for the
Authorizationheader.Use
cURLto call the JSON API with a request to get managed folders:curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/managedFolders/MANAGED_FOLDER_NAME"
Where:
BUCKET_NAMEis the name of the bucket that contains the managed folders you want to get. For example,my-bucket.MANAGED_FOLDER_NAMEis the name of the managed folder expressed as a path. For example,example-dir/. If the managed folder is nested, the slash (/) character in the managed folder path must be escaped. For example,example-dir1%2Fexample-dir2.
Move a managed folder
Console
Create a new managed folder in the destination bucket.
Copy the IAM policies from the original managed folder in the source bucket into the new managed folder in the destination bucket.
Copy the objects from the original managed folder in the source bucket to the new managed folder in the destination bucket.
Delete the original managed folder from the source bucket.
Command line
To move managed folders and the objects they contain, run the
gcloud storage mv command with the --include-managed-folders
option:
gcloud storage mv --include-managed-folders gs://SOURCE_BUCKET_NAME/MANAGED_FOLDER_NAME gs://DESTINATION_BUCKET_NAME/MANAGED_FOLDER_NAME
Where:
SOURCE_BUCKETis the name of your original bucket. For example,my-source-bucket`.DESTINATION_BUCKETis the name of the bucket you are moving your managed folder to. For example,my-destination-bucket.MANAGED_FOLDER_NAMEis the name of the managed folder you're moving. For example,my-managed-folder/.
REST APIs
JSON API
To move managed folders from one bucket to another, complete the following steps:
Create a new managed folder in the destination bucket.
Copy the IAM policies from the original managed folder in the source bucket to the new managed folder in the destination bucket.
Copy the objects from the original managed folder in the source bucket to the new managed folder in the destination bucket.
Delete the original managed folder from the source bucket.
Update the Rapid Cache ingest-on-write policy on a managed folder
This section describes how to enable or disable the Rapid Cache ingest-on-write setting at the prefix level, which uses managed folders as an underlying mechanism. If you don't use Rapid Cache or its ingest-on-write feature, skip this section.
To enable or disable the Rapid Cache ingest-on-write policy
for objects that share a managed folder prefix, you must update the
rapidCacheConfig configuration of the managed folder. These
instructions are only required when you use the JSON API to update a
cache's ingest-on-write policy.
For more details on how to enable or disable ingest-on-write at the prefix level, see Understanding ingest-on-write.
REST APIs
JSON API
To add, modify, or delete the Rapid Cache ingest-on-write policy on a managed folder:
Ensure that you've set the
ingestOnWriteproperty in the cache's configuration. Refer to Understanding ingest-on-write for which value to set the property to.Use
cURLto call the JSON API with aPATCHManagedFolder request. The request body differs depending on your use case:Enable or disable the ingest on write policy for a managed folder
To update the ingest on write configuration for one or multiple caches, use the following command:
curl -X PATCH -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ -d '{ "rapidCacheConfig": { "policies": { "RAPID_CACHE_ID": { "rapidCacheId": "RAPID_CACHE_ID", "ingestOnWrite": "INGEST_VALUE" } } } }' \ "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/managedFolders/MANAGED_FOLDER_NAME"Replace:
BUCKET_NAME: with the name of the bucket containing the managed folder.MANAGED_FOLDER_NAME: with the name of the managed folder.RAPID_CACHE_ID: with the identifier for the cache, which is the zone of the cache. For example,us-east1-b.INGEST_VALUE: with the ingestion behavior of the cache. When the value isenabled, ingest-on-write for managed folder prefixes is enabled. When the value isunspecified, the cache's ingest-on-write behavior is inherited either from a parent managed folder if it exists, or from the cache configuration on the bucket. For more information on the behaviors set by these values, see Ingest-on-write requirements. Carefully read about ingest-on-write inheritance to understand how a cache's ingest-on-write policy can be affected when theingestOnWritesetting for the cache is set tounspecified.
To configure ingest on write for multiple caches at a time, include multiple
policiesmaps in your request. For example:"rapidCacheConfig": { "policies": { "us-east1-a": { "rapidCacheId": "us-east1-a", "ingestOnWrite": "unspecified" } "us-east1-b": { "rapidCacheId": "us-east1-b", "ingestOnWrite": "enabled" } } }To disable prefix-level ingest on write for individual caches, remove the
policiesmap for the cache from therapidCacheConfigconfiguration.Delete an ingest-on-write policy on a managed folder
You can delete the ingest-on-write policy on a managed folder by using the instructions in this section. When you delete the ingest-on-write policy on a managed folder, the caches you specify in your request won't ingest objects on write by their managed folder prefix, and the ingestion behavior for objects in the bucket will be determined by the
ingestOnWritefield of the cache configuration. To learn how the ingest-on-write behavior is determined by theingestOnWritefield of a managed folder versus a cache configuration, see Understanding how to enable ingest-on-write and Ingest-on-write inheritance.To delete the ingest-on-write policy for a managed folder, use the following command. The following command disables prefix-level ingest-on-write on individual caches for the managed folder resource that contains this configuration:
curl -X PATCH -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ -d '{ "rapidCacheConfig": { "policies": { "us-east1-a": null } } }' "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/managedFolders/MANAGED_FOLDER_NAME"Replace:
BUCKET_NAME: with the name of the bucket containing the managed folder.MANAGED_FOLDER_NAME: with the name of the managed folder.RAPID_CACHE_ID: with the identifier for the cache, which is the zone of the cache. For example,us-east1-b. This field must be set tonull.
Alternatively, to delete the prefix-level ingest-on-write policy on a managed folder, set the
policiesmap tonullin your request:"rapidCacheConfig": { "policies": null }
Delete a managed folder
Console
- In the Google Cloud console, go to the Cloud Storage Buckets page.
In the list of buckets, click the name of the bucket that contains the managed folder you want to delete.
In the Bucket details page, click the More options icon next to the managed folder you want to delete.
Click Delete folder.
To confirm that you want to delete the managed folder, type
DELETEin Delete field.Click Delete.
The managed folder and its contents, including stored objects and other managed folders, are deleted from your Cloud Storage bucket.
Command line
To delete a managed folder and the objects it contains, run the
gcloud storage rm command:
gcloud storage rm -r gs://BUCKET_NAME/MANAGED_FOLDER_NAME
Where:
BUCKET_NAMEis the name of the bucket that contains the managed folder you want to delete. For example,my-bucket.MANAGED_FOLDER_NAMEis the name of the managed folder you want to delete. For example,my-managed-folder/.
Client libraries
For more information, see the
Cloud Storage C++ API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage C# API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Go API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Java API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Node.js API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage PHP API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Python API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Ruby API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
C++
C#
Go
Java
Node.js
PHP
Python
Ruby
Rust
REST APIs
JSON API
To delete a managed folder, you must first delete the objects within the managed folder.
Have gcloud CLI installed and initialized, which lets you generate an access token for the
Authorizationheader.Use
cURLto call the JSON API with aDELETEManagedFolder request:curl -X DELETE -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/managedFolders/MANAGED_FOLDER_NAME"
Where:
BUCKET_NAMEis the name of the bucket that contains the managed folder you want to delete. For example,my-bucket.MANAGED_FOLDER_NAMEis the name of the managed folder you want to delete. For example,my-managed-folder/.
By default, managed folders must be empty before they can be deleted. To delete a non-empty managed folder, include
allowNonEmpty=trueas a query parameter in your request.
Troubleshooting
For help creating and managing managed folders, refer to the Troubleshooting page.
What's next
Learn about the best practices for using managed folders.