AWS global condition context keys
When a principal makes a request to
AWS, AWS 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.
Request information is provided by different sources, including the principal making the
request, the resource the request is made against, and the metadata about the request
itself.
Global condition keys can be used across all AWS
services. While these condition keys can be used in all policies, the key is not available
in every request context. For example, the aws:SourceAccount condition key is
only available when the call to your resource is made directly by an AWS service principal. To learn more about the circumstances under which a
global key is included in the request context, see the Availability information for each key.
Some individual services create their own condition keys that are available in the request
context for other services. Cross-service condition keys
are a type of global condition key that include a prefix matching the name of the service,
such as ec2: or lambda:, but are available across other
services.
Service-specific condition keys are defined for use with
an individual AWS service. For example, Amazon S3 lets you write a policy with the
s3:VersionId condition key to limit access to a specific version of an Amazon S3
object. This condition key is unique to the service, meaning it only works with requests to
the Amazon S3 service. For condition keys that are service-specific, see Actions, Resources, and Condition Keys for AWS Services and choose the
service whose keys you want to view.
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. For more information about how a
policy is evaluated when a key is not present for other operators, see Condition
operators.
"Condition": {
"IpAddressIfExists": {"aws:SourceIp" : ["xxx"] },
"StringEqualsIfExists" : {"aws:SourceVpc" : ["yyy"]}
}Important
To compare your condition against a request context with multiple key values, you must
use the ForAllValues or ForAnyValue set operators. Use set
operators only with multivalued condition keys. Do not use set operators with
single-valued condition keys. For more information, see Set operators for multivalued context keys.
| Properties of the principal | Properties of a role session | Properties of the network | Properties of the resource | Properties of the request |
|---|---|---|---|---|
Sensitive condition keys
The following condition keys are considered sensitive. The use of wildcards in these condition keys does not have any valid use cases, even with a substring of the key value with a wildcard. This is because the wildcard might match the condition key to any value, which could pose a security risk.
Properties of the principal
Use the following condition keys to compare details about the principal making the request with the principal properties that you specify in the policy. For a list of principals that can make requests, see How to specify a principal.
aws:PrincipalArn
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.
-
Availability – This key is included in the request context for all signed requests. Anonymous requests do not include this key. You can specify the following types of principals in this condition key:
-
IAM role
-
IAM user
-
AWS STS federated user principal
-
AWS account root user
-
-
Data type – ARN
AWS recommends that you use ARN operators instead of string operators when comparing ARNs.
-
Value type – Single-valued
-
Example values The following list shows the request context value returned for different types of principals that you can specify in the
aws:PrincipalArncondition key:-
IAM role – The request context contains the following value for condition key
aws:PrincipalArn. Do not specify the assumed role session ARN as a value for this condition key. For more information about the assumed role session principal, see Role session principals.arn:aws:iam::123456789012:role/role-name -
IAM user – The request context contains the following value for condition key
aws:PrincipalArn.arn:aws:iam::123456789012:user/user-name -
AWS STS federated user principals – The request context contains the following value for condition key
aws:PrincipalArn.arn:aws:sts::123456789012:federated-user/user-name -
AWS account root user – The request context contains the following value for condition key
aws:PrincipalArn. When you specify the root user ARN as the value for theaws:PrincipalArncondition key, it limits permissions only for the root user of the AWS account. This is different from specifying the root user ARN in the principal element of a resource-based policy, which delegates authority to the AWS account. For more information about specifying the root user ARN in the principal element of a resource-based policy, see AWS account principals.arn:aws:iam::123456789012:root
-
You can specify the root user ARN as a value for condition key
aws:PrincipalArn in AWS Organizations service control policies (SCPs). SCPs
are a type of organization policy used to manage permissions in your organization
and affect only member accounts in the organization. An SCP restricts permissions
for IAM users and roles in member accounts, including the member account's root user.
For more information about the effect of SCPs on permissions, see SCP effects on permissions in the AWS Organizations User
Guide.
aws:PrincipalAccount
Use this key to compare the account to which the requesting principal belongs with
the account identifier that you specify in the policy. For anonymous requests, the
request context returns anonymous.
-
Availability – This key is included in the request context for all requests, including anonymous requests.
-
Data type – String
-
Value type – Single-valued
In the following example, access is denied except to principals with the account
number 123456789012.
aws:PrincipalOrgPaths
Use this key to compare the AWS Organizations path for the principal who is making the request to the path in the policy. That principal can be an IAM user, IAM role, AWS STS federated user principal, or AWS account root user. In a policy, this condition key ensures that the requester is an account member within the specified organization root or organizational units (OUs) in AWS Organizations. An AWS Organizations path is a text representation of the structure of an AWS Organizations entity. For more information about using and understanding paths, see Understand the AWS Organizations entity path.
-
Availability – This key is included in the request context only if the principal is a member of an organization. Anonymous requests do not include this key.
-
Data type – String (list)
-
Value type – Multivalued
Note
Organization IDs are globally unique but OU IDs and root IDs are unique only within an organization. This means that no two organizations share the same organization ID. However, another organization might have an OU or root with the same ID as yours. We recommend that you always include the organization ID when you specify an OU or root.
For example, the following
condition returns true for principals in accounts that are
attached directly to the ou-ab12-22222222 OU, but not in its child
OUs.
"Condition" : { "ForAnyValue:StringEquals" : { "aws:PrincipalOrgPaths":["o-a1b2c3d4e5/r-ab12/ou-ab12-11111111/ou-ab12-22222222/"] }}
The following
condition
returns true for principals in an account that is attached directly to
the OU or any of its child OUs. When you include a wildcard, you must use the
StringLike condition operator.
"Condition" : { "ForAnyValue:StringLike" : { "aws:PrincipalOrgPaths":["o-a1b2c3d4e5/r-ab12/ou-ab12-11111111/ou-ab12-22222222/*"] }}
The following
condition returns true for principals in an account that is attached
directly to any of the child OUs, but not directly to the parent OU. The previous
condition is for the OU or any children. The following condition is for only the
children (and any children of those children).
"Condition" : { "ForAnyValue:StringLike" : { "aws:PrincipalOrgPaths":["o-a1b2c3d4e5/r-ab12/ou-ab12-11111111/ou-ab12-22222222/ou-*"] }}
The following condition allows access for every principal in the
o-a1b2c3d4e5 organization, regardless of their parent OU.
"Condition" : { "ForAnyValue:StringLike" : { "aws:PrincipalOrgPaths":["o-a1b2c3d4e5/*"] }}
aws:PrincipalOrgPaths is a multivalued condition key. Multivalued
keys can have multiple values in the request context. When you use multiple values
with the ForAnyValue condition operator, the principal's path must
match one of the paths listed in the policy. For more information about multivalued
condition keys, see Set operators for multivalued context keys.
"Condition": { "ForAnyValue:StringLike": { "aws:PrincipalOrgPaths": [ "o-a1b2c3d4e5/r-ab12/ou-ab12-33333333/*", "o-a1b2c3d4e5/r-ab12/ou-ab12-22222222/*" ] } }
aws:PrincipalOrgID
Use this key to compare the identifier of the organization in AWS Organizations to which the requesting principal belongs with the identifier specified in the policy.
-
Availability – This key is included in the request context only if the principal is a member of an organization. Anonymous requests do not include this key.
-
Data type – String
-
Value type – Single-valued
This global key provides an alternative to listing all the account IDs for all
AWS accounts in an organization. You can use this condition key to simplify
specifying the Principal element in a resource-based policy. You
can specify the organization
ID in the condition element. When you add and remove accounts, policies
that include the aws:PrincipalOrgID key automatically include the
correct accounts and don't require manual updating.
For example, the following Amazon S3 bucket policy allows members of any account in the
o-xxxxxxxxxxx organization to add an object into the
amzn-s3-demo-bucket bucket.
Note
This global condition also applies to the management account of an AWS organization. This policy prevents all principals outside of the specified organization from accessing the Amazon S3 bucket. This includes any AWS services that interact with your internal resources, such as AWS CloudTrail sending log data to your Amazon S3 buckets. To learn how you can safely grant access for AWS services, see aws:PrincipalIsAWSService.
For more information about AWS Organizations, see What Is AWS Organizations? in the AWS Organizations User Guide.
aws:PrincipalTag/tag-key
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. Anonymous requests do not include this key.
-
Data type – String
-
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 Tags for AWS Identity and Access Management resources. You can use aws:PrincipalTag to control access for AWS
principals.
This example shows how you might create an identity-based policy that allows users with the department=hr
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.
aws:PrincipalIsAWSService
Use this key to check whether the call to your resource is being made directly by
an AWS service principal. For example,
AWS CloudTrail uses the service principal cloudtrail.amazonaws.com to write
logs to your Amazon S3 bucket. The request context key is set to true when a service uses
a service principal to perform a direct action on your resources. The context key is
set to false if the service uses the credentials of an IAM principal to make a
request on the principal's behalf. It is also set to false if the service uses a
service
role or service-linked role to make a call on the principal's
behalf.
-
Availability – This key is present in the request context for all signed API requests that use AWS credentials. Anonymous requests do not include this key.
-
Data type – Boolean
-
Value type – Single-valued
You can use this condition key to limit access to your trusted identities and expected network locations while safely granting access to AWS services.
In the following Amazon S3 bucket policy example, access to the bucket is restricted
unless the request originates from vpc-111bbb22 or is from a service
principal, such as CloudTrail.
In the following video, learn more
about how you might use the aws:PrincipalIsAWSService condition key in
a policy.
aws:PrincipalServiceName
Use this key to compare the service
principal name in the policy with the service principal that is making
requests to your resources. You can use this key to check whether this call is made
by a specific service principal. When a service principal makes a direct request to
your resource, the aws:PrincipalServiceName key contains the name of
the service principal. For example, the AWS CloudTrail service principal name is
cloudtrail.amazonaws.com.
-
Availability – This key is present in the request when the call is made by an AWS service principal. This key is not present in any other situation, including the following:
-
If the service uses a service role or service-linked role to make a call on the principal's behalf.
-
If the service uses the credentials of an IAM principal to make a request on the principal's behalf.
-
If the call is made directly by an IAM principal.
-
If the call is made by an anonymous requester.
-
-
Data type – String
-
Value type – Single-valued
You can use this condition key to limit access to your trusted identities and expected network locations while safely granting access to an AWS service.
In the following Amazon S3 bucket policy example, access to the bucket is restricted
unless the request originates from vpc-111bbb22 or is from a service
principal, such as CloudTrail.
aws:PrincipalServiceNamesList
This key provides a list of all service
principal names that belong to the service. This is an advanced condition
key. You can use it to restrict the service from accessing your resource from a
specific Region only. Some services might create Regional service principals to
indicate a particular instance of the service within a specific Region. You can
limit access to a resource to a particular instance of the service. When a service
principal makes a direct request to your resource, the
aws:PrincipalServiceNamesList contains an unordered list of all
service principal names associated with the Regional instance of the service.
-
Availability – This key is present in the request when the call is made by an AWS service principal. This key is not present in any other situation, including the following:
-
If the service uses a service role or service-linked role to make a call on the principal's behalf.
-
If the service uses the credentials of an IAM principal to make a request on the principal's behalf.
-
If the call is made directly by an IAM principal.
-
If the call is made by an anonymous requester.
-
-
Data type – String (list)
-
Value type – Multivalued
aws:PrincipalServiceNamesList is a multivalued condition key.
Multivalued keys can have multiple values in the request context. You must use the
ForAnyValue or ForAllValues set operators with string condition operators for this key. For
more information about multivalued condition keys, see Set operators for multivalued context keys.
aws:PrincipalType
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 How to specify a principal. For
specific examples of principal key values, see Principal key values.
-
Availability – This key is included in the request context for all requests, including anonymous requests.
-
Data type – String
-
Value type – Single-valued
aws:userid
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 How to specify a principal. For specific examples of
principal key values, see Principal key values.
-
Availability – This key is included in the request context for all requests, including anonymous requests.
-
Data type – String
-
Value type – Single-valued
aws:username
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 How to specify a principal. For specific examples of
principal key values, see Principal key values.
-
Availability – This key is always included in the request context for IAM users. Anonymous requests and requests that are made using the AWS account root user or IAM roles do not include this key. Requests made using IAM Identity Center credentials do not include this key in the context.
-
Data type – String
-
Value type – Single-valued
Properties of a role session
Use the following condition keys to compare properties of the role session at the time the session was generated. These condition keys are only available when a request is made by a principal with role session or federated user principal credentials. The values for these condition keys are embedded in the role’s session token.
A role is a type of principal. You can also use the condition keys from the Properties of the principal section to evaluate the properties of a role when a role is making a request.
aws:AssumedRoot
Use this key to check whether the request was made using AssumeRoot. AssumeRoot returns short term credentials for
a privileged root user session you can use to take privileged actions on member
accounts in your organization. For more information, see Centrally manage root access for member accounts.
-
Availability – This key is included in the request context only when the principal uses credentials from AssumeRoot to make the request.
-
Data type – Boolean
-
Value type – Single-valued
In the following example, when used as a service control policy, denies the usage
of the long term credentials of a root user in an AWS Organizations member account. The
policy does not deny AssumeRoot sessions from taking the actions
allowed by an AssumeRoot session.
aws:FederatedProvider
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 assumed using the
AssumeRoleWithWebIdentity AWS STS operation. 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 in the role-session of a role that was assumed using OpenID Connect (OIDC) provider, and in the role-trust policy when an OIDC provider is used to call
AssumeRoleWithWebIdentity. -
Data type – String*
-
Value type – Single-valued
* The data type depends on your IdP:
-
If you're using a built-in AWS IdP, like Amazon Cognito, the key value will be a string. The key value might look like:
cognito-identity.amazonaws.com. -
If you're using an IdP that is not built-in to AWS, like GitHub
or Amazon EKS, the key value will be ARN. The key value might look like: arn:aws:iam::.111122223333:oidc-provider/oidc.eks.region.amazonaws.com/id/OIDC_Provider_ID
For more information on external IdPs and AssumeRoleWithWebIdentity,
see Common scenarios. For more information, see
Role session principals.
aws:TokenIssueTime
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 AWS CLI, AWS API, or AWS SDK requests that are made using access keys.
-
Data type – Date
-
Value type – Single-valued
To learn which services support using temporary credentials, see AWS services that work with IAM.
aws:SignInSessionArn
Use this key to compare your AWS Sign-In OAuth session with the session that you specify in the policy.
When you use an OAuth-based flow such as AWS CLI login (aws login) or
AWS MCP Server, AWS Sign-In includes a sign-in session ARN in the issued
credentials. AWS Sign-In propagates that ARN to subsequent requests made using
OAuth access tokens. With this key, you can correlate API activity with the
originating sign-in session and apply IAM policies to individual
sessions.
For interactive OAuth flows, the refresh token determines the sign-in session ARN lifecycle. A new access token issued during a refresh continues to carry the same sign-in session ARN.
For non-interactive OAuth flows, the access token determines the sign-in session ARN lifecycle. Each new access token contains a new sign-in session ARN.
-
Availability – This key is included in the request context when the request originates from an AWS Sign-In OAuth session. This key is not available for console sessions.
-
Data type – ARN
-
Value type – Single-valued
Use ARN operators instead of string operators when you compare ARNs.
The following policy denies all actions associated with a specific AWS Sign-In session, although requests from other active sessions continue:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "DenySpecificSignInSession", "Effect": "Deny", "Action": "*", "Resource": "*", "Condition": { "ArnEquals": { "aws:SignInSessionArn": "arn:aws:signin:us-east-1:111122223333:session/session-id" } } } ] }
aws:MultiFactorAuthAge
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 AWS Multi-factor authentication in IAM.
Important
This condition key is not present for federated identities or requests made using access keys to sign AWS CLI, AWS API, or AWS SDK requests. To learn more about adding MFA protection to API operations with temporary security credentials, see Secure API access with MFA.
To check whether MFA is used to validate IAM federated identities, you can pass the authentication method from your identity provider to AWS as a session tag. For details, see Pass session tags in AWS STS. To enforce MFA for IAM Identity Center identities, you can enable attributes for access control to pass a SAML assertion claim with the authentication method from your identity provider to IAM Identity Center.
-
Availability – This key is included in the request context only when the principal uses temporary security credentials to make the request. Policies with MFA conditions can be attached to:
-
An IAM user or group
-
A resource such as an Amazon S3 bucket, Amazon SQS queue, or Amazon SNS topic
-
The trust policy of an IAM role that can be assumed by a user
-
-
Data type – Numeric
-
Value type – Single-valued
aws:MultiFactorAuthPresent
Use this key to check whether multi-factor authentication (MFA) was used to validate the temporary security credentials that made the request.
Important
This condition key is not present for federated identities or requests made using access keys to sign AWS CLI, AWS API, or AWS SDK requests. To learn more about adding MFA protection to API operations with temporary security credentials, see Secure API access with MFA.
To check whether MFA is used to validate IAM federated identities, you can pass the authentication method from your identity provider to AWS as a session tag. For details, see Pass session tags in AWS STS. To enforce MFA for IAM Identity Center identities, you can enable attributes for access control to pass a SAML assertion claim with the authentication method from your identity provider to IAM Identity Center.
-
Availability – This key is included in the request context only when the principal uses temporary credentials to make the request. Policies with MFA conditions can be attached to:
-
An IAM user or group
-
A resource such as an Amazon S3 bucket, Amazon SQS queue, or Amazon SNS topic
-
The trust policy of an IAM role that can be assumed by a user
-
-
Data type – Boolean
-
Value type – Single-valued
Temporary credentials are used to authenticate IAM roles and IAM users with temporary tokens from AssumeRole or GetSessionToken, and users of the AWS Management Console.
IAM user access keys are long-term credentials, but in some cases, AWS 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 AWS 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 AWS 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 CloudFormation to create an Amazon EC2 instance. For the subsequent request, AWS uses temporary credentials.
To learn which services support using temporary credentials, see AWS 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 AWS CLI or
AWS 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 AWS CLI or AWS
API.
Alternative Combinations
You can also use the BoolIfExists operator to allow MFA-authenticated requests and AWS CLI or AWS 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 AWS CLI, AWS API, and AWS 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:ChatbotSourceArn
Use this key to compare the source chat configuration ARN set by the principal to the chat configuration ARN you specify in the policy of the IAM role associated with your channel configuration. You can authorize requests based on the assume role session initiated by Amazon Q Developer in chat applications.
-
Availability – This key is included in the request context by the Amazon Q Developer in chat applications service whenever a role session is assumed. The key value is the chat configuration ARN, such as when you run an AWS CLI command from a chat channel.
-
Data type – ARN
-
Value type – Single-valued
-
Example value –
arn:aws::chatbot::123456789021:chat-configuration/slack-channel/private_channel
The following policy denies Amazon S3 put requests on the specified bucket for all requests originating from a Slack channel.