Restricting service account usage  |  Resource Manager Documentation  |  Google Cloud (2024)

The Resource Manager provides constraints that can be usedin organization policies to limit the usage ofIdentity and Access Management (IAM) service accounts.

Many of these constraints determine whether service accounts and other resourcescan be created or configured in specific ways. These constraints are notretroactive; they do not affect previously created and configured serviceaccounts.

Before you begin

You must have permission to modifyorganization policies to setconstraints. For example, theorgpolicy.policyAdminrole has permission to set organization policy constraints. Read theUsing Constraintspage to learn more about managing policies at the organization level.

Boolean constraints

The following constraints are types ofboolean constraint, which are set totrue or false.

Disable automatic role grants to default service accounts

Some Google Cloud services automatically createdefault service accounts. When a defaultservice account is created, it is automatically granted the Editor role(roles/editor) on your project.

To improve security, we strongly recommend that you disable the automatic rolegrant. Use the iam.automaticIamGrantsForDefaultServiceAccounts booleanconstraint to disable the automatic role grant.

Disable service account creation

You can use the iam.disableServiceAccountCreation boolean constraint todisable the creation of new service accounts. This allows you to centralizemanagement of service accounts while not restricting the other permissions yourdevelopers have on projects.

If you enforce this constraint in a project, then some Google Cloudservices cannot automatically createdefault service accounts. As a result, ifthe project runs workloads that need toimpersonate a service account, theproject might not contain a service account that the workload can use. Toaddress this issue, you canenable service account impersonation across projects.When you enable this feature, you can create service accounts in a centralizedproject, then attach the service accounts to resources in other projects.

For more information about organizing service accounts, seeWhere to create service accounts.

Disable service account key creation

You can use the iam.disableServiceAccountKeyCreation boolean constraint todisable the creation of new external service account keys. This allows you tocontrol the use of unmanaged long-term credentials for service accounts. Whenthis constraint is set, user-managed credentials cannot be created for serviceaccounts in projects affected by the constraint.

Disable service account key upload

You can use the iam.disableServiceAccountKeyUpload boolean constraint todisable the upload of external public keys to service accounts. When thisconstraint is set, users cannot upload public keys to service accounts inprojects affected by the constraint.

Disable attachment of service accounts to resources in other projects

Each service account is located in a project. You can use theiam.disableCrossProjectServiceAccountUsage boolean constraint to preventservice accounts in a project from being attached to resources in otherprojects.

If you want to allow service accounts to be used across projects, seeEnabling service account impersonation across projects.

Restrict removal of project liens when service accounts are used across projects

When you allow a project's service accounts to be attached to resources in otherprojects, IAM adds aproject lien that prevents you fromdeleting the project. By default, anyone who has theresourcemanager.projects.updateLiens permission on the project can delete thelien.

If you enforce the iam.restrictCrossProjectServiceAccountLienRemoval booleanconstraint, then principals can delete the lien only if they have theresourcemanager.projects.updateLiens permission on the organization.

We recommend enforcing this constraint if any of your projects allowservice account impersonation across projects.

Disable workload identity cluster creation

You can use the iam.disableWorkloadIdentityClusterCreation boolean constraintto require that any new Google Kubernetes Engine clusters have theWorkload Identity featuredisabled at the time of their creation. If you want to tightly control serviceaccount access in your organization, you may want to disable Workload Identityin addition to service account creation and service account key creation.

Existing GKE clusters with Workload Identity enabled willnot be affected, and will continue to work as normal.

Enforcing a boolean constraint

Console

To set an organization policy that enforces a constraint to restrict serviceaccount usage:

  1. In the Google Cloud console, go to the Organization policies page.

    Go to Organization policies

  2. From the project picker, select the organization for which you want torestrict service account usage.

  3. Click one of the service account usage boolean constraints listed on thispage.

  4. Click Manage policy.

  5. Under Applies to, select Override parent's policy.

  6. Click Add a rule.

  7. Under Enforcement, select On.

  8. To enforce the policy, click Set policy.

gcloud

Policies can be set through the Google Cloud CLI.

To restrict service account usage, run the following command:

gcloud resource-manager org-policies enable-enforce \ --organization 'ORGANIZATION_ID' \ BOOLEAN_CONSTRAINT

Where BOOLEAN_CONSTRAINT is the boolean constraint you want toenforce.

To disable enforcement, the same command can be issued with the

disable-enforce
command.

To learn about using constraints in organization policies, seeUsing Constraints.

Example policy with boolean constraint

The following code snippet shows an organization policy that enforces theiam.disableServiceAccountCreation boolean constraint, which prevents serviceaccounts from being created:

name: organizations/012345678901/policies/iam.disableServiceAccountCreationspec: rules: - enforce: true

List constraints

The following constraints are types oflist constraint,which are set to a list of values.

Extend lifetime of OAuth 2.0 access tokens

You can create an OAuth 2.0 access token that provides short-lived credentials for a service account.By default, the maximum lifetime of an access token is 1 hour (3,600 seconds).However, you can extend the maximum lifetime to 12 hours. To do so, identify theservice accounts that need an extended lifetime for access tokens, then addthese service accounts to an organization policy that includes the constraints/iam.allowServiceAccountCredentialLifetimeExtension list constraint.

Limit lifetime of service account keys

A service account key lets youauthenticate a request as a service account. By default, service account keysnever expire. You can change this default by setting an expiry time for allnewly created keys in your project, folder, or organization.

To set an expiry time, use the constraints/iam.serviceAccountKeyExpiryHourslist constraint to specify the number of hours for which a newly created key isvalid. After this amount of time, the service account key expires, and you canno longer use it.

This list constraint accepts the following ALLOW values; it does not acceptDENY values. As a best practice, use the shortest expiry time that meets yourneeds:

  • 1h: 1 hour
  • 8h: 8 hours
  • 24h: 24 hours (1 day)
  • 168h: 168 hours (7 days)
  • 336h: 336 hours (14 days)
  • 720h: 720 hours (30 days)
  • 1440h: 1,440 hours (60 days)
  • 2160h: 2,160 hours (90 days)

The constraints/iam.serviceAccountKeyExpiryHours constraint can't be mergedwith a parent policy. To enforce this constraint, you must either replace orinherit the parent policy.

Specify allowed external identity providers

If you useworkload identity federation, whichlets external identities access Google Cloud resources, you can specifywhich external identity providers are allowed. By default, all providers areallowed. To set a limit, use theconstraints/iam.workloadIdentityPoolProviders list constraint to specify URIsfor the allowed providers, using the following formats:

  • Amazon Web Services (AWS): https://sts.amazonaws.com

    To limit which AWS accounts are allowed, use theconstraints/iam.workloadIdentityPoolAwsAccounts list constraintas described on this page.

  • Microsoft Azure: https://sts.windows.net/azure-tenant-id

  • Other identity providers that support OpenID Connect (OIDC): Use the issuerURI from your identity provider.

Specify allowed AWS accounts

If you useworkload identity federation, whichlets external identities access Google Cloud resources, you can specifywhich AWS accounts are allowed to access your resources. By default, workloadsfrom any AWS account are allowed to access your Google Cloud resources. Tolimit which AWS accounts are allowed, use theconstraints/iam.workloadIdentityPoolAwsAccounts list constraint to specify alist of allowed account IDs.

Automatically disable exposed service account keys

Google Cloud occasionally detects that a particular service account key has beenexposed—for example, it might detect a key in a public repository. Tospecify what Google Cloud does with these keys, use theiam.serviceAccountKeyExposureResponse list constraint.

This list constraint accepts the following ALLOW values; it doesn't acceptDENY values.

  • DISABLE_KEY: If Google Cloud detects an exposed key, it willautomatically disable the key. It also creates a Cloud Audit Logs event andsends a notification about the exposed key to project owners and securitycontacts.

  • WAIT_FOR_ABUSE: Google Cloud won't proactively disable exposed keys.However, Google Cloud might still disable exposed keys if they're usedin ways that adversely affect the platform. Regardless of whether the exposedkey is disabled, Google Cloud creates a Cloud Audit Logs event andsends a notification about the exposed key to project owners and securitycontacts.

Cloud Audit Logs events are created when Google Cloud detects aleaked key or disables a key.

  • When Google Cloud detects that a key has been leaked, an abuse event iscreated in the Abuse Event logs.

  • When Google Cloud disables a key, the audit logs contain the disableaction by principal [email protected].

We strongly recommend that you set this constraint to DISABLE_KEY. Settingthis constraint to WAIT_FOR_ABUSE increases the risk that leaked keys will bemisused.

If you do decide to set the constraint to WAIT_FOR_ABUSE, we recommend thatyou subscribe to Cloud Audit Logs events, review your security contact informationin Essential Contacts,and ensure that your security contacts respond to notifications in a timely manner.

The iam.serviceAccountKeyExposureResponse constraint can't be merged with aparent policy. To enforce this constraint, you must replace the parent policy.

Setting a list constraint

Console

To set an organization policy that contains a list constraint:

  1. In the Google Cloud console, go to the Organization policies page.

    Go to Organization policies

  2. From the project picker, select the resource for which you wantto set the organization policy.

  3. On the Organization policies page, select a constraint from the list.The Policy details page for that constraint appears.

  4. To update the organization policy for this resource, clickManage policy.

  5. Under Policy enforcement, select an enforcement option:

    • To merge and evaluate your organization policies together, selectMerge with parent. For more information about inheritance and theresource hierarchy, seeUnderstanding hierarchy evaluation.
    • To override policies inherited from a parent resource, selectReplace.
  6. Click Add a rule.

  7. Under Policy values, select Custom.

  8. Under Policy type, select Allow.

  9. Under Custom values, enter the first value for the list constraint.

    1. If you want to add more values, click Add value to createmore rows, and add one value to each row.
  10. When you have finished adding values, click Done.

  11. To enforce the policy, click Set policy.

gcloud

Policies can be set through the Google Cloud CLI:

gcloud resource-manager org-policies allow \ CONSTRAINT_NAME \ VALUE_1 [VALUE_N ...] \ --organization=ORGANIZATION_ID \

Replace the following values:

  • CONSTRAINT_NAME: The name of the list constraint.For example,constraints/iam.allowServiceAccountCredentialLifetimeExtension.
  • VALUE_1, VALUE_N...:Values for the list constraint.

To learn about using constraints in organization policies, seeUsing Constraints.

Example policy with list constraint

The following code snippet shows an organization policy that enforces theiam.allowServiceAccountCredentialLifetimeExtension list constraint, whichextends the maximum lifetime of OAuth 2.0 access tokens for listed serviceaccounts:

name: organizations/012345678901/policies/iam.allowServiceAccountCredentialLifetimeExtensionspec: rules: - values: allowedValues: - SERVICE_ACCOUNT_ADDRESS

Error messages

Disable service account creation

If iam.disableServiceAccountCreation is enforced, creating a service accountwill fail with the error:

FAILED_PRECONDITION: Service account creation is not allowed on this project.

Disable service account key creation

If iam.disableServiceAccountKeyCreation is enforced, creating a service accountwill fail with the error:

FAILED_PRECONDITION: Key creation is not allowed on this service account.

Disable workload identity cluster creation

If iam.disableWorkloadIdentityClusterCreation is enforced, creating aGKE cluster with Workload Identity enabled will fail with theerror:

FAILED_PRECONDITION: Workload Identity is disabled by the organizationpolicy constraints/iam.disableWorkloadIdentityClusterCreation. Contact youradministrator to enable this feature.

Troubleshooting known issues

Default service accounts

Applying the iam.disableServiceAccountCreation constraint will prevent thecreation of service accounts in that project. This limitation also affectsGoogle Cloud services that, when enabled, automatically create defaultservice accounts in the project, such as:

  • Compute Engine
  • GKE
  • App Engine
  • Dataflow

If the iam.disableServiceAccountCreation constraint is applied, attempting toenable these services will fail because their default service accounts cannot becreated.

To resolve this issue:

  1. Temporarily remove the iam.disableServiceAccountCreation constraint.
  2. Enable the desired services.
  3. Create any other desired service accounts.
  4. Finally, re-apply the constraint.
Restricting service account usage  |  Resource Manager Documentation  |  Google Cloud (2024)

FAQs

How do I disable service account in GCP? ›

Disable a service account
  1. In the Google Cloud console, go to the Service accounts page. Go to Service accounts.
  2. Select a project.
  3. Click the name of the service account that you want to disable.
  4. Under Service account status, click Disable service account, then click Disable to confirm the change.

What is the difference between user account and service account in Google Cloud? ›

Service accounts differ from normal user accounts in multiple ways: They don't have a password and can't be used for browser-based sign-in. They're created and managed as a resource that belongs to a Google Cloud project. In contrast, users are managed in a Cloud Identity or Google Workspace account.

How to check service account permissions in GCP? ›

View current access
  1. In the Google Cloud console, go to the Service Accounts page. Go to Service Accounts.
  2. Select a project.
  3. Click the email address of the service account.
  4. Go to the Permissions tab. ...
  5. Optional: To view role grants for service agents, select the Include Google-provided role grants checkbox.

Which feature lets you set limits on the amount of resources that can be used by a project or user in Google Cloud? ›

Setting the organization policy

In the Google Cloud console, go to the Organization policies page. From the project picker, select the resource on which you want to set the organization policy. In the table of organization policies, select Restrict Resource Service Usage.

How do I revoke a service account in GCP? ›

In the Google Cloud console, go to the IAM permissions page. Select the project that you want to remove a user account from. Click the checkbox next to the row that contains the user account you want removed from the member list, then click Remove.

How do I disable services in Google Cloud run? ›

Cloud Run does not offer a direct way to make a service stop serving traffic, but you can achieve a similar result by revoking the permission to invoke the service to identities that are invoking the service. Notably, if your service is "public", remove allUsers from the Cloud Run Invoker role ( roles/run.

What is the main purpose of a service account? ›

A service account is a user account that's created explicitly to provide a security context for services that are running on Windows Server operating systems. The security context determines the service's ability to access local and network resources. Windows operating systems rely on services to run various features.

Why is a service account required in GCP? ›

Applications use service accounts to make authorized API calls by authenticating as either the service account itself, or as Google Workspace or Cloud Identity users through domain-wide delegation.

What is the default service account in GCP? ›

Default service accounts – This type of service account is created by Google Cloud and can execute cloud API calls to various resources in the project. Default service accounts are automatically given the Editor role when created.

How do I change permissions on Google Cloud service account? ›

Assign edit permission for all Cloud projects in an organization
  • Open the Cloud console at console.cloud.google.com.
  • Click Menu menu > IAM & Admin > Manage Resources.
  • Select your organization.
  • At the right, click Add Principal.
  • In New principals, add the users or groups you want to let edit projects.

How do I check permissions on a service account? ›

To see the Service permissions you can use the "sc" command from a Windows command-line prompt. To compare permissions for a particular Service, run it on two systems. See the outputs and compare each line in a notepad/wordpad session.

What is the difference between a shared account and a service account? ›

A service account is an account that is used by an automated process and is not used in an interactive way by a user. A single account and password that is given to students to log into a scientific instrument is a shared account.

How can we limit the use of resources? ›

Buy used items to reduce waste as well as the emissions created by producing new materials or disposing of them in landfills. Donate unused clothing, electronics and building materials to make sure others can reuse them too! Buy products made with recycled content.

How to limit Google Cloud spending? ›

Create and name the budget. If you have Cloud Billing account permissions, you can select from a list of billing accounts that you have permissions to access. Sign in to the Budgets & alerts page in the Google Cloud console. At the prompt, choose the Cloud Billing account for which you want to set a budget.

What are the resource limits for cloud functions? ›

Resource Limits

100MB (compressed) for sources. 500MB (uncompressed) for sources plus modules. 10MB for streaming responses. 32MB for non-streaming responses.

How do I disable Google Cloud service? ›

To close an account:

In the Google Cloud console, go to the Account management page. At the prompt, choose the Cloud Billing account that you want to close. The Account management page opens for the selected Cloud Billing account. At the top of the page, click cancel Close billing account.

How do I disable services? ›

Hello, To permanently disable a service, you can follow these steps:
  1. Press the Windows key + R to open the Run dialog box.
  2. Type "services. ...
  3. Find the service you want to disable and double-click on it.
  4. In the Properties window, click on the "Stop" button to stop the service if it is currently running.
Feb 12, 2024

How do I disable per user service? ›

To disable a per-user service, you need to directly edit the registry, either with group policy or a scripted solution. The templates are located in the registry at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services .

How do I disable service account key creation in Google workspace? ›

Navigate to the IAM & Admin > Organization policies page from the left panel. Enter Disable service account key creation in the Filter field to search for the organization policy, select the corresponding constraint from the result list.

Top Articles
What is Cross Rates - How Cross Currency Works | Angel One
Square Purchases and Cardholder Help | Square Support Center
11 beste sites voor Word-labelsjablonen (2024) [GRATIS]
Unraveling The Mystery: Does Breckie Hill Have A Boyfriend?
Costco in Hawthorne (14501 Hindry Ave)
Ogeechee Tech Blackboard
Which aspects are important in sales |#1 Prospection
The Many Faces of the Craigslist Killer
Craigslist Dog Kennels For Sale
Superhot Unblocked Games
Darksteel Plate Deepwoken
Cashtapp Atm Near Me
Daily Voice Tarrytown
Craigslist Free Stuff Greensboro Nc
Gdp E124
Roll Out Gutter Extensions Lowe's
G Switch Unblocked Tyrone
Vanessawest.tripod.com Bundy
Weepinbell Gen 3 Learnset
Nevermore: What Doesn't Kill
Rural King Credit Card Minimum Credit Score
Beverage Lyons Funeral Home Obituaries
Roane County Arrests Today
Kingdom Tattoo Ithaca Mi
Violent Night Showtimes Near Amc Dine-In Menlo Park 12
Mdt Bus Tracker 27
Speedstepper
Busted Mugshots Paducah Ky
Doctors of Optometry - Westchester Mall | Trusted Eye Doctors in White Plains, NY
Mini-Mental State Examination (MMSE) – Strokengine
How rich were the McCallisters in 'Home Alone'? Family's income unveiled
N.J. Hogenkamp Sons Funeral Home | Saint Henry, Ohio
Ucm Black Board
A Grade Ahead Reviews the Book vs. The Movie: Cloudy with a Chance of Meatballs - A Grade Ahead Blog
Wcostream Attack On Titan
Baldur's Gate 3 Dislocated Shoulder
Σινεμά - Τι Ταινίες Παίζουν οι Κινηματογράφοι Σήμερα - Πρόγραμμα 2024 | iathens.gr
Junior / medior handhaver openbare ruimte (BOA) - Gemeente Leiden
Henry County Illuminate
Levothyroxine Ati Template
Ladyva Is She Married
Top 40 Minecraft mods to enhance your gaming experience
Online-Reservierungen - Booqable Vermietungssoftware
Greg Steube Height
Unblocked Games 6X Snow Rider
Slug Menace Rs3
Lira Galore Age, Wikipedia, Height, Husband, Boyfriend, Family, Biography, Net Worth
Wera13X
Causeway Gomovies
Estes4Me Payroll
2121 Gateway Point
Latest Posts
Article information

Author: Edmund Hettinger DC

Last Updated:

Views: 5896

Rating: 4.8 / 5 (78 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Edmund Hettinger DC

Birthday: 1994-08-17

Address: 2033 Gerhold Pine, Port Jocelyn, VA 12101-5654

Phone: +8524399971620

Job: Central Manufacturing Supervisor

Hobby: Jogging, Metalworking, Tai chi, Shopping, Puzzles, Rock climbing, Crocheting

Introduction: My name is Edmund Hettinger DC, I am a adventurous, colorful, gifted, determined, precious, open, colorful person who loves writing and wants to share my knowledge and understanding with you.