해당 포스팅은 IAM: What happens when you assume a role?를 정리한 글입니다.
위의 사진은 AWS CLI명령어로 Assume Role을 수행한 결과입니다.
Assume Role을 이해하기 위해 필요한 개념을 정리하고 Assume Role에 대해서 이해하는 내용으로 포스팅을 하겠습니다.
1. Identity vs Principals 개념
용어 | 설명 | 예시 |
IAM Identities | IAM resource objects used for identification and grouping. | Users, Groups, Roles |
IAM Entities | IAM resource objects used by AWS for authentication. | IAM Users, IAM Roles |
Principals | A person or application that uses the AWS account root user, an IAM user, or an IAM role to sign in and make requests to AWS. | Root User, IAM Users, IAM Roles, Federated Users, Assumed Roles |
2. Principal이 API 호출시
단계 | 세부 단계 |
1. 인증(Authentication) | - Principal는 자신의 신원을 확인(증명)합니다. |
- Principal는 AWS 계정 루트 사용자, IAM 사용자 또는 IAM 역할로 AWS에 로그인하여 권한을 얻습니다. | |
- Principal는 자신이 누구인지를 입증해야 합니다. | |
2. 권한 부여(Authorization) | - 인증이 성공하면 권한 부여가 이루어집니다. |
- 권한 부여는 IAM의 Policy(정책)을 통해 이루어집니다. | |
- Policy(정책)은 Principal이 특정 Resource(리소스)에서 수행할 수 있는 Action(행동)을 Allow(허용)하거나 Deny(거부)합니다. |
|
- Policy(정책)은 주로 식별 기반 정책(Identity-based policies)과 리소스 기반 정책(Resource-based policies)로 구분됩니다. |
3. Identity-based Policy vs Resource-based Policy
특징 | 식별 기반 정책 | 리소스 기반 정책 |
핵심 | Which API calls(Action) can this identity perform (Effect) on which resources(Resource)? |
Which identities(Principal) can perform(Effect) which actions(Action) on me(Resource)? |
적용대상 | 주로 IAM 사용자, 그룹, 역할 | 주로 리소스(예: S3 버킷, Lambda 함수 등) |
규칙 정의 | Action, Resource, Effect | Action, Principal, Resource, Effect |
4. Role - Permission, Trust Relationship
권한 (Permissions) | Trust Relationship(신뢰 관계) |
- 역할의 권한은 역할이 가지는 권한과 허용되는 작업을 정의합니다. | - Trust Relationship은 Role을 어떤 principal(주체)가 Assume(가정)할 수 있는지를 정의합니다. |
- 이 권한은 역할이 가지고 있는 정책(Policies)을 통해 설정됩니다. | - 주로 다른 AWS 계정 내의 사용자, 서비스, 또는 역할과의 Trust Relationship(신뢰 관계)를 설정합니다. |
- 역할을 가정한 주체는 이러한 권한을 사용하여 AWS 리소스에 액세스하고 작업을 수행합니다. | - Trust Relationship은 JSON 형식의 문서로 구성되며, Role 정의에 포함됩니다. |
- Role을 Assume(가정)할 수 있는 Principal(주체)는 해당 Role(역할)의 Trust Relationship(신뢰 관계)에 명시된 조건을 충족해야 합니다. |
# Trust Relationship
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
# Permission Policy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ssm:DescribeAssociation",
"ssm:GetDeployablePatchSnapshotForInstance",
"ssm:GetDocument",
"ssm:DescribeDocument",
"ssm:GetManifest",
"ssm:GetParameters",
"ssm:ListAssociations",
"ssm:ListInstanceAssociations",
"ssm:PutInventory",
"ssm:PutComplianceItems",
"ssm:PutConfigurePackageResult",
"ssm:UpdateAssociationStatus",
"ssm:UpdateInstanceAssociationStatus",
"ssm:UpdateInstanceInformation"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ssmmessages:CreateControlChannel",
"ssmmessages:CreateDataChannel",
"ssmmessages:OpenControlChannel",
"ssmmessages:OpenDataChannel"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ec2messages:AcknowledgeMessage",
"ec2messages:DeleteMessage",
"ec2messages:FailMessage",
"ec2messages:GetEndpoint",
"ec2messages:GetMessages",
"ec2messages:SendReply"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"cloudwatch:PutMetricData"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ec2:DescribeInstanceStatus"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ds:CreateComputer",
"ds:DescribeDirectories"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams",
"logs:PutLogEvents"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:PutObject",
"s3:GetObject",
"s3:GetEncryptionConfiguration",
"s3:AbortMultipartUpload",
"s3:ListMultipartUploadParts",
"s3:ListBucket",
"s3:ListBucketMultipartUploads"
],
"Resource": "*"
}
]
}
5. Role - Maximue session duration
- Security Token Service (STS) enables you to request temporary, limited-privilege credentials for users.
- Assume Role은 Role(Trust Relationship)에 정의된 Principal에게 limited credentials을 발급해주는 것이다.