0

I'm trying to set up an AWS S3 bucket for storing files that a website will dish up to users of the site. The site is an intranet (only logged in users can access any pages which provide links to the assets from the S3 bucket).

When I include "Principle": "*" in my policy, AWS warns me about exposing the bucket to public access. Yet everything I've tried for granting only a specific user to have access doesn't work (results in AccessDenied errors).

After many hours reading online articles, AWS documents, and a long list of questions on ServerFault and StackExchange, I am none the wiser. I'm starting to think that perhaps I'm misunderstanding the ramifications of an S3 bucket having public access. Is it even an issue, since I can't seem to NOT grant public access whilst still having access to the files (via the web site that's storing them on there).

The website in question is a Craft 2 CMS site, with an AWS S3 plug-in. The plug-in requires an AWS "Access Key ID" and "Secret Access Key". I set up a user in IAM for this site, and used the Keys from that user.

What I've tried

  1. I've tried applying a policy to the bucket itself. If I use the following policy, on the bucket itself, I can access the files from the website. But I get the warning from AWS that this opens up public access (which I understand is due to the "Principle": "*" field).
{
    "Id": "Policy1599693986936",
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1599693977359",
            "Action": [
                "s3:GetBucketLocation",
                "s3:ListBucket",
                "s3:PutObject",
                "s3:GetObject",
                "s3:DeleteObject",
                "s3:GetObjectAcl",
                "s3:PutObjectAcl"
            ],
            "Effect": "Allow",
            "Resource": [
                "arn:aws:s3:::MY-BUCKET/*",
                "arn:aws:s3:::MY-BUCKET"
            ],
            "Principal": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetBucketLocation",
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::MY-BUCKET"
            ],
            "Principal": "*"
        }
    ]
}
  1. To avoid the Public Access issue/warning, I've tried having a policy on just the IAM user itself, and no policy on the bucket directly. I used this policy:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor1",
            "Effect": "Allow",
            "Action": [
                "s3:ListBucketMultipartUploads",
                "s3:ListBucket",
                "s3:GetBucketLocation"
            ],
            "Resource": "arn:aws:s3:::MY-BUCKET"
        },
        {
            "Sid": "VisualEditor2",
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:GetObjectAcl",
                "s3:GetObject",
                "s3:AbortMultipartUpload",
                "s3:DeleteObject",
                "s3:PutObjectAcl"
            ],
            "Resource": "arn:aws:s3:::MY-BUCKET/*"
        }
    ]
}

But this results in a <Code>AccessDenied</Code> error when I try to view the files via our web site. So it does not seem to grant the required permissions, even though it's granting the same permissions as the policy in #1 above, just that they are specific to this user (whose key I am using on the site).

  1. I've also tried applying a condition in the policy on the bucket, restricting access to the IP address of my website, but that results in AccessDenied error. The additional field I used was:
   "Condition": {
                "IpAddress": {
                    "aws:SourceIp": [
                        "SERVER-IP-ADDRESS"
                    ]
                }
            },

Questions

  1. Have I misunderstood how to grant a user (and therefore a specific website, with that user's credentials, access to an S3 bucket?
  2. What is the way to grant a web site (or any tool that accesses S3) exclusive access to a bucket, without opening the bucket up to public access?
  3. What are the actual risks of opening up "public access" in my usage scenario? Since it's an private website (a password access only intranet) does it even matter if I grant public access to the S3 bucket? Can I just ignore the warnings from AWS?
inspirednz
  • 173
  • 1
  • 9

1 Answers1

0

Do you have a VPN or DX connection you resources in a VPC in this AWS account? If that's the case, you can use that connection for accessing the website hosting in your S3 without having it "go out through the internet".

You'll need to configure and S3 Endpoint to your VPC and apply the correct policies to it from there (IIRC by default it allows everything, so maybe that works for you).

https://docs.aws.amazon.com/vpc/latest/userguide/vpc-endpoints-s3.html

It might be more restrictive as it won't just block users with the proper authentication, but also with the proper "communications" permissions since you'll need to allow all the users to access via the connection from wherever they are through the VPN/Dx to AWS, which may work in your case or not.

Oscar De León
  • 241
  • 1
  • 2
  • 6
  • Thanks Oscar. Should what you've suggested even be necessary? I'm still perplexed why setting up what seems like appropriate policies doesn't have the intended effect. – inspirednz Oct 27 '20 at 21:10
  • Well you did say the bucket can't be open to the public, so I understood that as saying you don't want any traffic going out to the internet. Using the S3 Endpoint in your VPC prevents just that and keeps all communications between the VPC and S3 routed internally and a VPN or DX to the VPC for external users. If I misunderstood you could continue as you were and limit the access via policy to the right network CIDR and go (securely) over the internet. – Oscar De León Oct 27 '20 at 22:27
  • Thanks. Perhaps my original post wasn't clear enough. I have no issue with the site accessing the S3 bucket, over the Internet. The issue is that I can't set up a policy that only allows a specific AWS user (assigned to the site software) to access the files. Since posting my question, I'm now suspecting there is a bug /issue in the way Craft CMS 2.9.2 handles the S3 connection, and that this is most likely the source of the permissions problem I have been facing. Because I see no other reason for it to not be working. – inspirednz Oct 27 '20 at 23:21