简体   繁体   English

Django Boto S3 Access

[英]Django Boto S3 Access

I can't figure this out. 我无法弄清楚这一点。

Here's what I want to happen ... 这就是我想要发生的事情......

I have an applications that users upload files to S3 using boto and django. 我有一个应用程序,用户使用boto和django将文件上传到S3。 I want those files to be private and only accessible through my app using my api credentials. 我希望这些文件是私有的,只能通过我的应用程序使用我的api凭据访问。

So if a user uploads a photo via my app, the only way he or anyone else can download it is via his account on my app. 因此,如果用户通过我的应用上传照片,他或其他任何人可以下载的唯一方法是通过我的应用上的帐户。 Is this possible, and if so how do I set it up using boto's acl rules. 这是可能的,如果是这样,我如何使用boto的acl规则进行设置。 I don't need the code, (hopefully) I can figure that out, just a walk through of how to do it. 我不需要代码,(希望)我可以解决这个问题,只需要了解如何做到这一点。

Does this make sense? 这有意义吗? I know I am not relaying it very well and I apologize in advance. 我知道我没有很好地传达它,我提前道歉。 Also, thanks for the help. 另外,谢谢你的帮助。

The docs for boto's ACLs are here . boto的ACL的文档在这里 I suggest just using the private "canned policy" -- since your users don't have S3 accounts anyway, it's by far the simplest idea. 我建议只使用private “预制策略” - 因为您的用户无论如何都没有S3帐户,这是迄今为止最简单的想法。 Your app will of course have to keep track of which user "owns" which files (which should be a very, very simple Django model!). 您的应用程序当然必须跟踪哪个用户“拥有”哪些文件(这应该是一个非常非常简单的Django模型!)。

I think you may be looking in the wrong area for what you'd like to accomplish. 我想你可能正在寻找你想要完成的事情。 The ACL interface allows you to grant permissions, but they depend on the users having Amazon S3 accounts. ACL接口允许您授予权限,但它们取决于拥有Amazon S3帐户的用户。 @Alex Martelli suggested using the private canned policy, and I agree — this will prevent any account but yours from being able to access your buckets/keys. @Alex Martelli建议使用private预制策略,我同意 - 这将阻止任何帐户,但您的帐户/密钥可以访问。

In order to enforce users only being able to download through your own application, just pass a small value to the expires_in parameter when generating the URL . 为了强制用户只能通过您自己的应用程序下载,只需在生成URL时将一个小值传递给expires_in参数。 Users will only get a valid download link through your application, and that link will be invalidated after their download. 用户只能通过您的应用程序获得有效的下载链接,并且该链接在下载后将无效。

django-storages already has methods for this problem and has a boto backend. django-storages已经有了解决这个问题的方法,并且有一个boto后端。 Don't roll your own except for edification. 除了启发之外,不要自己滚动。

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

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