@@ -26,7 +26,6 @@ const {
2626
2727const HttpAgent = require ( 'agentkeepalive' ) ;
2828const QuotaService = require ( './utilization/instance' ) ;
29- const routes = arsenal . s3routes . routes ;
3029const { parseLC, MultipleBackendGateway } = arsenal . storage . data ;
3130const websiteEndpoints = _config . websiteEndpoints ;
3231let client = dataWrapper . client ;
@@ -62,9 +61,11 @@ class S3Server {
6261 /**
6362 * This represents our S3 connector.
6463 * @constructor
64+ * @param {Object } config - Configuration object
6565 * @param {Worker } [worker=null] - Track the worker when using cluster
6666 */
67- constructor ( worker ) {
67+ constructor ( config , worker ) {
68+ this . config = config ;
6869 this . worker = worker ;
6970 this . cluster = true ;
7071 this . servers = [ ] ;
@@ -93,11 +94,29 @@ class S3Server {
9394 this . started = false ;
9495 }
9596
97+ /**
98+ * Route requests on 'internal s3' port
99+ * Same as routeRequest, but ignoring user's bucket policy. This should be used only for
100+ * backbeat and other internal/system processes that must not be affected by user's bucket
101+ * policy.
102+ * Note that this is not a temporary measure: eventually this should be improved to better
103+ * identify and isolate internal/system calls vs user calls, so that "system" bucket policies
104+ * may be applied to system requests, and the existing "user" bucket policies apply only to
105+ * user requests.
106+ * @param {http.IncomingMessage } req - http request object
107+ * @param {http.ServerResponse } res - http response object
108+ * @returns {undefined }
109+ */
110+ internalRouteRequest ( req , res ) {
111+ req . bypassUserBucketPolicies = true ; // eslint-disable-line no-param-reassign
112+ return this . routeRequest ( req , res ) ;
113+ }
114+
96115 /**
97116 * Route requests on 's3' port
98117 * @param {http.IncomingMessage } req - http request object
99118 * @param {http.ServerResponse } res - http response object
100- * @returns {void }
119+ * @returns {undefined }
101120 */
102121 routeRequest ( req , res ) {
103122 monitoringClient . httpActiveRequests . inc ( ) ;
@@ -144,21 +163,21 @@ class S3Server {
144163 dataRetrievalParams : {
145164 client,
146165 implName,
147- config : _config ,
166+ config : this . config ,
148167 kms,
149168 metadata,
150169 locStorageCheckFn : locationStorageCheck ,
151170 vault,
152171 } ,
153172 } ;
154- routes ( req , res , params , logger , _config ) ;
173+ arsenal . s3routes . routes ( req , res , params , logger , this . config ) ;
155174 }
156175
157176 /**
158177 * Route requests on 'admin' port
159178 * @param {http.IncomingMessage } req - http request object
160179 * @param {http.ServerResponse } res - http response object
161- * @returns {void }
180+ * @returns {undefined }
162181 */
163182 routeAdminRequest ( req , res ) {
164183 // use proxied hostname if needed
@@ -205,16 +224,16 @@ class S3Server {
205224 * @param {http.RequestListener } listener - Callback to handle requests
206225 * @param {number } port - Port to listen on
207226 * @param {string | undefined } ipAddress - IpAddress to listen on
208- * @returns {void }
227+ * @returns {undefined }
209228 */
210229 _startServer ( listener , port , ipAddress ) {
211230 // Todo: http.globalAgent.maxSockets, http.globalAgent.maxFreeSockets
212231 let server ;
213- if ( _config . https ) {
232+ if ( this . config . https ) {
214233 server = https . createServer ( {
215- cert : _config . https . cert ,
216- key : _config . https . key ,
217- ca : _config . https . ca ,
234+ cert : this . config . https . cert ,
235+ key : this . config . https . key ,
236+ ca : this . config . https . ca ,
218237 ciphers : arsenal . https . ciphers . ciphers ,
219238 dhparam : arsenal . https . dhparam . dhparam ,
220239 rejectUnauthorized : true ,
@@ -305,21 +324,30 @@ class S3Server {
305324 }
306325
307326 // Start API server(s)
308- if ( _config . listenOn . length > 0 ) {
309- _config . listenOn . forEach ( item => {
327+ if ( this . config . listenOn . length > 0 ) {
328+ this . config . listenOn . forEach ( item => {
310329 this . _startServer ( this . routeRequest , item . port , item . ip ) ;
311330 } ) ;
312- } else {
313- this . _startServer ( this . routeRequest , _config . port ) ;
331+ } else if ( this . config . port ) {
332+ this . _startServer ( this . routeRequest , this . config . port ) ;
333+ }
334+
335+ // Start internal API server(s)
336+ if ( this . config . internalListenOn . length > 0 ) {
337+ this . config . internalListenOn . forEach ( item => {
338+ this . _startServer ( this . internalRouteRequest , item . port , item . ip ) ;
339+ } ) ;
340+ } else if ( this . config . internalPort ) {
341+ this . _startServer ( this . internalRouteRequest , this . config . internalPort ) ;
314342 }
315343
316344 // Start metrics server(s)
317- if ( _config . metricsListenOn . length > 0 ) {
318- _config . metricsListenOn . forEach ( item => {
345+ if ( this . config . metricsListenOn . length > 0 ) {
346+ this . config . metricsListenOn . forEach ( item => {
319347 this . _startServer ( this . routeAdminRequest , item . port , item . ip ) ;
320348 } ) ;
321349 } else {
322- this . _startServer ( this . routeAdminRequest , _config . metricsPort ) ;
350+ this . _startServer ( this . routeAdminRequest , this . config . metricsPort ) ;
323351 }
324352
325353 // Start quota service health checks
@@ -353,7 +381,7 @@ function main() {
353381 this . cluster = workers > 1 ;
354382 if ( ! this . cluster ) {
355383 process . env . REPORT_TOKEN = _config . reportToken ;
356- const server = new S3Server ( ) ;
384+ const server = new S3Server ( _config ) ;
357385 server . initiateStartup ( logger . newRequestLogger ( ) ) ;
358386 }
359387 if ( this . cluster && cluster . isMaster ) {
@@ -399,10 +427,11 @@ function main() {
399427 } ) ;
400428 }
401429 if ( this . cluster && cluster . isWorker ) {
402- const server = new S3Server ( cluster . worker ) ;
430+ const server = new S3Server ( _config , cluster . worker ) ;
403431 server . initiateStartup ( logger . newRequestLogger ( ) ) ;
404432 }
405433 monitoringClient . collectDefaultMetrics ( { timeout : 5000 } ) ;
406434}
407435
408436module . exports = main ;
437+ module . exports . S3Server = S3Server ;
0 commit comments