Skip to content

Commit 2c7892b

Browse files
Support FIPS endpoints, disable S3 Transfer Acceleration in GovCloud (#730)
* Support FIPS endpoints, disable S3 Transfer Acceleration in GovCloud The Fog::AWS::Utils region_to_host method returns the standard S3 endpoints even when ENV['AWS_USE_FIPS_ENDPOINT']=='true'. When FIPS is called for, and we are in a region where FIPS endpoints are available, this method should return the FIPS endpoint. Furthermore, when S3 Transfer Acceleration (S3TA) is requested by configuration, the above endpoint gets overridden to select the S3TA endpoint. However, S3TA is not avaialble in GovCloud, and has no FIPS endpoint equivalents. In this instance, if the region is a GovCloud region, or if FIPS mode is called for, do _not_ override the endpoint to use S3TA. * lint cleanups * disable S3TA and warn if in GovCloud or FIPS mode * Update lib/fog/aws/storage.rb Fix a typo in acceleration disable warning. --------- Co-authored-by: Wesley Beary <geemus@gmail.com>
1 parent db97091 commit 2c7892b

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

lib/fog/aws/storage.rb

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ class Storage < Fog::Service
77

88
DEFAULT_REGION = 'us-east-1'
99
ACCELERATION_HOST = 's3-accelerate.amazonaws.com'
10+
AWS_FIPS_REGIONS = %w(us-east-1 us-east-2 us-west-1 us-west-2 us-gov-east-1 us-gov-west-1 ca-central-1 ca-west-1).freeze
11+
AWS_GOVCLOUD_REGIONS = %w(us-gov-east-1 us-gov-west-1).freeze
1012

1113
DEFAULT_SCHEME = 'https'
1214
DEFAULT_SCHEME_PORT = {
@@ -258,13 +260,17 @@ def v2_signed_params_for_url(params, expires)
258260
end
259261

260262
def region_to_host(region=nil)
261-
case region.to_s
262-
when DEFAULT_REGION, ''
263-
's3.amazonaws.com'
264-
when %r{\Acn-.*}
265-
"s3.#{region}.amazonaws.com.cn"
263+
if ENV['AWS_USE_FIPS_ENDPOINT'] == 'true' && AWS_FIPS_REGIONS.include?(region)
264+
"s3-fips.#{region}.amazonaws.com" # https://aws.amazon.com/compliance/fips/
266265
else
267-
"s3.#{region}.amazonaws.com"
266+
case region.to_s
267+
when DEFAULT_REGION, ''
268+
's3.amazonaws.com'
269+
when %r{\Acn-.*}
270+
"s3.#{region}.amazonaws.com.cn"
271+
else
272+
"s3.#{region}.amazonaws.com"
273+
end
268274
end
269275
end
270276

@@ -578,6 +584,13 @@ def initialize(options={})
578584
@port = options[:port] || DEFAULT_SCHEME_PORT[@scheme]
579585
end
580586

587+
# GovCloud doesn't support S3 Transfer Acceleration https://docs.aws.amazon.com/govcloud-us/latest/UserGuide/govcloud-s3.html
588+
# S3 Transfer Acceleration doesn't support FIPS endpoints. When both fog_aws_accelerate=true and AWS_USE_FIPS_ENDPOINT=true, don't use Accelerate.
589+
if @acceleration && (AWS_GOVCLOUD_REGIONS.include?(@region) || ENV['AWS_USE_FIPS_ENDPOINT'] == 'true')
590+
Fog::Logger.warning("fog: S3 Transfer Acceleration is not available in GovCloud regions or when AWS_USE_FIPS_ENDPOINT=true. Disabling acceleration.")
591+
@acceleration = false
592+
end
593+
581594
@host = ACCELERATION_HOST if @acceleration
582595
setup_credentials(options)
583596
end

0 commit comments

Comments
 (0)