Erro executing "PutObject" Laravel 8 - 403 Forbidden

Viewed 1244

I´ve created an IAM user just to upload files to S3, got the API keys but still got this error

"Error executing \"PutObject\" on \"https://s3.us-east-2.amazonaws.com/webroker.docs/13262668885/132626688851621017504.png\"; AWS HTTP error: Client error: `PUT https://s3.us-east-2.amazonaws.com/webroker.docs/13262668885/132626688851621017504.png` resulted in a `403 Forbidden` response:\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>GV1QDJ (truncated...)\n AccessDenied (client): Access Denied - <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>GV1QDJRW9NPAH9FY</RequestId><HostId>QHLSDFzDW7M9cXRU0P4feTKkCTIrLAeD/5zSosdUvncWiPV+IHbzSstufswsapqNuhZMmkhUFBs=</HostId></Error>"

I can see a lot of people facing the same issue than me, with no conclusion at all... anyone? Thanks in advance! Here´s my policy code created

{
    "Version": "2012-10-17",
    "Id": "Policy1621017443264",
    "Statement": [
        {
            "Sid": "Stmt1621017435001",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::676893604682:user/webroker-upload"
            },
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::webroker.docs"
        }
    ]
}
1 Answers

You don't seem to have provided object level access in your bucket policy.

Try this for read and write access:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "ListObjectsInBucket",
            "Effect": "Allow",
            "Principal": {
              "AWS": "arn:aws:iam::676893604682:user/webroker-upload"
            },
            "Action": ["s3:ListBucket"],
            "Resource": ["arn:aws:s3:::webroker.docs"]
        },
        {
            "Sid": "AllObjectActions",
            "Effect": "Allow",
            "Principal": {
              "AWS": "arn:aws:iam::676893604682:user/webroker-upload"
            },
            "Action": "s3:*Object",
            "Resource": ["arn:aws:s3:::webroker.docs/*"]
        }
    ]
}

If you just need PutObject, you can use:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "WriteActions",
            "Effect": "Allow",
            "Principal": {
              "AWS": "arn:aws:iam::676893604682:user/webroker-upload"
            },
            "Action": "s3:PutObject*",
            "Resource": ["arn:aws:s3:::webroker.docs/*"]
        }
    ]
}
Related