AWS 접근제어#3 IAM Policy

AWS IAM policy의 JSON 구조

{
    "version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow(허용) 또는 Deny(차단)",
            "Action": [
                ... 어떤 행위를?
            ],
            "Resource": [
                ... 어떤 객체(리소스)들에 대해?
            ],
            "Condtion": {
                ... 어떤 조건에서?(optional)
            }
        }
    ]
}

예제: DynamoDB로 부터 데이터 읽기

{
    "version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow(허용) 또는 Deny(차단)",
            "Action": [
                ... 어떤 행위를? "dynamodb:*"
            ],
            "Resource": [
                ... 어떤 객체(리소스)들에 대해? "*"
            ],
            "Condtion": {
                ... 어떤 조건에서?(optional)
            }
        }
    ]
}
{
    "version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow(허용) 또는 Deny(차단)",
            "Action": [
                "dynamodb:GetItem",
                "dynamodb:PutItem"
            ],
            "Resource": [
                "*"
            ],
            "Condtion": {
                ... 어떤 조건에서?(optional)
            }
        }
    ]
}
{
    "version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "dynamodb:GetItem",
                "dynamodb:PutItem"
            ],
            "Resource": [
                "arn:aws:dynamodb:ap-northeast-2:<accountidd>:table/example"
            ],
        }
    ]
}

리소스와 ARN(Amazon Resuouce Name) 리소스: aws 상의 관리 대상 자원들 예들 들어 s3버킷, dynamoDB테이블,EC2인스턴스, VPC등 IAM 보안주체들도 ARN이 부여된 ARN: a fully-qualified name for that resource, used throughout AWS

 "arn:aws:dynamodb:ap-northeast-2:<accountid>:table/example"

    service         region         accountid   service-specific name

리소스와 Amazon Resource Name Resource 또는 NotResource(여집합, 규정된 것 제외하고 나머지)를 지원

“Resouce”: “arn:aws:s3:::mybucket/” “NotResource”: “arn:aws:s3:::mybucket/” “Resouce”: [“arn:aws:s3:::my_bucket/*”, “arn:aws:dynamodb:ap-northeast-2::table/test"] 특정리전에 있는 전체 인스턴스 "Resouce":"arn:aws:ec2:ap-northeast-2::instace/\*",

아이피조건걸기

{
    "version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow(허용) 또는 Deny(차단)",
            "Action": [
                "dynamodb:GetItem",
                "dynamodb:PutItem"
            ],
            "Resource": [
                "*"
            ],
            "Condtion": {
                "IpAddress": {
                    "aws:SourceIp": "1.1.1.1"
                },
            }
        }
    ]
}

정책 condition 특정 시간때에 특정 IP 주소의 요청만 허용하거나 거부하고자 싶은면? “Condition”: { “DateGreaterThan”: {“aws:CurrentTime”: “2023-12-23T11:00:00Z”}, “DateLessThan”: {“aws:CurrentTime”: “2023-12-23T15:00:00Z”}, “IpAddress”: {“aws:SourceIp”: [“192.0.2.0/24”, “203.0.113.0/24”]} } 다음조건을 만족할 경우, 사용자가 자원에 접근하는 것을 허용, {“12/23/2023오전 11시 이후”, AND “12/23/23023 오후 3시까지”, IP주소 192.0.2.0/24 OR 203.0.113.0/24 대역} 에서

정책변수

{
    "version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": ["s3:ListBuckete"],
            "Resource": ["arn:aws:s3:::mybucket"],
            "Condtion": {"String": {"s3:prefix": ["sanghoon/*"]}}
        },
        {
            "Action": [
                "s3:GetObject",
                "s3:PutObject"
            ],
            "Effect": "Allow",
            "Resource": ["arn:aws:s3:::mybucket/sanghoon/*"]
        }
    ]
}

정책변수

$(Condition Key)형식으로 변수화 사용자마다 고유한 정책 사본을 만들 필요 없이 여러 사용자에게 작용하도록 정책을 일반화 정책 변수는 Resource 요소 / Conditon 요소의 문자열 비교에 사용 가능 이 정책을 평가할 때는 IAM이 정책 변수를 실제 요청의 string으로 대체

{
    "version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": ["s3:ListBuckete"],
            "Resource": ["arn:aws:s3:::mybucket"],
            "Condtion": {"String": {"s3:prefix": ["${aws:username}/*"]}}
        },
        {
            "Action": [
                "s3:GetObject",
                "s3:PutObject"
            ],
            "Effect": "Allow",
            "Resource": ["arn:aws:s3:::mybucket/${aws:username}/*"]
        },
    ]
}

iam policy 정책종류

정책 설명 포맷 정의 및 관리
Identitiy-based 정책 IAM 보안 주체(iam사용자,iam 그룹의 사용자집합,iam 역할)에 할당되어 해당 주체의 권한을 규정 JSON IAM
Resource-based 정책 정책이 할당될 리소스를 기준으로 어떤 보안 주체가 할 수 있(없)는 작업을 규정. JSON 개별서비스들
IAM Permisiion Boundary 정책 IAM 보안 주체 별로 획득할 수 있는 권한의 최대치를 규정 JSON IAM
Organization SCP Oragnization의 OU 또는 개별 어카운트 별로 권한의 최대치를 규정 주로 Root 어카운트의 권한을 제한 시킬 때 사용. JSON Organization
Session 정책 임시 자격증명의 기존 퍼미션을 해당 세션에 대해서만 제한할 때 사용 AssumeRole*,GetFederationToken API의 파라미터로 전달됨 JSON STS
ACL 정책 리소스 기주능로 정의하며, 주로 Cross-Account 간의 리소스 고유시, 보안주체에 대한 접근을 규정 XML 개별서비스들
Endpoint 정책 VPC G/W Endpoint에 적용되는 접근제어 정책.일종의 Reesource-based 정책 JSON VPC

Identity based 와 resource based policy