Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

S3 region ignored #31

Closed
Szasza opened this issue Oct 30, 2016 · 11 comments
Closed

S3 region ignored #31

Szasza opened this issue Oct 30, 2016 · 11 comments

Comments

@Szasza
Copy link

Szasza commented Oct 30, 2016

Hi @benesch,

Problem: it seems that the S3 region is not being picked up from the box_url.

Example URL: https://BUCKETNAME.s3-ap-southeast-2.amazonaws.com/JSONPATH

Result: a message stating S3 client configured for "us-east-1" but the bucket "BUCKETNAME" is in "ap-southeast-2"; Please configure the proper region to avoid multiple unnecessary redirects and signing attempts

Expected result: box fetched directly from "ap-southeast-2"

@benesch
Copy link
Contributor

benesch commented Oct 30, 2016

Hi @Szasza! Can you rerun with VAGRANT_LOG=debug vagrant whatever-command-you-ran and post relevant portions of the dump? (You can Cmd+F for "s3auth:" in the output.)

@Szasza
Copy link
Author

Szasza commented Oct 31, 2016

Thank you for the quick response @benesch, it is much appreciated.

It looks like that vagrant first tries to get the image without auth (no AWS params in the URL at the end of the start process line). Also, the error message for the 403 is misleading.

INFO warden: Calling IN action: #VagrantPlugins::S3Auth::ExpandS3Urls:0x007f19f82d39f8

INFO warden: Calling IN action: #VagrantPlugins::LoginCommand::AddAuthentication:0x007f19f82d39a8

DEBUG client: Using authentication token from disk at /home/USER/.vagrant.d/data/vagrant_login_token

INFO warden: Calling OUT action: #VagrantPlugins::LoginCommand::AddAuthentication:0x007f19f82d39a8

INFO warden: Calling OUT action: #VagrantPlugins::S3Auth::ExpandS3Urls:0x007f19f82d39f8

INFO box_add: Downloading box: https://BUCKETNAME.s3-ap-southeast-2.amazonaws.com/RESOURCEPATH => /home/USER/.vagrant.d/tmp/BOXID

INFO downloader: HEAD: https://BUCKETNAME.s3-ap-southeast-2.amazonaws.com/RESOURCEPATH

INFO subprocess: Starting process: ["/opt/vagrant/embedded/bin/curl", "-I", "-q", "--fail", "--location", "--max-redirs", "10", "--user-agent", "Vagrant/1.8.6 (+https://www.vagrantup.com; ruby2.2.5)", "--continue-at", "-", "-H", "Accept: application/json", "https://BUCKETNAME.s3-ap-southeast-2.amazonaws.com/RESOURCEPATH"]

DEBUG subprocess: Selecting on IO

DEBUG subprocess: stderr: % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0

DEBUG subprocess: stderr: curl: (22) The requested URL returned error: 403 Forbidden

DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 31999

DEBUG subprocess: Exit status: 22

WARN downloader: Downloader exit code: 22

S3 client configured for "us-east-1" but the bucket "BUCKETNAME" is in "ap-southeast-2"; Please configure the proper region to avoid multiple unnecessary redirects and signing attempts

INFO downloader: s3auth: Discovered S3 URL: https://BUCKETNAME.s3-ap-southeast-2.amazonaws.com/RESOURCEPATH

DEBUG downloader: s3auth: Bucket: "BUCKETNAME"

DEBUG downloader: s3auth: Key: "RESOURCEPATH"

INFO downloader: s3auth: Generating signed URL for HEAD

INFO subprocess: Starting process: ["/opt/vagrant/embedded/bin/curl", "-I", "-q", "--fail", "--location", "--max-redirs", "10", "--user-agent", "Vagrant/1.8.6 (+https://www.vagrantup.com; ruby2.2.5)", "--continue-at", "-", "-H", "Accept: application/json", "https://BUCKETNAME.s3-ap-southeast-2.amazonaws.com/RESOURCEPATH?AWSPARAMS"]

DEBUG subprocess: Selecting on IO

DEBUG subprocess: stderr: % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 340 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0

DEBUG subprocess: stdout: HTTP/1.1 200 OK
x-amz-id-2: AMZID
x-amz-request-id: AMZREQUESTID
Date: Mon, 31 Oct 2016 00:03:14 GMT
Last-Modified: Mon, 31 Oct 2016 00:02:10 GMT
ETag: "ETAG"
Accept-Ranges: bytes
Content-Type: application/json
Content-Length: 340
Server: AmazonS3

@benesch
Copy link
Contributor

benesch commented Oct 31, 2016

?!

vagrant-s3auth always lets Vagrant give the box URL an unauthenticated try first. (Source:

def execute_curl_with_s3auth(options, subprocess_options, &data_proc)
execute_curl_without_s3auth(options, subprocess_options, &data_proc)
rescue Errors::DownloaderError => e
# Ensure the progress bar from the just-failed request is cleared.
@ui.clear_line if @ui
s3auth_download(options, subprocess_options, &data_proc) || (raise e)
end
). This is to avoid breaking existing box downloads if vagrant-s3auth has a bug; as long as your box downloads successfully without vagrant-s3auth, vagrant-s3auth won't get involved at all.

But it seems the rest of the output is quite alright! Does the box get added successfully and just print a warning message along the way?

@Szasza
Copy link
Author

Szasza commented Oct 31, 2016

It explains it if vagrant-s3auth always gives the control to vagrant first, yes, the box gets addedd successfully apart from the message.

In this case, the following would be more of a nice-to-have:

  • An extra config parameter in vagrant-s3auth called force, priority, or similar, which would use vagrant-s3auth first, then fall back to vagrant.
  • Changing the error message in this specific case, because it is misleading, since the configuration is perfectly fine and points to the proper region.

Your consideration is highly appreciated.

@benesch
Copy link
Contributor

benesch commented Nov 6, 2016

Sorry for the delay—I just can't manage to repro this. It's quite possible that it's our internal AWS SDK that's generating that message, but I can't manage to trigger it on my machine.

Does this happen if you use an S3 URL instead? E.g., s3://BUCKET/JSONPATH.

@Szasza
Copy link
Author

Szasza commented Nov 10, 2016

I'm guilty as charged regarding the delay too. Yes, it happens with every type of URL, S3 included.

There is no other vagrant plugin in use either.

@benesch
Copy link
Contributor

benesch commented Nov 16, 2016

Hmmmmmmm. What version of Vagrant, what version of vagrant-s3auth, and what version of the OS are you using?

@Szasza
Copy link
Author

Szasza commented Nov 25, 2016

Vagrant 1.8.6
vagrant-s3auth 1.3.0
OS Ubuntu 16.04 LTS

@benesch
Copy link
Contributor

benesch commented Dec 30, 2016

Ahhh, finally managed to reproduce this. Sorry for the long delay! Turns out it's an upstream bug in the AWS SDK. I've filed a PR! aws/aws-sdk-ruby#1374

I assume your bucket doesn't include any periods (.) in its name? The integration tests for this project generate bucket names with dots (travis-$TRAVIS_JOB_NUMBER.vagrant-s3auth.com), which don't trigger the warning you saw. So thanks for reporting, @Szasza! If upstream is slow to merge, I'll release a workaround in vagrant-s3auth in a few days.

benesch added a commit that referenced this issue Dec 31, 2016
The AWS SDK attempts to use host-style endpoints when the bucket name
contains only DNS-compliant characters and no periods. (Names with
periods break the SSL wildcard certificate.) Unfortunately, due to the
implementation details of AWS Signature V4, the GetBucketLocation
request now requires path-style endpoints, even when the bucket name is
otherwise compatible with host-style endpoints. The AWS SDK has a bug,
aws/aws-sdk-ruby#1374, that causes GetBucketLocation requests to be made
with host-style endpoints instead of path-style endpoints. The AWS SDK
catches the error and retries with the appropriate request, but prints
an annoying warning in the process.

This commit works around the issue for now, thus fixing #31.
@benesch benesch closed this as completed Dec 31, 2016
@Szasza
Copy link
Author

Szasza commented Dec 31, 2016

Thank you @benesch for looking into the matter, it is much appreciated.

@benesch
Copy link
Contributor

benesch commented Jan 3, 2017

Of course! vagrant-s3auth 1.3.1 (just released on Saturday) should solve the issue!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants