简体   繁体   English

是否可以将来自EC2实例的访问限制为仅使用来自特定帐户的S3存储桶?

[英]Is it possible to restrict access from EC2 instance to use only S3 buckets from specific account?

Goal : I would like to keep sensitive data in s3 buckets and process it on EC2 instances, located in the private cloud. 目标 :我想将敏感数据保存在s3存储桶中,并在私有云中的EC2实例上进行处理。 I researched that there is possbility to set up S3 buckets policy by IP and user(iam) arn's thus i consider that data in s3 bucket is 'on the safe side'. 我研究了可以通过IP和用户(iam)arn设置S3存储桶策略的可能性,因此我认为s3存储桶中的数据“安全”。 But i am worriyng about the next scenario: 但是我担心下一个场景:
1) there is vpc 1)有vpc
2) inside theres is an ec2 isntance 2)里面有一个EC2符号
3) there is an user under controlled(allowed) account with permissions to connect and work with ec2 instance and buckets. 3)有一个处于受控(允许)帐户下的用户,该用户具有连接和使用ec2实例和存储桶的权限。 Buckets are defined and configured to work with only with known(authorized) ec2-instances. 定义并配置存储桶,使其仅与已知(授权)ec2实例一起使用。
Security leak: user uploads malware application on ec2 instance and during processing data executes malware application that transfer data to other(unauthorized) buckets under different AWS account. 安全漏洞:用户在ec2实例上上传恶意软件应用程序,并且在处理数据期间执行恶意软件应用程序,该数据会将数据传输到其他AWS账户下的其他(未经授权)存储桶。
Disabling uploading data to ec2-instance is not an option in my case. 在我的情况下,不能选择禁止将数据上传到ec2-instance。
Question: is it possible to restrict access on vpc firewal in such way that it will be access to some specific s3 buckets but it will be denied access to any other buckets? 问题:是否可以通过某种方式限制对vpc firewal的访问,使其可以访问某些特定的s3存储桶,但将拒绝访问任何其他存储桶? Assumed that user might upload malware application to ec2 instance and within it upload data to other buckets(under third-party AWS account). 假设用户可能将恶意软件应用程序上传到ec2实例,并在其中将数据上传到其他存储桶(在第三方AWS账户下)。

There is not really a solution for what you are asking, but then again, you seem to be attempting to solve the wrong problem (if I understand your question correctly). 您提出的问题并没有真正的解决方案,但是再次,您似乎正在尝试解决错误的问题(如果我正确理解了您的问题)。

If you have a situation where untrustworthy users are in a position where they are able to "connect and work with ec2 instance and buckets" and upload and execute application code inside your VPC, then all bets are off and the game is already over. 如果您遇到无法信任的用户处于能够“连接并使用ec2实例和存储桶并使用它们”并上载和执行VPC内部应用程序代码的情况,那么所有的赌注都将关闭,游戏已经结束。 Shutting down your application is the only fix available to you. 关闭应用程序是唯一可用的修复程序。 Trying to limit the damage by preventing the malicious code from uploading sensitive data to other buckets in S3 should be the absolute least of your worries. 通过阻止恶意代码将敏感数据上传到S3中的其他存储桶来限制损害的方法,绝对是您的后顾之忧。 There are so many other options available to a malicious user other than putting the data back into S3 but in a different bucket. 除了将数据放回S3中但位于不同存储桶中之外,恶意用户还有许多其他选择。

It's also possible that I am interpreting "connect and work with ec2 instance and buckets" more broadly than you intended, and all you mean is that users are able to upload data to your application. 我也可能比您预期的更广泛地解释“连接并使用ec2实例和存储桶”,而您的意思是用户能够将数据上传到您的应用程序。 Well, okay... but your concern still seems to be focused on the wrong point. 好吧,好吧...但是您的担忧似乎仍然集中在错误的地方。

I have applications where users can upload data. 我有一些用户可以在其中上传数据的应用程序。 They can upload all the malware they want, but there's no way any code -- malicious or benign -- that happens to be contained in the data they upload will ever get executed. 他们可以上载他们想要的所有恶意软件,但是上载数据中所包含的任何代码(恶意或良性)都将永远无法执行。 My systems will never confuse uploaded data with something to be executed or handle it in a way that this is even remotely possible. 我的系统永远不会将上载的数据与要执行的内容混淆,也不会以遥不可及的方式进行处理。 If your code will, then you again have a problem that can only be fixed by fixing your code -- not by restricting which buckets your instance can access. 如果您的代码可以,那么您又遇到了一个问题,只能通过修复代码来解决问题,而不能通过限制实例可以访问哪些存储桶来解决。

Actually, I lied, when I said there wasn't a solution. 实际上,当我说没有解决方案时,我撒了谎。 There is a solution, but it's fairly preposterous: 有一个解决方案,但这很荒谬:

Set up a reverse web proxy, either in EC2 or somewhere outside, but of course make its configuration inaccessible to the malicious users. 在EC2或外部某个地方设置反向Web代理,但是当然会使恶意用户无法访问其配置。 In this proxy's configuration, configure it to only allow access to the desired bucket. 在此代理的配置中,将其配置为仅允许访问所需的存储桶。 With apache, for example, if the bucket were called "mybucket," that might look something like this: 以apache为例,如果存储桶名为“ mybucket”,则可能看起来像这样:

ProxyPass /mybucket http://s3.amazonaws.com/mybucket

Additional configuration on the proxy would deny access to the proxy from anywhere other than your instance. 代理上的其他配置将拒绝您实例以外的任何地方对代理的访问。 Then instead of allowing your instance to access the s3 endpoints directly, only allow outbound http toward the proxy (via the security group for the compromised instance). 然后,不要允许您的实例直接访问s3端点,而只能允许对代理的出站http(通过受感染实例的安全组使用)。 Requests for buckets other than yours will not make it through the proxy, which is now the only way "out." 对您的存储桶以外的存储桶的请求将不会通过代理进行,这是目前唯一的“出路”。 Problem solved. 问题解决了。 At least, the specific problem you were hoping to solved should be solvable by some variation of this approach. 至少,您希望解决的特定问题可以通过此方法的一些变体来解决。

Update to clarify: 更新以澄清:

To access the bucket called "mybucket" in the normal way, there are two methods: 要以正常方式访问名为“ mybucket”的存储桶,有两种方法:

http://s3.amazonaws.com/mybucket/object_key
http://mybucket.s3.amazonaws.com/object_key

With this configuration, you would block (not allow) all access to all S3 endpoints from your instances via your security group configuration, which would prevent accessing buckets with either method. 使用此配置,您将通过安全组配置阻止(不允许)从您的实例对所有S3端点的所有访问,这将阻止使用任何一种方法访问存储桶。 You would, instead, allow access from your instances to the proxy. 相反,您将允许从实例访问代理。

If the proxy, for example, were at 172.31.31.31 then you would access buckets and their objects like this: 例如,如果代理位于172.31.31.31,则可以按以下方式访问存储桶及其对象:

http://172.31.31.31/mybucket/object_key

The proxy, being configured to only permit certain patterns in the path to be forwarded -- and any others denied -- would be what controls whether a particular bucket is accessible or not. 代理配置为仅允许转发路径中的某些模式-拒绝其他任何模式-将控制特定存储桶是否可访问。

Use VPC Endpoints . 使用VPC端点 This allows you to restrict which S3 buckets your EC2 instances in a VPC can access. 这使您可以限制VPC中的EC2实例可以访问哪些S3存储桶。 It also allows you to create a private connection between your VPC and the S3 service, so you don't have to allow wide open outbound internet access. 它还允许您在VPC和S3服务之间创建专用连接,因此您不必允许广泛的出站Internet访问。 There are sample IAM policies showing how to control access to buckets. IAM策略示例显示了如何控制对存储桶的访问。

There's an added bonus with VPC Endpoints for S3 that certain major software repos, such as Amazon's yum repos and Ubuntu's apt-get repos, are hosted in S3 so you can also allow your EC2 instances to get their patches without giving them wide open internet access. S3的VPC端点还有一个额外的好处 ,即某些主要的软件仓库(例如Amazon的yum仓库和Ubuntu的apt-get仓库)都托管在S3中,因此您也可以允许您的EC2实例获取其补丁程序而无需提供广泛的互联网访问权限。 That's a big win. 那是一个很大的胜利。

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

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