Skip to content

rclone copy S3 Access Denied with minimal PutObject ACL #4449

Closed

Description

@EmilienCourt

What is the problem you are having with rclone?

rclone will not copy files to a Amazon S3 bucket with only the PutObject authorization granted to the IAM role attached to an EC2 instance.

What is your rclone version (output from rclone version)

rclone v1.52.2

Which OS you are using and how many bits (eg Windows 7, 64 bit)

os/arch: windows/amd64 : Windows 10 64 bits

Which cloud storage system are you using? (eg Google Drive)

S3

The command you were trying to run (eg rclone copy /tmp remote:tmp)

rclone.exe copy file.txt s3bucket:redactedbucketname/somefolder/file.txt --no-check-dest --no-traverse --retries 1

A log from the command with the -vv flag (eg output from rclone -vv copy /tmp remote:tmp)

2020/07/20 08:57:49 DEBUG : rclone: Version "v1.52.2" starting with parameters ["rclone.exe" "copy" "file.txt" "s3bucket:redactedbucketname/somefolder/file.txt" "-vv" "--no-check-dest" "--dump" "headers" "--no-traverse" "--retries" "1"]
2020/07/20 08:57:49 DEBUG : Using config file from "C:\\Users\\Administrator\\.config\\rclone\\rclone.conf"
2020/07/20 08:57:49 DEBUG : fs cache: renaming cache item "file.txt" to be canonical "//?/C:/Users/Administrator/Downloads/rclone-current-windows-amd64/rclone-v1.52.2-windows-amd64"
2020/07/20 08:57:49 DEBUG : You have specified to dump information. Please be noted that the Accept-Encoding as shown may not be correct in the request and the response may not show Content-Encoding if the go standard libraries auto gzip encoding was in effect. In this case the body of the request will be gunzipped before showing it.
2020/07/20 08:57:49 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2020/07/20 08:57:49 DEBUG : HTTP REQUEST (req [REDACTED])
2020/07/20 08:57:49 DEBUG : PUT /latest/api/token HTTP/1.1
Host: 169.254.169.254
User-Agent: rclone/v1.52.2
Content-Length: 0
X-Aws-Ec2-Metadata-Token-Ttl-Seconds: 21600
Accept-Encoding: gzip

2020/07/20 08:57:49 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2020/07/20 08:57:49 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2020/07/20 08:57:49 DEBUG : HTTP RESPONSE (req [REDACTED])
2020/07/20 08:57:49 DEBUG : HTTP/1.1 200 OK
Connection: close
Content-Length: 56
Content-Type: text/plain
Date: Mon, 20 Jul 2020 08:57:49 GMT
Server: EC2ws
X-Aws-Ec2-Metadata-Token-Ttl-Seconds: 21600

2020/07/20 08:57:49 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2020/07/20 08:57:49 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2020/07/20 08:57:49 DEBUG : HTTP REQUEST (req [REDACTED])
2020/07/20 08:57:49 DEBUG : GET /latest/meta-data/iam/security-credentials/ HTTP/1.1
Host: 169.254.169.254
User-Agent: rclone/v1.52.2
X-Aws-Ec2-Metadata-Token: [REDACTED]
Accept-Encoding: gzip

2020/07/20 08:57:49 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2020/07/20 08:57:49 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2020/07/20 08:57:49 DEBUG : HTTP RESPONSE (req [REDACTED])
2020/07/20 08:57:49 DEBUG : HTTP/1.1 200 OK
Connection: close
Content-Length: 35
Accept-Ranges: none
Content-Type: text/plain
Date: Mon, 20 Jul 2020 08:57:49 GMT
Last-Modified: Mon, 20 Jul 2020 08:47:27 GMT
Server: EC2ws
X-Aws-Ec2-Metadata-Token-Ttl-Seconds: 21600

2020/07/20 08:57:49 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2020/07/20 08:57:49 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2020/07/20 08:57:49 DEBUG : HTTP REQUEST (req [REDACTED])
2020/07/20 08:57:49 DEBUG : GET /latest/meta-data/iam/security-credentials/REDACTEDIAMROLE HTTP/1.1
Host: 169.254.169.254
User-Agent: rclone/v1.52.2
X-Aws-Ec2-Metadata-Token: [REDACTED]
Accept-Encoding: gzip

2020/07/20 08:57:49 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2020/07/20 08:57:49 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2020/07/20 08:57:49 DEBUG : HTTP RESPONSE (req [REDACTED])
2020/07/20 08:57:49 DEBUG : HTTP/1.1 200 OK
Connection: close
Content-Length: 1298
Accept-Ranges: none
Content-Type: text/plain
Date: Mon, 20 Jul 2020 08:57:49 GMT
Last-Modified: Mon, 20 Jul 2020 08:47:27 GMT
Server: EC2ws
X-Aws-Ec2-Metadata-Token-Ttl-Seconds: 21600

2020/07/20 08:57:49 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2020/07/20 08:57:49 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2020/07/20 08:57:49 DEBUG : HTTP REQUEST (req [REDACTED])
2020/07/20 08:57:49 DEBUG : HEAD /somefolder/file.txt HTTP/1.1
Host: redactedbucketname.s3.us-east-2.amazonaws.com
User-Agent: rclone/v1.52.2
Authorization: XXXX
X-Amz-Content-Sha256: [REDACTED]
X-Amz-Date: 20200720T085749Z
X-Amz-Security-Token: [REDACTED]

2020/07/20 08:57:49 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2020/07/20 08:57:49 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2020/07/20 08:57:49 DEBUG : HTTP RESPONSE (req [REDACTED])
2020/07/20 08:57:49 DEBUG : HTTP/1.1 403 Forbidden
Transfer-Encoding: chunked
Content-Type: application/xml
Date: Mon, 20 Jul 2020 08:57:49 GMT
Server: AmazonS3
X-Amz-Id-2: [REDACTED]
X-Amz-Request-Id: [REDACTED]


2020/07/20 08:57:49 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2020/07/20 08:57:49 DEBUG : file.txt: Need to transfer - File not found at Destination
2020/07/20 08:57:49 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2020/07/20 08:57:49 DEBUG : HTTP REQUEST (req [REDACTED])
2020/07/20 08:57:49 DEBUG : PUT / HTTP/1.1
Host: redactedbucketname.s3.us-east-2.amazonaws.com
User-Agent: rclone/v1.52.2
Content-Length: 153
Authorization: XXXX
X-Amz-Acl: private
X-Amz-Content-Sha256: [REDACTED]
X-Amz-Date: 20200720T085749Z
X-Amz-Security-Token: [REDACTED]
Accept-Encoding: gzip

2020/07/20 08:57:49 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2020/07/20 08:57:49 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2020/07/20 08:57:49 DEBUG : HTTP RESPONSE (req [REDACTED])
2020/07/20 08:57:49 DEBUG : HTTP/1.1 403 Forbidden
Transfer-Encoding: chunked
Content-Type: application/xml
Date: Mon, 20 Jul 2020 08:57:49 GMT
Server: AmazonS3
X-Amz-Id-2: [REDACTED]
X-Amz-Request-Id: [REDACTED]

2020/07/20 08:57:49 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2020/07/20 08:57:49 ERROR : file.txt: Failed to copy: AccessDenied: Access Denied
        status code: 403, request id: [REDACTED], host id: [REDACTED]
2020/07/20 08:57:49 ERROR : Attempt 1/1 failed with 1 errors and: AccessDenied: Access Denied
        status code: 403, request id: [REDACTED], host id: [REDACTED]
2020/07/20 08:57:49 INFO  :
Transferred:             0 / 0 Bytes, -, 0 Bytes/s, ETA -
Errors:                 1 (retrying may help)
Elapsed time:         0.0s

2020/07/20 08:57:49 DEBUG : 4 go routines active
2020/07/20 08:57:49 Failed to copy: AccessDenied: Access Denied
        status code: 403, request id: [REDACTED], host id: [REDACTED]

Here is the bucket access policy :

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::redactedaccountnumber:role/REDACTEDIAMROLE"
            },
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::redactedbucketname/*"
        }
    ]
}

The equivalent aws s3 cp file.txt s3://redactedbucketname/somefolder/file.txt works fine.

The rclone config section is as follows :

[s3bucket]
type = s3
provider = AWS
env_auth = true
region = us-east-2

Regards

Activity

  1. ncw commented on Jul 21, 2020

    @ncw
    Member

    This is rclone trying to create the bucket if it doesn't exist.

    This is quite a similar problem to #4297 which was fixed by 723c1df

    This fix would work here too, but because you've used --no-traverse and --no-check-existing by the time rclone comes to do the upload it doesn't know if the bucket exists or not because it hasn't listed it or anything within it.

    So I guess options are

    • ignore the 403 forbidden message when we come to create the bucket. The could potentially mask other errors though
    • don't try to create the bucket - maybe make a --s3-assume-bucket-exists flag or something like that

    Thoughts?

    Any other idea?

  2. added and removed on Jul 21, 2020
  3. added this to the v1.53 milestone on Jul 21, 2020
  4. EmilienCourt commented on Jul 21, 2020

    @EmilienCourt
    Author

    This is rclone trying to create the bucket if it doesn't exist.

    This is quite a similar problem to #4297 which was fixed by 723c1df

    This fix would work here too, but because you've used --no-traverse and --no-check-existing by the time rclone comes to do the upload it doesn't know if the bucket exists or not because it hasn't listed it or anything within it.

    So I guess options are

    * ignore the 403 forbidden message when we come to create the bucket. The could potentially mask other errors though
    
    * don't try to create the bucket - maybe make a `--s3-assume-bucket-exists` flag or something like that
    

    Thoughts?

    Any other idea?

    Thanks @ncw for the answer.

    I have tried with and without the --no-traverse and --no-check-existing options, but it would not work either (due to the very restrictive bucket policy).

    The --s3-assume-bucket-exists would be the best option, according to me.

    Maybe a more global switch like --bare-requests would also be appropriate (only for copy) ?

    This would just send the PUT requests (which is what aws s3api cp does). I think it would be more convenient than having to set --no-traverse, --no-check-existing and --s3-assume-bucket-exists.

  5. added a commit that references this issue on Jul 22, 2020
    5ef6948
  6. ncw commented on Jul 22, 2020

    @ncw
    Member

    I have tried with and without the --no-traverse and --no-check-existing options, but it would not work either (due to the very restrictive bucket policy).

    Sure

    The --s3-assume-bucket-exists would be the best option, according to me.

    I made a --s3-no-check-bucket flag here - can you have a go?

    v1.52.2-233-g5ef6948d-fix-4449-s3-no-check-bucket-beta on branch fix-4449-s3-no-check-bucket (uploaded in 15-30 mins)

    However this is still doing a post copy HEAD request to check the file was uploaded correctly...

    Maybe a more global switch like --bare-requests would also be appropriate (only for copy) ?

    This would just send the PUT requests (which is what aws s3api cp does). I think it would be more convenient than having to set --no-traverse, --no-check-existing and --s3-assume-bucket-exists.

    This is a bit difficult to fit into rclone's framework...

    I could do a backend command for s3 say rclone backend put s3:bucket file or something like that which just did the put.

  7. EmilienCourt commented on Jul 22, 2020

    @EmilienCourt
    Author

    I've just tested the beta version you have linked, it works just fine. Thanks !

    There is indeed a HEAD request before (the result of which is ignored) and after the copy. The result of the operation is "Failed", because of the latter (as you mentionned).


    Regarding the backend command, I would not personally use it if implemented (as I have to copy entire folders) but it might be useful to some.

  8. ncw commented on Jul 27, 2020

    @ncw
    Member

    I've merged this to master now which means it will be in the latest beta in 15-30 mins and released in v1.53

    I'll leave the backend command for the moment :-)

  9. added a commit that references this issue on Jul 20, 2026
    ca70a78
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions