Sets the IAM policy that is attached to a ServiceAccount.
Use this method to grant or revoke access to the service account. For example, you could grant a principal the ability to impersonate the service account.
This method does not enable the service account to access other resources. To grant roles to a service account on a resource, follow these steps:
Call the resource's getIamPolicy method to get its current IAM policy.
Edit the policy so that it binds the service account to an IAM role for the resource.
Call the resource's setIamPolicy method to update its IAM policy.
REQUIRED: The complete policy to be applied to the resource. The size of the policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Google Cloud services (such as Projects) might reject them.
OPTIONAL: A FieldMask specifying which fields of the policy to modify. Only the fields in the mask will be modified. If no mask is provided, the following default mask is used:
paths: "bindings, etag"
This is a comma-separated list of fully qualified names of fields. Example: "user.displayName,photo".
Response body
If successful, the response body contains an instance of Policy.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-05-21 UTC."],[[["\u003cp\u003eThis method sets the IAM policy for a specified ServiceAccount, granting or revoking access, such as the ability for a principal to impersonate the service account.\u003c/p\u003e\n"],["\u003cp\u003eThe HTTP request uses a \u003ccode\u003ePOST\u003c/code\u003e method and includes a resource identifier in the URL, following gRPC Transcoding syntax, and requires a resource string in path parameter to identify the resource.\u003c/p\u003e\n"],["\u003cp\u003eThe request body is required and uses a JSON representation, specifying the policy and an optional update mask, with the policy having a size limit.\u003c/p\u003e\n"],["\u003cp\u003eA successful request returns a Policy object as the response body.\u003c/p\u003e\n"],["\u003cp\u003eAuthorization requires either the \u003ccode\u003ehttps://www.googleapis.com/auth/iam\u003c/code\u003e or \u003ccode\u003ehttps://www.googleapis.com/auth/cloud-platform\u003c/code\u003e OAuth scope.\u003c/p\u003e\n"]]],[],null,[]]