Tool: analyze_iam_policy
Analyzes Google Cloud IAM allow policies to determine who can do what on which resources. It can perform policy analysis such as finding resources accessible to a principal, finding principals with access to a resource, or checking access paths.
This tool requires the analysis_query parameter, which specifies the root container where policies are analyzed (scope) and offers optional selectors for resource names, principal identifiers, and applicable roles and permissions.
- Folder and Organization scopes are not supported.
scopemust be a project scope (projects/PROJECT_ID). - When analyzing policies in a specific project (for example, 'in
PROJECT_ID'), setscopetoprojects/PROJECT_IDand do not setresource_selector. - Only set
resource_selector.full_resource_name(for example,//storage.googleapis.com/BUCKET_NAME) if the user specifically asks for access to a particular resource within that scope. - If a project scope is not specified in the request, confirm the scope before calling this tool.
- If
execution_timeoutis not specified in the request, setexecution_timeoutto60sas a string with suffix 's'.
You can also provide options to expand_groups, expand_roles, expand_resources (default false), and analyze_service_account_impersonation (default false). For supported policy types, see https://docs.cloud.google.com/policy-intelligence/docs/policy-analyzer-overview#supported-policy-types. For BYOID support, see https://docs.cloud.google.com/iam/docs/federated-identity-supported-services#policy-intelligence.
The following code sample shows how to use curl to call the analyze_iam_policy MCP tool.
| Curl Request |
|---|
curl --location 'https://cloudasset.googleapis.com/mcp' \ --header 'content-type: application/json' \ --header 'accept: application/json, text/event-stream' \ --data '{ "method": "tools/call", "params": { "name": "analyze_iam_policy", "arguments": { // Provide these details according to the MCP tool specification. } }, "jsonrpc": "2.0", "id": 1 }' |
Input Schema
A request message for AssetService.AnalyzeIamPolicy.
AnalyzeIamPolicyRequest
| JSON representation |
|---|
{
"analysisQuery": {
object ( |
| Fields | |
|---|---|
analysisQuery |
Required. The request query. |
savedAnalysisQuery |
Optional. The name of a saved query, which must be in the format of
If both Note that you cannot override primitive fields with default value, such as 0 or empty string, etc., because we use proto3, which doesn't support field presence yet. |
executionTimeout |
Optional. Amount of time executable has to complete. See JSON representation of Duration. If this field is set with a value less than the RPC deadline, and the execution of your query hasn't finished in the specified execution timeout, you will get a response with partial result. Otherwise, your query's execution will continue until the RPC deadline. If it's not finished until then, you will get a DEADLINE_EXCEEDED error. Default is empty. A duration in seconds with up to nine fractional digits, ending with ' |
IamPolicyAnalysisQuery
| JSON representation |
|---|
{ "scope": string, "resourceSelector": { object ( |
| Fields | |
|---|---|
scope |
Required. The relative name of the root asset. Only resources and IAM policies within the scope will be analyzed. This can only be a project ID (such as "projects/my-project-id") or a project number (such as "projects/12345"). To know how to get a folder or project ID, visit here . |
resourceSelector |
Optional. Specifies a resource for analysis. |
identitySelector |
Optional. Specifies an identity for analysis. |
accessSelector |
Optional. Specifies roles or permissions for analysis. This is optional. |
options |
Optional. The query options. |
conditionContext |
Optional. The hypothetical context for IAM conditions evaluation. |
ResourceSelector
| JSON representation |
|---|
{ "fullResourceName": string } |
| Fields | |
|---|---|
fullResourceName |
Required. The full resource name of a resource of supported resource types. |
IdentitySelector
| JSON representation |
|---|
{ "identity": string } |
| Fields | |
|---|---|
identity |
Required. The identity appear in the form of principals in IAM policy binding. The examples of supported forms are: "user:mike@example.com", "group:admins@example.com", "domain:google.com", "serviceAccount:my-project-id@appspot.gserviceaccount.com". Notice that wildcard characters (such as * and ?) are not supported. You must give a specific identity. |
AccessSelector
| JSON representation |
|---|
{ "roles": [ string ], "permissions": [ string ] } |
| Fields | |
|---|---|
roles[] |
Optional. The roles to appear in result. |
permissions[] |
Optional. The permissions to appear in result. |
Options
| JSON representation |
|---|
{ "expandGroups": boolean, "expandRoles": boolean, "expandResources": boolean, "outputResourceEdges": boolean, "outputGroupEdges": boolean, "analyzeServiceAccountImpersonation": boolean } |
| Fields | |
|---|---|
expandGroups |
Optional. If true, the identities section of the result will expand any Google groups appearing in an IAM policy binding. If If true, the default max expansion per group is 1000 for AssetService.AnalyzeIamPolicy][]. Default is false. |
expandRoles |
Optional. If true, the access section of result will expand any roles appearing in IAM policy bindings to include their permissions. If Default is false. |
expandResources |
Optional. If true and For example, if the request analyzes for which resources user A has permission P, and the results include an IAM policy with P on a Google Cloud folder, the results will also include resources in that folder with permission P. If true and For example, if the request analyzes for which users have permission P on a Google Cloud project with this option enabled, the results will include all users who have permission P on that project or any lower resource. If true, the default max expansion per resource is 1000 for AssetService.AnalyzeIamPolicy][] and 100000 for AssetService.AnalyzeIamPolicyLongrunning][]. Default is false. |
outputResourceEdges |
Optional. If true, the result will output the relevant parent/child relationships between resources. Default is false. |
outputGroupEdges |
Optional. If true, the result will output the relevant membership relationships between groups and other groups, and between groups and principals. Default is false. |
analyzeServiceAccountImpersonation |
Optional. If true, the response will include access analysis from identities to resources via service account impersonation. This is a very expensive operation, because many derived queries will be executed. We highly recommend you use For example, if the request analyzes for which resources user A has permission P, and there's an IAM policy states user A has iam.serviceAccounts.getAccessToken permission to a service account SA, and there's another IAM policy states service account SA has permission P to a Google Cloud folder F, then user A potentially has access to the Google Cloud folder F. And those advanced analysis results will be included in Another example, if the request analyzes for who has permission P to a Google Cloud folder F, and there's an IAM policy states user A has iam.serviceAccounts.actAs permission to a service account SA, and there's another IAM policy states service account SA has permission P to the Google Cloud folder F, then user A potentially has access to the Google Cloud folder F. And those advanced analysis results will be included in Only the following permissions are considered in this analysis:
Default is false. |
ConditionContext
| JSON representation |
|---|
{ // Union field |
| Fields | |
|---|---|
Union field TimeContext. The IAM conditions time context. TimeContext can be only one of the following: |
|
accessTime |
The hypothetical access timestamp to evaluate IAM conditions. Note that this value must not be earlier than the current time; otherwise, an INVALID_ARGUMENT error will be returned. Uses RFC 3339, where generated output will always be Z-normalized and use 0, 3, 6 or 9 fractional digits. Offsets other than "Z" are also accepted. Examples: |
Timestamp
| JSON representation |
|---|
{ "seconds": string, "nanos": integer } |
| Fields | |
|---|---|
seconds |
Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must be between -62135596800 and 253402300799 inclusive (which corresponds to 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z). |
nanos |
Non-negative fractions of a second at nanosecond resolution. This field is the nanosecond portion of the duration, not an alternative to seconds. Negative second values with fractions must still have non-negative nanos values that count forward in time. Must be between 0 and 999,999,999 inclusive. |
Duration
| JSON representation |
|---|
{ "seconds": string, "nanos": integer } |
| Fields | |
|---|---|
seconds |
Signed seconds of the span of time. Must be from -315,576,000,000 to +315,576,000,000 inclusive. Note: these bounds are computed from: 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years |
nanos |
Signed fractions of a second at nanosecond resolution of the span of time. Durations less than one second are represented with a 0 |
Output Schema
A response message for AssetService.AnalyzeIamPolicy.
AnalyzeIamPolicyResponse
| JSON representation |
|---|
{ "mainAnalysis": { object ( |
| Fields | |
|---|---|
mainAnalysis |
The main analysis that matches the original request. |
serviceAccountImpersonationAnalysis[] |
The service account impersonation analysis if |
fullyExplored |
Represents whether all entries in the |
IamPolicyAnalysis
| JSON representation |
|---|
{ "analysisQuery": { object ( |
| Fields | |
|---|---|
analysisQuery |
The analysis query. |
analysisResults[] |
A list of |
fullyExplored |
Represents whether all entries in the |
nonCriticalErrors[] |
A list of non-critical errors happened during the query handling. |
IamPolicyAnalysisQuery
| JSON representation |
|---|
{ "scope": string, "resourceSelector": { object ( |
| Fields | |
|---|---|
scope |
Required. The relative name of the root asset. Only resources and IAM policies within the scope will be analyzed. This can only be a project ID (such as "projects/my-project-id") or a project number (such as "projects/12345"). To know how to get a project ID, visit here . |
resourceSelector |
Optional. Specifies a resource for analysis. |
identitySelector |
Optional. Specifies an identity for analysis. |
accessSelector |
Optional. Specifies roles or permissions for analysis. This is optional. |
options |
Optional. The query options. |
conditionContext |
Optional. The hypothetical context for IAM conditions evaluation. |
ResourceSelector
| JSON representation |
|---|
{ "fullResourceName": string } |
| Fields | |
|---|---|
fullResourceName |
Required. The full resource name of a resource of supported resource types. |
IdentitySelector
| JSON representation |
|---|
{ "identity": string } |
| Fields | |
|---|---|
identity |
Required. The identity appear in the form of principals in IAM policy binding. The examples of supported forms are: "user:mike@example.com", "group:admins@example.com", "domain:google.com", "serviceAccount:my-project-id@appspot.gserviceaccount.com". Notice that wildcard characters (such as * and ?) are not supported. You must give a specific identity. |
AccessSelector
| JSON representation |
|---|
{ "roles": [ string ], "permissions": [ string ] } |
| Fields | |
|---|---|
roles[] |
Optional. The roles to appear in result. |
permissions[] |
Optional. The permissions to appear in result. |
Options
| JSON representation |
|---|
{ "expandGroups": boolean, "expandRoles": boolean, "expandResources": boolean, "outputResourceEdges": boolean, "outputGroupEdges": boolean, "analyzeServiceAccountImpersonation": boolean } |
| Fields | |
|---|---|
expandGroups |
Optional. If true, the identities section of the result will expand any Google groups appearing in an IAM policy binding. If If true, the default max expansion per group is 1000 for AssetService.AnalyzeIamPolicy][]. Default is false. |
expandRoles |
Optional. If true, the access section of result will expand any roles appearing in IAM policy bindings to include their permissions. If Default is false. |
expandResources |
Optional. If true and For example, if the request analyzes for which resources user A has permission P, and the results include an IAM policy with P on a Google Cloud folder, the results will also include resources in that folder with permission P. If true and For example, if the request analyzes for which users have permission P on a Google Cloud project with this option enabled, the results will include all users who have permission P on that project or any lower resource. If true, the default max expansion per resource is 1000 for AssetService.AnalyzeIamPolicy][] and 100000 for AssetService.AnalyzeIamPolicyLongrunning][]. Default is false. |
outputResourceEdges |
Optional. If true, the result will output the relevant parent/child relationships between resources. Default is false. |
outputGroupEdges |
Optional. If true, the result will output the relevant membership relationships between groups and other groups, and between groups and principals. Default is false. |
analyzeServiceAccountImpersonation |
Optional. If true, the response will include access analysis from identities to resources via service account impersonation. This is a very expensive operation, because many derived queries will be executed. We highly recommend you use For example, if the request analyzes for which resources user A has permission P, and there's an IAM policy states user A has iam.serviceAccounts.getAccessToken permission to a service account SA, and there's another IAM policy states service account SA has permission P to a Google Cloud folder F, then user A potentially has access to the Google Cloud folder F. And those advanced analysis results will be included in Another example, if the request analyzes for who has permission P to a Google Cloud folder F, and there's an IAM policy states user A has iam.serviceAccounts.actAs permission to a service account SA, and there's another IAM policy states service account SA has permission P to the Google Cloud folder F, then user A potentially has access to the Google Cloud folder F. And those advanced analysis results will be included in Only the following permissions are considered in this analysis:
Default is false. |
ConditionContext
| JSON representation |
|---|
{ // Union field |
| Fields | |
|---|---|
Union field TimeContext. The IAM conditions time context. TimeContext can be only one of the following: |
|
accessTime |
The hypothetical access timestamp to evaluate IAM conditions. Note that this value must not be earlier than the current time; otherwise, an INVALID_ARGUMENT error will be returned. Uses RFC 3339, where generated output will always be Z-normalized and use 0, 3, 6 or 9 fractional digits. Offsets other than "Z" are also accepted. Examples: |
Timestamp
| JSON representation |
|---|
{ "seconds": string, "nanos": integer } |
| Fields | |
|---|---|
seconds |
Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must be between -62135596800 and 253402300799 inclusive (which corresponds to 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z). |
nanos |
Non-negative fractions of a second at nanosecond resolution. This field is the nanosecond portion of the duration, not an alternative to seconds. Negative second values with fractions must still have non-negative nanos values that count forward in time. Must be between 0 and 999,999,999 inclusive. |
IamPolicyAnalysisResult
| JSON representation |
|---|
{ "attachedResourceFullName": string, "iamBinding": { object ( |
| Fields | |
|---|---|
attachedResourceFullName |
The full resource name of the resource to which the |
iamBinding |
The IAM policy binding under analysis. |
accessControlLists[] |
The access control lists derived from the |
identityList |
The identity list derived from members of the |
fullyExplored |
Represents whether all analyses on the |
Binding
| JSON representation |
|---|
{
"role": string,
"members": [
string
],
"condition": {
object ( |
| Fields | |
|---|---|
role |
Role that is assigned to the list of For an overview of the IAM roles and permissions, see the IAM documentation. For a list of the available pre-defined roles, see here. |
members[] |
Specifies the principals requesting access for a Google Cloud resource.
|
condition |
The condition that is associated with this binding. If the condition evaluates to If the condition evaluates to To learn which resources support conditions in their IAM policies, see the IAM documentation. |
Expr
| JSON representation |
|---|
{ "expression": string, "title": string, "description": string, "location": string } |
| Fields | |
|---|---|
expression |
Textual representation of an expression in Common Expression Language syntax. |
title |
Optional. Title for the expression, i.e. a short string describing its purpose. This can be used e.g. in UIs which allow to enter the expression. |
description |
Optional. Description of the expression. This is a longer text which describes the expression, e.g. when hovered over it in a UI. |
location |
Optional. String indicating the location of the expression for error reporting, e.g. a file name and a position in the file. |
AccessControlList
| JSON representation |
|---|
{ "resources": [ { object ( |
| Fields | |
|---|---|
resources[] |
The resources that match one of the following conditions: - The resource_selector, if it is specified in request; - Otherwise, resources reachable from the policy attached resource. |
accesses[] |
The accesses that match one of the following conditions: - The access_selector, if it is specified in request; - Otherwise, access specifiers reachable from the policy binding's role. |
resourceEdges[] |
Resource edges of the graph starting from the policy attached resource to any descendant resources. The |
conditionEvaluation |
Condition evaluation for this AccessControlList, if there is a condition defined in the above IAM policy binding. |
Resource
| JSON representation |
|---|
{
"fullResourceName": string,
"analysisState": {
object ( |
| Fields | |
|---|---|
fullResourceName |
|
analysisState |
The analysis state of this resource. |
IamPolicyAnalysisState
| JSON representation |
|---|
{
"code": enum ( |
| Fields | |
|---|---|
code |
The Google standard error code that best describes the state. For example: - OK means the analysis on this entity has been successfully finished; - PERMISSION_DENIED means an access denied error is encountered; - DEADLINE_EXCEEDED means the analysis on this entity hasn't been started in time; |
cause |
The human-readable description of the cause of failure. |
Access
| JSON representation |
|---|
{ "analysisState": { object ( |
| Fields | |
|---|---|
analysisState |
The analysis state of this access. |
Union field
|
|
role |
The role. |
permission |
The permission. |
Edge
| JSON representation |
|---|
{ "sourceNode": string, "targetNode": string } |
| Fields | |
|---|---|
sourceNode |
The source node of the edge. For example, it could be a full resource name for a resource node or an email of an identity. |
targetNode |
The target node of the edge. For example, it could be a full resource name for a resource node or an email of an identity. |
ConditionEvaluation
| JSON representation |
|---|
{
"evaluationValue": enum ( |
| Fields | |
|---|---|
evaluationValue |
The evaluation result. |
IdentityList
| JSON representation |
|---|
{ "identities": [ { object ( |
| Fields | |
|---|---|
identities[] |
Only the identities that match one of the following conditions will be presented: - The identity_selector, if it is specified in request; - Otherwise, identities reachable from the policy binding's members. |
groupEdges[] |
Group identity edges of the graph starting from the binding's group members to any node of the |
Identity
| JSON representation |
|---|
{
"name": string,
"analysisState": {
object ( |
| Fields | |
|---|---|
name |
The identity of members, formatted as appear in an IAM policy binding. For example, they might be formatted like the following:
|
analysisState |
The analysis state of this identity. |
Code
The canonical error codes for gRPC APIs.
Sometimes multiple error codes may apply. Services should return the most specific error code that applies. For example, prefer OUT_OF_RANGE over FAILED_PRECONDITION if both codes apply. Similarly prefer NOT_FOUND or ALREADY_EXISTS over FAILED_PRECONDITION.
| Enums | |
|---|---|
OK |
Not an error; returned on success. HTTP Mapping: 200 OK |
CANCELLED |
The operation was cancelled, typically by the caller. HTTP Mapping: 499 Client Closed Request |
UNKNOWN |
Unknown error. For example, this error may be returned when a HTTP Mapping: 500 Internal Server Error |
INVALID_ARGUMENT |
The client specified an invalid argument. Note that this differs from HTTP Mapping: 400 Bad Request |
DEADLINE_EXCEEDED |
The deadline expired before the operation could complete. For operations that change the state of the system, this error may be returned even if the operation has completed successfully. For example, a successful response from a server could have been delayed long enough for the deadline to expire. HTTP Mapping: 504 Gateway Timeout |
NOT_FOUND |
Some requested entity (e.g., file or directory) was not found. Note to server developers: if a request is denied for an entire class of users, such as gradual feature rollout or undocumented allowlist, HTTP Mapping: 404 Not Found |
ALREADY_EXISTS |
The entity that a client attempted to create (e.g., file or directory) already exists. HTTP Mapping: 409 Conflict |
PERMISSION_DENIED |
The caller does not have permission to execute the specified operation. HTTP Mapping: 403 Forbidden |
UNAUTHENTICATED |
The request does not have valid authentication credentials for the operation. HTTP Mapping: 401 Unauthorized |
RESOURCE_EXHAUSTED |
Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space. HTTP Mapping: 429 Too Many Requests |
FAILED_PRECONDITION |
The operation was rejected because the system is not in a state required for the operation's execution. For example, the directory to be deleted is non-empty, an rmdir operation is applied to a non-directory, etc. Service implementors can use the following guidelines to decide between HTTP Mapping: 400 Bad Request |
ABORTED |
The operation was aborted, typically due to a concurrency issue such as a sequencer check failure or transaction abort. See the guidelines above for deciding between HTTP Mapping: 409 Conflict |
OUT_OF_RANGE |
The operation was attempted past the valid range. E.g., seeking or reading past end-of-file. Unlike There is a fair bit of overlap between HTTP Mapping: 400 Bad Request |
UNIMPLEMENTED |
The operation is not implemented or is not supported/enabled in this service. HTTP Mapping: 501 Not Implemented |
INTERNAL |
Internal errors. This means that some invariants expected by the underlying system have been broken. This error code is reserved for serious errors. HTTP Mapping: 500 Internal Server Error |
UNAVAILABLE |
The service is currently unavailable. This is most likely a transient condition, which can be corrected by retrying with a backoff. Note that it is not always safe to retry non-idempotent operations. See the guidelines above for deciding between HTTP Mapping: 503 Service Unavailable |
DATA_LOSS |
Unrecoverable data loss or corruption. HTTP Mapping: 500 Internal Server Error |
EvaluationValue
Value of this expression.
| Enums | |
|---|---|
EVALUATION_VALUE_UNSPECIFIED |
Reserved for future use. |
TRUE |
The evaluation result is true. |
FALSE |
The evaluation result is false. |
CONDITIONAL |
The evaluation result is conditional when the condition expression contains variables that are either missing input values or have not been supported by Policy Analyzer yet. |
Tool Annotations
Tool annotations are sent to MCP clients to describe the basic risk of a given tool. Most clients treat these hints as untrusted, but they can be used to decide when a confirmation prompt might be sent to a user.
Along with the title string, the following boolean hints are defined as follows:
readOnlyHint: If true, the tool doesn't modify its environment. Default: false.destructiveHint: If true, then the tool can perform destructive actions. If false, then the tool can only perform additive actions. Default: true.idempotentHint: If true, then calling the tool repeatedly with the same arguments will have no additional effect on its environment. Default: false.openWorldHint: If true, then the tool can interact with an 'open world' of external entities. If false, then the tool can only interact with internal entities. For example, a web search tool would be open world, while a memory tool would not be open world.
Destructive Hint: ❌ | Idempotent Hint: ✅ | Read Only Hint: ✅ | Open World Hint: ✅