mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(s3): check a presigned copy's source read against its credential (#5891)
Under IAM enforcement, CopyObject and UploadPartCopy also need s3:GetObject on the copy source, or s3:GetObjectVersion for a version, and S3Controller checks it itself, since the source appears only in the x-amz-copy-source header. It passed IAM the Authorization header, which a presigned request does not have, so IAM skipped the check. A user allowed to write one place could presign a copy of any object they cannot read into it. The check now uses the request's credential, the header's or a presigned URL's query credential, as the copied-tags check next to it already does. The S3 user guide says "The capabilities of a presigned URL are limited by the permissions of the user who created it." The test signer's presignedQuery also signs the parameters already in its URI's query, such as an UploadPartCopy's upload id, so a presigned part copy verifies, and refuses a URI that is already presigned. docs/services/iam.md lists the copy source check.
This commit is contained in:
1 parent
63cf09a396
commit
377c09733a
5 files changed
+177
-10
No files matched your search
@@ -859,8 +859,8 @@ public class S3Controller {
|
||||
s3Service.authorizeObjectWrite(bucket, key, "s3:PutObject", authorization);
|
||||
int parsedPartNumber = PartRange.parseUploadPartNumber(partNumber);
|
||||
if (copySource != null && !copySource.isEmpty()) {
|
||||
return handleUploadPartCopy(
|
||||
copySource, bucket, key, uploadId, parsedPartNumber, httpHeaders, authorization);
|
||||
return handleUploadPartCopy(copySource, bucket, key, uploadId, parsedPartNumber,
|
||||
httpHeaders, uriInfo, authorization);
|
||||
}
|
||||
requireDeclaredSizeWithin(httpHeaders, contentEncoding, contentSha256, S3Service.MAX_PART_SIZE);
|
||||
Part part = s3Service.storePart(bucket, key, uploadId, parsedPartNumber,
|
||||
@@ -3067,7 +3067,7 @@ public class S3Controller {
|
||||
ObjectLockHeaders lock) {
|
||||
CopySourceRef sourceObject = parseCopySource(copySource);
|
||||
String sourceBucket = sourceObject.bucket();
|
||||
authorizeCopySourceRead(httpHeaders, sourceObject, authorization);
|
||||
authorizeCopySourceRead(httpHeaders, uriInfo, sourceObject, authorization);
|
||||
authorizeCopiedTags(httpHeaders, uriInfo, sourceObject, destBucket, destKey, authorization);
|
||||
String copyContentEncoding = toPersistedContentEncoding(httpHeaders.getHeaderString("Content-Encoding"));
|
||||
String copyContentDisposition = httpHeaders.getHeaderString("Content-Disposition");
|
||||
@@ -3155,10 +3155,10 @@ public class S3Controller {
|
||||
|
||||
private Response handleUploadPartCopy(String copySource, String destBucket, String destKey,
|
||||
String uploadId, int partNumber, HttpHeaders httpHeaders,
|
||||
S3Service.RequestAuthorization authorization) {
|
||||
UriInfo uriInfo, S3Service.RequestAuthorization authorization) {
|
||||
CopySourceRef sourceObject = parseCopySource(copySource);
|
||||
String sourceBucket = sourceObject.bucket();
|
||||
authorizeCopySourceRead(httpHeaders, sourceObject, authorization);
|
||||
authorizeCopySourceRead(httpHeaders, uriInfo, sourceObject, authorization);
|
||||
String copySourceRange = httpHeaders.getHeaderString("x-amz-copy-source-range");
|
||||
String eTag = s3Service.uploadPartCopy(destBucket, destKey, uploadId, partNumber,
|
||||
sourceBucket, sourceObject.objectKey(), sourceObject.versionId(), copySourceRange,
|
||||
@@ -4376,9 +4376,11 @@ public class S3Controller {
|
||||
* in the {@code x-amz-copy-source} header and is otherwise invisible to the request-level IAM filter
|
||||
* that authorizes the destination from the URL path. Real S3 requires both permissions: a caller
|
||||
* allowed to write to the destination bucket must not be able to exfiltrate an object it cannot read.
|
||||
* A no-op when IAM enforcement is disabled, matching {@link IamEnforcementFilter}'s own bypass rules.
|
||||
* IAM checks it against the request's credential, the header's or a presigned URL's, as the filter
|
||||
* checks the destination. A no-op when IAM enforcement is disabled, matching
|
||||
* {@link IamEnforcementFilter}'s own bypass rules.
|
||||
*/
|
||||
private void authorizeCopySourceRead(HttpHeaders httpHeaders, CopySourceRef source,
|
||||
private void authorizeCopySourceRead(HttpHeaders httpHeaders, UriInfo uriInfo, CopySourceRef source,
|
||||
S3Service.RequestAuthorization authorization) {
|
||||
String action = source.versionId() == null ? "s3:GetObject" : "s3:GetObjectVersion";
|
||||
String resource = S3PublicAccessEvaluator.objectArn(
|
||||
@@ -4386,8 +4388,7 @@ public class S3Controller {
|
||||
S3Service.SignedPrincipalResourcePolicyEvaluation resourcePolicyEvaluation =
|
||||
s3Service.signedPrincipalResourcePolicyDecision(
|
||||
source.bucket(), action, resource, authorization);
|
||||
iamEnforcementFilter.authorizeAdditionalResource(
|
||||
httpHeaders.getHeaderString("Authorization"), action, resource,
|
||||
iamEnforcementFilter.authorizeAdditionalResource(iamCredential(httpHeaders, uriInfo), action, resource,
|
||||
resourcePolicyEvaluation.decision(), resourcePolicyEvaluation.resourceOwnerAccountId());
|
||||
s3Service.authorizeGetObject(
|
||||
source.bucket(), source.objectKey(), source.versionId(), authorization);
|
||||
|
||||
Reference in new issue
Block a user