简体   繁体   中英

AWS Security Group and IAM Role

To connect my ec2-instance to S3 or RDS, I usually need to give ec2 instance a role with appropriate permissions, correct?

If I have my ec2-instance in one SecurityGroup and s3/RD3 in another security group, won't just giving a S3/RDS role and permission to ec2 suffice?

Trying to understand when should I use role vs security groups to allow various AWS resources to talk to each other.

  • IAM roles are for restricting AWS user/account/role access to the AWS API.
  • Security groups are for restricting network access to resources that exist inside your VPC.

Note how EC2 and RDS (and Redshift and Elasticache...) are servers that exist in your VPC, and you interact with those resources by making direct network connections to those servers. So you secure network access to these with Security Groups.

Note how you have no visibility into the what servers your S3 (or DynamoDB or SQS or SNS...) resources are on, those resources are not running inside your VPC, and you interact with those resources exclusively via the AWS API. So you secure AWS API access to these via AWS Identity and Access Management (IAM).

Roles and Security Groups serve two different purposes.

Roles

Roles are used to give permissions to an EC2 instance to execute certain AWS API calls.

It does not play a part in network security.

Security Groups

Security groups DO play a part in network security, and they do not play a part in EC2 permissions to access the API.

Conclusion

Use EC2 Roles when you need to give an instance permissions to execute API functions, such as accessing S3, or controlling an RDS instance (not querying data).

Use Security Groups when you need to give an instance permissions to access a network resource, such as when querying data in an RDS instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM