Restrict access to website hosted on S3

后端 未结 3 993
野趣味
野趣味 2020-12-04 19:39

I would like to host a static website at amazon S3, but I need to restrict access to it to certain users. This maybe by ip address or by amazon credentials (only logged in u

3条回答
  •  臣服心动
    2020-12-04 20:15

    Yes it indeed is possible. Better starting point for you would be read S3 access control.

    But by default the buckets created on S3 aren't public. So the default behaviour should be that it will only be accessible to person/program who/which has knowledge of your access and secret key.

    You may also edit bucket permission in order to give access to a particular AWS account or an email id.

    In order to restrict access to certain IPs, you may create additional bucket policy.

    Restricting Access to Specific IP Addresses

    This statement grants permissions to any user to perform any S3 action on objects in the specified bucket. However, the request must originate from the range of IP addresses specified in the condition. The condition in this statement identifies 192.168.143.* range of allowed IP addresses with one exception, 192.168.143.188.

    Note that the IPAddress and NotIpAddress values specified in the condition uses CIDR notation described in RFC 2632. For more information, go to http://www.rfc-editor.org/rfc/rfc4632.txt.

    {
        "Version": "2012-10-17",
        "Id": "S3PolicyId1",
        "Statement": [
            {
                "Sid": "IPAllow",
                "Effect": "Allow",
                "Principal": "*",
                "Action": "s3:*",
                "Resource": "arn:aws:s3:::bucket/*",
                "Condition" : {
                    "IpAddress" : {
                        "aws:SourceIp": "192.168.143.0/24" 
                    },
                    "NotIpAddress" : {
                        "aws:SourceIp": "192.168.143.188/32" 
                    } 
                } 
            } 
        ]
    }
    

    For more, read here and here.

提交回复
热议问题