Rails implementation for securing S3 documents

后端 未结 3 865
旧巷少年郎
旧巷少年郎 2021-02-05 22:47

I would like to protect my s3 documents behind by rails app such that if I go to:

www.myapp.com/attachment/5 that should authenticate the user prior to displaying/downlo

3条回答
  •  天涯浪人
    2021-02-05 23:30

    You'd want to do two things:

    1. Make the bucket and all objects inside it private. The naming convention doesn't actually matter, the simpler the better.

    2. Generate signed URLs, and redirect to them from your application. This way, your app can check if the user is authenticated and authorized, and then generate a new signed URL and redirect them to it using a 301 HTTP Status code. This means that the file will never go through your servers, so there's no load or bandwidth on you. Here's the docs to presign a GET_OBJECT request:

    https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Presigner.html

提交回复
热议问题