statamic / v2-hub

Statamic 2 - Feature Requests and Bug Reports
https://statamic.com
95 stars 5 forks source link

Assets not uploading to s3 or anywhere in local. #2540

Closed janejanejane closed 2 years ago

janejanejane commented 2 years ago

Describe the bug Assets not uploading to s3 or anywhere in local. The network tab indicates a success in upload.

To Reproduce

// inside Control Panel page
fields:
    video:
      type: assets
      display: Video URL
      container: videos
// /videos.yaml
key: **
secret: **
bucket: **
path: content/videos
region: us-west-2
title: Videos
driver: s3
url: /content/videos

Screenshots When creating inside the assets folder, no error is logged and no file uploaded.

Screen Shot 2021-07-21 at 3 49 41 PM

When creating in s3 manually, files are shown in assets folder.

Screen Shot 2021-07-21 at 3 54 13 PM Screen Shot 2021-07-21 at 3 54 03 PM

Expected behavior Files should have been uploaded to s3.

Environment details (please complete the following information):

Additional context Error logged when creating New Folder using Statamic assets interface (removed company details):

ERROR: exception 'Aws\S3\Exception\S3Exception' with message 'Error executing "PutObject" on "https://**.us-west-2.amazonaws.com/content/videos/test/"; AWS HTTP error: Client error: `PUT https://**.us-west-2.amazonaws.com/content/videos/test/` resulted in a `403 Forbidden` response:
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>** (truncated...)
 AccessDenied (client): Access Denied - <?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>**</RequestId><HostId>**</HostId></Error>'

GuzzleHttp\Exception\ClientException: Client error: `PUT https://**.us-west-2.amazonaws.com/content/videos/test/` resulted in a `403 Forbidden` response:
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>

Setting the action to *"s3:"** uploads the file. But this is too relaxed. What is the recommended actions for the bucket?

kentaro00 commented 2 years ago

I encountered this problem as well, but I've found through trial and error that for a minimally-granted IAM policy, in order to successfully upload a file you need at least:

{
  "Effect": "Allow",
    "Action": [
      "s3:PutObject",
      "s3:PutObjectAcl"
     ]
...
}

Hope that helps

janejanejane commented 2 years ago

Thanks @kentaro00 . It worked. 👍