This example shows how you might create an identity-based policy that allows full access to all AWS API operations in Amazon EC2. However, it explicitly denies access to StopInstances
and TerminateInstances
API operations if the user is not authenticated using multi-factor authentication (MFA). To do this programmatically, the user must include optional SerialNumber
and TokenCode
values while calling the GetSessionToken
operation. This operation returns temporary credentials that were authenticated using MFA. To learn more about GetSessionToken, see Requesting credentials for users in untrusted environments.
What does this policy do?
The AllowAllActionsForEC2
statement allows all Amazon EC2 actions.
The DenyStopAndTerminateWhenMFAIsNotPresent
statement denies the StopInstances
and TerminateInstances
actions when the MFA context is missing. This means that the actions are denied when the multi-factor authentication context is missing (meaning MFA was not used). A deny overrides the allow.
The condition check for MultiFactorAuthPresent
in the Deny
statement should not be a {"Bool":{"aws:MultiFactorAuthPresent":false}}
because that key is not present and cannot be evaluated when MFA is not used. So instead, use the BoolIfExists
check to see whether the key is present before checking the value. For more information, see ...IfExists condition operators.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowAllActionsForEC2",
"Effect": "Allow",
"Action": "ec2:*",
"Resource": "*"
},
{
"Sid": "DenyStopAndTerminateWhenMFAIsNotPresent",
"Effect": "Deny",
"Action": [
"ec2:StopInstances",
"ec2:TerminateInstances"
],
"Resource": "*",
"Condition": {
"BoolIfExists": {"aws:MultiFactorAuthPresent": false}
}
}
]
}
EC2: Start or stop an instance, modify security group (includes console)
EC2: Limit terminating instances to IP range
Did this page help you? - Yes
Thanks for letting us know we're doing a good job!
If you've got a moment, please tell us what we did right so we can do more of it.
Did this page help you? - No
Thanks for letting us know this page needs work. We're sorry we let you down.
If you've got a moment, please tell us how we can make the documentation better.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4