Single-valued vs. multivalued context keys (original) (raw)

The difference between single-valued and multivalued context keys lies in the number of values in the request context, not the number of values in the policy condition.

Important

Multivalued context keys require a condition set operator. Do not use condition set operators ForAllValues or ForAnyValue with single-valued context keys. To learn more about condition set operators, see Multivalued context keys.

The Single-valued and Multivalued classifications are included in the description of each condition context key as_Value type_ in the AWS global condition context keys topic. The Service Authorization Reference uses a different value type classification for multivalued context keys, using an ArrayOf prefix followed by the condition operator category type, such as ArrayOfString orArrayOfARN.

For example, a request can originate from at most one VPC endpoint, so aws:SourceVpce is a single-valued context key. Since a service can have more than one service principal name that belongs to the service,aws:PrincipalServiceNamesList is a multivalued context key.

You can use any available single-valued context key as a policy variable, but you cannot use a multivalued context key as a policy variable. For more information about policy variables, see IAM policy elements: Variables and tags.

When using context keys that include key-value pairs, it's important to note that even though there can be multiple tag-key values, each`tag-key` can have only one value. Therefore,aws:RequestTag and aws:ResourceTag are both single-valued context keys. Using condition set operators with single-valued context keys can lead to overly permissive policies.

Multivalued context keys

To compare your condition context key against a request context key with multiple values, you must use theForAllValues or ForAnyValue set operators. These set operators are used to compare two sets of values, such as the set of tags in a request and the set of tags in a policy condition.

The ForAllValues and ForAnyValue qualifiers add set-operation functionality to the condition operator, allowing you to test request context keys with multiple values against multiple context key values in a policy condition. Additionally, if you include a multivalued string context key in your policy with a wildcard or a variable, you must also use the StringLike condition operator. Multiple condition key values must be enclosed in brackets like an array, for example, "Key2":["Value2A", "Value2B"].

Important

Use caution if you use ForAllValues with an Allow effect, as it can be overly permissive if the presence of missing context keys or context keys with empty values in the request context is unexpected. You can include the Null condition operator in your policy with afalse value to check if the context key exists and its value is not null. For an example, see Controlling access based on tag keys.

Note

The difference between single-valued and multivalued context keys depends on the number of values in the request context, not the number of values in the policy condition.