This document describes supported attributes in a condition expression.
Supported condition attributes
The following sections summarize the supported attributes and indicate which Trusted Cloud by S3NS services recognize each attribute.
Resource attributes
The following attributes relate to the resource that is the subject of the request.
Attribute | Usage summary | Supported Trusted Cloud services |
---|---|---|
Resource service attribute |
Manage access based on the Trusted Cloud service being used. You can use this attribute in allow policy role bindings. |
|
Resource type attribute |
Manage access based on the resource type. You can use this attribute in allow policy role bindings. |
|
Resource name attribute |
Manage access based on the name of the resource. You can use this attribute in allow policy role bindings. |
|
Resource tags |
Manage access based on the tags attached to the resource. You can use this attribute in the following places:
|
All Trusted Cloud services (see Support for inherited conditions) |
For more details about resource attributes, see Resource attributes on this page.
Request attributes
The following attributes relate to the details of the request.
Attribute | Usage summary | Supported Trusted Cloud services |
---|---|---|
Manage access based on data provided by a specific Trusted Cloud API or service. You can use this attribute in allow policy role bindings. |
|
|
Set expirable, scheduled, or limited-duration access to Trusted Cloud resources. You can use these attributes in allow policy role bindings. |
All Trusted Cloud services (see Support for inherited conditions) |
|
Specify the types of forwarding rules that a principal can create. For example, you could allow a principal to create forwarding rules for internal Trusted Cloud by S3NS load balancers, which handle traffic that originates inside a Trusted Cloud network, but not for external Trusted Cloud load balancers, which handle traffic that originates from the internet. You can use these attributes in allow policy role bindings. |
|
For more details about request attributes, see Request attributes on this page.
Support for inherited conditions
Some types of Trusted Cloud resources don't allow conditions in their allow policies. However, you can add conditional role bindings at the organization, folder, or project level, and other resources will inherit those role bindings through the resource hierarchy. For details, see Resource types that accept conditional role bindings.
When you use attributes at the organization, folder, or project level, keep in
mind that most attributes are available only for specific resource types. If
part of a condition uses an attribute that is not available, then that part of
the condition is never interpreted as granting access. For example, the
condition resource.name.endsWith == devResource
will never grant access to any
IAM resource, because IAM resources don't
provide the resource name.
To prevent this issue, use the resource type and
resource service attributes described on this page to limit
the scope of the condition. For example, the following condition evaluates to
true
for all resource types other than Compute Engine instances; in
contrast, for Compute Engine instances, the condition checks resource name:
resource.type != 'compute.googleapis.com/Disk' ||
resource.name.endsWith('devResource')
You don't need to limit the scope of conditions that check the tags attached to a resource. When a condition checks tag keys and values, it cannot check any other attributes, including the resource type and resource service.
Resource attributes
The resource service, resource type, and resource name attributes are typically used to change the scope of an access grant provided by the role binding. When a role contains permissions that apply to different resource-specific attributes, resource-based conditions can be used to grant a subset of the role's permissions for specific type(s) or for specific service(s).
resource.service attribute
The resource.service
attribute lets you set a condition based on the
Trusted Cloud service being used. For example, you could set a condition
limiting a user's access to resources that use the
cloudresourcemanager.googleapis.com
service. For a list of supported values,
see Resource service values.
You can use the resource.service
attribute in allow policy role bindings.
Attribute variable | resource.service |
---|---|
Attribute type |
For a list of supported values, see Resource service values. |
Supported operators | , |
Details |
When you use the resource.type attribute in conditions,
check for exact equality ( ) or exact
inequality ( ) with the attribute.
Other comparisons, such as checking for a prefix or suffix, might give
you unexpected results.
|
Example |
Returns resource.service == "compute.googleapis.com" |
Supported services |
|
resource.type attribute
The resource.type
attribute lets you set a condition based on the resource's
type. For example, you could set a condition limiting a user's access to
resources of the type storage.googleapis.com/Object
. For a list of supported
values, see Resource type values.
If your condition uses the resource.name
attribute, we strongly recommend that
you use the resource.type
attribute to control which resource types the
condition applies to. For details, see
resource.name
attribute on this page.
You can use the resource.type
attribute in allow policy role bindings.
Attribute variable | resource.type |
||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Attribute type |
For a list of supported values, see Resource type values. |
||||||||||||||||||||||
Supported operators | , |
||||||||||||||||||||||
Details |
When you use the resource.type attribute in conditions,
check for exact equality ( ) or exact
inequality ( ) with the attribute. Other
comparisons, such as checking for a prefix or suffix, might give you
unexpected results.
|
||||||||||||||||||||||
Examples |
Returns resource.type != "compute.googleapis.com/Image"
Returns (resource.type == "compute.googleapis.com/Image" || resource.type == "compute.googleapis.com/Disk") |
||||||||||||||||||||||
Supported resource types |
1 Cloud Key Management Service uses this resource type as the parent of key ring resources. |
resource.name attribute
The resource.name
attribute lets you set a condition based on all or part of a
resource name. For a list of resource name formats, see Resource name
format.
The resource.name
attribute is available only for specific resource types,
which are listed in the table in this section. We strongly recommend that you
limit the applicability of the condition to the intended resource type. If a
role contains permissions for a resource type that does not provide the
resource.name
attribute, you should ensure that those permissions are not
restricted by the part of the condition that checks resource.name
.
The following example shows how to ensure this behavior. In this example, the
condition allows access to all resource types except Cloud Storage buckets and
objects. In contrast, for buckets and objects, the condition only allows access
to the bucket example-bucket
and the objects it contains:
(resource.type != 'storage.googleapis.com/Bucket' &&
resource.type != 'storage.googleapis.com/Object') ||
resource.name.startsWith('projects/_/buckets/example-bucket')
Note that the first part of the condition checks whether the resource is neither
a bucket nor an object. If the resource has a different type, then the entire
condition evaluates to true
, regardless of the resource name.
Also, note that the condition checks the resource.type
attribute, not the
resource.service
attribute. There are a few benefits of checking the
resource.type
attribute:
- It limits the
resource.name
check to the appropriate set of resources. For example, if you want to grant access to Compute Engine instances with a specific name, it makes sense to exclude all resource types other than Compute Engine instances. - It prevents the scope of the condition from changing if a service adds new resource types in the future.
Finally, note that the condition uses the startsWith()
function to evaluate
the resource name, rather than checking for equality with the
operator. Because the condition looks at the start of the resource name, it
matches a bucket as well as the objects in that bucket. If it checked for
equality, it would only match the bucket.
You cannot use wildcard characters such as *
to match multiple resource
names. Consider these alternatives:
Use the
extract()
function to extract a value from a resource name. For example, you can extract a project ID from the resource name of a Compute Engine VM instance, then write a condition expression that refers to the project ID.For details, see Extracting values from attributes on this page.
Use the
startsWith()
orendsWith()
function to write a condition that evaluates the start or end of the resource name.
You can use the resource.name
attribute in allow policy role bindings.
Attribute variable | resource.name |
||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Attribute type |
Each resource type uses a specific format for the resource name. For a list of formats, see Resource name format. |
||||||||||||||||
Supported functions and operators |
startsWith(), endsWith(), extract(),
, |
||||||||||||||||
Details |
The
The
The
The
The |
||||||||||||||||
Examples |
Returns resource.name != "projects/_/buckets/secret-bucket-123"
Returns resource.name.startsWith("projects/project-123/zones/us-east1-b/instances/prod-")
Returns resource.name.startsWith("projects/_/buckets/my_bucket/objects/test-object-")
Returns resource.name.endsWith(".jpg") Returns the project name or number if it's present: resource.name.extract("projects/{project}/") |
||||||||||||||||
Supported resource types |
|
Resource tags
The resource tag functions let you set a condition based on the tags that are
attached to supported resources or inherited by those
resources' descendants. For example, you can set a condition that grants a
role only for resources that have the tag env: prod
attached. To learn more
about controlling access with tags, see
Tags and access control.
Each tag consists of a key and a value. There are a few different types of identifiers for each key and value:
-
A permanent ID, which is globally unique and can never be reused. For example, a tag
key could have the permanent ID
tagKeys/123456789012
, and a tag value could have the permanent IDtagValues/567890123456
. -
A short name. The short name for each key must be unique within the project or
organization under which the key is defined, and the short name for each value must be unique
for its associated key. For example, a tag key could have the short name
env
, and a tag value could have the short nameprod
. -
A namespaced name, which adds your organization's numeric ID or project's ID to the
short name of a tag key. For example, a tag key created for an organization could have the
namespaced name
123456789012/env
. To learn how to get your organization ID, see Getting your organization resource ID. A tag key created for a project could have the namespaced namemyproject/env
. To learn how to get your project ID, see Identifying projects.
For guidance on choosing which type of identifier to use in your conditions, see Tag definitions and identifiers.
You can use tag-based conditions to conditionalize access to any resource. This includes resources with their own tags, as well as resources that inherit tags from other resources. To learn more about how tags are inherited through the resource hierarchy, see Tag inheritance.
However, certain areas of the Trusted Cloud console don't recognize allow policy role bindings with tag-based conditions. As a result, if you have a role with a tag-based condition, then the Trusted Cloud console might incorrectly prevent you from performing certain actions. If you encounter this issue, then use an alternate method, such as the gcloud CLI, to perform the action.
You can use tag-based conditions in the following:
- Allow policy role bindings
- Deny policy deny rules
You can use the following functions to set conditions based on tags:
Function | Description |
---|---|
resource.hasTagKey(
bool
|
Checks whether the resource for the request has a tag with the
specified key. The tag key is looked up by its namespaced
name. To check for a tag key using its permanent ID, use
the function
|
resource.hasTagKeyId(
bool
|
Checks whether the resource for the request has a tag with the
specified key. The tag key is looked up by its permanent ID.
To check for a tag key using its namespaced name, use the
function
|
resource.matchTag(
bool
|
Checks whether the resource for the request has a tag with the
specified key and value. The key is looked up by its namespaced
name, and the value is looked up by its short name. To
check for a tag key and value using their permanent IDs, use
the function
|
resource.matchTagId(
bool
|
Checks whether the resource for the request has a tag with the
specified key and value. The key and value are looked up by their
permanent IDs. To check for a tag key using its
namespaced name and a value using its short name,
use the function
|
Request attributes
Request attributes enable you to create conditions that evaluate details about the request, such as the roles modified by a request or the request's date and time.
API attributes
API attributes help you manage access based on data provided by a specific Trusted Cloud API or service. You can use API attributes in allow policy role bindings.
For examples of when you might need to use API attributes in a condition, see the following pages:
Not all services recognize API attributes. The following sections indicate which services recognize each API attribute.
Functions for API attributes
You can use the following function to work with API attributes:
Function | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
api.getAttribute(
V<T>
|
Gets the requested API attribute.
|
||||||||||||
hasOnly(
bool |
Checks that a list contains only the allowed items, or a subset of
those items. You can call the function on a list returned by
|
IAM API attributes
IAM provides the following API attribute:
Attribute variable | iam.googleapis.com/modifiedGrantsByRole |
---|---|
Attribute type | list<string> |
Details |
For a request to set the allow policy of a resource, this attribute contains the role names from the role bindings that the request modifies. For other types of requests, the attribute is not defined. |
Resource types that accept this attribute |
The following resource types accept conditions with the
|
Services that recognize this attribute |
The following services recognize the
|
Date/time attribute
The date/time attribute is used to set expirable, scheduled, or limited-duration access to Trusted Cloud resources. You can use date/time attributes in allow policy role bindings.
This attribute is supported for all Trusted Cloud services and resource types. To learn how to apply date/time conditions to resources that don't directly support them, see Support for inherited conditions on this page.
The request.time
attribute contains the timestamp for the request. You can
compare this timestamp to another timestamp, or to a duration of time.
The following sections list the functions that you can use to set conditions based on timestamps and durations.
Create, compare, and modify timestamps and durations
Function or operator | Description |
---|---|
date(
Timestamp |
Converts a date from a
|
duration(
Duration |
Converts an amount of time from a
|
timestamp(
Timestamp |
Converts a
|
, , , |
Compares two
|
|
Add or subtract a
|
Extract information from a timestamp
The functions in this section let you extract information from a timestamp, such as the day of the week that the timestamp falls on.
In IAM Conditions, all timestamps are in UTC. However, you might want to extract information based on a different time zone. For example, you might want to know whether a UTC timestamp falls on a Monday in the time zone for Berlin, Germany.
To specify a different time zone, pass the time zone into the function. Use a
name or UTC offset from the
IETF
Time Zone Database. For example, you could use Europe/Berlin
or +01:00
for Central European Time (CET).
Supported functions and operators | Description |
---|---|
Timestamp.getDate(
int
|
Gets the day of the month from the
|
Timestamp.getDayOfMonth(
int
|
Gets the day of the month from the
|
Timestamp.getDayOfWeek(
int
|
Gets the day of the week from the
|
Timestamp.getDayOfYear(
int
|
Gets the day of the year from the
|
Timestamp.getFullYear(
int
|
Gets the year from the
|
Timestamp.getHours(
int
|
Gets the hour of the day from the
You can combine this function with
|
Timestamp.getMilliseconds(
int
|
Gets the number of milliseconds from the
|
Timestamp.getMinutes(
int
|
Gets the number of minutes after the hour from the
|
Timestamp.getMonth(
int
|
Gets the month of the year from the
|
Timestamp.getSeconds(
int
|
Gets the number of seconds from the
|
, , , |
Compares the output of two functions in this table. |
Forwarding rule attributes
The forwarding rule attributes enable you to specify the types of forwarding rules that a principal can create. For example, you could allow a principal to create forwarding rules for internal Trusted Cloud by S3NS load balancers, which handle traffic that originates inside a Trusted Cloud network, but not for external Trusted Cloud load balancers, which handle traffic that originates from the internet. You can use forwarding rule attributes in allow policy role bindings.
For Cloud Load Balancing, the forwarding rule attributes don't affect the ability to create other components of a Trusted Cloud load balancer, such as backend services, target proxies, health checks, and URL maps.
Supported functions
Function | Description |
---|---|
compute.isForwardingRule
bool
|
Checks whether the request is creating a forwarding rule.
|
compute.matchLoad
bool
|
Checks whether the request affects one of the specified types of load balancing scheme. To find the identifier for each load balancing scheme, as well as more details, see Using IAM Conditions on Trusted Cloud load balancers.
|
Supported resource types
This attribute is available for requests to create the following resource types:
Service | Resource types |
---|---|
Cloud Load Balancing | Forwarding rules |
Cloud VPN | Forwarding rules (global and regional) |
Compute Engine | Forwarding rules (for protocol forwarding) |
Cloud Service Mesh1 | Forwarding rules |
1 Uses the resource attributes for Compute Engine.
Extract values from attributes
You can use the extract()
function to extract a value from an attribute. For
example, you can extract an arbitrary part of a resource name, then write a
condition expression that refers to the text you extracted.
To use the extract()
function, you provide an extraction template, which
specifies the part of the attribute to extract. For example, if you want to
extract a project ID from the resource name of a Compute Engine VM
instance, you might use the template projects/{project}/
.
An extraction template contains the following parts:
An identifier, enclosed in curly braces, that identifies the substring to extract.
Choose a short, meaningful identifier that makes it clear what value you want to extract. You can use uppercase and lowercase letters from
A
toZ
; numeric digits; and underscores (_
).In the template
projects/{project}/
, the identifier isproject
.Optional: A prefix, which must appear before the substring to extract.
In the template
projects/{project}/
, the prefix isprojects/
.Optional: A suffix, which must appear after the substring to extract.
In the template
projects/{project}/
, the suffix is/
.
The extract()
function extracts different parts of the attribute based on
whether the extraction template has a prefix, a suffix, or both:
Has prefix | Has suffix | Extracted value |
---|---|---|
— | — | The entire attribute |
— | The characters after the first occurrence of the prefix, or an empty string if there are no characters after the prefix | |
— | The characters before the first occurrence of the suffix, or an empty string if there are no characters before the suffix | |
The characters between the first occurrence of the prefix and the first subsequent occurrence of the suffix, or an empty string if there are no characters between the prefix and the suffix |
If you specify a prefix or suffix that don't appear in the attribute, or if the
suffix appears only before the prefix, the extract()
function returns an empty
string.
The following examples show the output from several different extraction
templates. These examples refer to a resource name for a Cloud Storage
object,
projects/_/buckets/acme-orders-aaa/objects/data_lake/orders/
:
Extraction template | Output |
---|---|
/order_date={date}/ |
2019-11-03 |
buckets/{name}/ |
acme-orders-aaa |
/orders/{empty}order_date |
Empty string |
{start}/objects/data_lake |
projects/_/buckets/acme-orders-aaa |
orders/{end} |
order_date=2019-11-03/aef87g87ae0876 |
{all} |
projects/_/buckets/acme-orders-aaa/objects/data_lake/orders/ |
/orders/{none}/order_date= |
Empty string |
/orders/order_date=2019-11-03/ |
Empty string |
If you extract a string that represents a date, you can use the
date/time functions and operators on this page to convert the
extracted value to a Timestamp
. For examples, see
Configuring resource-based access.