Manage access to custom images Stay organized with collections Save and categorize content based on your preferences.
To let users create, delete, use, or share your custom images, you mustgrant them the appropriate Identity and Access Management (IAM) roles. This documentdescribes the required IAM permissions for creating and managingcustom images and how to give them to users.
For general information about granting access toCompute Engine resources, seeManaging access to Compute Engine resources.For information about IAM, read theIAMdocumentation.
Before you begin
- Read theIAM documentation.
- Read aboutCompute Engine IAM roles, in particular, the Compute Image User role (
roles/compute.imageUser). - If you haven't already, set upauthentication. Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
Install the Google Cloud CLI. After installation,initialize the Google Cloud CLI by running the following command:
gcloudinit
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.- Set a default region and zone.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI. After installation,initialize the Google Cloud CLI by running the following command:
gcloudinit
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.For more information, seeAuthenticate for using REST in the Google Cloud authentication documentation.
Required roles
To get the permissions that you need to manage access to custom images, ask your administrator to grant you the following IAM roles:
- Project IAM Admin (
roles/resourcemanager.projectIamAdmin) on the project - Compute Admin (
roles/compute.admin) on the project
For more information about granting roles, seeManage access to projects, folders, and organizations.
These predefined roles contain the permissions required to manage access to custom images. To see the exact permissions that are required, expand theRequired permissions section:
Required permissions
The following permissions are required to manage access to custom images:
- To give users or service accounts the permissions needed to create, share custom images:
resourcemanager.projects.getIamPolicyon the projectresourcemanager.projects.setIamPolicyon the project
- To give users or service accounts the permissions needed to delete custom images:
resourcemanager.projects.getIamPolicyon the projectresourcemanager.projects.setIamPolicyon the projectcompute.images.getIamPolicyon the imagecompute.images.setIamPolicyon the image
- To revoke user or service account access to custom images:
resourcemanager.projects.getIamPolicyon the projectresourcemanager.projects.setIamPolicyon the project
- To create an instance using a shared image:
compute.instances.createon the project- To use a custom image to create the VM:
compute.images.useReadOnlyon the image - To use a snapshot to create the VM:
compute.snapshots.useReadOnlyon the snapshot - To use an instance template to create the VM:
compute.instanceTemplates.useReadOnlyon the instance template - To assign alegacy network to the VM:
compute.networks.useon the project - To specify a static IP address for the VM:
compute.addresses.useon the project - To assign an external IP address to the VM when using a legacy network:
compute.networks.useExternalIpon the project - To specify a subnet for the VM:
compute.subnetworks.useon the project or on the chosen subnet - To assign an external IP address to the VM when using a VPC network:
compute.subnetworks.useExternalIpon the project or on the chosen subnet - To set VM instance metadata for the VM:
compute.instances.setMetadataon the project - To set tags for the VM:
compute.instances.setTagson the VM - To set labels for the VM:
compute.instances.setLabelson the VM - To set a service account for the VM to use:
compute.instances.setServiceAccounton the VM - To create a new disk for the VM:
compute.disks.createon the project - To attach an existing disk in read-only or read-write mode:
compute.disks.useon the disk - To attach an existing disk in read-only mode:
compute.disks.useReadOnlyon the disk
You might also be able to get these permissions withcustom roles or otherpredefined roles.
Limitations
On images, you can't grant roles to the special member typeallUsers.
Give permission to create custom images
You can give users the ability to createcustom imagesin your organization or project.
Compute Engine offers the predefinedCompute Storage Admin role(roles/compute.storageAdmin)that you can assign to users so that they can create, delete, and managestorage-related resources, including images, disks, and snapshots. If you need arole that allows for only image creation, you must create acustomrole. In your customrole, include the following permissions:
compute.images.createto create new imagescompute.images.listto list images in the projectcompute.disks.useif the image is created from a diskcompute.disks.listif users need to list all disks in a project
If you give a user the ability to create custom images at the organizationlevel, the user can create custom images for any project within theorganization.
Console
In the Google Cloud console, go to theIAM page for theproject or organization.
To add a new member, clickGrant access.
In theNew principals field, enter the email address of the identitythat you want to grant access to.
For example:
- Google Account email:
test-user@gmail.com - Google group:
admins@googlegroups.com - Identity from anexternal identity provider:
principal://iam.googleapis.com/locations/global/workforcePools/altostrat-contractors/subject/raha@altostrat.com - Service account:
server@example.gserviceaccount.com - Google Workspace domain:
example.com
- Google Account email:
In theSelect a role list, selectCompute Engine>Compute Storage Admin, or select a custom role if you created one.
Optional: To further control user's access to Google Cloud resources,add conditional role binding.
Save your changes.
gcloud
To grant theroles/compute.storageAdmin role at an organization level, usethegcloud organizations add-iam-policy-binding command:
gcloud organizations add-iam-policy-bindingORGANIZATION_ID \ --member='MEMBER' \ --role='roles/compute.storageAdmin'
To grant theroles/compute.storageAdmin role at a project level, use thegcloud projects add-iam-policy-binding command:
gcloud projects add-iam-policy-bindingPROJECT_ID \ --member='MEMBER' \ --role='roles/compute.storageAdmin'
Replace the following:
ORGANIZATION_IDorPROJECT_ID:the organization ID or the project ID—for example,my-organization-1ormy-project-1MEMBER: a valid identity to which you want togrant the roleFor example:
- Google Account email:
user:user@gmail.com - Google group:
group:admins@googlegroups.com - Identity from anexternal identity provider:
principal://iam.googleapis.com/locations/global/workforcePools/altostrat-contractors/subject/raha@altostrat.com - Service account:
serviceAccount:server@example.gserviceaccount.com - Google Workspace domain:
domain:example.com
- Google Account email:
REST
Read the existing policy with the resource's
getIamPolicymethod. Forprojects, use theprojects.getIamPolicymethod.POST https://cloudresourcemanager.googleapis.com/v1/projects/PROJECT_ID:getIamPolicy
Replace
PROJECT_IDwith the projectID—for example,my-project-1.For organizations, use the
organizations.getIamPolicymethod.POST https://cloudresourcemanager.googleapis.com/v1/organizations/ORGANIZATION_ID:getIamPolicy
Replace
ORGANIZATION_IDwith the organizationID—for example,123456578920.Compute Engine returns the current policy in the response.
To add or remove members and their associated roles, edit the policy witha text editor. Use the following format to add members:
user:test-user@gmail.comgroup:admins@example.comserviceAccount:test123@example.domain.comdomain:example.domain.com
For example, to grant the
roles/compute.storageAdminrole togroup:admins@example.com, add the following binding to the policy:{ "members": [ "group:admins@example.com" ], "role":"roles/compute.storageAdmin"}Write the updated policy by using the
setIamPolicymethod.For example, to seta policy at the project level, use the
project.setIamPolicymethod. Inthe body of the request, provide the updated IAM policyfrom the previous step.POST https://cloudresourcemanager.googleapis.com/v1/projects/PROJECT_ID:setIamPolicy
Replace the
PROJECT_IDwith the project ID.
Give permissions to delete custom images
Depending on your needs, you can give users permission to do the following:
- Delete a specific image
- Delete images owned by a specific project
- Delete images for any project in an organization
Giving permission at the project level lets users delete all images owned bythat project. Giving permission at the organization level lets the user deleteany images owned by that organization, regardless of the project.
Compute Engine offers the predefinedCompute Storage Adminrole(roles/compute.storageAdmin) that you can assign to users so that they cancreate, delete, and manage storage-related resources, including images, disks,and snapshots. If you need a role that allows for only image deletion, you mustcreate acustom role.In your custom role, include the following permissions:
compute.images.deleteto delete imagescompute.images.listif users need to list images in the project ororganizationcompute.images.getto get the images
Console
To give permission to delete specific images, do the following:
In the Google Cloud console, go to theImages page.
Select the images that you want to give permissions to.
To expand the permissions column, clickShow info panel.
To add one or more members, clickAdd principal.
In theNew principals field, enter the email address of the identity youwant to share the image with.
For example:
- Google Account email:
test-user@gmail.com - Google group:
admins@googlegroups.com - Identity from anexternal identity provider:
principal://iam.googleapis.com/locations/global/workforcePools/altostrat-contractors/subject/raha@altostrat.com - Service account:
server@example.gserviceaccount.com - Google Workspace domain:
example.com
- Google Account email:
In theRole list, hold the pointer overCompute Engine and selectStorage Admin, or select a custom role from theCustom list.
Optional: To further control user's access to Google Cloud resources,add conditional role binding.
Save your changes.
To give permission to delete images for a project or organization, do thefollowing:
Go to theIAM page for the project or organization.
ClickGrant access.
In theNew principals field, enter the email address of the identity youwant to grant access to. For example:
- Google Account email:
test-user@gmail.com - Google group:
admins@googlegroups.com - Identity from anexternal identity provider:
principal://iam.googleapis.com/locations/global/workforcePools/altostrat-contractors/subject/raha@altostrat.com - Service account:
server@example.gserviceaccount.com - Google Workspace domain:
example.com
- Google Account email:
In theRole list, hold the pointer overCompute Engine and selectStorage Admin, or select a custom role from theCustom list.
Optional: To further control user's access to Google Cloud resources,add conditional role binding.
Save your changes.
gcloud
To give permissions to delete images at the organization level, use thegcloud organizations add-iam-policy-bindingcommand:
gcloud organizations add-iam-policy-bindingORGANIZATION_ID \ --member='MEMBER' \ --role='ROLE'
To give permissions to delete images on a project level, use thegcloudprojects add-iam-policy-bindingcommand:
gcloud projects add-iam-policy-bindingPROJECT_ID \ --member='MEMBER' \ --role='ROLE'
To give permissions to delete a specific image, use thegcloud computeimages add-iam-policy-bindingcommand:
gcloud compute images add-iam-policy-bindingIMAGE_NAME \ --member='MEMBER' \ --role='ROLE'
Replace the following:
ORGANIZATION_IDorPROJECT_IDorIMAGE_NAME:the 12-digit numeric organization ID, the project ID, or the imagename—for example,123456578920,my-project-1, ormy-custom-imageMEMBER: a valid identity to which you want togrant the roleFor example:
- Google Account email:
user:user@gmail.com - Google Group:
group:admins@googlegroups.com - Identity from anexternal identity provider:
principal://iam.googleapis.com/locations/global/workforcePools/altostrat-contractors/subject/raha@altostrat.com - Service account:
serviceAccount:server@example.gserviceaccount.com - Google Workspace domain:
domain:example.com
- Google Account email:
ROLE: the role to assign to thisidentity—for example, theroles/compute.storageAdminrole, or acustom role such asroles/customImageDeletionRole
REST
Read the existing policy with the resource's respective
getIamPolicymethod. For projects, use theprojects.getIamPolicymethod:POST https://cloudresourcemanager.googleapis.com/v1/projects/PROJECT_ID:getIamPolicy
Replace
PROJECT_IDwith the project ID.For organizations, use the
organizations.getIamPolicymethod:POST https://cloudresourcemanager.googleapis.com/v1/organizations/ORGANIZATION_ID:getIamPolicy
Replace
ORGANIZATION_IDwith the 12-digitnumeric organization ID.For a specific image, use the
images.getIamPolicymethod:POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images/IMAGE_NAME:getIamPolicy
Replace the following:
PROJECT_ID: the project IDIMAGE_NAME: the name of the image
Compute Engine returns the current policy in the response.
To add or remove members and their associated roles, you can edit thepolicy with a text editor. Use the following format to add members:
user:test-user@gmail.comgroup:admins@example.comserviceAccount:test123@example.domain.comdomain:example.domain.com
For example, to grant the
roles/compute.storageAdminrole touser:test-email@example.com, add the following binding to thepolicy:{ "members": [ "user:test-email@example.com" ], "role":"roles/compute.storageAdmin"}Write the updated policy by using the
setIamPolicymethod.For example, to set a policy at a project level, use the
project.setIamPolicymethod.In the body of the request, provide the updated IAM policyfrom the previous step.POST https://cloudresourcemanager.googleapis.com/v1/projects/PROJECT_ID:setIamPolicy
Replace
PROJECT_IDwith the project ID.
Give permissions to share custom images within an organization
If your project belongs to an organization, the organization can have severalother projects with varying levels of access to other projects. When you createcustom images, you can share these images with other users from otherprojects within the organization.
Compute Engine offers the following predefined IAM rolesthat you can use for image management:
- Compute Image User (
roles/compute.imageUser): permission to list, read, anduse images in your requests, without having other permissions on the image - Compute Storage Admin (
roles/compute.storageAdmin): permissions to create,modify, and delete disks, images, and snapshots
Alternatively, you can also create your owncustom IAM role.
As a best practice, we recommend that you keep all your custom images in asingle project dedicated to host these images.This practice improves the management of those images, and lets you grantspecific teams access to only the images that they need. You can also grantteams access to the entire image project, but because team access to the entireimage project violates the principle of least privilege, we do not recommend it.
The example below shows how to add a group so that users of that group haveaccess to the image.
Console
In the Google Cloud console, go to theImages page.
Select the image that you want to share with other users.
To expand the permissions column, clickShow info panel.
To add one or more members, clickAdd principal.
In theNew principals field, enter the email address of the identity youwant to share the image with.
For example:
- Google Account email:
test-user@gmail.com - Google group:
admins@googlegroups.com - Identity from anexternal identity provider:
principal://iam.googleapis.com/locations/global/workforcePools/altostrat-contractors/subject/raha@altostrat.com - Service account:
server@example.gserviceaccount.com - Google Workspace domain:
example.com
- Google Account email:
In theRole list, hold the pointer overCompute Engine and selectImage User orStorage Admin, or select a custom role.
Optional: To further control user's access to Google Cloudresources,add conditional role binding.
Save your changes.
To let users launch shared custom images from the Google Cloud console,grant users the Viewer IAM role (roles/viewer) for theimage project. Granting this role helps ensure that the shared images appearin the image selection list.
In the Google Cloud console, go to theIAM page.
ClickGrant access.
In theNew principals field, enter the email address of the identity youwant to share the image with. For example:
- Google Account email:
test-user@gmail.com - Google group:
admins@googlegroups.com - Identity from anexternal identity provider:
principal://iam.googleapis.com/locations/global/workforcePools/altostrat-contractors/subject/raha@altostrat.com - Service account:
server@example.gserviceaccount.com - Google Workspace domain:
example.com
- Google Account email:
In theRole list, hold the pointer overProject and selectViewer.
Optional: To further control user's access to Google Cloudresources,add conditional role binding.
Save your changes.
gcloud
To update the IAM policy for a specific image, use thegcloud compute images add-iam-policy-binding command:
gcloud compute images add-iam-policy-bindingIMAGE_NAME \ --member='MEMBER' \ --role='ROLE'
Replace the following:
IMAGE_NAME: the name of theimage—for example,custom-centos-8MEMBER: a valid identity for which you want togrant the roleFor example:
user:test-user@gmail.comgroup:admins@example.comserviceAccount:test123@example.domain.comdomain:example.domain.com
ROLE: the role to assign this identity to, such asroles/compute.imageUser,roles/compute.storageAdmin, or a custom role
Optionally, to let users see these shared images in theirimages.listrequests, grant users the Viewer IAM role (roles/viewer)for the image project by using thegcloud projects add-iam-policy-bindingcommand. If you don'tneed your users to be able to view the list of shared images, you can skipthis step.
gcloud projects add-iam-policy-bindingPROJECT_ID \ --member='MEMBER' \ --role='roles/viewer'
REST
Read the existing policy with the resource's
getIamPolicymethod. For example, to get the policy on a specific image, use theimages.getIamPolicymethod:POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images/IMAGE_NAME:getIamPolicy
Replace the following:
PROJECT_ID: the project ID of the project this image belongs toIMAGE_NAME: the name of the image
Compute Engine returns the current policy in the response.
To add or remove members and their associated roles, edit the policy with atext editor. Use the following format to add members:
user:test-user@gmail.comgroup:admins@example.comserviceAccount:test123@example.domain.comdomain:example.domain.com
For example, to grant
roles/compute.imageUsertotest-email@example.com,add the following binding to the policy:{ "members": [ "user:test-email@example.com" ], "role":"roles/compute.imageUser"}Write the updated policy by using the
setIamPolicymethod. For example,to set policy on a specific image, use theproject.setIamPolicymethod.In the body of the request, provide the updated IAM policyfrom the previous step.POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images/IMAGE_NAME:setIamPolicy
Replace the following:
PROJECT_ID: the project ID of the project this image belongs toIMAGE_NAME: the name of the image
Optionally, to let users see these shared images in theirimages.listrequests, grant users the Viewer IAM role (roles/viewer) for theimage project by using theprojects.setIamPolicy method.If you don't need your users to be able to view the list of shared images,you can skip this step.
POST https://cloudresourcemanager.googleapis.com/v1/projects/PROJECT_ID:setIamPolicy
Give permissions to share custom images between organizations
Creating a catalog of custom images can be useful for sharing images withpartners, users, or contractors that are outside of your organization. To shareyour images with users outside of the organization, add them as Image Usersto your project:
Console
In the Google Cloud console, go to theImages page.
Select the image that you want to share with other users.
To expand the permissions column, clickShow info panel.
To add one or more members, clickAdd principal.
In theNew principals field, enter the email address of the group youwant to share the image with. For example,
admins@example.com.In theRole list, hold the pointer overCompute Engine and selectCompute Image User.
Optional: To further control user's access to Google Cloudresources,add conditional role binding.
Save your changes.
To let users launch shared custom images from the Google Cloud console,grant users the Viewer IAM role (roles/viewer) for theimage project. Grantingthis role helps ensure that the shared images appear in the image selectionlist.
In the Google Cloud console, go to theIAM page.
ClickGrant access.
In theNew principals field, enter the email address of the identity youwant to share the image with. For example,
admins@example.com.In theRole list, hold the pointer overProject and selectViewer.
Optional: To further control user's access to Google Cloudresources,add conditional role binding.
Save your changes.
gcloud
To grant theroles/compute.imageUser role to users, use thegcloudcompute images add-iam-policy-binding command:
gcloud compute images add-iam-policy-bindingIMAGE_NAME \ --member='MEMBER' \ --role='roles/compute.imageUser'
Replace the following:
IMAGE_NAME: the name of the image—forexample,custom-centos-8MEMBER: a valid identity for which you want togrant the role—for example,group:admins@example.com
Optionally, to let users see these shared images in theirimages.listrequests, grant users the Viewer IAM role (roles/viewer)for the image project by using thegcloud projects add-iam-policy-bindingcommand. If youdon't need your users to be able to view the list of shared images, you canskip this step.
gcloud projects add-iam-policy-bindingPROJECT_ID \ --member='MEMBER' \ --role='roles/viewer'
REST
Read the existing policy with the resource's
getIamPolicymethod. For example, to get the policy on a specific image, use theimages.getIamPolicymethod:POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images/IMAGE_NAME:getIamPolicy
Replace the following:
PROJECT_ID: the project ID of the project this image belongs toIMAGE_NAME: the name of the image
Compute Engine returns the current policy in the response.
To add or remove members and their associated roles, you can edit thepolicy with a text editor. Use the following format to add members:
user:test-user@gmail.comgroup:admins@example.comserviceAccount:test123@example.domain.comdomain:example.domain.com
For example, to grant
roles/compute.imageUsertotest-user@example.com, add the following binding to the policy:{ "members": [ "user:test-user@example.com" ], "role":"roles/compute.imageUser"}Write the updated policy by using the
setIamPolicymethod. For example,to set a policy on a specific image, use theimages.setIamPolicymethod.In the body of the request, provide the updated IAM policyfrom the previous step.POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images/IMAGE_NAME:setIamPolicy
Replace the following:
PROJECT_ID: the project ID of the project this image belongs toIMAGE_NAME: the name of the image
Optionally, to let users see these shared images in their
images.listrequests, grant users the Viewer IAM role (roles/viewer)for the image project by using theprojects.setIamPolicymethod. If youdon't need your users to be able to view the list of shared images, you canskip this step.POST https://cloudresourcemanager.googleapis.com/v1/projects/PROJECT_ID:setIamPolicy
Give permissions to share custom images publicly
You can share your custom images with all authenticated Compute Engineusers, regardless of whether they are part of your organization or project.
You can only share resources, such as images, with all authenticated users;you cannot share projects or organizations with all authenticatedusers. This restriction, and the resource hierarchy, helps prevent anorganization from inadvertently sharing their entire project with allauthenticated Compute Engine users.
The following example shows how to grant all authenticated Compute Engineusers the Compute Image User role (roles/compute.imageUser) to a custom image.
images.list request.gcloud
To make images public, use thegcloud compute images add-iam-policy-binding command:
gcloud compute images add-iam-policy-bindingIMAGE_NAME \ --member='allAuthenticatedUsers' \ --role='roles/compute.imageUser'
ReplaceIMAGE_NAME with the name of the resource—for example,my_image.
REST
Read the existing policy with the
getIamPolicymethod. For example, to get the policy on a specific image, use theimages.getIamPolicymethod:POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images/IMAGE_NAME:getIamPolicy
Replace the following:
PROJECT_ID: the project ID of the project this image belongs toIMAGE_NAME: the name of the image
Compute Engine returns the current policy in the response.
To add or remove members and their associated roles, edit the policy with a text editor:
{ "members": [ "allAuthenticatedUsers" ], "role":"roles/compute.imageUser"}Write the updated policy by using the
setIamPolicymethod. For example,to set a policy on a specific image, use theimages.setIamPolicymethod.In the body of the request, provide the updated IAM policyfrom the previous step.POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images/IMAGE_NAME:setIamPolicy
Replace the following:
PROJECT_ID: the project ID of the project this image belongs toIMAGE_NAME: the name of the image
Grant a managed instance group access to images
Compute Engine lets you create groups of instances, either asmanaged orunmanagedinstance groups. If you create a managed instance group (MIG),Compute Engine uses theGoogle APIs Service Agentto call the Compute Engine API and perform actions related tothe group, such as recreating unhealthy instances and updating instances.
If you want to create a MIG using an image from anotherproject, grant the Compute Image User role (roles/compute.imageUser) to theAPIs service account belonging to the project that creates the MIG. For example:
- Project A wants to create a MIG using images owned byProject B.
- Project B grants Project A's service account the Compute Image User role.
- Project A can now use images from Project B to create MIGs.
After granting the Compute Image User role, you can access the imagefrom the other projects by using the console or the image's URL when youcreate theinstance templatefor the managed group.
Get the email address of the service account
In the Google Cloud console, go to theIAM page of the project whoseservice account you want to grant access to.
If prompted, select your project from the list.
Look for theGoogle APIs Service Agent, which has the emailaddress in the following format:
Note: This email address requires the projectnumber, not theproject ID. To learn how to identify the project number, seeIdentifying projects.PROJECT_NUMBER@cloudservices.gserviceaccount.com
After retrieving the email address of the service account, you can go to one ofthe following sections:
Grant a MIG access to all images in a project
Now that you have the email address of a service account, you can add theaddress to another project and grant it the Compute Image User role(roles/compute.imageUser).
Console
In the Google Cloud console, go to theIAM page of the imageproject.
To add a new member, clickGrant access.
In theNew principals field, add the service account email address.
In theRole list, hold the pointer overCompute and selectCompute Image User.
Optional: To further control user's access to Google Cloudresources,add conditional role binding.
ClickSave.
Switch back to the service account's project.
You can nowcreate an instance templatebased on an image from the image project andcreate a MIGbased on the instance template.
gcloud
Add a service account from image project using thegcloud projectsadd-iam-policy-binding command:
gcloud projects add-iam-policy-bindingPROJECT_ID \ --member='serviceAccount:SERVICE_ACCOUNT_EMAIL' --role='roles/compute.imageUser'
Replace the following:
PROJECT_ID: the ID of the project containingimages you want to shareSERVICE_ACCOUNT_EMAIL: the email of theservice account
You can nowcreate an instance templatebased on an image from the image project andcreate a MIGbased on the instance template.
REST
Get the IAM policy of the image project, by using the
projects.getIamPolicymethod:POST https://cloudresourcemanager.googleapis.com/v1/projects/PROJECT_ID:getIamPolicy
Replace
PROJECT_IDwith the project ID of theimage project.To grant the
roles/compute.imageUserrole to the service account, edit the policy with a text editor:{ "bindings": [ { "role": "roles/compute.imageUser", "members": [ "serviceAccount:SERVICE_ACCOUNT_EMAIL" ] } ]}Replace the
SERVICE_ACCOUNT_EMAILwith theservice account email.Write the updated policy by using the
projects.setIamPolicy.In the body of the request, provide the updated IAM policyfrom the previous step.POST https://cloudresourcemanager.googleapis.com/v1/projects/PROJECT_ID:setIamPolicy
Replace
PROJECT_IDwith the product ID of theimage project.You can nowcreate an instance templatebased on an image from the image project andcreate a MIGbased on the instance template.
Grant a MIG access to specific images in a project
Now that you have the email address of a service account, you can add theaddress to another project and grant the Compute Image User role (roles/compute.imageUser)for certain images.
Console
In the Google Cloud console, go to theImages page of the imageproject.
Select the checkboxes next to the images you want to share.
To expand the permissions column, clickShow info panel.
In thePermissions panel, clickAdd principal.
In theNew principals field, enter the service account email that you want to share the image with.For example,
test123@example.domain.com.In theRole list, chooseCompute and selectCompute Image User.
Optional: To further control user's access to Google Cloud resources,add conditional role binding.
ClickSave.
Switch back to the service account's project.
You can nowcreate an instance templatebased on an image from the image project andcreate a MIGbased on the instance template.
gcloud
To grant a service account access to a specific image, use thegcloud compute images add-iam-policy-binding command:
gcloud compute images add-iam-policy-bindingIMAGE_NAME \ --member='serviceAccount:SERVICE_ACCOUNT_EMAIL' \ --role='roles/compute.imageUser'
Replace the following:
IMAGE_NAME: the image name you want to shareSERVICE_ACCOUNT_EMAIL: the email of theservice account
You can nowcreate an instance templatebased on an image from the image project andcreate a MIGbased on the instance template.
REST
Get the IAM policy of an image by using the
images.getIamPolicymethod:POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images/IMAGE_NAME:getIamPolicy
Replace the following:
PROJECT_ID: the project ID of the imageprojectIMAGE_NAME: the name of the image you wantto share
To grant the
roles/compute.imageUserrole to the service account, editthe policy with a text editor:{ "bindings": [ { "role": "roles/compute.imageUser", "members": [ "serviceAccount:SERVICE_ACCOUNT_EMAIL" ] } ]}Replace the
SERVICE_ACCOUNT_EMAILwith theservice account email.Write the updated policy by using the
images.setIamPolicymethod.In the body of the request, provide the updated IAM policyfrom the previous step.POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images/IMAGE_NAME:setIamPolicy
Replace the following:
PROJECT_ID: the project ID of the imageprojectIMAGE_NAME: the name of the image you wantto share
You can nowcreate an instance templatebased on an image from the image project andcreate a MIGbased on the instance template.
Control the use of your shared images and snapshots
After sharing your images with other users, you can control where those usersemploy those resources within your organization. Set theconstraints/compute.storageResourceUseRestrictions constraintto define the projects where users are permitted to use your storage resources.
You must have permission to modify your organization's policies to set theseconstraints. For example, theresourcemanager.organizationAdmin rolehas permission to set these constraints.
Find the organization ID for your organization by using the
gcloudorganization listcommand:gcloud organizations list
Get the existing policy settings for your organization by using the
gcloudresource-manager org-policies describecommand:gcloud resource-manager org-policies describe \ compute.storageResourceUseRestrictions \ --organizationORGANIZATION_ID > org-policy.yaml
ReplaceORGANIZATION_ID with your 12-digit numericorganization ID.
Open the
org-policy.yamlfile in a text editor and modify thecompute.storageResourceUseRestrictionsconstraint. Add the restrictionsthat you need, or remove the restrictions that you no longer require.When you finish editing the file, save your changes. For example,you might set the following constraint entry in your policy file: Note: You can also specify a folder ID using theconstraint: compute.storageResourceUseRestrictionslistPolicy: allowedValues: - under:organization/organization-id
under:folder/FOLDER_IDformat to organizeall projects into a folder.Apply the
org-policy.yamlfile to your organization by using thegcloud resource-manager org-policies set-policycommand:gcloud resource-manager org-policies set-policy \ --organization=ORGANIZATION_ID org-policy.yaml
ReplaceORGANIZATION_ID with your 12-digit numericorganization ID.
When you finish configuring the constraints in your organization policy, testthose constraints to ensure that they create the restrictions that you want.
Use images from another project
If someone grants you access to one or more images in another project,you can access these images in the project by specifying the image project inyour requests.
For example, to create an instance using a shared image from another project,follow the steps listed inCreate an instance from a shared image.
You can also create boot disk volumes from images in another project. Forinformation about creating a boot disk from an image, seeCreating a standalone boot persistent disk.
Revoke access to shared images
After a user no longer needs access to your Compute Engine resources,revoke their access by using the Google Cloud console, the Google Cloud CLI, orREST.
Console
In the Google Cloud console, go to theImages page of the imageproject.
Select the checkboxes next to the images you want to update.
To expand the permissions column, clickShow info panel.
Expand the role for which you want to remove users.
To remove a user from that role, clickDelete.
gcloud
To remove a user from a role on an image, use thegcloud compute imagesremove-iam-policy-bindingcommandwith the--member and--role flags:
gcloud compute images remove-iam-policy-bindingIMAGE_NAME \ --member='MEMBER' \ --role='ROLE'
Replace the following:
IMAGE_NAME: the name of the image—forexample,my_imageMEMBER: the identity you want to removeMust be of the form
user|group|serviceAccount:emailordomain:domain.For example:user:test-user@gmail.comgroup:admins@example.comserviceAccount:test123@example.domain.comdomain:example.domain.com
ROLE: the role from which you want to removethe identity
If you are revoking access to a resource that is in beta, useagcloud beta compute command instead.
REST
Read the existing policy with the
images.getIamPolicymethod:POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images/IMAGE_NAME:getIamPolicy
Replace the following:
PROJECT_ID: the project ID this imagebelongs toIMAGE_NAME: the name of the image
Compute Engine returns the current policy in the response.
To remove members and their associated roles, edit the policy with a texteditor.
Write the updated policy by using the
images.setIamPolicymethod.In the body of the request, provide the updated IAM policyfrom the previous step.POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/global/images/IMAGE_NAME:setIamPolicy
Replace the following:
PROJECT_ID: the project ID this imagebelongs toIMAGE_NAME: the name of the image
What's next
- Read aboutIAM.
- See a list ofCompute Engine IAM roles.
- Learn aboutimages.
- Learn how tocreate an instance by using a shared image.
- Learn how tocreate a standalone boot persistent disk.
- Learn how to use this role with yourDeployment Manager deployments.
- Apply the principle of least privilege bygranting access to specific Compute Engine resourcesinstead of to a whole project.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.