Reference documentation and code samples for the Cloud Storage API class Google::Cloud::Storage::PolicyV3.
A subclass of Policy that supports access to #bindings
and #version=. Attempts to call #roles and relate helpers will raise a runtime
error. This class may be used to update the Policy version and add bindings with a newer
syntax. To obtain instances of this class, call Bucket#policy
with requested_policy_version: 3.
require"google/cloud/storage"storage=Google::Cloud::Storage.newbucket=storage.bucket"my-bucket"bucket.uniform_bucket_level_access=truebucket.policyrequested_policy_version:3do|p|p.version# the value is 1p.version=3expr="resource.name.startsWith(\"projects/_/buckets/bucket-name/objects/prefix-a-\")"p.bindings.insert({role:"roles/storage.admin",members:["user:owner@example.com"],condition:{title:"my-condition",description:"description of condition",expression:expr}})end
Using Policy version 3:
require"google/cloud/storage"storage=Google::Cloud::Storage.newbucket=storage.bucket"my-bucket"bucket.uniform_bucket_level_access?# truebucket.policyrequested_policy_version:3do|p|p.version=3# Must be explicitly set to opt-in to support for conditions.expr="resource.name.startsWith(\"projects/_/buckets/bucket-name/objects/prefix-a-\")"p.bindings.insert({role:"roles/storage.admin",members:["user:owner@example.com"],condition:{title:"my-condition",description:"description of condition",expression:expr}})end
Updates the syntax schema version of the policy. Each version of the
policy contains a specific syntax schema that can be used by bindings.
The newer version may contain role bindings with the newer syntax schema
that is unsupported by earlier versions. This field is not intended to
be used for any purposes other than policy syntax schema control.
The following policy versions are valid:
1 - The first version of Cloud IAM policy schema. Supports binding one
role to one or more members. Does not support conditional bindings.
3 - Introduces the condition field in the role binding, which further
constrains the role binding via context-based and attribute-based rules.
See Understanding policies
and Overview of Cloud IAM Conditions
for more information.
Parameter
new_version (Integer) — The syntax schema version of the policy.
Example
Updating Policy version 1 to version 3:
require"google/cloud/storage"storage=Google::Cloud::Storage.newbucket=storage.bucket"my-bucket"bucket.uniform_bucket_level_access=truebucket.policyrequested_policy_version:3do|p|p.version# the value is 1p.version=3expr="resource.name.startsWith(\"projects/_/buckets/bucket-name/objects/prefix-a-\")"p.bindings.insert({role:"roles/storage.admin",members:["user:owner@example.com"],condition:{title:"my-condition",description:"description of condition",expression:expr}})end
[[["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-09-04 UTC."],[],[],null,["# Cloud Storage API - Class Google::Cloud::Storage::PolicyV3 (v1.57.0)\n\nVersion latestkeyboard_arrow_down\n\n- [1.57.0 (latest)](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV3)\n- [1.56.0](/ruby/docs/reference/google-cloud-storage/1.56.0/Google-Cloud-Storage-PolicyV3)\n- [1.55.0](/ruby/docs/reference/google-cloud-storage/1.55.0/Google-Cloud-Storage-PolicyV3)\n- [1.54.0](/ruby/docs/reference/google-cloud-storage/1.54.0/Google-Cloud-Storage-PolicyV3)\n- [1.53.0](/ruby/docs/reference/google-cloud-storage/1.53.0/Google-Cloud-Storage-PolicyV3)\n- [1.52.0](/ruby/docs/reference/google-cloud-storage/1.52.0/Google-Cloud-Storage-PolicyV3)\n- [1.51.0](/ruby/docs/reference/google-cloud-storage/1.51.0/Google-Cloud-Storage-PolicyV3)\n- [1.50.0](/ruby/docs/reference/google-cloud-storage/1.50.0/Google-Cloud-Storage-PolicyV3)\n- [1.49.0](/ruby/docs/reference/google-cloud-storage/1.49.0/Google-Cloud-Storage-PolicyV3)\n- [1.48.1](/ruby/docs/reference/google-cloud-storage/1.48.1/Google-Cloud-Storage-PolicyV3)\n- [1.47.0](/ruby/docs/reference/google-cloud-storage/1.47.0/Google-Cloud-Storage-PolicyV3)\n- [1.46.0](/ruby/docs/reference/google-cloud-storage/1.46.0/Google-Cloud-Storage-PolicyV3)\n- [1.45.0](/ruby/docs/reference/google-cloud-storage/1.45.0/Google-Cloud-Storage-PolicyV3)\n- [1.44.0](/ruby/docs/reference/google-cloud-storage/1.44.0/Google-Cloud-Storage-PolicyV3)\n- [1.43.0](/ruby/docs/reference/google-cloud-storage/1.43.0/Google-Cloud-Storage-PolicyV3)\n- [1.42.0](/ruby/docs/reference/google-cloud-storage/1.42.0/Google-Cloud-Storage-PolicyV3)\n- [1.41.0](/ruby/docs/reference/google-cloud-storage/1.41.0/Google-Cloud-Storage-PolicyV3)\n- [1.40.0](/ruby/docs/reference/google-cloud-storage/1.40.0/Google-Cloud-Storage-PolicyV3)\n- [1.39.0](/ruby/docs/reference/google-cloud-storage/1.39.0/Google-Cloud-Storage-PolicyV3)\n- [1.38.0](/ruby/docs/reference/google-cloud-storage/1.38.0/Google-Cloud-Storage-PolicyV3)\n- [1.37.0](/ruby/docs/reference/google-cloud-storage/1.37.0/Google-Cloud-Storage-PolicyV3)\n- [1.36.2](/ruby/docs/reference/google-cloud-storage/1.36.2/Google-Cloud-Storage-PolicyV3)\n- [1.35.0](/ruby/docs/reference/google-cloud-storage/1.35.0/Google-Cloud-Storage-PolicyV3) \nReference documentation and code samples for the Cloud Storage API class Google::Cloud::Storage::PolicyV3.\n\nA subclass of [Policy](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy \"Google::Cloud::Storage::Policy (class)\") that supports access to [#bindings](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV3#Google__Cloud__Storage__PolicyV3_bindings_instance_ \"Google::Cloud::Storage::PolicyV3#bindings (method)\")\nand [#version=](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV3#Google__Cloud__Storage__PolicyV3_version__instance_ \"Google::Cloud::Storage::PolicyV3#version= (method)\"). Attempts to call [#roles](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV3#Google__Cloud__Storage__PolicyV3_roles_instance_ \"Google::Cloud::Storage::PolicyV3#roles (method)\") and relate helpers will raise a runtime\nerror. This class may be used to update the Policy version and add bindings with a newer\nsyntax. To obtain instances of this class, call [Bucket#policy](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket#Google__Cloud__Storage__Bucket_policy_instance_ \"Google::Cloud::Storage::Bucket#policy (method)\")\nwith `requested_policy_version: 3`. \n\nInherits\n--------\n\n- [Google::Cloud::Storage::Policy](./Google-Cloud-Storage-Policy)\n\nExamples\n--------\n\nUpdating Policy version 1 to version 3: \n\n```ruby\nrequire \"google/cloud/storage\"\n\nstorage = Google::Cloud::Storage.new\nbucket = storage.bucket \"my-bucket\"\n\nbucket.uniform_bucket_level_access = true\n\nbucket.policy requested_policy_version: 3 do |p|\n p.version # the value is 1\n p.version = 3\n\n expr = \"resource.name.startsWith(\\\"projects/_/buckets/bucket-name/objects/prefix-a-\\\")\"\n p.bindings.insert({\n role: \"roles/storage.admin\",\n members: [\"user:owner@example.com\"],\n condition: {\n title: \"my-condition\",\n description: \"description of condition\",\n expression: expr\n }\n })\nend\n```\n\nUsing Policy version 3: \n\n```ruby\nrequire \"google/cloud/storage\"\n\nstorage = Google::Cloud::Storage.new\nbucket = storage.bucket \"my-bucket\"\n\nbucket.uniform_bucket_level_access? # true\n\nbucket.policy requested_policy_version: 3 do |p|\n p.version = 3 # Must be explicitly set to opt-in to support for conditions.\n\n expr = \"resource.name.startsWith(\\\"projects/_/buckets/bucket-name/objects/prefix-a-\\\")\"\n p.bindings.insert({\n role: \"roles/storage.admin\",\n members: [\"user:owner@example.com\"],\n condition: {\n title: \"my-condition\",\n description: \"description of condition\",\n expression: expr\n }\n })\nend\n```\n\nMethods\n-------\n\n### #bindings\n\n def bindings() -\u003e Bindings\n\nReturns the Policy's bindings object that associate roles with\nan array of members. Conditions can be configured on the [Google::Cloud::Storage::Policy::Binding](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Binding \"Google::Cloud::Storage::Policy::Binding (class)\") object. See\n[Understanding Roles](https://cloud.google.com/iam/docs/understanding-roles) for a\nlisting of primitive and curated roles. See [Buckets:\nsetIamPolicy](https://cloud.google.com/storage/docs/json_api/v1/buckets/setIamPolicy)\nfor a listing of values and patterns for members. \n**Returns**\n\n- ([Bindings](./Google-Cloud-Storage-Policy-Bindings)) --- the current value of bindings\n\n### #bindings=\n\n def bindings=(value) -\u003e Bindings\n\nReturns the Policy's bindings object that associate roles with\nan array of members. Conditions can be configured on the [Google::Cloud::Storage::Policy::Binding](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Binding \"Google::Cloud::Storage::Policy::Binding (class)\") object. See\n[Understanding Roles](https://cloud.google.com/iam/docs/understanding-roles) for a\nlisting of primitive and curated roles. See [Buckets:\nsetIamPolicy](https://cloud.google.com/storage/docs/json_api/v1/buckets/setIamPolicy)\nfor a listing of values and patterns for members. \n**Parameter**\n\n- **value** ([Bindings](./Google-Cloud-Storage-Policy-Bindings)) --- the newly set value \n**Returns**\n\n- ([Bindings](./Google-Cloud-Storage-Policy-Bindings)) --- the newly set value\n\n### #version=\n\n def version=(new_version)\n\nUpdates the syntax schema version of the policy. Each version of the\npolicy contains a specific syntax schema that can be used by bindings.\nThe newer version may contain role bindings with the newer syntax schema\nthat is unsupported by earlier versions. This field is not intended to\nbe used for any purposes other than policy syntax schema control.\n\nThe following policy versions are valid:\n\n- 1 - The first version of Cloud IAM policy schema. Supports binding one role to one or more members. Does not support conditional bindings.\n- 3 - Introduces the condition field in the role binding, which further constrains the role binding via context-based and attribute-based rules. See [Understanding policies](https://cloud.google.com/iam/docs/policies) and [Overview of Cloud IAM Conditions](https://cloud.google.com/iam/docs/conditions-overview) for more information. \n**Parameter**\n\n- **new_version** (Integer) --- The syntax schema version of the policy.\n**Example**\n\nUpdating Policy version 1 to version 3: \n\n```ruby\nrequire \"google/cloud/storage\"\n\nstorage = Google::Cloud::Storage.new\nbucket = storage.bucket \"my-bucket\"\n\nbucket.uniform_bucket_level_access = true\n\nbucket.policy requested_policy_version: 3 do |p|\n p.version # the value is 1\n p.version = 3\n\n expr = \"resource.name.startsWith(\\\"projects/_/buckets/bucket-name/objects/prefix-a-\\\")\"\n p.bindings.insert({\n role: \"roles/storage.admin\",\n members: [\"user:owner@example.com\"],\n condition: {\n title: \"my-condition\",\n description: \"description of condition\",\n expression: expr\n }\n })\nend\n```"]]