[์ผ] S3์ ์ ๋ก๋ํ ์ฌ์ง : S3 ํผ๋ธ๋ฆญ ์์ธ์ค ์ฐจ๋จ ํ์ฑํ(1)

1. IAM ์ฌ์ฉ์์๊ฒ S3FullAccess ๊ถํ์ ์ฃผ์๋ค
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:*",
"s3-object-lambda:*"
],
"Resource": "*"
}
]
}
2. ํผ๋ธ๋ฆญ ์ก์ธ์ค ์ฐจ๋จ์ ํผ ์ฑ S3 ๋ฒํท์ ์์ฑํ๋ค

3. ์คํ๋ง ๋ถํธ ์ ํ๋ฆฌ์ผ์ด์ ์ ์๋์ ๊ฐ์ ์์กด์ฑ์ ์ถ๊ฐํ๊ณ ์ค์ ์ ํ์๋ค
implementation group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.12.518'
@Configuration
public class AmazonS3Config {
@Value("${cloud.aws.credentials.accessKey}")
private String accessKey;
@Value("${cloud.aws.credentials.secretKey}")
private String secretKey;
@Value("${cloud.aws.region.static}")
private String region;
@Bean
public AmazonS3Client amazonS3Client() {
AWSCredentials basicAWSCredentials = new BasicAWSCredentials(accessKey, secretKey);
return (AmazonS3Client)AmazonS3ClientBuilder
.standard()
.withCredentials(new AWSStaticCredentialsProvider(basicAWSCredentials))
.withRegion(region)
.build();
}
}
4. IAM ์ฌ์ฉ์์ ๊ถํ์ S3์ ์ฐ๊ธฐ ๊ถํ์ด ์์ผ๋ฏ๋ก ์ฌ์ฉ์๊ฐ ์ฌ์ง ๋ฑ๋ก์ ์์ฒญํ๋ฉด,
์ผ ๋ฐฑ์๋ ํ๋ก๊ทธ๋จ์์ ์
๋ก๋ ํ ์ ์๋ค.
5. ํด๋ผ์ด์ธํธ์๊ฒ ๊ฐ์ฒด URL์ ์ ๋ฌํ๊ณ ํด๋ผ์ด์ธํธ๋ ์ด๋ฅผ ํ๋ฉด์ ๋ณด์ฌ์คฌ๋ค
1. IAM ์ฌ์ฉ์๊ฐ ๋ชจ๋ S3๊ฐ์ฒด์ ์ ๊ทผ์ด ๊ฐ๋ฅํ๋ค.
์ง๊ธ ๋ฒํท์ด ํ๋๋ฐ์ ์๊ธด ํ์ง๋ง ๋ค๋ฅธ ์๋น์ค ๋ฒํท์ด ์๋ ๊ฒฝ์ฐ ๋ค ์ ๊ทผ์ด ๊ฐ๋ฅํ ์ํ์ด๋ค.
2. S3์ ์๋ง์ Get์์ฒญ์ด ๋ค์ด์ค๋ฉฐ ๋๋ฆฌ๋ค
3. ํด๋น ๊ฐ์ฒด๋ ์ธํฐ๋ท ๋ชจ๋ ์ฌ์ฉ์๊ฐ ๊ฐ์ฒด URL ๋ง ์๊ณ ์๋ค๋ฉด ์ ๊ทผ์ด ๊ฐ๋ฅํ ์ํ์ด๋ค.
์ผ ์ฌ์ฉ์๋ค๋ง ์ ๊ทผ์ด ๊ฐ๋ฅํด์ผ ํ๋ค. (์ด๊ฑฐ๋ฅผ ํซ๋งํฌ ๋ฌธ์ ๋ผ๊ณ ํ๋ค๋ ๊ฑธ ๋ฐฐ์ ๋ค)
1. IAM ์ฌ์ฉ์์ ๊ถํ(Resource)์ ์ถ์ํ์๋ค
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:*",
"s3-object-lambda:*"
],
"Resource": [
"arn:aws:s3:::vvue-s3",
"arn:aws:s3:::vvue-s3/*"
]
}
]
}
2. CloudFront ๋์
- S3 ๋ฒํท ์์ CloudFront ๋์
CloudFront๋ ์ ์ , ๋์ ์ปจํ
์ธ ๋ฅผ ๋น ๋ฅด๊ฒ ์๋ตํ๊ธฐ ์ํ ์บ์ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ CDN์๋น์ค์ด๋ค.
์์ธํ ๋ด์ฉ์ ๊ณต์๋ฌธ์๋ฅผ ์ฐพ์๋ณด์
https://docs.aws.amazon.com/ko_kr/AmazonCloudFront/latest/DeveloperGuide/Introduction.html
Amazon CloudFront๋ ๋ฌด์์ ๋๊น? - Amazon CloudFront
Amazon CloudFront๋ ๋ฌด์์ ๋๊น? Amazon CloudFront๋ .html, .css, .js ๋ฐ ์ด๋ฏธ์ง ํ์ผ๊ณผ ๊ฐ์ ์ ์ ๋ฐ ๋์ ์น ์ฝํ ์ธ ๋ฅผ ์ฌ์ฉ์์๊ฒ ๋ ๋นจ๋ฆฌ ๋ฐฐํฌํ๋๋ก ์ง์ํ๋ ์น ์๋น์ค์ ๋๋ค. CloudFront๋ ์ฃ์ง ๋ก์ผ์ด์
docs.aws.amazon.com
CloudFront์ S3๋ฅผ ์ฐ๋ํด๋ณด์
1. CloudFront์์ ๋ฒํท์ ๋ํ ๋ฐฐํฌ๋ฅผ ์์ฑํ๋ค.


2. S3 ๋ฒํท ์ ์ฑ ์ ๋ณต์ฌํด์ ๋ณ๊ฒฝํ๊ณ ํผ๋ธ๋ฆญ์์ธ์ค ์ฐจ๋จ์ ํ์ฑํํ๋ค

{
"Version": "2008-10-17",
"Id": "PolicyForCloudFrontPrivateContent",
"Statement": [
{
"Sid": "AllowCloudFrontServicePrincipal",
"Effect": "Allow",
"Principal": {
"Service": "cloudfront.amazonaws.com"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::๋ฒํท๋ช
/*",
"Condition": {
"StringEquals": {
"AWS:SourceArn": "arn:aws:cloudfront::์ซ์:distribution/๋ฌธ์"
}
}
}
]
}


3. (์ ํ์ฌํญ) CloudFront์ ๋ฐฐํฌ > ์ค์ ์ผ๋ก ์ด๋ํ์ฌ ๋์ฒด ๋๋ฉ์ธ์ ๋ฑ๋กํ๋ค
1) Request certificate๋ฅผ ๋๋ฌ ๋๋ฉ์ธ ์ด๋ฆ์ ์
๋ ฅํ๋ค

๊ทธ๋ฌ๋ฉด ๋๋ฉ์ธ ์์ญ์ ๊ฒ์ฆ๋๊ธฐ์ค์ด๋ผ๊ณ ๋จ๋ฉฐ
์ ํ, CNAME์ด๋ฆ, CNAME๊ฐ์ด ๋์ค๋๋ฐ
์ด ๊ฐ์ ์
๋ ฅํด์ ๊ฒ์ฆ์ ์งํํ๋ฉด ๋๋ค
2) ๊ฐ๋น์์์ ๋๋ฉ์ธ์ ๊ตฌ์
ํ์ผ๋ฏ๋ก ๊ฐ๋น์์ ๊ฐ์
์์ ๊ฒ์ฆ๊ฐ๊ณผ ํจ๊ป CNAME ๋๋ฉ์ธ์ด๋ฆ ํด๋ผ์ฐ๋ํ๋ก ํธ๋๋ฉ์ธ ์ ์
๋ ฅํ๋ค
30์ด๋ ์๋์ด์ ๋ฐ๊ธ๋์๋ค๊ณ ๋จ๊ฒ ๋๋ค
์ ์ฅ ๋ฒํผ์ ๋๋ฅด๋ฉด ๋๋ฉ์ธ ๋ฑ๋ก์ด ์๋ฃ๋์์ผ๋ฉฐ ๋์ฒด ๋๋ฉ์ธ ์ด๋ฆ์ผ๋ก๋ ์ฌ์ง์ ์ ๊ทผ์ด ๊ฐ๋ฅํ๋ค
๋ด๊ฐ ์ํ๋ ๋๋ฉ์ธ์์๋ง ์ด๋ฏธ์ง์ ์ ๊ทผ์ด ๊ฐ๋ฅํ๋๋ก ๋ณ๊ฒฝํด๋ณด์
(ํซ๋งํฌ ๋ฐฉ์ง)
๋ค์ํ ๋ฐฉ๋ฒ์ด ์๋ค (์๋ ๋งํฌ ํ์ธ)
https://aws.amazon.com/ko/blogs/security/how-to-prevent-hotlinking-by-using-aws-waf-amazon-cloudfront-and-referer-checking/
How to Prevent Hotlinking by Using AWS WAF, Amazon CloudFront, and Referer Checking | Amazon Web Services
At some point, you might have to deal with hotlinking: when third parties embed in their websites the content they find on your websites. The third-party website does not incur the cost of hosting the content, which means your website can end up paying for
aws.amazon.com
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html
Serve private content with signed URLs and signed cookies - Amazon CloudFront
Thanks for letting us know this page needs work. We're sorry we let you down. If you've got a moment, please tell us how we can make the documentation better.
docs.aws.amazon.com