Skip to content

Commit

Permalink
chore(s3util): add allowFipsEndpoint option in validateArnRegion (#3962)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Nov 16, 2021
1 parent 8724023 commit e929589
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changes/next-release/feature-s3util-4a5bd10b.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "feature",
"category": "s3util",
"description": "Add allowFipsEndpoint option in validateArnRegion"
}
19 changes: 14 additions & 5 deletions lib/services/s3util.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,16 @@ var s3util = {
/**
* Validate region field in ARN supplied in Bucket parameter is a valid region
*/
validateArnRegion: function validateArnRegion(req) {
validateArnRegion: function validateArnRegion(req, options) {
if (options === undefined) {
options = {};
}

var useArnRegion = s3util.loadUseArnRegionConfig(req);
var regionFromArn = req._parsedArn.region;
var clientRegion = req.service.config.region;
var useFipsEndpoint = req.service.config.useFipsEndpoint;
var allowFipsEndpoint = options.allowFipsEndpoint || false;

if (!regionFromArn) {
throw AWS.util.error(new Error(), {
Expand All @@ -145,16 +150,20 @@ var s3util = {
});
}

if (
useFipsEndpoint ||
regionFromArn.indexOf('fips') >= 0
) {
if (useFipsEndpoint && !allowFipsEndpoint) {
throw AWS.util.error(new Error(), {
code: 'InvalidConfiguration',
message: 'ARN endpoint is not compatible with FIPS region'
});
}

if (regionFromArn.indexOf('fips') >= 0) {
throw AWS.util.error(new Error(), {
code: 'InvalidConfiguration',
message: 'FIPS region not allowed in ARN'
});
}

if (!useArnRegion && regionFromArn !== clientRegion) {
throw AWS.util.error(new Error(), {
code: 'InvalidConfiguration',
Expand Down

0 comments on commit e929589

Please sign in to comment.