fog/fog-aws

Incorrect bucket redirection URL generation

Closed this issue · 0 comments

Fog fails with following error when connecting to a bucket from different region, while following a redirect.

client = Fog::AWS::Storage.new(
  aws_access_key_id: ENV.fetch('AWS_S3_ACCESS_KEY_ID', nil),
  aws_secret_access_key: ENV.fetch('AWS_S3_SECRET_ACCESS_KEY', nil),
  region: ENV.fetch('AWS_S3_REGION', nil)
)

client.directories.get('documents-staging')

Excon::Error::Socket: hostname "signature-documents-sqa.signature-documents-sqa.s3-us-west-2.amazonaws.com" does not match the server certificate (OpenSSL::SSL::SSLError)
from /Users/romeo/.rbenv/versions/2.5.1/lib/ruby/2.5.0/openssl/ssl.rb:394:in `post_connection_check'
Caused by OpenSSL::SSL::SSLError: hostname "signature-documents-sqa.signature-documents-sqa.s3-us-west-2.amazonaws.com" does not match the server certificate
from /Users/romeo/.rbenv/versions/2.5.1/lib/ruby/2.5.0/openssl/ssl.rb:394:in `post_connection_check'
Caused by Excon::Error::Socket: hostname "signature-documents-sqa.signature-documents-sqa.s3-us-west-2.amazonaws.com" does not match the server certificate (OpenSSL::SSL::SSLError)
from /Users/romeo/.rbenv/versions/2.5.1/lib/ruby/2.5.0/openssl/ssl.rb:394:in `post_connection_check'
Caused by OpenSSL::SSL::SSLError: hostname "signature-documents-sqa.signature-documents-sqa.s3-us-west-2.amazonaws.com" does not match the server certificate
from /Users/romeo/.rbenv/versions/2.5.1/lib/ruby/2.5.0/openssl/ssl.rb:394:in `post_connection_check'
Caused by Excon::Error::Socket: hostname "signature-documents-sqa.signature-documents-sqa.s3-us-west-2.amazonaws.com" does not match the server certificate (OpenSSL::SSL::SSLError)
from /Users/romeo/.rbenv/versions/2.5.1/lib/ruby/2.5.0/openssl/ssl.rb:394:in `post_connection_check'
Caused by OpenSSL::SSL::SSLError: hostname "signature-documents-sqa.signature-documents-sqa.s3-us-west-2.amazonaws.com" does not match the server certificate
from /Users/romeo/.rbenv/versions/2.5.1/lib/ruby/2.5.0/openssl/ssl.rb:394:in `post_connection_check'
Caused by Excon::Error::Socket: hostname "signature-documents-sqa.signature-documents-sqa.s3-us-west-2.amazonaws.com" does not match the server certificate (OpenSSL::SSL::SSLError)
from /Users/romeo/.rbenv/versions/2.5.1/lib/ruby/2.5.0/openssl/ssl.rb:394:in `post_connection_check'
Caused by OpenSSL::SSL::SSLError: hostname "signature-documents-sqa.signature-documents-sqa.s3-us-west-2.amazonaws.com" does not match the server certificate
from /Users/romeo/.rbenv/versions/2.5.1/lib/ruby/2.5.0/openssl/ssl.rb:394:in `post_connection_check'
Caused by Excon::Error::MovedPermanently: Expected(200) <=> Actual(301 Moved Permanently)

Complete Error Log

[fog][WARNING] fog: followed redirect to documents-staging.s3.us-west-1.amazonaws.com, connecting to the matching region will be more performant [fog][WARNING] fog: followed redirect to documents-staging.s3.us-west-1.amazonaws.com, connecting to the matching region will be more performant Excon::Error::Socket: hostname "documents-staging.documents-staging.s3-us-west-2.amazonaws.com" does not match the server certificate (OpenSSL::SSL::SSLError) from /Users/romeo/.rbenv/versions/2.5.1/lib/ruby/2.5.0/openssl/ssl.rb:394:in `post_connection_check' Caused by OpenSSL::SSL::SSLError: hostname "documents-staging.documents-staging.s3-us-west-2.amazonaws.com" does not match the server certificate from /Users/romeo/.rbenv/versions/2.5.1/lib/ruby/2.5.0/openssl/ssl.rb:394:in `post_connection_check' Caused by Excon::Error::Socket: hostname "documents-staging.documents-staging.s3-us-west-2.amazonaws.com" does not match the server certificate (OpenSSL::SSL::SSLError) from /Users/romeo/.rbenv/versions/2.5.1/lib/ruby/2.5.0/openssl/ssl.rb:394:in `post_connection_check' Caused by OpenSSL::SSL::SSLError: hostname "documents-staging.documents-staging.s3-us-west-2.amazonaws.com" does not match the server certificate from /Users/romeo/.rbenv/versions/2.5.1/lib/ruby/2.5.0/openssl/ssl.rb:394:in `post_connection_check' Caused by Excon::Error::Socket: hostname "documents-staging.documents-staging.s3-us-west-2.amazonaws.com" does not match the server certificate (OpenSSL::SSL::SSLError) from /Users/romeo/.rbenv/versions/2.5.1/lib/ruby/2.5.0/openssl/ssl.rb:394:in `post_connection_check' Caused by OpenSSL::SSL::SSLError: hostname "documents-staging.documents-staging.s3-us-west-2.amazonaws.com" does not match the server certificate from /Users/romeo/.rbenv/versions/2.5.1/lib/ruby/2.5.0/openssl/ssl.rb:394:in `post_connection_check' Caused by Excon::Error::Socket: hostname "documents-staging.documents-staging.s3-us-west-2.amazonaws.com" does not match the server certificate (OpenSSL::SSL::SSLError) from /Users/romeo/.rbenv/versions/2.5.1/lib/ruby/2.5.0/openssl/ssl.rb:394:in `post_connection_check' Caused by OpenSSL::SSL::SSLError: hostname "documents-staging.documents-staging.s3-us-west-2.amazonaws.com" does not match the server certificate from /Users/romeo/.rbenv/versions/2.5.1/lib/ruby/2.5.0/openssl/ssl.rb:394:in `post_connection_check' Caused by Excon::Error::MovedPermanently: Expected(200) <=> Actual(301 Moved Permanently) excon.error.response :body => "\nPermanentRedirectThe bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.documents-staging.s3-us-west-2.amazonaws.comdocuments-stagingx-amz-request-idx-amz-id-2" :cookies => [ ] :headers => { "Content-Type" => "application/xml" "Date" => "Tue, 09 Feb 2021 08:39:05 GMT" "Server" => "AmazonS3" "x-amz-bucket-region" => "us-west-2" "x-amz-id-2" => "x-amz-id-2" "x-amz-request-id" => "x-amz-request-id" } :host => "documents-staging.s3.us-west-1.amazonaws.com" :local_address => "192.168.1.10" :local_port => 49878 :path => "/" :port => 443 :reason_phrase => "Moved Permanently" :remote_ip => "52.219.116.97" :status => 301 :status_line => "HTTP/1.1 301 Moved Permanently\r\n"

from /Users/romeo/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/excon-0.76.0/lib/excon/middlewares/expects.rb:13:in `response_call'
Caused by Excon::Error::MovedPermanently: Expected(200) <=> Actual(301 Moved Permanently)
excon.error.response
:body => "\nPermanentRedirectThe bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.documents-staging.s3-us-west-2.amazonaws.comdocuments-stagingx-amz-request-idx-amz-id-2"
:cookies => [
]
:headers => {
"Content-Type" => "application/xml"
"Date" => "Tue, 09 Feb 2021 08:39:04 GMT"
"Server" => "AmazonS3"
"x-amz-bucket-region" => "us-west-2"
"x-amz-id-2" => "x-amz-id-2"
"x-amz-request-id" => "x-amz-request-id"
}
:host => "documents-staging.s3.us-west-1.amazonaws.com"
:local_address => "192.168.1.10"
:local_port => 49876
:path => "/"
:port => 443
:reason_phrase => "Moved Permanently"
:remote_ip => "52.219.116.97"
:status => 301
:status_line => "HTTP/1.1 301 Moved Permanently\r\n"

from /Users/romeo/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/excon-0.76.0/lib/excon/middlewares/expects.rb:13:in `response_call'
Caused by Excon::Error::MovedPermanently: Expected(200) <=> Actual(301 Moved Permanently)
excon.error.response
:body => "\nPermanentRedirectThe bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.documents-staging.s3-us-west-2.amazonaws.comdocuments-stagingx-amz-request-idx-amz-id-2"
:cookies => [
]
:headers => {
"Content-Type" => "application/xml"
"Date" => "Tue, 09 Feb 2021 08:39:03 GMT"
"Server" => "AmazonS3"
"x-amz-bucket-region" => "us-west-2"
"x-amz-id-2" => "x-amz-id-2"
"x-amz-request-id" => "x-amz-request-id"
}
:host => "documents-staging.s3.us-west-1.amazonaws.com"
:local_address => "192.168.1.10"
:local_port => 49873
:path => "/"
:port => 443
:reason_phrase => "Moved Permanently"
:remote_ip => "52.219.116.97"
:status => 301
:status_line => "HTTP/1.1 301 Moved Permanently\r\n"

from /Users/romeo/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/excon-0.76.0/lib/excon/middlewares/expects.rb:13:in `response_call'
Caused by Excon::Error::MovedPermanently: Expected(200) <=> Actual(301 Moved Permanently)
excon.error.response
:body => "\nPermanentRedirectThe bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.documents-staging.s3-us-west-2.amazonaws.comdocuments-stagingx-amz-request-idx-amz-id-2"
:cookies => [
]
:headers => {
"Content-Type" => "application/xml"
"Date" => "Tue, 09 Feb 2021 08:39:02 GMT"
"Server" => "AmazonS3"
"x-amz-bucket-region" => "us-west-2"
"x-amz-id-2" => "x-amz-id-2"
"x-amz-request-id" => "x-amz-request-id"
}
:host => "documents-staging.s3.us-west-1.amazonaws.com"
:local_address => "192.168.1.10"
:local_port => 49872
:path => "/"
:port => 443
:reason_phrase => "Moved Permanently"
:remote_ip => "52.219.116.97"
:status => 301
:status_line => "HTTP/1.1 301 Moved Permanently\r\n"

from /Users/romeo/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/excon-0.76.0/lib/excon/middlewares/expects.rb:13:in `response_call'