Obtaining Negative Validity When Using Fog AWS S3 & Rails

I am trying to create a signed url for a file in S3 using Fog ; however, the returned URL always returns a negative expiration, which forces the URL 400.

connection = Fog::Storage.new(
  region: 'us-west-1',
  provider: 'AWS',
  aws_access_key_id: ENV['AWS_ACCESS_KEY'],
  aws_secret_access_key: ENV['AWS_SECRET_KEY']
)
bucket = connection.directories.get(BUCKET)
file = 'test.jpg'
p file_url = bucket.files.get_https_url("uploads/#{file}", 300)

URL generated:

https://account.s3-us-west-x.amazonaws.com/files/test.doc?X-Amz-Expires=-1443648781&X-Amz-Date=20150930T213801Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AAAVA***FA/20150930/us-west-x/s3/aws4_request&X
-Amz-SignedHeaders=host&X-Amz-Signature=e31663f9b2470e***215825d585b14c37e

Am I missing something? Why does the generated url give me a negative ending ( X-Amz-Expires)?

+4
source share
2 answers

The argument expiresapparently expects an absolute expiration time in the unix epoch era ... not the number of seconds from now.

true, "300" "1970-01-01 00:05:00 UTC", , , 1443648781 , , URL.

, , AWS Signature V4, URL- ... AWS V2 , , , ... url... .

+3

:

# url that expires in 5 minutes
p file_url = bucket.files.get_https_url("uploads/#{file}", Time.now + (5 * 60))
0

Source: https://habr.com/ru/post/1609827/


All Articles