This document shows how to update the Cloud Storage buckets for a Cloud FTP user, including which buckets a user can access and what permissions the user has.
At a high level, these are the steps to update the buckets for a user:
- Update the IAM roles for the user's service account.
- Map the user's directories to the updated buckets.
Before you begin
Create one or more Cloud Storage buckets to store the data that the user will work with, if the buckets don't already exist. You can grant a user access to a maximum of 10 buckets.
Required roles
To get the permission that
you need to update SFTP users,
ask your administrator to grant you the
FTP Admin (roles/ftp.admin) IAM role on your project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
This predefined role contains the
ftp.users.update
permission,
which is required to
update SFTP users.
You might also be able to get this permission with custom roles or other predefined roles.
Update IAM roles for a user's service account
If you change which buckets a user can access, or if you change the permission that a user has for an existing directory mapping, then you must update the user's service account with the relevant IAM roles. Do the following:
Get the email address of the user's service account. For steps, see Get details about a user.
If you add new buckets to the directory mapping or increase access to existing buckets, do the following:
Grant yourself the Storage Bucket Viewer (
roles/storage.bucketViewer) role on the bucket, if you don't have the role already:gcloud storage buckets add-iam-policy-binding gs://BUCKET_NAME \ --member="user:ADMINISTRATOR_EMAIL" \ --role="roles/storage.bucketViewer"
Replace the following:
ADMINISTRATOR_EMAIL: the email address of the principal who is creating the SFTP user. If you're creating the user (as opposed to an application), then this value is the email address that you use to access Google Cloud.BUCKET_NAME: the name of the bucket.
Grant yourself the Storage Object Viewer (
roles/storage.objectViewer) role on the bucket, if you don't have the role already:gcloud storage buckets add-iam-policy-binding gs://BUCKET_NAME \ --member="user:ADMINISTRATOR_EMAIL" \ --role="roles/storage.objectViewer"
Grant the user's service account the IAM roles that are necessary to access the buckets:
gcloud storage buckets add-iam-policy-binding gs://BUCKET_NAME \ --member="serviceAccount:SERVICE_ACCOUNT" \ --role="ROLE_TO_GRANT"
Replace the following:
SERVICE_ACCOUNT: the email address of the user's service account.ROLE_TO_GRANT: the IAM role to grant. Specify one of the following roles:- For read-only access, use the
roles/storage.objectViewerrole. - For read and write access, use the
roles/storage.objectAdminrole.
- For read-only access, use the
Repeat the previous steps for each bucket that the user needs to access.
If you remove buckets from the directory mapping or decrease access to existing buckets, then revoke access from the user's service account:
gcloud storage buckets remove-iam-policy-binding gs://BUCKET_NAME \ --member="serviceAccount:SERVICE_ACCOUNT" \ --role="ROLE_TO_REVOKE"
Replace
ROLE_TO_REVOKEwith the IAM role that you want to revoke.Repeat this step for each bucket and IAM role that the user should no longer have access to.
Update a user's buckets
gcloud
To update the buckets for an SFTP user, run the
gcloud alpha storage ftp users update command.
Before using any of the command data below, make the following replacements:
- USERNAME: the SFTP user's username.
- LOCATION_ID: the location of
the server, such as
us-west1. - SERVER_ID: the server ID.
- BUCKET_NAME: the name of a bucket that the SFTP user is granted access to, such as
example-bucket. Omit thegs://. - (Optional) BUCKET_PREFIX: the path of a folder within the bucket to set as the
root directory for this directory mapping.
If you omit the
bucket_prefixproperty, then Cloud FTP uses the bucket root. -
DIRECTORY: the logical landing directory path that is presented to the SFTP user. For example,
/home/uploads.If you map multiple buckets or folders, then provide a unique directory path for each mapping.
Nested logical directories aren't supported. If you provide multiple mappings for a directory, then provide the directories in a flat structure instead of a nested structure. For example, use
/dir1and/dir2instead of/dir1and/dir1/dir2. - SFTP_PERMISSION: the access level for the directory. For read-only access, set this
value to
READ_ONLY. For read and write access, set this value toREAD_WRITE.
To grant a user access to multiple buckets, provide the --storage-directory-mapping
flag multiple times, with a directory mapping for each bucket.
Execute the following command:
Linux, macOS, or Cloud Shell
gcloud alpha storage ftp users update USERNAME --location=LOCATION_ID \ --server=SERVER_ID \ --storage-directory-mapping=bucket=BUCKET_NAME,bucket_prefix=BUCKET_PREFIX,directory=DIRECTORY,permission=SFTP_PERMISSION
Windows (PowerShell)
gcloud alpha storage ftp users update USERNAME --location=LOCATION_ID ` --server=SERVER_ID ` --storage-directory-mapping=bucket=BUCKET_NAME,bucket_prefix=BUCKET_PREFIX,directory=DIRECTORY,permission=SFTP_PERMISSION
Windows (cmd.exe)
gcloud alpha storage ftp users update USERNAME --location=LOCATION_ID ^ --server=SERVER_ID ^ --storage-directory-mapping=bucket=BUCKET_NAME,bucket_prefix=BUCKET_PREFIX,directory=DIRECTORY,permission=SFTP_PERMISSION
If a user has an active SFTP connection, they might need to disconnect and then reconnect for the updated bucket settings to take effect.
REST
To update the buckets for an SFTP user, use the
servers.users.patch method.
In the updateMask query parameter, provide the
storageDirectoryMappings field.
Before using any of the request data, make the following replacements:
- PROJECT_ID: the Google Cloud project ID of the server.
- LOCATION_ID: the location of
the server, such as
us-west1. - SERVER_ID: the server ID.
- USERNAME: the SFTP user's username.
- BUCKET_NAME: the name of a bucket that the SFTP user is granted access to, such as
example-bucket. Omit thegs://. - (Optional) BUCKET_PREFIX: the path of a folder within the bucket to set as the root directory for this directory mapping. If you omit this value, then Cloud FTP uses the bucket root.
-
DIRECTORY: the logical landing directory path that is presented to the SFTP user. For example,
/home/uploads. If you omit this value, then Cloud FTP sets the landing directory to/.If you map multiple buckets or folders, then provide a unique directory path for each mapping.
Nested logical directories aren't supported. If you provide multiple mappings for a directory, then provide the directories in a flat structure instead of a nested structure. For example, use
/dir1and/dir2instead of/dir1and/dir1/dir2. - SFTP_PERMISSION: the access level for the directory. For read-only access, set this
value to
READ_ONLY. For read and write access, set this value toREAD_WRITE.
To grant a user access to multiple buckets, provide multiple bucket mappings in the
storageDirectoryMappings list.
HTTP method and URL:
PATCH https://ftp.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/servers/SERVER_ID/users/USERNAME?updateMask=storageDirectoryMappings
Request JSON body:
{
"storageDirectoryMappings": [
{
"bucket": "BUCKET_NAME",
"bucketPrefix": "BUCKET_PREFIX",
"directory": "DIRECTORY",
"permission": "SFTP_PERMISSION"
}
]
}
To send your request, expand one of these options:
The response identifies a long-running operation. It takes a few seconds for the user to be updated.If a user has an active SFTP connection, they might need to disconnect and then reconnect for the updated bucket settings to take effect.