Skip to content

Commit 48643d0

Browse files
author
Fabian Morgan
committed
fix delete-objects issue
1 parent fd45502 commit 48643d0

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

hadoop-ozone/dist/src/main/smoketest/security/ozone-secure-sts.robot

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,34 @@ STS session policy s3:* on * must allow ListAllMyBuckets, Create/ListBucket, and
12091209
${output} = Execute aws s3api --endpoint-url ${S3G_ENDPOINT_URL} delete-bucket --bucket ${bucket} --profile sts
12101210
Should Not Contain ${output} AccessDenied
12111211

1212+
STS session policy containing only GetObject must deny DeleteObjects
1213+
${bucket_suffix} = Generate Random String 8 [LOWER]
1214+
${bucket} = Set Variable sts-bucket-deleteobjects-${bucket_suffix}
1215+
${key_suffix} = Generate Random String 8 [LOWER]
1216+
${key} = Set Variable sts-deny-deleteobjects-${key_suffix}.txt
1217+
${local_path} = Set Variable ${TEMP_DIR}/${key}
1218+
Create File ${local_path} deleteobjects deny test content
1219+
1220+
# Create bucket and object with full STS temp-bucket role permissions.
1221+
Assume Role And Configure STS Profile perm_access_key_id=${PERMANENT_ACCESS_KEY_ID} perm_secret_key=${PERMANENT_SECRET_KEY} role_arn=${STS_TEMP_BUCKET_ROLE_ARN}
1222+
${output} = Execute aws s3api --endpoint-url ${S3G_ENDPOINT_URL} create-bucket --bucket ${bucket} --profile sts
1223+
Should Contain ${output} Location
1224+
${output} = Execute aws s3api --endpoint-url ${S3G_ENDPOINT_URL} put-object --bucket ${bucket} --key ${key} --body ${local_path} --profile sts
1225+
Should Contain ${output} "ETag"
1226+
1227+
# Restrict token to GetObject-only via session policy. DeleteObjects must return AccessDenied.
1228+
${session_policy} = Set Variable {"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":"s3:GetObject","Resource":"arn:aws:s3:::${bucket}/*"}]}
1229+
Assume Role And Configure STS Profile policy_json=${session_policy} perm_access_key_id=${PERMANENT_ACCESS_KEY_ID} perm_secret_key=${PERMANENT_SECRET_KEY} role_arn=${STS_TEMP_BUCKET_ROLE_ARN}
1230+
${output} = Execute And Ignore Error aws s3api --endpoint-url ${S3G_ENDPOINT_URL} delete-objects --bucket ${bucket} --delete 'Objects=[{Key=${key}}],Quiet=false' --profile sts
1231+
Run Keyword And Continue On Failure Should Contain ${output} AccessDenied
1232+
1233+
# Cleanup using a full-permission token.
1234+
Assume Role And Configure STS Profile perm_access_key_id=${PERMANENT_ACCESS_KEY_ID} perm_secret_key=${PERMANENT_SECRET_KEY} role_arn=${STS_TEMP_BUCKET_ROLE_ARN}
1235+
${output} = Execute aws s3api --endpoint-url ${S3G_ENDPOINT_URL} delete-object --bucket ${bucket} --key ${key} --profile sts
1236+
Should Not Contain ${output} AccessDenied
1237+
${output} = Execute aws s3api --endpoint-url ${S3G_ENDPOINT_URL} delete-bucket --bucket ${bucket} --profile sts
1238+
Should Not Contain ${output} AccessDenied
1239+
12121240
Revoking Permanent User Must Revoke Existing Session Token
12131241
# Create session tokens for both buckets, verify they work, then revoke permanent user secret and verify both fail.
12141242
Assume Role And Get Temporary Credentials perm_access_key_id=${PERMANENT_ACCESS_KEY_ID} perm_secret_key=${PERMANENT_SECRET_KEY} role_arn=${ICEBERG_ALL_ACCESS_ROLE_OBS_ARN}

hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import javax.ws.rs.core.MediaType;
4747
import javax.ws.rs.core.Response;
4848
import org.apache.commons.lang3.StringUtils;
49+
import org.apache.hadoop.hdds.scm.client.HddsClientUtils;
4950
import org.apache.hadoop.ozone.audit.AuditEventStatus;
5051
import org.apache.hadoop.ozone.audit.AuditMessage;
5152
import org.apache.hadoop.ozone.audit.S3GAction;
@@ -351,7 +352,14 @@ public MultiDeleteResponse multiDelete(
351352
throw newError(S3ErrorTable.MALFORMED_XML, bucketName);
352353
}
353354

354-
OzoneBucket bucket = getVolume().getBucket(bucketName);
355+
final OzoneBucket bucket;
356+
try {
357+
bucket = getVolume().getBucket(bucketName);
358+
} catch (OMException ex) {
359+
throw newError(bucketName, ex);
360+
} catch (IOException ex) {
361+
throw newError(S3ErrorTable.INTERNAL_ERROR, bucketName, ex);
362+
}
355363
MultiDeleteResponse result = new MultiDeleteResponse();
356364
List<String> deleteKeys = new ArrayList<>();
357365

@@ -380,8 +388,12 @@ public MultiDeleteResponse multiDelete(
380388
}
381389
getMetrics().updateDeleteKeySuccessStats(startNanos);
382390
} catch (IOException ex) {
383-
LOG.error("Delete key failed: {}", ex.getMessage());
384391
getMetrics().updateDeleteKeyFailureStats(startNanos);
392+
final OMException omEx = (OMException) HddsClientUtils.containsException(ex, OMException.class);
393+
if (omEx != null && S3ErrorTable.translateResultCode(omEx) == S3ErrorTable.ACCESS_DENIED) {
394+
throw newError(S3ErrorTable.ACCESS_DENIED, bucketName, omEx);
395+
}
396+
LOG.error("Delete key failed: {}", ex.getMessage());
385397
result.addError(
386398
new Error("ALL", "InternalError",
387399
ex.getMessage()));

0 commit comments

Comments
 (0)