s3 bucket policy

0

Hello. I have an s3 bucket. it's open for getObject for everyone. I want to allow putObject method only for s3 signed url and cloudfront signed url. How should I adjust my policy?

1개 답변
0
수락된 답변

Hello, you can adjust the bucket policy to include a condition that checks for the presence of a specific query string parameter that is included in the signed URLs. below is example for this:

{
    "Version": "2012-10-17",
    "Id": "S3PolicyId1",
    "Statement": [
        {
            "Sid": "Allow-put-object-only-with-signed-url",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::bucket-name/*",
            "Condition": {
                "StringLike": {
                    "aws:url-param": "URL-signature=*"
                }
            }
        }
    ]
}

This gonna allows putObject for S3 signed URLs that include "url singature" query string parameter. As for the CloudFront signed URLs, you can use cloudfront:signedUrl in the Principal field, and also include a condition that checks the presence of the CloudFront-Signature query string parameter.

{
    "Version": "2012-10-17",
    "Id": "CloudFrontPolicyId1",
    "Statement": [
        {
            "Sid": "Allow-put-object-only-with-signed-url",
            "Effect": "Allow",
            "Principal": {"AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity"},
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::bucket-name/*",
            "Condition": {
                "StringLike": {
                    "aws:url-param": "CloudFront-Signature=*"
                }
            }
        }
    ]
}
profile picture
답변함 일 년 전
profile picture
전문가
검토됨 2달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인