File tree Expand file tree Collapse file tree 5 files changed +57
-4
lines changed
Expand file tree Collapse file tree 5 files changed +57
-4
lines changed Original file line number Diff line number Diff line change 142142 },
143143 "kmip" : {
144144 "providerName" : " thales"
145+ },
146+ "apiBodySizeLimits" : {
147+ "multiObjectDelete" : 2097152 ,
148+ "bucketPutPolicy" : 20480
145149 }
146150}
Original file line number Diff line number Diff line change @@ -96,11 +96,14 @@ const constants = {
9696 oneMegaBytes : 1024 * 1024 ,
9797 halfMegaBytes : 512 * 1024 ,
9898
99- // Some apis may need a custom body length limit :
100- apisLengthLimits : {
99+ // Some apis may need a custom body length limit
100+ defaultApiBodySizeLimits : {
101101 // Multi Objects Delete request can be large : up to 1000 keys of 1024 bytes is
102102 // already 1mb, with the other fields it could reach 2mb
103103 'multiObjectDelete' : 2 * 1024 * 1024 ,
104+ // AWS sets the maximum size for bucket policies to 20 KB
105+ // https://docs.aws.amazon.com/AmazonS3/latest/userguide/add-bucket-policy.html
106+ 'bucketPutPolicy' : 20 * 1024 ,
104107 } ,
105108
106109 // hex digest of sha256 hash of empty string:
@@ -266,5 +269,4 @@ const constants = {
266269 onlyOwnerAllowed : [ 'bucketDeletePolicy' , 'bucketGetPolicy' , 'bucketPutPolicy' ] ,
267270} ;
268271
269-
270272module . exports = constants ;
Original file line number Diff line number Diff line change @@ -1730,6 +1730,21 @@ class Config extends EventEmitter {
17301730 }
17311731
17321732 this . supportedLifecycleRules = parseSupportedLifecycleRules ( config . supportedLifecycleRules ) ;
1733+
1734+ this . apiBodySizeLimits = { ...constants . defaultApiBodySizeLimits } ;
1735+ if ( config . apiBodySizeLimits ) {
1736+ assert ( typeof config . apiBodySizeLimits === 'object' &&
1737+ config . apiBodySizeLimits !== null &&
1738+ ! Array . isArray ( config . apiBodySizeLimits ) ,
1739+ 'bad config: apiBodySizeLimits must be an object' ) ;
1740+
1741+ for ( const [ apiKey , limit ] of Object . entries ( config . apiBodySizeLimits ) ) {
1742+ assert ( Number . isInteger ( limit ) && limit > 0 ,
1743+ `bad config: apiBodySizeLimits for "${ apiKey } " must be a positive integer` ) ;
1744+ this . apiBodySizeLimits [ apiKey ] = limit ;
1745+ }
1746+ }
1747+
17331748 return config ;
17341749 }
17351750
Original file line number Diff line number Diff line change @@ -75,6 +75,7 @@ const { tagConditionKeyAuth } = require('./apiUtils/authorization/tagConditionKe
7575const { isRequesterASessionUser } = require ( './apiUtils/authorization/permissionChecks' ) ;
7676const checkHttpHeadersSize = require ( './apiUtils/object/checkHttpHeadersSize' ) ;
7777const constants = require ( '../../constants' ) ;
78+ const { config } = require ( '../Config.js' ) ;
7879
7980const monitoringMap = policies . actionMaps . actionMonitoringMapS3 ;
8081
@@ -223,7 +224,7 @@ const api = {
223224
224225 const defaultMaxPostLength = request . method === 'POST' ?
225226 constants . oneMegaBytes : constants . halfMegaBytes ;
226- const MAX_POST_LENGTH = constants . apisLengthLimits [ apiMethod ] || defaultMaxPostLength ;
227+ const MAX_POST_LENGTH = config . apiBodySizeLimits [ apiMethod ] || defaultMaxPostLength ;
227228 const post = [ ] ;
228229 let postLength = 0 ;
229230 request . on ( 'data' , chunk => {
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ const {
1313const {
1414 LOCATION_NAME_DMF ,
1515} = require ( '../constants' ) ;
16+ const constants = require ( '../../constants' ) ;
1617
1718const { ValidLifecycleRules : supportedLifecycleRules } = require ( 'arsenal' ) . models ;
1819
@@ -893,4 +894,34 @@ describe('Config', () => {
893894 assert . strictEqual ( config . instanceId . length , 6 ) ;
894895 } ) ;
895896 } ) ;
897+
898+ describe ( 'apisLengthLimits configuration' , ( ) => {
899+ let sandbox ;
900+ let readFileStub ;
901+
902+ beforeEach ( ( ) => {
903+ sandbox = sinon . createSandbox ( ) ;
904+ readFileStub = sandbox . stub ( fs , 'readFileSync' ) ;
905+ readFileStub . callThrough ( ) ;
906+ } ) ;
907+
908+ afterEach ( ( ) => {
909+ sandbox . restore ( ) ;
910+ } ) ;
911+
912+ it ( 'should use default API and overwrite when config is provided' , ( ) => {
913+ const multiObjectDeleteSize = 42 ;
914+ const modifiedConfig = {
915+ ...defaultConfig ,
916+ apiBodySizeLimits : { 'multiObjectDelete' : multiObjectDeleteSize } ,
917+ } ;
918+ readFileStub . withArgs ( sinon . match ( / c o n f i g .j s o n $ / ) ) . returns ( JSON . stringify ( modifiedConfig ) ) ;
919+ const config = new ConfigObject ( ) ;
920+
921+ assert . deepStrictEqual ( config . apiBodySizeLimits , {
922+ 'multiObjectDelete' : multiObjectDeleteSize , // Configured: overwrites default
923+ 'bucketPutPolicy' : constants . defaultApiBodySizeLimits [ 'bucketPutPolicy' ] , // Not configured: default
924+ } ) ;
925+ } ) ;
926+ } ) ;
896927} ) ;
You can’t perform that action at this time.
0 commit comments