ArnNotEqualsIfExists

Warning:

In spite of the name difference ArnNotEqualsIfExists behaves exactly the same as ArnNotLikeIfExists. Switch to ArnNotLikeIfExists so people don't ask later what in the world you were thinking.

ArnNotEqualsIfExists

ArnNotEqualsIfExists compares an ARN in a request to a list of ARN patterns in your policy. The policy values can include asterisks (*) to match multiple characters and question marks (?) to match a single character within an ARN segement. Wildcards cannot be used to span ARN segment, so the partition, service, region, account, and resource must all be present in your policy value, even if they are all wildcards. The comparision is case sensitive.

To match a request, the context key can be absent, but if present it must NOT match any of the ARN patterns in your policy.

You can use policy variables in the value of this operator.

So you know:

ArnNotEqualsIfExists behaves exactly the same as ArnNotEquals. "Negative" operators such as ArnNotEquals already match requests if the key is not present so the IfExists suffix has no effect.

There is no harm in adding IfExists to ArnNotEquals; it probably makes the intent more clear. We know you already knew this, but put this message in for everyone else. 😉

ArnNotEqualsIfExists in an Allow Statement

Given the Policy Condition:
"ArnNotEqualsIfExists": {
  "aws:PrincipalArn": [
    "arn:aws:iam::*:role/*",
    "arn:aws:ec2:*:*:instance/i-?????"
  ]
}
When the Request Context has:
aws:PrincipalArn: null
Then the result is:
Allowed Allowed Assuming no explicit Deny elsewhere
Given the Policy Condition:
"ArnNotEqualsIfExists": {
  "aws:PrincipalArn": [
    "arn:aws:iam::*:role/*",
    "arn:aws:ec2:*:*:instance/i-?????"
  ]
}
When the Request Context has:
aws:PrincipalArn:
   arn:aws:iam::*:user/User
Then the result is:
Allowed Allowed Assuming no explicit Deny elsewhere
Given the Policy Condition:
"ArnNotEqualsIfExists": {
  "aws:PrincipalArn": [
    "arn:aws:iam::*:role/*",
    "arn:aws:ec2:*:*:instance/i-?????"
  ]
}
When the Request Context has:
aws:PrincipalArn:
   arn:aws:iam::123456789012:role/AdminRole
Then the result is:
Not Allowed Not Allowed Statement does not apply

ArnNotEqualsIfExists in a Deny Statement

Given the Policy Condition:
"ArnNotEqualsIfExists": {
  "aws:PrincipalArn": [
    "arn:aws:iam::*:role/*",
    "arn:aws:ec2:*:*:instance/i-?????"
  ]
}
When the Request Context has:
aws:PrincipalArn: null
Then the result is:
Denied Denied
Given the Policy Condition:
"ArnNotEqualsIfExists": {
  "aws:PrincipalArn": [
    "arn:aws:iam::*:role/*",
    "arn:aws:ec2:*:*:instance/i-?????"
  ]
}
When the Request Context has:
aws:PrincipalArn:
   arn:aws:iam::*:user/User
Then the result is:
Denied Denied
Given the Policy Condition:
"ArnNotEqualsIfExists": {
  "aws:PrincipalArn": [
    "arn:aws:iam::*:role/*",
    "arn:aws:ec2:*:*:instance/i-?????"
  ]
}
When the Request Context has:
aws:PrincipalArn:
   arn:aws:iam::123456789012:role/AdminRole
Then the result is:
Not Denied Not Denied May be allowed by another statement