AWS Policy to Terminate Instances Based on Profile by@0x0ece
1,899 reads

AWS Policy to Terminate Instances Based on Profile

Read on Terminal Reader

Too Long; Didn't Read


Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - AWS Policy to Terminate Instances Based on Profile
Emanuele Cesena HackerNoon profile picture

@0x0ece

Emanuele Cesena

Co-founder at Everdragons2, SoloKeys. Former security at Pinterest.

About @0x0ece
LEARN MORE ABOUT @0X0ECE'S EXPERTISE AND PLACE ON THE INTERNET.
react to story with heart

Terminating EC2 instances is a critical action that should be denied by default, and only explicitly allowed for specific roles.

There are situations where we want an instance to be able to terminate other instances, for example a Worker role to be able to check the health status of the Web instances and terminate the bad ones.

Most of the examples I've found on allowing ec2:TerminateInstances through a IAM policy specify conditions based on source ip, user authentication methods, or target instance tags.

The following snippet shows how to allow ec2:TerminateInstances based on the target instance profile:

{"Sid": "TerminateWebInstances","Action": ["ec2:TerminateInstances"],"Condition": {"StringEquals":{ "ec2:InstanceProfile":"arn:aws:iam::<accountId>:instance-profile/<Web>" } },"Resource": ["arn:aws:ec2:us-west-1:<accountId>:instance/*"],"Effect": "Allow"}

In the example above, this snippet would be added to the policy of the role Worker, and will allow Worker to terminate any target with instance profile Web.

Make sure to change your account region, account id, and <Web> with the target instance profile you'd like to terminate.

Do you let instances terminate other instances, and if so, how? I'd be interested to know. Please comment below or find me on Twitter.

Hacker Noon is how hackers start their afternoons. We’re a part of the @AMIfamily. We are now accepting submissions and happy to discuss advertising & sponsorship opportunities.

To learn more, read our about page, like/message us on Facebook, or simply, tweet/DM @HackerNoon.

If you enjoyed this story, we recommend reading our latest tech stories and trending tech stories. Until next time, don’t take the realities of the world for granted!

RELATED STORIES

L O A D I N G
. . . comments & more!
Hackernoon hq - po box 2206, edwards, colorado 81632, usa