[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[[["\u003cp\u003eAllow policy version 1 may display role names with \u003ccode\u003ewithcond\u003c/code\u003e and a hash value, indicating a hidden conditional role binding.\u003c/p\u003e\n"],["\u003cp\u003eTo view and manage all policy details, including conditions, you must specify policy version 3 when getting or setting an allow policy.\u003c/p\u003e\n"],["\u003cp\u003eUpdate gcloud CLI to version 263.0.0 or later, and update client libraries to the latest version that supports allow policy versions to work properly with allow policies.\u003c/p\u003e\n"],["\u003cp\u003eWhen setting an allow policy, always include the \u003ccode\u003eetag\u003c/code\u003e field to avoid data loss from overwriting, and be sure to not accept changes from management tools that create duplicate role bindings without conditions.\u003c/p\u003e\n"]]],[],null,["# Troubleshooting \"withcond\" in policies and role bindings\n\nWhen you view an [allow policy](/iam/docs/allow-policies), you might see role names that include\nthe string `withcond`, followed by a hash value. For example, you might see a\nrole name like `roles/iam.serviceAccountAdmin_withcond_2b17cc25d2cd9e2c54d8`.\n\nThis page explains when and why you might see the string `withcond` in an allow\npolicy. It also recommends actions you should take if you see this string.\n\nPolicy versions and conditional role bindings\n---------------------------------------------\n\nAn allow policy can be represented in several different forms. Each form is\nknown as an [*allow policy version*](/iam/docs/allow-policies#versions).\n\nIn an allow policy that uses version `1`, some role bindings might contain the\nstring `withcond` in a role name, followed by a hash value: \n\n {\n \"bindings\": [\n {\n \"members\": [\n \"user:dana@example.com\"\n ],\n \"role\": \"roles/iam.serviceAccountAdmin_withcond_2b17cc25d2cd9e2c54d8\"\n }\n ],\n \"etag\": \"BwUjMhCsNvY=\",\n \"version\": 1\n }\n\nThis format indicates that the role binding is\n[conditional](/iam/docs/allow-policies#conditional-bindings). In other words, the role is granted\nonly if specific conditions are met.\n\nVersion `1` allow policies don't show these conditions. If you see the string\n`withcond` and a hash value, then the role binding includes a condition that you\ncannot see.\n\nSolution: Specify policy version 3\n----------------------------------\n\nTo ensure that you can view and update the entire allow policy, including its\nconditions, you must always specify version `3` when you\nget or set an allow policy. To specify version `3`,\ncomplete the tasks in the following sections.\n\n### Update the gcloud tool\n\nIf you use the Google Cloud CLI, run `gcloud version` to check its version\nnumber. The output includes a string similar to `Google Cloud CLI 279.0.0`.\n\nIf the version number is less than 263.0.0, run\n`gcloud components update` to update the gcloud CLI. In version\n263.0.0 and later, the gcloud CLI\nautomatically specifies an allow policy version that supports conditions.\n\n### Update client libraries\n\nIf your application uses a client library, follow these steps:\n\n1. Find the name and version number for the client library, then check the list\n of\n [client libraries that support allow policy versions](/iam/docs/allow-policies#libraries).\n\n - If you already use a recent version of the client library, and it supports\n allow policy versions, you don't need to update your client library.\n Continue to the next step.\n\n - If you use an older version of the client library, and a later version\n supports allow policy versions, update your client library to the latest\n version.\n\n - If you use a client library that does not support allow policy versions,\n you can add another client library that supports allow policy versions to\n your application. Use that client library to work with allow policies.\n Alternatively, you can use the\n [IAM REST API](/iam/docs/reference/rest) directly.\n\n2. Update any code in your application that gets and sets allow policies:\n\n\n - When you get an allow policy, always [specify version `3`](/iam/docs/allow-policies#specifying-version-get) in the request.\n - When you set an allow policy, always\n [set the `version` field of the allow policy to `3`](/iam/docs/allow-policies#specifying-version-set),\n and include the [`etag` field](/iam/docs/allow-policies#etag) in your request.\n\n | **Important:** If you omit the `etag` field, IAM allows you to overwrite the old allow policy with the new allow policy, even if this action causes data loss.\n\n \u003cbr /\u003e\n\n### Update REST API calls\n\nIf your application uses the [IAM REST API](/iam/docs/reference/rest)\ndirectly, update any code that gets and sets allow policies:\n\n\n- When you get an allow policy, always [specify version `3`](/iam/docs/allow-policies#specifying-version-get) in the request.\n- When you set an allow policy, always\n [set the `version` field of the allow policy to `3`](/iam/docs/allow-policies#specifying-version-set),\n and include the [`etag` field](/iam/docs/allow-policies#etag) in your request.\n\n | **Important:** If you omit the `etag` field, IAM allows you to overwrite the old allow policy with the new allow policy, even if this action causes data loss.\n\n\u003cbr /\u003e\n\n### Update management tools for policies\n\nIf you keep local copies of your allow policies---for example, if you store them\nin a version control system and treat them as code---make sure that all of the\ntools you use meet these criteria:\n\n- All requests to get or set an allow policy specify version `3`\n- All requests to set an allow policy include the `etag` field in the request\n\nIf a tool does not meet these criteria, check for an updated version of the\ntool.\n\nAlso, make sure your management tools preserve conditional role grants, rather\nthan adding a duplicate role grant that does not include a condition. For\nexample, consider the following scenario:\n\n1. You grant the Create Service Accounts role\n (`roles/iam.serviceAccountCreator`) to the user Mahan on the\n folder `my-folder`. The allow policy for the folder looks similar to this\n example:\n\n {\n \"bindings\": [\n {\n \"members\": \\[\n \"user:mahan@example.com\"\n \\],\n \"role\": \"roles/iam.serviceAccountCreator\"\n }\n ],\n \"etag\": \"BuFmmMhCsNY=\",\n \"version\": 1\n }\n\n2. You use a tool to retrieve the allow policy and store it in a version\n control system.\n\n3. You add a condition so that Mahan can create service accounts only during\n the normal work week, based on the date and time in Berlin, Germany. The\n updated allow policy looks similar to this example:\n\n {\n \"bindings\": [\n {\n \"members\": [\n \"user:mahan@example.com\"\n ],\n \"role\": \"roles/iam.serviceAccountCreator\",\n \"condition\": {\n \"title\": \"work_week_only\",\n \"expression\": \"request.time.getDayOfWeek('Europe/Berlin') \\\u003e= 1 \\&\\& request.time.getDayOfWeek('Europe/Berlin') \\\u003c= 5\"\n }\n }\n ],\n \"etag\": \"BwWcR/B3tNk=\",\n \"version\": 3\n }\n\n4. You use a tool to retrieve the updated allow policy. The tool does not\n specify an allow policy version when it requests the allow policy, so you\n receive a version `1` allow policy with a modified role name:\n\n {\n \"bindings\": [\n {\n \"members\": [\n \"user:mahan@example.com\"\n ],\n \"role\": \"roles/iam.serviceAccountCreator_withcond_a75dc089e6fa084bd379\"\n }\n ],\n \"etag\": \"BwWcR/B3tNk=\",\n \"version\": 1\n }\n\nAt this point, the management tool might decide that the binding from Mahan to\nthe role `roles/iam.serviceAccountCreator` has disappeared, and that it should\nrestore the original role binding to the allow policy:\n\nAvoid: Additional role binding with no condition \n\n {\n \"bindings\": [\n {\n \"members\": [\n \"user:mahan@example.com\"\n ],\n \"role\": \"roles/iam.serviceAccountCreator_withcond_a75dc089e6fa084bd379\"\n },\n {\n \"members\": \\[\n \"user:mahan@example.com\"\n \\],\n \"role\": \"roles/iam.serviceAccountCreator\"\n }\n ],\n \"etag\": \"BwWd3HjhKxE=\",\n \"version\": 1\n }\n\n**This change is not correct.** It grants the role\n`roles/iam.serviceAccountCreator` to Mahan regardless of the day of the week. As\na result, the condition in the first role binding has no effect.\n\nIf your management tools try to make this type of change, don't approve the\nchange. Instead, you must update your management tools to specify version\n`3` in requests.\n\nWhat's next\n-----------\n\n- Learn more about [allow policies](/iam/docs/allow-policies).\n- Find out how to specify an allow policy version when you [get an allow policy](/iam/docs/allow-policies#specifying-version-get) or [set an allow policy](/iam/docs/allow-policies#specifying-version-set).\n- Understand how to grant access conditionally with [IAM Conditions](/iam/docs/conditions-overview)."]]