Intro.
s3에 있는 파일을 eb instance에 넣고 싶을 때 설정하는 방법이다.
AWS 보안의 핵심은 IAM user에 있다. IAM으로 접근 권한을 설정해서 특정 서비스만 접근하도록 설정할 수가 있다.
여기에서 사용할 내용은 s3, .ebextensions, iam user이다.
1. .ebextensions
Resources:
  AWSEBAutoScalingGroup:
    Metadata:
      AWS::CloudFormation::Authentication:
        S3Auth:
          type: "s3"
          buckets: ["example"]
          roleName:
            "Fn::GetOptionSetting":
              Namespace: "aws:autoscaling:launchconfiguration"
              OptionName: "IamInstanceProfile"
              DefaultValue: "aws-elasticbeanstalk-ec2-role"
files:
  "/home/ec2-user/.ssh/example.pem":
    mode: "000400"
    owner: root
    group: root
    authentication: "S3Auth"
    source: https://example.s3.ap-northeast-2.amazonaws.com/example.pem
  "/home/ec2-user/.ssh/config":
    mode: "000400"
    owner: root
    group: root
    authentication: "S3Auth"
    source: https://example.s3.ap-northeast-2.amazonaws.com/config- roleName: Defaultvalue: aws EB IAM instance profile을 적어준다.
이렇게 정의해 놓으면 files에서 해당하는 경로에 s3에 있는 파일을 업로드한다.
- mode는 권한 설정인데, 읽기 전용 파일이라면 읽기 전용으로 설정해줘야한다.
- source는 버킷 파일 접근 경로이다.
2. iam user 설정
- AWS EB가 연결 된 IAM instance profile인 aws-elasticbeanstalk-ec2-role 에 접근해 s3 접근 권한을 주어야 한다.

IAM > 역할 > aws-elasticbeanstalk-ec2-role > 권한 추가 > 정책 연결 클릭

s3 검색 > AmazonS3ReadOnlyAccess 선택 > 정책 연결 클릭
3. s3
- 버킷을 생성한다. 퍼블릭 액세스는 차단한 상태로 생성해야 한다.

버킷 > 권한 클릭

버킷 정책에 EB IAM instance profile arn 값 추가.
{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Sid": "getObject",
			"Effect": "Allow",
			"Principal": {
				"AWS": "arn aws-elasticbeanstalk-ec2-role 값"
			},
			"Action": "s3:GetObject",
			"Resource": "파일 접근할 버킷의 이름/*"
		}
	]
}- 버전은 해당 설정이 적용할 수 있는 범위의 시작
- sid는 해당 statement의 이름이다.
- effect는 allow or denied가 있다.
- principal은 접근을 허용하고 싶은 유저를 등록한다.
- action은 무슨 행동을 하고 싶은지 지정한다.
- resource는 어디 버컷에서 가져올지를 설정한다. 버킷 이름 + '/*'
references
1. ebextensions config
https://docs.aws.amazon.com/ko_kr/elasticbeanstalk/latest/dg/awseb-dg.pdf#ebextensions
2. s3 policy
https://docs.aws.amazon.com/ko_kr/AmazonS3/latest/userguide/example-bucket-policies.html
3. eb instance ssh 접근
https://docs.aws.amazon.com/ko_kr/elasticbeanstalk/latest/dg/eb3-ssh.html
4. s3 butcket access config
https://docs.aws.amazon.com/ko_kr/AmazonS3/latest/userguide/s3-userguide.pdf#s3-access-control
https://docs.aws.amazon.com/ko_kr/AmazonS3/latest/userguide/UsingBucket.html
5. EB에서 s3 접근 방법
https://aws.amazon.com/ko/premiumsupport/knowledge-center/elastic-beanstalk-s3-bucket-instance/
'AWS' 카테고리의 다른 글
| IAM 계정 설정 (0) | 2022.07.25 | 
|---|---|
| [Github Action] Application Load Balancer 상태 확인이 실패하는 문제를 수정 및 해결 방법(추가 배치를 사용한 롤링) (0) | 2022.07.18 | 
| [CI/CD] Github Action for a test (0) | 2022.07.13 | 
| [CI/CD] Github Prod Repo + Github Action + ECR tag + Dockerrun.aws.json 설정 (0) | 2022.07.12 | 
| [CI/CD] Github Dev Repo + Github Action + ECR tag + Dockerrun.aws.json 자동 할당 설정 (0) | 2022.07.11 | 
 
									
								 
									
								