S3 Cross Account Access는 여러 AWS 계정을 사용하는 환경에서, 특정 계정이 소유한 S3 버킷에 다른 계정에서 접근해야 할 때 자주 사용됩니다. 이를 통해 각 계정 간 데이터 공유나 협업을 쉽게 할 수 있습니다.
기업에서 보안 및 비용 관리를 위해 여러 AWS 계정을 운영하는 경우, 중앙 계정에서 S3 버킷을 생성하고 다른 계정이 해당 버킷에 접근해야 할 때 Cross Account Access를 설정합니다.
예시: 개발 계정과 운영 계정 간 데이터 공유
다른 AWS 계정에 데이터를 공유해야 할 때, S3 Cross Account Access를 설정해 특정 버킷에 접근할 수 있도록 권한을 부여할 수 있습니다.
여러 계정에 걸쳐 데이터를 백업하거나 복제할 때, S3 Cross Account Access를 사용해 한 계정의 S3 버킷에서 다른 계정의 버킷으로 데이터를 전송하거나 동기화할 수 있습니다.
보안 및 권한 분리를 위해 각 계정마다 역할을 분리하고, 필요할 때만 S3 리소스에 접근 권한을 부여하여 보안을 강화할 수 있습니다.
각기 다른 팀이나 프로젝트가 개별 계정을 사용하는 마이크로서비스 아키텍처에서, 공통 데이터를 저장하는 S3 버킷을 하나의 계정에서 운영하고 각 계정이 접근하도록 설정할 수 있습니다.
실습을 진행하기 전에 다음 사항들을 준비해주세요:
graph TB
A[Account A<br/>Source Bucket] --> |Cross Account Access| B[Account B<br/>Destination Bucket]
A --> |IAM Role| C[yeom-accountA-s3]
B --> |IAM Role| D[yeom-accountB-s3]
C --> |AssumeRole| D
실습 구성:
# S3 버킷 생성
aws s3api create-bucket \
--bucket yeom-a-s3 \
--region ap-northeast-2 \
--create-bucket-configuration LocationConstraint=ap-northeast-2 \
--profile yeom-a
정책 파일 생성:
# yeom-a-s3-access-b-s3.json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "S3Access",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::AccountB:role/yeom-accountB-s3"
},
"Action": [
"s3:ListBucket",
"s3:GetObject",
"s3:GetObjectTagging",
"s3:GetObjectVersion",
"s3:GetObjectVersionTagging"
],
"Resource": [
"arn:aws:s3:::yeom-a-s3",
"arn:aws:s3:::yeom-a-s3/*"
]
}
]
}
신뢰 관계 정책:
# yeom-a-role-access-b.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::AccountB:user/yeom"
},
"Action": "sts:AssumeRole"
}
]
}
역할 생성:
aws iam create-role \
--role-name yeom-accountA-s3 \
--assume-role-policy-document file://yeom-a-role-access-b.json \
--profile yeom-a
응답 예시:
{
"Role": {
"Path": "/",
"RoleName": "yeom-accountA-s3",
"RoleId": "AROA3BSYMHURZ74RTAQ7X",
"Arn": "arn:aws:iam::AccountA:role/yeom-accountA-s3",
"CreateDate": "2024-09-21T10:22:06+00:00",
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::AccountB:user/yeom"
},
"Action": "sts:AssumeRole"
}
]
}
}
}
신뢰 관계 정책:
# yeom-b-role-access-a.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::AccountB:user/yeom-a"
},
"Action": "sts:AssumeRole"
}
]
}
역할 생성:
aws iam create-role \
--role-name yeom-accountB-s3 \
--assume-role-policy-document file://yeom-b-role-access-a.json \
--profile yeom-b
aws s3api create-bucket \
--bucket yeom-b-s3 \
--region ap-northeast-2 \
--create-bucket-configuration LocationConstraint=ap-northeast-2 \
--profile yeom-b
버킷 정책:
# yeom-b-s3-access-a-s3.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::AccountA:root"
},
"Action": [
"s3:ListBucket",
"s3:PutObject",
"s3:PutObjectAcl",
"s3:PutObjectTagging",
"s3:GetObjectTagging",
"s3:GetObjectVersion",
"s3:GetObjectVersionTagging"
],
"Resource": [
"arn:aws:s3:::yeom-b-s3",
"arn:aws:s3:::yeom-b-s3/*"
]
}
]
}
정책 적용:
# 버킷 정책 적용
aws s3api put-bucket-policy \
--bucket yeom-b-s3 \
--policy file://yeom-b-s3-access-a-s3.json \
--profile yeom-b
# 정책 확인
aws s3api get-bucket-policy \
--bucket yeom-b-s3 \
--profile yeom-b
# A 계정 S3에 테스트 파일 업로드
aws s3 cp ~/Desktop/1.jpg s3://yeom-a-s3 --profile yeom-a
# 파일 확인
aws s3 ls s3://yeom-a-s3 --profile yeom-a
# 출력: 2024-09-21 19:50:01 13788 1.jpg
aws sts assume-role \
--role-arn "arn:aws:iam::AccountB:role/yeom-accountB-s3" \
--role-session-name AWSCLI-session \
--profile yeom-a
export AWS_ACCESS_KEY_ID=ASIA4RSDH4TSVI6UV35S
export AWS_SECRET_ACCESS_KEY=4pq3FaJURJoUBtEFBHhA8fC+kBVnVd/jYViy1ccn
export AWS_SESSION_TOKEN=IQoJb3JpZ2luX2VjEFMaDmFwLW5vcnRoZWFzdC0yIkYw~
aws sts get-caller-identity
응답:
{
"UserId": "AROA4RSDH4TS3O7DQPAHA:AWSCLI-session",
"Account": "862355711205",
"Arn": "arn:aws:sts::AccountB:assumed-role/yeom-accountB-s3/AWSCLI-session"
}
aws s3 sync s3://yeom-a-s3/ s3://yeom-b-s3/ \
--source-region ap-northeast-2 \
--region us-east-2 \
--profile yeom-a
출력:
copy: s3://yeom-a-s3/1.jpg to s3://yeom-b-s3/1.jpg
# A 계정 프로파일로 B 계정 버킷 확인 (임시 권한 사용)
aws s3 ls s3://yeom-b-s3 --profile yeom-a
# 출력: 2024-09-21 20:12:48 13788 1.jpg
# B 계정 프로파일로 확인
aws s3 ls s3://yeom-b-s3 --profile yeom-b
# 출력: 2024-09-21 20:12:48 13788 1.jpg
{
"Condition": {
"DateLessThan": {
"aws:CurrentTime": "2024-12-31T23:59:59Z"
}
}
}
{
"Condition": {
"IpAddress": {
"aws:SourceIp": "203.0.113.0/24"
}
}
}
{
"Condition": {
"Bool": {
"aws:MultiFactorAuthPresent": "true"
}
}
}
#!/bin/bash
# 매일 자정에 실행되는 크론잡
0 0 * * * /usr/local/bin/backup-cross-account.sh
# GitHub Actions 예시
- name: Deploy to Production S3
run: |
aws sts assume-role --role-arn $PROD_ROLE_ARN --role-session-name github-actions
aws s3 sync ./dist/ s3://prod-bucket/
여러 부서의 데이터를 중앙 집중화된 데이터 레이크로 수집
S3 Cross Account Access는 엔터프라이즈 환경에서 필수적인 기능입니다. 올바른 권한 설정과 보안 모범 사례를 따라 안전하고 효율적인 다중 계정 아키텍처를 구축할 수 있습니다.
이 가이드를 통해 AWS 다중 계정 환경에서의 S3 데이터 공유 방법을 마스터하시길 바랍니다!