Amazon global condition context keys - Amazon Identity and Access Management
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

Amazon global condition context keys

When a principal makes a request to Amazon, Amazon gathers the request information into a request context. You can use the Condition element of a JSON policy to compare keys in the request context with key values that you specify in your policy. To learn more about the circumstances under which a global key is included in the request context, see the Availability information for each global condition key. For information about how to use the Condition element in a JSON policy, see IAM JSON policy elements: Condition.

Note

If you use condition keys that are available only in some circumstances, you can use the IfExists versions of the condition operators. If the condition keys are missing from a request context, the policy can fail the evaluation. For example, use the following condition block with ...IfExists operators to match when a request comes from a specific IP range or from a specific VPC. If either or both keys are not included in the request context, the condition still returns true. The values are only checked if the specified key is included in the request context.

"Condition": { "IpAddressIfExists": {"aws:SourceIp" : ["xxx"] }, "StringEqualsIfExists" : {"aws:SourceVpc" : ["yyy"]} }

Global condition keys are condition keys with an aws: prefix. Amazon services can support global condition keys or provide service-specific keys that include their service prefix. For example, IAM condition keys include the iam: prefix. For more information, see Actions, Resources, and Condition Keys for Amazon Services and choose the service whose keys you want to view.

aws:CalledVia

Works with string operators.

Use this key to compare the services in the policy with the services that made requests on behalf of the IAM principal (user or role). When a principal makes a request to an Amazon service, that service might use the principal's credentials to make subsequent requests to other services. The aws:CalledVia key contains an ordered list of each service in the chain that made requests on the principal's behalf.

For example, you can use Amazon CloudFormation to read and write from an Amazon DynamoDB table. DynamoDB then uses encryption supplied by Amazon Key Management Service (Amazon KMS).

  • Availability – This key is present in the request when a service that supports aws:CalledVia uses the credentials of an IAM principal to make a request to another service. This key is not present if the service uses a service role or service-linked role to make a call on the principal's behalf. This key is also not present when the principal makes the call directly.

  • Value type – Multivalued

To use the aws:CalledVia condition key in a policy, you must provide the service principals to allow or deny Amazon service requests. Amazon supports using the following services with aws:CalledVia.

CalledVia services
Amazon service Service principal
Amazon Athena athena.amazonaws.com.cn
Amazon CloudFormation cloudformation.amazonaws.com.cn
Amazon DynamoDB dynamodb.amazonaws.com.cn
Amazon Key Management Service (Amazon KMS) kms.amazonaws.com.cn

To allow or deny access when any service makes a request using the principal's credentials, use the aws:ViaAWSService condition key. That condition key supports Amazon services.

The aws:CalledVia key is a multivalued key. However, you can't enforce order using this key in a condition. Using the example above, User 1 makes a request to Amazon CloudFormation, which calls DynamoDB, which calls Amazon KMS. These are three separate requests. The final call to Amazon KMS is performed by User 1 via Amazon CloudFormation and then DynamoDB.


                Example using aws:CalledVia

In this case, the aws:CalledVia key in the request context includes cloudformation.amazonaws.com.cn and dynamodb.amazonaws.com.cn, in that order. If you care only that the call was made via DynamoDB somewhere in the chain of requests, you can use this condition key in your policy.

For example, the following policy allows managing the Amazon KMS key named my-example-key, but only if DynamoDB is one of the requesting services. The ForAnyValue:StringEquals condition operator ensures that DynamoDB is one of the calling services. If the principal makes the call to Amazon KMS directly, the condition returns false and the request is not allowed by this policy.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "KmsActionsIfCalledViaDynamodb", "Effect": "Allow", "Action": [ "kms:Encrypt", "kms:Decrypt", "kms:ReEncrypt*", "kms:GenerateDataKey", "kms:DescribeKey" ], "Resource": "arn:aws:kms:region:111122223333:key/my-example-key", "Condition": { "ForAnyValue:StringEquals": { "aws:CalledVia": ["dynamodb.amazonaws.com.cn"] } } } ] }

If you want to enforce which service makes the first or last call in the chain, you can use the aws:CalledViaFirst and aws:CalledViaLast keys. For example, the following policy allows managing the key named my-example-key in Amazon KMS. These Amazon KMS operations are allowed only if multiple requests were included in the chain. The first request must be made via Amazon CloudFormation and the last via DynamoDB. If other services make requests in the middle of the chain, the operation is still allowed.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "KmsActionsIfCalledViaChain", "Effect": "Allow", "Action": [ "kms:Encrypt", "kms:Decrypt", "kms:ReEncrypt*", "kms:GenerateDataKey", "kms:DescribeKey" ], "Resource": "arn:aws:kms:region:111122223333:key/my-example-key", "Condition": { "StringEquals": { "aws:CalledViaFirst": "cloudformation.amazonaws.com.cn", "aws:CalledViaLast": "dynamodb.amazonaws.com.cn" } } } ] }

The aws:CalledViaFirst and aws:CalledViaLast keys are present in the request when a service uses an IAM principal's credentials to call another service. They indicate the first and last services that made calls in the chain of requests. For example, assume that Amazon CloudFormation calls another service named X Service, which calls DynamoDB, which then calls Amazon KMS. The final call to Amazon KMS is performed by User 1 via Amazon CloudFormation, then X Service, and then DynamoDB. It was first called via Amazon CloudFormation and last called via DynamoDB.


                Example using aws:CalledViaFirst and aws:CalledViaLast

aws:CalledViaFirst

Works with string operators.

Use this key to compare the services in the policy with the first service that made a request on behalf of the IAM principal (user or role). For more information, see aws:CalledVia.

  • Availability – This key is present in the request when a service uses the credentials of an IAM principal to make at least one other request to a different service. This key is not present if the service uses a service role or service-linked role to make a call on the principal's behalf. This key is also not present when the principal makes the call directly.

  • Value type – Single-valued

aws:CalledViaLast

Works with string operators.

Use this key to compare the services in the policy with the last service that made a request on behalf of the IAM principal (user or role). For more information, see aws:CalledVia.

  • Availability – This key is present in the request when a service uses the credentials of an IAM principal to make at least one other request to a different service. This key is not present if the service uses a service role or service-linked role to make a call on the principal's behalf. This key is also not present when the principal makes the call directly.

  • Value type – Single-valued

aws:CurrentTime

Works with date operators.

Use this key to compare the date and time of the request with the date and time that you specify in the policy. To view an example policy that uses this condition key, see Amazon: Allows access based on date and time.

  • Availability – This key is always included in the request context.

  • Value type – Single-valued

aws:EpochTime

Works with date operators or numeric operators.

Use this key to compare the date and time of the request in epoch or Unix time with the value that you specify in the policy. This key also accepts the number of seconds since January 1, 1970.

  • Availability – This key is always included in the request context.

  • Value type – Single-valued

aws:FederatedProvider

Works with string operators.

Use this key to compare the principal's issuing identity provider (IdP) with the IdP that you specify in the policy. This means that an IAM role was assumed using the AssumeRoleWithWebIdentity or AssumeRoleWithSAML Amazon STS operations. When the resulting role session's temporary credentials are used to make a request, the request context identifies the IdP that authenticated the original federated identity.

  • Availability – This key is present when the principal is a role session principal and that session was issued using a third-party identity provider.

  • Value type – Single-valued

For example, if the user was authenticated through Amazon Cognito, the request context includes the value cognito-identity.amazonaws.com.cn. Similarly, if the user was authenticated through Login with Amazon, the request context includes the value www.amazon.cn.

You can use any single-valued condition key as a variable. The following example resource-based policy uses the aws:FederatedProvider key as a policy variable in the ARN of a resource. This policy allows any principal who authenticated using an IdP to get objects out of an Amazon S3 bucket with a path that's specific to the issuing identity provider.

{ "Version": "2012-10-17", "Statement": { "Effect": "Allow", "Principal": "*", "Action": "s3:GetObject", "Resource": "arn:aws-cn:s3:::BUCKET-NAME/${aws:FederatedProvider}/*" } }

aws:MultiFactorAuthAge

Works with numeric operators.

Use this key to compare the number of seconds since the requesting principal was authorized using MFA with the number that you specify in the policy. For more information about MFA, see Using multi-factor authentication (MFA) in Amazon.

  • Availability – This key is included in the request context only if the principal making the call was authenticated using MFA. If MFA was not used, this key is not present.

  • Value type – Single-valued

aws:MultiFactorAuthPresent

Works with Boolean operators.

Use this key to check whether multi-factor authentication (MFA) was used to validate the temporary security credentials that made the request.

  • Availability – This key is included in the request context only when the principal uses temporary credentials to make the request. The key is not present in Amazon CLI, Amazon API, or Amazon SDK requests that are made using long-term credentials.

  • Value type – Single-valued

Temporary credentials are used to authenticate IAM roles, federated users, IAM users with temporary tokens from sts:GetSessionToken, and users of the Amazon Web Services Management Console. IAM user access keys are long-term credentials, but in some cases, Amazon creates temporary credentials on behalf of IAM users to perform operations. In these cases, the aws:MultiFactorAuthPresent key is present in the request and set to a value of false. There are two common cases where this can happen:

  • IAM users in the Amazon Web Services Management Console unknowingly use temporary credentials. Users sign into the console using their user name and password, which are long-term credentials. However, in the background, the console generates temporary credentials on behalf of the user.

  • If an IAM user makes a call to an Amazon service, the service re-uses the user's credentials to make another request to a different service. For example, when calling Athena to access an Amazon S3 bucket, or when using Amazon CloudFormation to create an Amazon EC2 instance. For the subsequent request, Amazon uses temporary credentials.

To learn which services support using temporary credentials, see Amazon services that work with IAM.

The aws:MultiFactorAuthPresent key is not present when an API or CLI command is called with long-term credentials, such as user access key pairs. Therefore we recommend that when you check for this key that you use the ...IfExists versions of the condition operators.

It is important to understand that the following Condition element is not a reliable way to check whether a request is authenticated using MFA.

##### WARNING: NOT RECOMMENDED ##### "Effect" : "Deny", "Condition" : { "Bool" : { "aws:MultiFactorAuthPresent" : "false" } }

This combination of the Deny effect, Bool element, and false value denies requests that can be authenticated using MFA, but were not. This applies only to temporary credentials that support using MFA. This statement does not deny access to requests that are made using long-term credentials, or to requests that are authenticated using MFA. Use this example with caution because its logic is complicated and it does not test whether MFA-authentication was actually used.

Also do not use the combination of the Deny effect, Null element, and true because it behaves the same way and the logic is even more complicated.

Recommended Combination

We recommend that you use the BoolIfExists operator to check whether a request is authenticated using MFA.

"Effect" : "Deny", "Condition" : { "BoolIfExists" : { "aws:MultiFactorAuthPresent" : "false" } }

This combination of Deny, BoolIfExists, and false denies requests that are not authenticated using MFA. Specifically, it denies requests from temporary credentials that do not include MFA. It also denies requests that are made using long-term credentials, such as Amazon CLI or Amazon API operations made using access keys. The *IfExists operator checks for the presence of the aws:MultiFactorAuthPresent key and whether or not it could be present, as indicated by its existence. Use this when you want to deny any request that is not authenticated using MFA. This is more secure, but can break any code or scripts that use access keys to access the Amazon CLI or Amazon API.

Alternative Combinations

You can also use the BoolIfExists operator to allow MFA-authenticated requests and Amazon CLI or Amazon API requests that are made using long-term credentials.

"Effect" : "Allow", "Condition" : { "BoolIfExists" : { "aws:MultiFactorAuthPresent" : "true" } }

This condition matches either if the key exists and is present or if the key does not exist. This combination of Allow, BoolIfExists, and true allows requests that are authenticated using MFA, or requests that cannot be authenticated using MFA. This means that Amazon CLI, Amazon API, and Amazon SDK operations are allowed when the requester uses their long-term access keys. This combination does not allow requests from temporary credentials that could, but do not include MFA.

When you create a policy using the IAM console visual editor and choose MFA required, this combination is applied. This setting requires MFA for console access, but allows programmatic access with no MFA.

Alternatively, you can use the Bool operator to allow programmatic and console requests only when authenticated using MFA.

"Effect" : "Allow", "Condition" : { "Bool" : { "aws:MultiFactorAuthPresent" : "true" } }

This combination of the Allow, Bool, and true allows only MFA-authenticated requests. This applies only to temporary credentials that support using MFA. This statement does not allow access to requests that were made using long-term access keys, or to requests made using temporary credentials without MFA.

Do not use a policy construct similar to the following to check whether the MFA key is present:

##### WARNING: USE WITH CAUTION ##### "Effect" : "Allow", "Condition" : { "Null" : { "aws:MultiFactorAuthPresent" : "false" } }

This combination of the Allow effect, Null element, and false value allows only requests that can be authenticated using MFA, regardless of whether the request is actually authenticated. This allows all requests that are made using temporary credentials, and denies access for long-term credentials. Use this example with caution because it does not test whether MFA-authentication was actually used.

aws:PrincipalAccount

Works with string operators.

Use this key to compare the account to which the requesting principal belongs with the account identifier that you specify in the policy.

  • Availability – This key is always included in the request context.

  • Value type – Single-valued

aws:PrincipalArn

Works with ARN operators and string operators.

Use this key to compare the Amazon Resource Name (ARN) of the principal that made the request with the ARN that you specify in the policy. For IAM roles, the request context returns the ARN of the role, not the ARN of the user that assumed the role. To learn which types of principals you can specify in this condition key, see Specifying a principal.

  • Availability – This key is always included in the request context.

  • Value type – Single-valued

aws:PrincipalTag

Works with string operators.

Use this key to compare the tag attached to the principal making the request with the tag that you specify in the policy. If the principal has more than one tag attached, the request context includes one aws:PrincipalTag key for each attached tag key.

  • Availability – This key is included in the request context if the principal is using an IAM user with attached tags. It is included for a principal using an IAM role with attached tags or session tags.

  • Value type – Single-valued

You can add custom attributes to a user or role in the form of a key-value pair. For more information about IAM tags, see Tagging IAM resources. You can use aws:PrincipalTag to control access for Amazon principals.

This example shows how you might create an IAM policy that allows users with the tagManager=true tag to manage IAM users, groups, or roles. To use this policy, replace the italicized placeholder text in the example policy with your own information. Then, follow the directions in create a policy or edit a policy.

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "iam:*", "Resource": "*", "Condition": {"StringEquals": {"aws:PrincipalTag/tagManager": "true"}} } ] }

aws:PrincipalType

Works with string operators.

Use this key to compare the type of principal making the request with the principal type that you specify in the policy. For more information, see Specifying a principal.

  • Availability – This key is always included in the request context.

  • Value type – Single-valued

aws:referer

Works with string operators.

Use this key to compare who referred the request in the client browser with the referer that you specify in the policy. The aws:referer request context value is provided by the caller in an HTTP header. The Referer header is included in a web browser request when you select a link on a web page. The Referer header contains the URL of the web page where the link was selected.

  • Availability – This key is included in the request context only if the request to the Amazon resource was invoked by linking from a web page URL in the browser. This key is not included for programmatic requests because it doesn't use a browser link to access the Amazon resource.

  • Value type – Single-valued

For example, you can access an Amazon S3 object directly using a URL or using direct API invocation. For more information, see Amazon S3 API operations directly using a web browser. When you access an Amazon S3 object from a URL that exists in a webpage, the URL of the source web page is in used in aws:referer. When you access an Amazon S3 object by typing the URL into your browser, aws:referer is not present. When you invoke the API directly, aws:referer is also not present. You can use the aws:referer condition key in a policy to allow requests made from a specific referer, such as a link on a web page in your company's domain.

Warning

This key should be used carefully. It is dangerous to include a publicly known referer header value. Unauthorized parties can use modified or custom browsers to provide any aws:referer value that they choose. As a result, aws:referer should not be used to prevent unauthorized parties from making direct Amazon requests. It is offered only to allow customers to protect their digital content, such as content stored in Amazon S3, from being referenced on unauthorized third-party sites.

aws:RequestedRegion

Works with string operators.

Use this key to compare the Amazon Region that was called in the request with the Region that you specify in the policy. You can use this global condition key to control which Regions can be requested. To view the Amazon Regions for each service, see Service endpoints and quotas in the Amazon Web Services General Reference.

  • Availability – This key is always included in the request context.

  • Value type – Single-valued

Some global services, such as IAM, have a single endpoint. Because this endpoint is physically located in the US East (N. Virginia) Region, IAM calls are always made to the us-east-1 Region. For example, if you create a policy that denies access to all services if the requested Region is not us-west-2, then IAM calls always fail. To view an example of how to work around this, see NotAction with Deny.

Note

The aws:RequestedRegion condition key allows you to control which endpoint of a service is invoked but does not control the impact of the operation. Some services have cross-Region impacts. For example, Amazon S3 has API operations that control cross-Region replication. You can invoke s3:PutBucketReplication in one Region (which is affected by the aws:RequestedRegion condition key), but other Regions are affected based on the replications configuration settings.

You can use this context key to limit access to Amazon services within a given set of Regions. For example, the following policy allows a user to view all of the Amazon EC2 instances in the Amazon Web Services Management Console. However it only allows them to make changes to instances in Ireland (eu-west-1), London (eu-west-2), or Paris (eu-west-3).

{ "Version": "2012-10-17", "Statement": [ { "Sid": "InstanceConsoleReadOnly", "Effect": "Allow", "Action": [ "ec2:Describe*", "ec2:Export*", "ec2:Get*", "ec2:Search*" ], "Resource": "*" }, { "Sid": "InstanceWriteRegionRestricted", "Effect": "Allow", "Action": [ "ec2:Associate*", "ec2:Import*", "ec2:Modify*", "ec2:Monitor*", "ec2:Reset*", "ec2:Run*", "ec2:Start*", "ec2:Stop*", "ec2:Terminate*" ], "Resource": "*", "Condition": { "StringEquals": { "aws:RequestedRegion": [ "eu-west-1", "eu-west-2", "eu-west-3" ] } } } ] }

aws:RequestTag/tag-key

Works with string operators.

Use this key to compare the tag key-value pair that was passed in the request with the tag pair that you specify in the policy. For example, you could check whether the request includes the tag key "Dept" and that it has the value "Accounting". For more information, see Controlling access during Amazon requests.

  • Availability – This key is included in the request context when tags are passed in the request. When multiple tags are passed in the request, there is one context key for each tag key-value pair.

  • Value type – Single-valued

This context key is formatted "aws:RequestTag/tag-key":"tag-value" where tag-key and tag-value are a tag key and value pair.

Because you can include multiple tag key-value pairs in a request, the request content could be a multivalued request. In this case, you should consider using the ForAllValues or ForAnyValue set operators. For more information, see Using multiple keys and values.

aws:ResourceTag/tag-key

Works with string operators.

Use this key to compare the tag key-value pair that you specify in the policy with the key-value pair that is attached to the resource. For example, you could require that access to a resource is allowed only if the resource has the attached tag key "Dept" with the value "Marketing". For more information, see Controlling access to Amazon resources.

  • Availability – This key is included in the request context when the requested resource already has attached tags. This key is returned only for resources that support authorization based on tags. There is one context key for each tag key-value pair.

  • Value type – Single-valued

This context key is formatted "aws:ResourceTag/tag-key":"tag-value" where tag-key and tag-value are a tag key and value pair.

For examples of using the aws:ResourceTag key to control access to IAM resources, see Controlling access to Amazon resources.

For examples of using the aws:ResourceTag key to control access to other Amazon resources, see Controlling access to Amazon resources using tags.

For a tutorial on using the aws:ResourceTag condition key for attribute based access control (ABAC), see IAM tutorial: Define permissions to access Amazon resources based on tags.

aws:SecureTransport

Works with Boolean operators.

Use this key to check whether the request was sent using SSL. The request context returns true or false. In a policy, you can allow specific actions only if the request is sent using SSL.

  • Availability – This key is always included in the request context.

  • Value type – Single-valued

aws:SourceAccount

Works with string operators.

Use this key to compare the account ID of the resource making a service-to-service request with the account ID that you specify in the policy.

  • Availability – This key is included in the request context only if accessing a resource triggers an Amazon service to call another service on behalf of the resource owner. The calling service must pass the resource account ID of the source to the called service. This account ID includes the source account ID.

  • Value type – Single-valued

You can use this condition key to prevent an Amazon service from being used as a confused deputy during transactions between services. Set the value of this condition key to the account of the resource in the request. For example, when an Amazon S3 bucket update triggers an Amazon SNS topic post, the Amazon S3 service invokes the sns:Publish API operation. In the policy that allows the sns:Publish operation, set the value of the condition key to the account ID of the Amazon S3 bucket. For information about how and when these condition keys are recommended, see the documentation for the Amazon services you are using.

aws:SourceArn

Works with ARN operators and string operators. Amazon recommends that you use ARN operators instead of string operators when comparing ARNs.

Use this key to compare the Amazon Resource Name (ARN) of the resource making a service-to-service request with the ARN that you specify in the policy.

This key does not work with the ARN of the principal making the request. Instead, use aws:PrincipalArn. The source's ARN includes the account ID, so it is not necessary to use aws:SourceAccount with aws:SourceArn.

  • Availability – This key is included in the request context only if accessing a resource triggers an Amazon service to call another service on behalf of the resource owner. The calling service must pass the ARN of the original resource to the called service.

  • Value type – Single-valued

You can use this condition key to prevent an Amazon service from being used as a confused deputy during transactions between services. Set the value of this condition key to the ARN of the resource in the request. For example, when an Amazon S3 bucket update triggers an Amazon SNS topic post, the Amazon S3 service invokes the sns:Publish API operation. In the policy that allows the sns:Publish operation, set the value of the condition key to the ARN of the Amazon S3 bucket. For information about how and when these condition keys are recommended, see the documentation for the Amazon services you are using.

aws:SourceIdentity

Works with string operators.

Use this key to compare the source identity that was set by the principal with the source identity that you specify in the policy.

  • Availability – This key is included in the request context after a source identity has been set when a role is assumed using any Amazon STS assume-role CLI command, or Amazon STS AssumeRole API operation.

  • Value type – Single-valued

You can use this key in a policy to allow actions in Amazon by principals that have set a source identity when assuming a role. Activity for the role's specified source identity appears in Amazon CloudTrail. This makes it easier for administrators to determine who or what performed actions with a role in Amazon.

Unlike sts:RoleSessionName, after the source identity is set, the value cannot be changed. It is present in the request context for all actions taken by the role. The value persists into subsequent role sessions when you use the session credentials to assume another role. Assuming one role from another is called role chaining.

The sts:SourceIdentity key is present in the request when the principal initially sets a source identity while assuming a role using any Amazon STS assume-role CLI command, or Amazon STS AssumeRole API operation. The aws:SourceIdentity key is present in the request for any actions that are taken with a role session that has a source identity set.

The following role trust policy for CriticalRole in account 111122223333 contains a condition for aws:SourceIdentity that prevents a principal without a source identity that is set to Saanvi or Diego from assuming the role.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AssumeRoleIfSourceIdentity", "Effect": "Allow", "Principal": {"AWS": " arn:aws:iam::111122223333:role/CriticalRole"}, "Action": [ "sts:AssumeRole", "sts:SetSourceIdentity" ], "Condition": { "StringLike": { "aws:SourceIdentity": ["Saanvi","Diego"] } } } ] }

To learn more about using source identity information, see Monitor and control actions taken with assumed roles.

aws:SourceIp

Works with IP address operators.

Use this key to compare the requester's IP address with the IP address that you specify in the policy. The aws:SourceIp condition key can only be used for public IP address ranges.

  • Availability – This key is included in the request context, except when the requester uses a VPC endpoint to make the request.

  • Value type – Single-valued

The aws:SourceIp condition key can be used in a policy to allow principals to make requests only from within a specified IP range. However, this policy denies access if an Amazon service makes calls on the principal's behalf. In this case, you can use aws:SourceIp with the aws:ViaAWSService key to ensure that the source IP restriction applies only to requests made directly by a principal.

For example, you can attach the following policy to an IAM user. This policy allows the user to put an object into the my-service-bucket Amazon S3 bucket directly if they make the call from the specified IP address. However, if the user makes another request that causes a service to call Amazon S3, the IP address restriction does not apply. The PrincipalPutObjectIfIpAddress statement restricts the IP address only if the request is not made by a service. The ServicePutObject statement allows the operation without IP address restriction if the request is made by a service.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "PrincipalPutObjectIfIpAddress", "Effect": "Allow", "Action": "s3:PutObject", "Resource": "arn:aws:s3:::my-service-bucket/*", "Condition": { "Bool": {"aws:ViaAWSService": "false"}, "IpAddress": {"aws:SourceIp": "123.45.167.89"} } }, { "Sid": "ServicePutObject", "Effect": "Allow", "Action": "s3:PutObject", "Resource": "arn:aws:s3:::my-service-bucket/*", "Condition": { "Bool": {"aws:ViaAWSService": "true"} } } ] }

If the request comes from a host that uses an Amazon VPC endpoint, then the aws:SourceIp key is not available. You should instead use a VPC-specific key such as aws:VpcSourceIp. For more information about using VPC endpoints, see VPC Endpoints - Controlling the Use of Endpoints in the Amazon VPC User Guide.

aws:SourceVpc

Works with string operators.

Use this key to check whether the request comes from the VPC that you specify in the policy. In a policy, you can use this key to allow access to only a specific VPC. For more information, see Restricting Access to a Specific VPC in the Amazon Simple Storage Service User Guide.

  • Availability – This key is included in the request context only if the requester uses a VPC endpoint to make the request.

  • Value type – Single-valued

aws:SourceVpce

Works with string operators.

Use this key to compare the VPC endpoint identifier of the request with the endpoint ID that you specify in the policy. In a policy, you can use this key to restrict access to a specific VPC endpoint. For more information, see Restricting Access to a Specific VPC Endpoint in the Amazon Simple Storage Service User Guide.

  • Availability – This key is included in the request context only if the requester uses a VPC endpoint to make the request.

  • Value type – Single-valued

aws:TagKeys

Works with string operators.

Use this key to compare the tag keys in a request with the keys that you specify in the policy. As a best practice when you use policies to control access using tags, use the aws:TagKeys condition key to define what tag keys are allowed. For example policies and more information, see Controlling access based on tag keys.

  • Availability – This key is included in the request context only if the operation supports attaching tags to resources.

  • Value type – Multivalued

This context key is formatted "aws:TagKeys":"tag-key" where tag-key is a list of tag keys without values (for example, ["Dept","Cost-Center"]).

Because you can include multiple tag key-value pairs in a request, the request content could be a multivalued request. In this case, you must use the ForAllValues or ForAnyValue set operators. For more information, see Using multiple keys and values.

Some services support tagging with resource operations, such as creating, modifying, or deleting a resource. To allow tagging and operations as a single call, you must create a policy that includes both the tagging action and the resource-modifying action. You can then use the aws:TagKeys condition key to enforce using specific tag keys in the request. For example, to limit tags when someone creates an Amazon EC2 snapshot, you must include the ec2:CreateSnapshot creation action and the ec2:CreateTags tagging action in the policy. To view a policy for this scenario that uses aws:TagKeys, see Creating a Snapshot with Tags in the Amazon EC2 User Guide for Linux Instances.

aws:TokenIssueTime

Works with date operators.

Use this key to compare the date and time that temporary security credentials were issued with the date and time that you specify in the policy.

  • Availability – This key is included in the request context only when the principal uses temporary credentials to make the request. The key is not present in Amazon CLI, Amazon API, or Amazon SDK requests that are made using access keys.

  • Value type – Single-valued

To learn which services support using temporary credentials, see Amazon services that work with IAM.

aws:UserAgent

Works with string operators.

Use this key to compare the requester's client application with the application that you specify in the policy.

  • Availability – This key is always included in the request context.

  • Value type – Single-valued

Warning

This key should be used carefully. Since the aws:UserAgent value is provided by the caller in an HTTP header, unauthorized parties can use modified or custom browsers to provide any aws:UserAgent value that they choose. As a result, aws:UserAgent should not be used to prevent unauthorized parties from making direct Amazon requests. You can use it to allow only specific client applications, and only after testing your policy.

aws:userid

Works with string operators.

Use this key to compare the requester's principal identifier with the ID that you specify in the policy. For IAM users, the request context value is the user ID. For IAM roles, this value format can vary. For details about how the information appears for different principals, see Specifying a principal.

  • Availability – This key is included in the request context for all signed requests. Anonymous requests do not include this key.

  • Value type – Single-valued

aws:username

Works with string operators.

Use this key to compare the requester's user name with the user name that you specify in the policy. For details about how the information appears for different principals, see Specifying a principal.

  • Availability – This key is always included in the request context for IAM users. Anonymous requests and requests that are made using the Amazon Web Services account root user or IAM roles do not include this key. Requests made using Amazon Web Services SSO credentials do not include this key in the context. To learn how to control access to Amazon Web Services SSO users, see identitystore:UserId in Using predefined attributes from the Amazon Web Services SSO identity store for access control in Amazon.

  • Value type – Single-valued

aws:ViaAWSService

Works with Boolean operators.

Use this key to check whether an Amazon service makes a request to another service on your behalf.

The request context key returns true when a service uses the credentials of an IAM principal to make a request on behalf of the principal. The context key returns false if the service uses a service role or service-linked role to make a call on the principal's behalf. The request context key also returns false when the principal makes the call directly.

  • Availability – This key is always included in the request context.

  • Value type – Single-valued

You can use this condition key to allow or deny access based on whether a request was made by a service. To view an example policy, see Amazon: Denies access to Amazon based on the source IP.

aws:VpcSourceIp

Works with IP address operators.

Use this key to compare the IP address from which a request was made with the IP address that you specify in the policy. In a policy, the key matches only if the request originates from the specified IP address and it goes through a VPC endpoint.

  • Availability – This key is included in the request context only if the request is made using a VPC endpoint.

  • Value type – Single-valued

For more information, see Controlling Access to Services with VPC Endpoints in the Amazon VPC User Guide.

Other cross-service condition keys

Global condition keys are condition keys with an aws: prefix. Individual services can create their own condition keys. These service-specific condition keys include a prefix that matches the name of the service, such as iam: or sts:.

Services can create service-specific keys that are available in the request context for other services. These keys are available across multiple services, but are not global condition keys. For example, Amazon STS supports SAML-based federation condition keys. These keys are available when a user who was federated using SAML performs Amazon operations in other services. Other examples include identitystore:UserId and ec2:SourceInstanceArn.

To view the service-specific condition keys for a service, see Actions, Resources, and Condition Keys for Amazon Services and choose the service whose keys you want to view.