简体   繁体   English

Amazon S3文件基于IP地址访问策略

[英]Amazon S3 files access policy based on IP Address

Is there any way to limit the access of a file stored in Amazon S3 based on the client IP address? 有没有办法根据客户端IP地址限制存储在Amazon S3中的文件的访问权限?

I have a file stored there, which should be access only by specific IP address. 我有一个存储在那里的文件,只能通过特定的IP地址访问。 How to do this? 这该怎么做?

Yes there is, although I have not used this myself. 是的,虽然我自己没有用过。

S3 supports granular control over buckets and objects in them using "Access Policy Language". S3支持使用“访问策略语言”对存储桶和对象进行粒度控制。 There is specific whitelist and blacklist IP statements available. 可以使用特定的白名单和黑名单IP语句。 You will have to write the APL statements and upload them, however. 但是,您必须编写APL语句并上传它们。

http://docs.amazonwebservices.com/AmazonS3/latest/dev/AccessPolicyLanguage.html http://docs.amazonwebservices.com/AmazonS3/latest/dev/AccessPolicyLanguage.html

Here are 2 condition section examples: 以下是两个条件部分示例:

Whitelist 白名单

"Condition" :  {
       "IpAddress" : {
          "aws:SourceIp" : ["192.168.176.0/24","192.168.143.0/24"]
      }
}

Blacklist 黑名单

"Condition" :  {
       "NotIpAddress" : {
          "aws:SourceIp" : ["192.168.176.0/24","192.168.143.0/24"]
      }
}

Amazon describes this in their S3 docs under "Bucket Policy Examples", at Restricting Access to Specific IP Addresses : 亚马逊在限制访问特定IP地址的 “存储桶策略示例”下的S3文档中对此进行了描述:

The condition in this statement identifies the 54.240.143.* range of allowed IP addresses, with one exception: 54.240.143.188. 此语句中的条件标识允许的IP地址范围为54.240.143。*,但有一个例外:54.240.143.188。

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

You could add something like that in the AWS S3 console. 您可以在AWS S3控制台中添加类似的内容。 Select your bucket, click the Properties tab, then Permissions. 选择您的存储桶,单击Properties选项卡,然后单击Permissions。 Click "Add bucket policy" and paste it into the popup dialogue's form. 单击“添加存储桶策略”并将其粘贴到弹出对话框的表单中。

I modified Amazon's example to show how multiple IP ranges can be included in the policy by providing a JSON array instead of a string. 我修改了Amazon的示例,以显示如何通过提供JSON数组而不是字符串来在策略中包含多个IP范围。 The "aws:SourceIp" entry of "1.2.3.4/32" means that the single IP address, 1.2.3.4, is also granted access. “1.2.3.4/32”的“aws:SourceIp”条目表示单个IP地址1.2.3.4也被授予访问权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM