Skip to content

Commit d2ac2e3

Browse files
committed
Merge branches 'w/9.4/improvement/CLDSRV-945/support_cross_account_rate_limiting' and 'q/w/6225/9.3/improvement/CLDSRV-945/support_cross_account_rate_limiting' into tmp/octopus/q/9.4
3 parents e1c807e + 5d28d8c + dee4314 commit d2ac2e3

6 files changed

Lines changed: 563 additions & 231 deletions

File tree

lib/api/api.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ const {
9191
buildRateChecksFromConfig,
9292
checkRateLimitsForRequest,
9393
} = require('./apiUtils/rateLimit/helpers');
94+
const rateLimitCache = require('./apiUtils/rateLimit/cache');
9495

9596
const monitoringMap = policies.actionMaps.actionMonitoringMapS3;
9697

@@ -284,6 +285,18 @@ function callApiHandler(apiMethod, apiHandler, request, response, log, callback)
284285
// Attach the names to the current request
285286
request.apiMethods = apiMethods;
286287

288+
// If we have a cached bucket owner for the targeted bucket, pass it to
289+
// Vault as a hint so the returned rate limit config is the target account.
290+
// Only included when the cache has a hit.
291+
const authOptions = {};
292+
if (request.bucketName) {
293+
const cachedOwner = rateLimitCache.getCachedBucketOwner(request.bucketName);
294+
if (cachedOwner) {
295+
request.rateLimitTargetAccount = cachedOwner;
296+
authOptions.targetAccount = cachedOwner;
297+
}
298+
}
299+
287300
return async.waterfall(
288301
[
289302
next =>
@@ -305,6 +318,7 @@ function callApiHandler(apiMethod, apiHandler, request, response, log, callback)
305318
},
306319
's3',
307320
requestContexts,
321+
authOptions,
308322
),
309323
(userInfo, authorizationResults, streamingV4Params, infos, next) => {
310324
const authNames = { accountName: userInfo.getAccountDisplayName() };

0 commit comments

Comments
 (0)