CLDSRV-945: Support cross account rate limiting#6225
Open
tmacro wants to merge 6 commits into
Open
Conversation
Contributor
Hello tmacro,My role is to assist you with the merge of this Available options
Available commands
Status report is not available. |
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
View the full list of 1 ❄️ flaky test(s)
To view more test analytics, go to the Test Analytics Dashboard |
Contributor
Request integration branchesWaiting for integration branch creation to be requested by the user. To request integration branches, please comment on this pull request with the following command: Alternatively, the |
Comment on lines
253
to
-328
| @@ -279,172 +277,198 @@ function callApiHandler(apiMethod, apiHandler, request, response, log, callback) | |||
| return process.nextTick(callback, httpHeadersSizeError); | |||
| } | |||
|
|
|||
| const requestContexts = prepareRequestContexts(apiMethod, request, | |||
| sourceBucket, sourceObject, sourceVersionId); | |||
| const requestContexts = prepareRequestContexts(apiMethod, request, sourceBucket, sourceObject, sourceVersionId); | |||
|
|
|||
| // Extract all the _apiMethods and store them in an array | |||
| const apiMethods = requestContexts ? requestContexts.map(context => context._apiMethod) : []; | |||
| // Attach the names to the current request | |||
| request.apiMethods = apiMethods; | |||
|
|
|||
| return async.waterfall([ | |||
| next => auth.server.doAuth( | |||
| request, log, (err, userInfo, authorizationResults, streamingV4Params, infos) => { | |||
| if (request.serverAccessLog) { | |||
| request.serverAccessLog.authInfo = userInfo; | |||
| // If we have a cached bucket owner for the targeted bucket, pass it to | |||
| // Vault as a hint so the returned rate limit config is the target account. | |||
| // Only included when the cache has a hit. | |||
| const authOptions = {}; | |||
| if (request.bucketName) { | |||
| const cachedOwner = rateLimitCache.getCachedBucketOwner(request.bucketName); | |||
| if (cachedOwner) { | |||
| request.rateLimitTargetAccount = cachedOwner; | |||
| authOptions.targetAccount = cachedOwner; | |||
| } | |||
| } | |||
|
|
|||
| return async.waterfall( | |||
| [ | |||
| next => | |||
| auth.server.doAuth( | |||
| request, | |||
| log, | |||
| (err, userInfo, authorizationResults, streamingV4Params, infos) => { | |||
| if (request.serverAccessLog) { | |||
| request.serverAccessLog.authInfo = userInfo; | |||
| } | |||
| if (err) { | |||
| // VaultClient returns standard errors, but the route requires | |||
| // Arsenal errors | |||
| const arsenalError = err.metadata ? err : errors[err.code] || errors.InternalError; | |||
| log.trace('authentication error', { error: err }); | |||
| return next(arsenalError); | |||
| } | |||
| return next(null, userInfo, authorizationResults, streamingV4Params, infos); | |||
| }, | |||
| 's3', | |||
| requestContexts, | |||
| authOptions, | |||
| ), | |||
| (userInfo, authorizationResults, streamingV4Params, infos, next) => { | |||
| const authNames = { accountName: userInfo.getAccountDisplayName() }; | |||
| if (userInfo.isRequesterAnIAMUser()) { | |||
| authNames.userName = userInfo.getIAMdisplayName(); | |||
| } | |||
| if (err) { | |||
| // VaultClient returns standard errors, but the route requires | |||
| // Arsenal errors | |||
| const arsenalError = err.metadata ? err : errors[err.code] || errors.InternalError; | |||
| log.trace('authentication error', { error: err }); | |||
| return next(arsenalError); | |||
| if (isRequesterASessionUser(userInfo)) { | |||
| authNames.sessionName = userInfo.getShortid().split(':')[1]; | |||
| } | |||
| return next(null, userInfo, authorizationResults, streamingV4Params, infos); | |||
| }, 's3', requestContexts), | |||
| (userInfo, authorizationResults, streamingV4Params, infos, next) => { | |||
| const authNames = { accountName: userInfo.getAccountDisplayName() }; | |||
| if (userInfo.isRequesterAnIAMUser()) { | |||
| authNames.userName = userInfo.getIAMdisplayName(); | |||
| } | |||
| if (isRequesterASessionUser(userInfo)) { | |||
| authNames.sessionName = userInfo.getShortid().split(':')[1]; | |||
| } | |||
Comment on lines
+398
to
+412
| } | ||
| return next(null, userInfo, authResultsWithTags, streamingV4Params, infos); | ||
| }, | ||
| ), | ||
| (userInfo, authorizationResults, streamingV4Params, infos, next) => | ||
| handleAuthorizationResults( | ||
| request, | ||
| authorizationResults, | ||
| apiMethod, | ||
| returnTagCount, | ||
| log, | ||
| (err, res) => { | ||
| request.accountQuotas = infos?.accountQuota; | ||
| request.accountLimits = infos?.limits; | ||
| if (err) { |
Comment on lines
+413
to
+429
| return next(err); | ||
| } | ||
| returnTagCount = res.returnTagCount; | ||
| return next(null, userInfo, authorizationResults, streamingV4Params); | ||
| }, | ||
| ), | ||
| ], | ||
| (err, userInfo, authorizationResults, streamingV4Params) => { | ||
| if (err) { | ||
| return callback(err); | ||
| } | ||
| const methodCallback = (err, ...results) => | ||
| async.forEachLimit( | ||
| request.finalizerHooks, | ||
| 5, | ||
| (hook, done) => hook(err, done), | ||
| () => callback(err, ...results), |
| if (apiMethod === 'objectCopy' || apiMethod === 'objectPutCopyPart') { | ||
| return apiHandler(userInfo, request, sourceBucket, sourceObject, sourceVersionId, log, methodCallback); | ||
| } | ||
| if (apiMethod === 'objectGet') { |
| return process.nextTick(() => next(null, masterMD)); | ||
| async.waterfall( | ||
| [ | ||
| next => metadata.getObjectMD(bucketName, objectKey, {}, log, next), |
Comment on lines
+98
to
+113
| (masterMD, next) => { | ||
| if (masterMD.isNull || !masterMD.versionId) { | ||
| log.debug('null version is master version'); | ||
| return process.nextTick(() => next(null, masterMD)); | ||
| } | ||
| if (masterMD.nullVersionId) { | ||
| // the latest version is not the null version, but null version exists | ||
| // NOTE: for backward-compat with old null version scheme | ||
| log.debug('get the null version via nullVersionId'); | ||
| const getOptions = { | ||
| versionId: masterMD.nullVersionId, | ||
| }; | ||
| return metadata.getObjectMD(bucketName, objectKey, getOptions, log, next); | ||
| } | ||
| return next(errors.NoSuchKey); | ||
| }, |
Comment on lines
+366
to
+389
| next => { | ||
| // versionId may be 'null', which asks metadata to fetch the null key specifically | ||
| const getOptions = { versionId }; | ||
| if (getDeleteMarker) { | ||
| getOptions.getDeleteMarker = true; | ||
| } | ||
| return metadata.getBucketAndObjectMD( | ||
| bucketName, | ||
| objectKey, | ||
| getOptions, | ||
| log, | ||
| (err, getResult, raftSessionId) => { | ||
| if (err) { | ||
| // if some implicit iamAuthzResults, return AccessDenied | ||
| // before leaking any state information | ||
| if (actionImplicitDenies && Object.values(actionImplicitDenies).some(v => v === true)) { | ||
| return next(errors.AccessDenied); | ||
| } | ||
| return next(err); | ||
| } | ||
| return next(err); | ||
| return next(null, getResult, raftSessionId); | ||
| }, | ||
| ); | ||
| }, |
Comment on lines
+390
to
+419
| (getResult, raftSessionId, next) => { | ||
| const bucket = getResult.bucket ? BucketInfo.deSerialize(getResult.bucket) : undefined; | ||
| if (!bucket) { | ||
| log.debug('bucketAttrs is undefined', { | ||
| bucket: bucketName, | ||
| method: 'metadataValidateBucketAndObj', | ||
| }); | ||
| return next(errors.NoSuchBucket, raftSessionId); | ||
| } | ||
| const validationError = validateBucket(bucket, params, log, actionImplicitDenies); | ||
| if (validationError) { | ||
| return next(validationError, bucket, raftSessionId); | ||
| } | ||
|
|
||
| // Rate limiting check if not already done in api.js | ||
| return checkRateLimitIfNeeded(request, authInfo, bucket, log, err => { | ||
| if (err) { | ||
| return next(err, bucket); | ||
| } | ||
| return next(null, getResult, raftSessionId); | ||
| }); | ||
| }, | ||
| (getResult, raftSessionId, next) => { | ||
| const bucket = getResult.bucket ? | ||
| BucketInfo.deSerialize(getResult.bucket) : undefined; | ||
| if (!bucket) { | ||
| log.debug('bucketAttrs is undefined', { | ||
| bucket: bucketName, | ||
| method: 'metadataValidateBucketAndObj', | ||
| }); | ||
| return next(errors.NoSuchBucket, raftSessionId); | ||
| } | ||
| const validationError = validateBucket(bucket, params, log, actionImplicitDenies); | ||
| if (validationError) { | ||
| return next(validationError, bucket, raftSessionId); | ||
| } | ||
|
|
||
| // Rate limiting check if not already done in api.js | ||
| return checkRateLimitIfNeeded(request, authInfo, bucket, log, err => { | ||
| if (err) { | ||
| return next(err, bucket); | ||
| // Continue with object metadata processing | ||
| const objMD = getResult.obj ? JSON.parse(getResult.obj) : undefined; | ||
| if (!objMD && versionId === 'null') { | ||
| return getNullVersionFromMaster(bucketName, objectKey, log, (err, nullVer) => | ||
| next(err, bucket, nullVer, raftSessionId), | ||
| ); | ||
| } | ||
| return next(null, bucket, objMD, raftSessionId); | ||
| }); | ||
| }, |
Comment on lines
+420
to
+474
| (bucket, objMD, raftSessionId, next) => { | ||
| const objMetadata = objMD; | ||
| const canonicalID = authInfo.getCanonicalID(); | ||
| if ( | ||
| !isObjAuthorized( | ||
| bucket, | ||
| objMetadata, | ||
| requestType, | ||
| canonicalID, | ||
| authInfo, | ||
| log, | ||
| request, | ||
| actionImplicitDenies, | ||
| ) | ||
| ) { | ||
| log.debug('access denied for user on object', { requestType }); | ||
| return next(errors.AccessDenied, bucket, undefined, raftSessionId); | ||
| } | ||
|
|
||
| // Continue with object metadata processing | ||
| const objMD = getResult.obj ? JSON.parse(getResult.obj) : undefined; | ||
| if (!objMD && versionId === 'null') { | ||
| return getNullVersionFromMaster(bucketName, objectKey, log, | ||
| (err, nullVer) => next(err, bucket, nullVer, raftSessionId)); | ||
| if (!objMetadata) { | ||
| return next(null, bucket, objMetadata, raftSessionId); | ||
| } | ||
| return next(null, bucket, objMD, raftSessionId); | ||
| }); | ||
| }, | ||
| (bucket, objMD, raftSessionId, next) => { | ||
| const objMetadata = objMD; | ||
| const canonicalID = authInfo.getCanonicalID(); | ||
| if (!isObjAuthorized(bucket, objMetadata, requestType, canonicalID, authInfo, log, request, | ||
| actionImplicitDenies)) { | ||
| log.debug('access denied for user on object', { requestType }); | ||
| return next(errors.AccessDenied, bucket, undefined, raftSessionId); | ||
| } | ||
|
|
||
| if (!objMetadata) { | ||
| return next(null, bucket, objMetadata, raftSessionId); | ||
| } | ||
| let returnTagCount = false; | ||
| if (params.returnTagCount) { | ||
| // If returnTagCount is true we know that Vault authorized the request so it is not an implicitDeny. | ||
| const implicitDeny = false; | ||
| if (requestType.some(r => r === 'objectGet')) { | ||
| returnTagCount = isObjAuthorized( | ||
| bucket, | ||
| objMetadata, | ||
| ['objectGetTagging'], | ||
| canonicalID, | ||
| authInfo, | ||
| log, | ||
| request, | ||
| implicitDeny, | ||
| ); | ||
| } else if (requestType.some(r => r === 'objectGetVersion')) { | ||
| returnTagCount = isObjAuthorized( | ||
| bucket, | ||
| objMetadata, | ||
| ['objectGetTaggingVersion'], | ||
| canonicalID, | ||
| authInfo, | ||
| log, | ||
| request, | ||
| implicitDeny, | ||
| ); | ||
| } | ||
|
|
||
| let returnTagCount = false; | ||
| if (params.returnTagCount) { | ||
| // If returnTagCount is true we know that Vault authorized the request so it is not an implicitDeny. | ||
| const implicitDeny = false; | ||
| if (requestType.some(r => r === 'objectGet')) { | ||
| returnTagCount = isObjAuthorized(bucket, objMetadata, ['objectGetTagging'], canonicalID, authInfo, | ||
| log, request, implicitDeny); | ||
| } else if (requestType.some(r => r === 'objectGetVersion')) { | ||
| returnTagCount = isObjAuthorized(bucket, objMetadata, ['objectGetTaggingVersion'], | ||
| canonicalID, authInfo, log, request, implicitDeny); | ||
| objMetadata.returnTagCount = returnTagCount; | ||
| } | ||
|
|
||
| objMetadata.returnTagCount = returnTagCount; | ||
| } | ||
| return next(null, bucket, objMetadata, raftSessionId); | ||
| }, | ||
| (bucket, objMD, raftSessionId, next) => { | ||
| const needQuotaCheck = requestType => requestType.some(type => actionNeedQuotaCheck[type] || | ||
| actionWithDataDeletion[type]); | ||
| const checkQuota = params.checkQuota === undefined ? needQuotaCheck(requestType) : params.checkQuota; | ||
| // withVersionId cover cases when an object is being restored with a specific version ID. | ||
| // In this case, the storage space was already accounted for when the RestoreObject API call | ||
| // was made, so we don't need to add any inflight, but quota must be evaluated. | ||
| if (!checkQuota) { | ||
| return next(null, bucket, objMD, raftSessionId); | ||
| return next(null, bucket, objMetadata, raftSessionId); | ||
| }, |
Comment on lines
+475
to
+504
| (bucket, objMD, raftSessionId, next) => { | ||
| const needQuotaCheck = requestType => | ||
| requestType.some(type => actionNeedQuotaCheck[type] || actionWithDataDeletion[type]); | ||
| const checkQuota = params.checkQuota === undefined ? needQuotaCheck(requestType) : params.checkQuota; | ||
| // withVersionId cover cases when an object is being restored with a specific version ID. | ||
| // In this case, the storage space was already accounted for when the RestoreObject API call | ||
| // was made, so we don't need to add any inflight, but quota must be evaluated. | ||
| if (!checkQuota) { | ||
| return next(null, bucket, objMD, raftSessionId); | ||
| } | ||
| const contentLength = processBytesToWrite( | ||
| request.apiMethod, | ||
| bucket, | ||
| versionId, | ||
| request?.parsedContentLength || 0, | ||
| objMD, | ||
| params.destObjMD, | ||
| ); | ||
| return validateQuotas( | ||
| request, | ||
| bucket, | ||
| request.accountQuotas, | ||
| requestType, | ||
| request.apiMethod, | ||
| contentLength, | ||
| withVersionId, | ||
| log, | ||
| err => next(err, bucket, objMD, raftSessionId), | ||
| ); | ||
| }, |
tcarmet
approved these changes
Jul 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
targetAccountif it has been previously cached.targetAccountdiffers from the requesting account targetAccount's rate limit config is retrieved and returned in response