This is an automated email from the ASF dual-hosted git repository.
smengcl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new b08b3803019 HDDS-17029. Add support for new ListObjectVersions api to
STS (#11572)
b08b3803019 is described below
commit b08b38030192d4b9b316e0422ed43bd4575647db
Author: fmorg-git <[email protected]>
AuthorDate: Sat Oct 17 00:35:58 2026 -0700
HDDS-17029. Add support for new ListObjectVersions api to STS (#11572)
---
.../security/acl/iam/IamSessionPolicyResolver.java | 32 ++--
.../acl/iam/TestIamSessionPolicyResolver.java | 203 +++++++++++++++++----
.../main/smoketest/security/ozone-secure-sts.robot | 32 ++++
.../org/apache/hadoop/ozone/audit/S3GAction.java | 1 +
.../hadoop/ozone/s3/endpoint/BucketEndpoint.java | 3 +
.../hadoop/ozone/s3/util/S3GActionIamMapper.java | 2 +
.../TestS3ActionOverrideForOwnerVerification.java | 87 +++++++++
.../ozone/s3/util/TestS3GActionIamMapper.java | 1 +
8 files changed, 307 insertions(+), 54 deletions(-)
diff --git
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/security/acl/iam/IamSessionPolicyResolver.java
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/security/acl/iam/IamSessionPolicyResolver.java
index 50ea6f3107a..bcb21f5510e 100644
---
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/security/acl/iam/IamSessionPolicyResolver.java
+++
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/security/acl/iam/IamSessionPolicyResolver.java
@@ -111,6 +111,10 @@ public final class IamSessionPolicyResolver {
@VisibleForTesting
static final Map<String, Set<S3Action>> S3_ACTION_MAP_CI =
buildCaseInsensitiveS3ActionMap();
+ // The actions that support s3:prefix condition
+ private static final Set<S3Action> PREFIX_CONDITION_ACTIONS =
Collections.unmodifiableSet(
+ EnumSet.of(S3Action.LIST_BUCKET, S3Action.LIST_BUCKET_VERSIONS));
+
private IamSessionPolicyResolver() {
}
@@ -170,9 +174,9 @@ public static Set<AssumeRoleRequest.OzoneGrant>
resolve(String policyJson, Strin
continue;
}
- // s3:prefix is only applicable to the ListBucket action because we
don't support ListBucketVersions
+ // s3:prefix is only applicable to the ListBucket and ListBucketVersions
actions
// (see
https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazons3.html
and search for
- // s3:prefix). If a statement carries a Condition, non-ListBucket
actions (ex GetObject, PutObject,
+ // s3:prefix). If a statement carries a Condition, non-listing actions
(ex GetObject, PutObject,
// ListBucketMultipartUploads, etc.) in that statement do not apply.
final Set<S3Action> filteredS3Actions =
filterActionsWhenConditionPresent(mappedS3Actions, condition);
if (filteredS3Actions.isEmpty()) {
@@ -530,20 +534,17 @@ static Set<S3Action>
mapPolicyActionsToS3Actions(Set<String> actions) {
}
/**
- * Filters out actions when a Condition is present if the action is not
ListBucket.
+ * Filters out actions when a Condition is present if the action does not
support s3:prefix.
*/
private static Set<S3Action> filterActionsWhenConditionPresent(Set<S3Action>
mappedS3Actions, Condition condition) {
if (condition == null) {
return mappedS3Actions;
}
- if (mappedS3Actions.contains(S3Action.LIST_BUCKET)) {
- final Set<S3Action> filteredActions = new HashSet<>();
- filteredActions.add(S3Action.LIST_BUCKET);
- return filteredActions;
- }
-
- return Collections.emptySet();
+ final Set<S3Action> filteredActions = EnumSet.noneOf(S3Action.class);
+ filteredActions.addAll(mappedS3Actions);
+ filteredActions.retainAll(PREFIX_CONDITION_ACTIONS);
+ return filteredActions;
}
/**
@@ -748,7 +749,7 @@ private static void processResourceTypeAny(String
volumeName, AuthorizerType aut
addAclsForObj(objToAclsMap, volumeObj, action.volumePerms);
addAclsForObj(objToAclsMap, bucketObj, action.bucketPerms);
- if (condition != null && action == S3Action.LIST_BUCKET) {
+ if (condition != null && PREFIX_CONDITION_ACTIONS.contains(action)) {
// Ensure the volume and bucket get the action
addActionForKind(objToActionsMap, action, volumeObj, bucketObj, null);
@@ -795,9 +796,9 @@ private static void processBucketResource(String
volumeName, Set<S3Action> mappe
addActionForKind(objToActionsMap, action, volumeObj, bucketObj, null);
}
- if (action == S3Action.LIST_BUCKET) {
+ if (PREFIX_CONDITION_ACTIONS.contains(action)) {
// If condition prefixes are present, these would constrain the object
permissions if the action
- // is s3:ListBucket
+ // is s3:ListBucket or s3:ListBucketVersions
if (condition != null && condition.prefixes != null &&
!condition.prefixes.isEmpty()) {
for (String prefix : condition.prefixes) {
// If operator is StringEquals, we should ignore any prefix
containing wildcards - this is AWS behavior
@@ -929,7 +930,7 @@ private static void addActionForKind(Map<IOzoneObj,
Set<String>> objToActionsMap
addActionForObj(objToActionsMap, bucketObj, action.name);
}
if (objectObj != null) {
- if (kind == ActionKind.OBJECT || action == S3Action.LIST_BUCKET) {
+ if (kind == ActionKind.OBJECT ||
PREFIX_CONDITION_ACTIONS.contains(action)) {
addActionForObj(objToActionsMap, objectObj, action.name);
}
}
@@ -1135,6 +1136,9 @@ enum S3Action {
EnumSet.noneOf(ACLType.class)),
// Used for HeadBucket, ListObjects and ListObjectsV2 apis
LIST_BUCKET("s3:ListBucket", ActionKind.BUCKET, EnumSet.of(READ),
EnumSet.of(READ, LIST), EnumSet.of(READ)),
+ // Used for ListObjectVersions API
+ LIST_BUCKET_VERSIONS("s3:ListBucketVersions", ActionKind.BUCKET,
EnumSet.of(READ),
+ EnumSet.of(READ, LIST), EnumSet.of(READ)),
// Used for ListMultipartUploads API
LIST_BUCKET_MULTIPART_UPLOADS("s3:ListBucketMultipartUploads",
ActionKind.BUCKET, EnumSet.of(READ),
EnumSet.of(READ, LIST), EnumSet.noneOf(ACLType.class)),
diff --git
a/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/security/acl/iam/TestIamSessionPolicyResolver.java
b/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/security/acl/iam/TestIamSessionPolicyResolver.java
index 4b32cab1d73..054c9205256 100644
---
a/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/security/acl/iam/TestIamSessionPolicyResolver.java
+++
b/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/security/acl/iam/TestIamSessionPolicyResolver.java
@@ -45,6 +45,7 @@
import static
org.apache.hadoop.ozone.security.acl.iam.IamSessionPolicyResolver.S3Action.LIST_ALL_MY_BUCKETS;
import static
org.apache.hadoop.ozone.security.acl.iam.IamSessionPolicyResolver.S3Action.LIST_BUCKET;
import static
org.apache.hadoop.ozone.security.acl.iam.IamSessionPolicyResolver.S3Action.LIST_BUCKET_MULTIPART_UPLOADS;
+import static
org.apache.hadoop.ozone.security.acl.iam.IamSessionPolicyResolver.S3Action.LIST_BUCKET_VERSIONS;
import static
org.apache.hadoop.ozone.security.acl.iam.IamSessionPolicyResolver.S3Action.LIST_MULTIPART_UPLOAD_PARTS;
import static
org.apache.hadoop.ozone.security.acl.iam.IamSessionPolicyResolver.S3Action.PUT_BUCKET_ACL;
import static
org.apache.hadoop.ozone.security.acl.iam.IamSessionPolicyResolver.S3Action.PUT_BUCKET_LIFECYCLE;
@@ -87,7 +88,8 @@ public class TestIamSessionPolicyResolver {
private static final Set<String> ALL_BUCKET_ACTIONS = strSet(
"CreateBucket", "DeleteBucket", "GetBucketAcl", "GetBucketTagging",
"GetLifecycleConfiguration", "ListBucket",
- "ListBucketMultipartUploads", "PutBucketAcl", "PutBucketTagging",
"PutLifecycleConfiguration");
+ "ListBucketMultipartUploads", "ListBucketVersions", "PutBucketAcl",
"PutBucketTagging",
+ "PutLifecycleConfiguration");
private static final Set<String> ALL_BUCKET_ACTIONS_WITH_LIST_ALL_MY_BUCKETS;
@@ -113,6 +115,14 @@ public class TestIamSessionPolicyResolver {
ALL_OBJECT_ACTIONS_WITH_LIST_BUCKET = Collections.unmodifiableSet(tempSet);
}
+ private static final Set<String> ALL_OBJECT_ACTIONS_WITH_LIST_BUCKET_ACTIONS;
+
+ static {
+ final Set<String> tempSet = new
HashSet<>(ALL_OBJECT_ACTIONS_WITH_LIST_BUCKET);
+ tempSet.add("ListBucketVersions");
+ ALL_OBJECT_ACTIONS_WITH_LIST_BUCKET_ACTIONS =
Collections.unmodifiableSet(tempSet);
+ }
+
@Test
public void testUnsupportedConditionOperatorThrows() {
final String json = "{\n" +
@@ -815,7 +825,8 @@ public void testBuildCaseInsensitiveS3ActionMap() {
// Verify s3:List* contains List actions
final Set<S3Action> listActions =
caseInsensitiveS3ActionMap.get("s3:list*");
assertThat(listActions).containsOnly(
- LIST_BUCKET, LIST_ALL_MY_BUCKETS, LIST_BUCKET_MULTIPART_UPLOADS,
LIST_MULTIPART_UPLOAD_PARTS);
+ LIST_BUCKET, LIST_BUCKET_VERSIONS, LIST_ALL_MY_BUCKETS,
LIST_BUCKET_MULTIPART_UPLOADS,
+ LIST_MULTIPART_UPLOAD_PARTS);
// Verify s3:Delete* contains Delete actions
final Set<S3Action> deleteActions =
caseInsensitiveS3ActionMap.get("s3:delete*");
@@ -859,6 +870,15 @@ public void
testMapPolicyActionsToS3ActionsWithSingleActionMapsCorrectly() {
final Set<S3Action> listBucketCi =
mapPolicyActionsToS3Actions(Collections.singleton("S3:ListBuCKet"));
assertThat(listBucketCi).containsOnly(LIST_BUCKET);
+ final Set<S3Action> listBucketVersions = mapPolicyActionsToS3Actions(
+ Collections.singleton("s3:ListBucketVersions"));
+ assertThat(listBucketVersions).containsOnly(LIST_BUCKET_VERSIONS);
+
+ // Ensure case-insensitive action works
+ final Set<S3Action> listBucketVersionsCi = mapPolicyActionsToS3Actions(
+ Collections.singleton("S3:LISTBUCKETVERSIONS"));
+ assertThat(listBucketVersionsCi).containsOnly(LIST_BUCKET_VERSIONS);
+
final Set<S3Action> deleteObject =
mapPolicyActionsToS3Actions(Collections.singleton("s3:DeleteObject"));
assertThat(deleteObject).containsOnly(DELETE_OBJECT);
@@ -1633,7 +1653,7 @@ public void
testCreatePathsAndPermissionsWithAllConcreteS3Actions() {
new OzoneGrant(
objSet(bucket("bucket2")), acls(READ, LIST, CREATE, DELETE,
READ_ACL, WRITE_ACL, WRITE),
ALL_BUCKET_ACTIONS),
- new OzoneGrant(objSet(prefix("bucket2", "")), acls(READ),
strSet("ListBucket")));
+ new OzoneGrant(objSet(prefix("bucket2", "")), acls(READ),
strSet("ListBucket", "ListBucketVersions")));
final Map<IOzoneObj, Set<ACLType>> objToAclsMapRanger = new
LinkedHashMap<>();
final Map<IOzoneObj, Set<String>> objToActionsMapRanger = new
LinkedHashMap<>();
@@ -1646,7 +1666,7 @@ public void
testCreatePathsAndPermissionsWithAllConcreteS3Actions() {
new OzoneGrant(
objSet(bucket("bucket2")), acls(READ, LIST, CREATE, DELETE,
READ_ACL, WRITE_ACL, WRITE),
ALL_BUCKET_ACTIONS),
- new OzoneGrant(objSet(key("bucket2", "*")), acls(READ),
strSet("ListBucket")));
+ new OzoneGrant(objSet(key("bucket2", "*")), acls(READ),
strSet("ListBucket", "ListBucketVersions")));
}
@@ -1834,18 +1854,20 @@ public void
testDeduplicatesAcrossMultipleStatementsWhenAllActionPresent() throw
// Ensure what we got is what we expected
final Set<OzoneGrant> expectedResolvedNative = new LinkedHashSet<>();
- // Expected for native: bucket union of supported bucket ACLs; volume
READ; prefix "" READ (from ListBucket)
+ // Expected for native: bucket union of supported bucket ACLs; volume
READ; prefix "" READ from list actions
final Set<IOzoneObj> bucketSet = objSet(bucket("my-bucket"));
final Set<ACLType> bucketAcls = acls(READ, LIST, CREATE, DELETE, READ_ACL,
WRITE_ACL, WRITE);
expectedResolvedNative.add(new OzoneGrant(bucketSet, bucketAcls,
ALL_BUCKET_ACTIONS));
- expectedResolvedNative.add(new OzoneGrant(objSet(prefix("my-bucket", "")),
acls(READ), strSet("ListBucket")));
+ expectedResolvedNative.add(
+ new OzoneGrant(objSet(prefix("my-bucket", "")), acls(READ),
strSet("ListBucket", "ListBucketVersions")));
expectedResolvedNative.add(new OzoneGrant(objSet(volume()), acls(READ),
ALL_BUCKET_ACTIONS));
assertThat(resolvedFromNativeAuthorizer).isEqualTo(expectedResolvedNative);
final Set<OzoneGrant> expectedResolvedRanger = new LinkedHashSet<>();
- // Expected for Ranger: bucket union of supported bucket ACLs; volume
READ; key "*" READ (from ListBucket)
+ // Expected for Ranger: bucket union of supported bucket ACLs; volume
READ; key "*" READ from list actions
expectedResolvedRanger.add(new OzoneGrant(bucketSet, bucketAcls,
ALL_BUCKET_ACTIONS));
- expectedResolvedRanger.add(new OzoneGrant(objSet(key("my-bucket", "*")),
acls(READ), strSet("ListBucket")));
+ expectedResolvedRanger.add(
+ new OzoneGrant(objSet(key("my-bucket", "*")), acls(READ),
strSet("ListBucket", "ListBucketVersions")));
expectedResolvedRanger.add(new OzoneGrant(objSet(volume()), acls(READ),
ALL_BUCKET_ACTIONS));
assertThat(resolvedFromRangerAuthorizer).isEqualTo(expectedResolvedRanger);
}
@@ -1926,8 +1948,8 @@ public void testAllActionsForKeyWithPrefixCondition()
throws OMException {
final Set<OzoneGrant> resolvedFromNativeAuthorizer = resolve(json, VOLUME,
NATIVE);
final Set<OzoneGrant> resolvedFromRangerAuthorizer = resolve(json, VOLUME,
RANGER);
- // Ensure what we got is what we expected - only ListBucket supports
s3:prefix and that is a bucket action,
- // not object action
+ // Ensure what we got is what we expected - ListBucket and
ListBucketVersions support s3:prefix as bucket
+ // actions, not object actions
assertThat(resolvedFromNativeAuthorizer).isEmpty();
assertThat(resolvedFromRangerAuthorizer).isEmpty();
}
@@ -1947,18 +1969,20 @@ public void testAllActionsForBucket() throws
OMException {
// Ensure what we got is what we expected
final Set<OzoneGrant> expectedResolvedNative = new LinkedHashSet<>();
- // Expected for native: union of supported bucket ACLs for bucket; volume
READ; prefix "" READ (from ListBucket)
+ // Expected for native: union of supported bucket ACLs for bucket; volume
READ; prefix "" READ from list actions
final Set<IOzoneObj> bucketSet = objSet(bucket("my-bucket"));
final Set<ACLType> allBucketAcls = acls(READ, LIST, CREATE, DELETE,
READ_ACL, WRITE_ACL, WRITE);
expectedResolvedNative.add(new OzoneGrant(bucketSet, allBucketAcls,
ALL_BUCKET_ACTIONS));
- expectedResolvedNative.add(new OzoneGrant(objSet(prefix("my-bucket", "")),
acls(READ), strSet("ListBucket")));
+ expectedResolvedNative.add(
+ new OzoneGrant(objSet(prefix("my-bucket", "")), acls(READ),
strSet("ListBucket", "ListBucketVersions")));
expectedResolvedNative.add(new OzoneGrant(objSet(volume()), acls(READ),
ALL_BUCKET_ACTIONS));
assertThat(resolvedFromNativeAuthorizer).isEqualTo(expectedResolvedNative);
- // Expected for Ranger: union of supported bucket ACLs for bucket; volume
READ; key "*" READ (from ListBucket)
+ // Expected for Ranger: union of supported bucket ACLs for bucket; volume
READ; key "*" READ from list actions
final Set<OzoneGrant> expectedResolvedRanger = new LinkedHashSet<>();
expectedResolvedRanger.add(new OzoneGrant(bucketSet, allBucketAcls,
ALL_BUCKET_ACTIONS));
- expectedResolvedRanger.add(new OzoneGrant(objSet(key("my-bucket", "*")),
acls(READ), strSet("ListBucket")));
+ expectedResolvedRanger.add(
+ new OzoneGrant(objSet(key("my-bucket", "*")), acls(READ),
strSet("ListBucket", "ListBucketVersions")));
expectedResolvedRanger.add(new OzoneGrant(objSet(volume()), acls(READ),
ALL_BUCKET_ACTIONS));
assertThat(resolvedFromRangerAuthorizer).isEqualTo(expectedResolvedRanger);
}
@@ -1983,25 +2007,26 @@ public void
testAllActionsForBucketWithPrefixCondition() throws OMException {
// Ensure what we got is what we expected
final Set<OzoneGrant> expectedResolvedNative = new LinkedHashSet<>();
- // Expected for native: READ, LIST ACLs for bucket (only ListBucket
supports s3:prefix); volume READ;
- // prefix "team/folder", "team/folder/" READ
+ // Expected for native: READ, LIST ACLs for bucket (ListBucket and
ListBucketVersions support s3:prefix);
+ // volume READ; prefix "team/folder", "team/folder/" READ
final Set<IOzoneObj> bucketSet = objSet(bucket("my-bucket"));
final Set<ACLType> bucketAcls = acls(READ, LIST);
expectedResolvedNative.add(
new OzoneGrant(
objSet(volume(), prefix("my-bucket", "team/folder"),
- prefix("my-bucket", "team/folder/")), acls(READ),
strSet("ListBucket")));
- expectedResolvedNative.add(new OzoneGrant(bucketSet, bucketAcls,
strSet("ListBucket")));
+ prefix("my-bucket", "team/folder/")), acls(READ),
+ strSet("ListBucket", "ListBucketVersions")));
+ expectedResolvedNative.add(new OzoneGrant(bucketSet, bucketAcls,
strSet("ListBucket", "ListBucketVersions")));
assertThat(resolvedFromNativeAuthorizer).isEqualTo(expectedResolvedNative);
- // Expected for Ranger: READ, LIST ACLs for bucket (only ListBucket
supports s3:prefix); volume READ,
- // key "team/folder", "team/folder/*" READ
+ // Expected for Ranger: READ, LIST ACLs for bucket (ListBucket and
ListBucketVersions support s3:prefix);
+ // volume READ, key "team/folder", "team/folder/*" READ
final Set<OzoneGrant> expectedResolvedRanger = new LinkedHashSet<>();
expectedResolvedRanger.add(
new OzoneGrant(
objSet(volume(), key("my-bucket", "team/folder"), key("my-bucket",
"team/folder/*")),
- acls(READ), strSet("ListBucket")));
- expectedResolvedRanger.add(new OzoneGrant(bucketSet, bucketAcls,
strSet("ListBucket")));
+ acls(READ), strSet("ListBucket", "ListBucketVersions")));
+ expectedResolvedRanger.add(new OzoneGrant(bucketSet, bucketAcls,
strSet("ListBucket", "ListBucketVersions")));
assertThat(resolvedFromRangerAuthorizer).isEqualTo(expectedResolvedRanger);
}
@@ -2086,7 +2111,8 @@ public void testMultipleResourcesInOneStatement() throws
OMException {
bucketSet, acls(READ, LIST, CREATE, DELETE, READ_ACL, WRITE_ACL,
WRITE), ALL_BUCKET_AND_OBJECT_ACTIONS));
expectedResolvedNative.add(
new OzoneGrant(
- objSet(prefix("my-bucket", "")), acls(READ, CREATE, WRITE,
DELETE), ALL_OBJECT_ACTIONS_WITH_LIST_BUCKET));
+ objSet(prefix("my-bucket", "")), acls(READ, CREATE, WRITE, DELETE),
+ ALL_OBJECT_ACTIONS_WITH_LIST_BUCKET_ACTIONS));
expectedResolvedNative.add(new OzoneGrant(objSet(volume()), acls(READ),
ALL_BUCKET_AND_OBJECT_ACTIONS));
assertThat(resolvedFromNativeAuthorizer).isEqualTo(expectedResolvedNative);
@@ -2097,7 +2123,8 @@ public void testMultipleResourcesInOneStatement() throws
OMException {
bucketSet, acls(READ, LIST, CREATE, DELETE, READ_ACL, WRITE_ACL,
WRITE), ALL_BUCKET_AND_OBJECT_ACTIONS));
expectedResolvedRanger.add(
new OzoneGrant(
- objSet(key("my-bucket", "*")), acls(READ, CREATE, WRITE, DELETE),
ALL_OBJECT_ACTIONS_WITH_LIST_BUCKET));
+ objSet(key("my-bucket", "*")), acls(READ, CREATE, WRITE, DELETE),
+ ALL_OBJECT_ACTIONS_WITH_LIST_BUCKET_ACTIONS));
expectedResolvedRanger.add(new OzoneGrant(objSet(volume()), acls(READ),
ALL_BUCKET_AND_OBJECT_ACTIONS));
assertThat(resolvedFromRangerAuthorizer).isEqualTo(expectedResolvedRanger);
}
@@ -2243,6 +2270,90 @@ public void testListBucketOperationsWithNoPrefixes()
throws OMException {
assertThat(resolvedFromRangerAuthorizer).isEqualTo(expectedResolvedRanger);
}
+ @Test
+ public void testListBucketVersionsWithNoPrefixes() throws OMException {
+ final String json = "{\n" +
+ " \"Statement\": [{\n" +
+ " \"Effect\": \"Allow\",\n" +
+ " \"Action\": \"s3:ListBucketVersions\",\n" +
+ " \"Resource\": \"arn:aws:s3:::proj\"\n" +
+ " }]\n" +
+ "}";
+
+ final Set<OzoneGrant> resolvedFromNativeAuthorizer = resolve(json, VOLUME,
NATIVE);
+ final Set<OzoneGrant> resolvedFromRangerAuthorizer = resolve(json, VOLUME,
RANGER);
+ final Set<IOzoneObj> bucketSet = objSet(bucket("proj"));
+ final Set<ACLType> bucketAcls = acls(READ, LIST);
+ final Set<String> actions = strSet("ListBucketVersions");
+
+ assertThat(resolvedFromNativeAuthorizer).containsExactlyInAnyOrder(
+ new OzoneGrant(bucketSet, bucketAcls, actions),
+ new OzoneGrant(objSet(volume(), prefix("proj", "")), acls(READ),
actions));
+ assertThat(resolvedFromRangerAuthorizer).containsExactlyInAnyOrder(
+ new OzoneGrant(bucketSet, bucketAcls, actions),
+ new OzoneGrant(objSet(volume(), key("proj", "*")), acls(READ),
actions));
+ }
+
+ @Test
+ public void testListBucketVersionsWithStringEqualsPrefixCondition() throws
OMException {
+ final String json = "{\n" +
+ " \"Statement\": [{\n" +
+ " \"Effect\": \"Allow\",\n" +
+ " \"Action\": \"s3:ListBucketVersions\",\n" +
+ " \"Resource\": \"arn:aws:s3:::proj\",\n" +
+ " \"Condition\": {\n" +
+ " \"StringEquals\": {\n" +
+ " \"s3:prefix\": [\"team/folder\", \"team/folder/*\"]\n" +
+ " }\n" +
+ " }\n" +
+ " }]\n" +
+ "}";
+
+ final Set<OzoneGrant> resolvedFromNativeAuthorizer = resolve(json, VOLUME,
NATIVE);
+ final Set<OzoneGrant> resolvedFromRangerAuthorizer = resolve(json, VOLUME,
RANGER);
+ final Set<ACLType> bucketAcls = acls(READ, LIST);
+ final Set<String> actions = strSet("ListBucketVersions");
+
+ assertThat(resolvedFromNativeAuthorizer).containsExactlyInAnyOrder(
+ new OzoneGrant(objSet(volume(), prefix("proj", "team/folder")),
acls(READ), actions),
+ new OzoneGrant(objSet(bucket("proj")), bucketAcls, actions));
+ assertThat(resolvedFromRangerAuthorizer).containsExactlyInAnyOrder(
+ new OzoneGrant(objSet(volume(), key("proj", "team/folder")),
acls(READ), actions),
+ new OzoneGrant(objSet(bucket("proj")), bucketAcls, actions));
+ }
+
+ @Test
+ public void testListBucketVersionsWithStringLikePrefixCondition() throws
OMException {
+ final String json = "{\n" +
+ " \"Statement\": [{\n" +
+ " \"Effect\": \"Allow\",\n" +
+ " \"Action\": \"s3:ListBucketVersions\",\n" +
+ " \"Resource\": \"arn:aws:s3:::proj\",\n" +
+ " \"Condition\": {\n" +
+ " \"StringLike\": {\n" +
+ " \"s3:prefix\": [\"team/folder\", \"team/folder/*\"]\n" +
+ " }\n" +
+ " }\n" +
+ " }]\n" +
+ "}";
+
+ final Set<OzoneGrant> resolvedFromNativeAuthorizer = resolve(json, VOLUME,
NATIVE);
+ final Set<OzoneGrant> resolvedFromRangerAuthorizer = resolve(json, VOLUME,
RANGER);
+ final Set<ACLType> bucketAcls = acls(READ, LIST);
+ final Set<String> actions = strSet("ListBucketVersions");
+
+ assertThat(resolvedFromNativeAuthorizer).containsExactlyInAnyOrder(
+ new OzoneGrant(
+ objSet(volume(), prefix("proj", "team/folder"), prefix("proj",
"team/folder/")),
+ acls(READ), actions),
+ new OzoneGrant(objSet(bucket("proj")), bucketAcls, actions));
+ assertThat(resolvedFromRangerAuthorizer).containsExactlyInAnyOrder(
+ new OzoneGrant(
+ objSet(volume(), key("proj", "team/folder"), key("proj",
"team/folder/*")),
+ acls(READ), actions),
+ new OzoneGrant(objSet(bucket("proj")), bucketAcls, actions));
+ }
+
@Test
public void testIgnoresUnsupportedActionsWhenSupportedActionsAreIncluded()
throws OMException {
final String json = "{\n" +
@@ -2257,6 +2368,7 @@ public void
testIgnoresUnsupportedActionsWhenSupportedActionsAreIncluded() throw
" \"s3:GetObject\",\n" + // object-level
action not applied for bucket
" \"s3:GetObjectAcl\",\n" + // unsupported
action
" \"s3:ListBucket\",\n" +
+ " \"s3:ListBucketVersions\",\n" +
" \"s3:ListBucketMultipartUploads\"\n" + // ignored because
it doesn't support s3:prefix condition
" ],\n" +
" \"Resource\": \"arn:aws:s3:::bucket1\",\n" +
@@ -2278,20 +2390,20 @@ public void
testIgnoresUnsupportedActionsWhenSupportedActionsAreIncluded() throw
// Expected for native: READ, LIST bucket acls; volume and prefixes
"team/folder", "team/folder/" READ
final Set<IOzoneObj> bucketSet = objSet(bucket("bucket1"));
final Set<ACLType> bucketAcls = acls(READ, LIST);
- expectedResolvedNative.add(new OzoneGrant(bucketSet, bucketAcls,
strSet("ListBucket")));
+ expectedResolvedNative.add(new OzoneGrant(bucketSet, bucketAcls,
strSet("ListBucket", "ListBucketVersions")));
expectedResolvedNative.add(
new OzoneGrant(
objSet(volume(), prefix("bucket1", "team/folder"),
prefix("bucket1", "team/folder/")),
- acls(READ), strSet("ListBucket")));
+ acls(READ), strSet("ListBucket", "ListBucketVersions")));
assertThat(resolvedFromNativeAuthorizer).isEqualTo(expectedResolvedNative);
final Set<OzoneGrant> expectedResolvedRanger = new LinkedHashSet<>();
// Expected for Ranger: READ, LIST bucket acls; volume and keys
"team/folder" and "team/folder/*" READ
- expectedResolvedRanger.add(new OzoneGrant(bucketSet, bucketAcls,
strSet("ListBucket")));
+ expectedResolvedRanger.add(new OzoneGrant(bucketSet, bucketAcls,
strSet("ListBucket", "ListBucketVersions")));
expectedResolvedRanger.add(
new OzoneGrant(
objSet(volume(), key("bucket1", "team/folder"), key("bucket1",
"team/folder/*")),
- acls(READ), strSet("ListBucket")));
+ acls(READ), strSet("ListBucket", "ListBucketVersions")));
assertThat(resolvedFromRangerAuthorizer).isEqualTo(expectedResolvedRanger);
}
@@ -2487,12 +2599,15 @@ public void
testAllActionsOnAllResourcesWithPrefixCondition() throws OMException
final Set<OzoneGrant> resolvedFromRangerAuthorizer = resolve(json, VOLUME,
RANGER);
// Ensure what we got is what we expected
final Set<OzoneGrant> expectedResolvedRanger = new LinkedHashSet<>();
- // Expected for Ranger: (only ListBucket supports s3:prefix) READ volume;
READ, LIST acl on bucket;
+ // Expected for Ranger: (ListBucket and ListBucketVersions support
s3:prefix) READ volume;
+ // READ, LIST acl on bucket;
// READ on key "team/folder", "team/folder/*"
- expectedResolvedRanger.add(new OzoneGrant(objSet(bucket("*")), acls(READ,
LIST), strSet("ListBucket")));
+ expectedResolvedRanger.add(
+ new OzoneGrant(objSet(bucket("*")), acls(READ, LIST),
strSet("ListBucket", "ListBucketVersions")));
expectedResolvedRanger.add(
new OzoneGrant(
- objSet(volume(), key("*", "team/folder"), key("*",
"team/folder/*")), acls(READ), strSet("ListBucket")));
+ objSet(volume(), key("*", "team/folder"), key("*", "team/folder/*")),
acls(READ),
+ strSet("ListBucket", "ListBucketVersions")));
assertThat(resolvedFromRangerAuthorizer).isEqualTo(expectedResolvedRanger);
}
@@ -2522,7 +2637,9 @@ public void testAllActionsOnAllResources() throws
OMException {
objSet(bucket("*")), acls(READ, LIST, CREATE, DELETE, READ_ACL,
WRITE_ACL, WRITE),
ALL_BUCKET_AND_OBJECT_ACTIONS));
expectedResolvedRanger.add(
- new OzoneGrant(objSet(key("*", "*")), acls(READ, CREATE, WRITE,
DELETE), ALL_OBJECT_ACTIONS_WITH_LIST_BUCKET));
+ new OzoneGrant(
+ objSet(key("*", "*")), acls(READ, CREATE, WRITE, DELETE),
+ ALL_OBJECT_ACTIONS_WITH_LIST_BUCKET_ACTIONS));
assertThat(resolvedFromRangerAuthorizer).isEqualTo(expectedResolvedRanger);
}
@@ -2546,7 +2663,8 @@ public void testAllActionsOnAllBucketResources() throws
OMException {
final Set<IOzoneObj> bucketSet = objSet(bucket("*"));
final Set<ACLType> bucketAcls = acls(READ, LIST, CREATE, DELETE, READ_ACL,
WRITE_ACL, WRITE);
expectedResolvedRanger.add(new OzoneGrant(bucketSet, bucketAcls,
ALL_BUCKET_ACTIONS));
- expectedResolvedRanger.add(new OzoneGrant(objSet(key("*", "*")),
acls(READ), strSet("ListBucket")));
+ expectedResolvedRanger.add(
+ new OzoneGrant(objSet(key("*", "*")), acls(READ), strSet("ListBucket",
"ListBucketVersions")));
expectedResolvedRanger.add(
new OzoneGrant(objSet(volume()), acls(READ, LIST),
ALL_BUCKET_ACTIONS_WITH_LIST_ALL_MY_BUCKETS));
assertThat(resolvedFromRangerAuthorizer).isEqualTo(expectedResolvedRanger);
@@ -2656,12 +2774,15 @@ public void testWildcardActionGroupListStar() throws
OMException {
expectedResolvedNative.add(
new OzoneGrant(
readAndListObjectsNative, acls(READ, LIST),
- strSet("ListBucket", "ListBucketMultipartUploads",
"ListMultipartUploadParts")));
+ strSet("ListBucket", "ListBucketVersions",
"ListBucketMultipartUploads", "ListMultipartUploadParts")));
expectedResolvedNative.add(
- new OzoneGrant(objSet(volume()), acls(READ),
- strSet("ListBucket", "ListBucketMultipartUploads",
"ListMultipartUploadParts")));
+ new OzoneGrant(
+ objSet(volume()), acls(READ),
+ strSet("ListBucket", "ListBucketVersions",
"ListBucketMultipartUploads", "ListMultipartUploadParts")));
expectedResolvedNative.add(
- new OzoneGrant(objSet(prefix("my-bucket", "")), acls(READ),
strSet("ListBucket", "ListMultipartUploadParts")));
+ new OzoneGrant(
+ objSet(prefix("my-bucket", "")), acls(READ),
+ strSet("ListBucket", "ListBucketVersions",
"ListMultipartUploadParts")));
assertThat(resolvedFromNativeAuthorizer).isEqualTo(expectedResolvedNative);
final Set<OzoneGrant> expectedResolvedRanger = new LinkedHashSet<>();
@@ -2671,13 +2792,15 @@ readAndListObjectsNative, acls(READ, LIST),
expectedResolvedRanger.add(
new OzoneGrant(
readAndListObjectRanger, acls(READ, LIST),
- strSet("ListBucket", "ListBucketMultipartUploads",
"ListMultipartUploadParts")));
+ strSet("ListBucket", "ListBucketVersions",
"ListBucketMultipartUploads", "ListMultipartUploadParts")));
expectedResolvedRanger.add(
new OzoneGrant(
objSet(volume()), acls(READ),
- strSet("ListBucket", "ListBucketMultipartUploads",
"ListMultipartUploadParts")));
+ strSet("ListBucket", "ListBucketVersions",
"ListBucketMultipartUploads", "ListMultipartUploadParts")));
expectedResolvedRanger.add(
- new OzoneGrant(objSet(key("my-bucket", "*")), acls(READ),
strSet("ListBucket", "ListMultipartUploadParts")));
+ new OzoneGrant(
+ objSet(key("my-bucket", "*")), acls(READ),
+ strSet("ListBucket", "ListBucketVersions",
"ListMultipartUploadParts")));
assertThat(resolvedFromRangerAuthorizer).isEqualTo(expectedResolvedRanger);
}
diff --git
a/hadoop-ozone/dist/src/main/smoketest/security/ozone-secure-sts.robot
b/hadoop-ozone/dist/src/main/smoketest/security/ozone-secure-sts.robot
index 81c784382c8..35f4e1fa326 100644
--- a/hadoop-ozone/dist/src/main/smoketest/security/ozone-secure-sts.robot
+++ b/hadoop-ozone/dist/src/main/smoketest/security/ozone-secure-sts.robot
@@ -816,6 +816,37 @@ STS session policy ListBucketMultipartUploads must require
bucket READ and LIST
${output} = Execute And Ignore Error aws s3api
--endpoint-url ${S3G_ENDPOINT_URL} list-multipart-uploads --bucket
${ICEBERG_BUCKET_OBS} --profile sts
Should Contain ${output} AccessDenied
+STS session policy ListBucketVersions must require bucket READ and LIST
+ # Positive control
+ ${session_policy} = Set Variable
{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":"s3:ListBucketVersions","Resource":"arn:aws:s3:::${ICEBERG_BUCKET_OBS}"}]}
+ 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=${ICEBERG_ALL_ACCESS_ROLE_OBS_ARN}
+ ${output} = Execute aws s3api
--endpoint-url ${S3G_ENDPOINT_URL} list-object-versions --bucket
${ICEBERG_BUCKET_OBS} --profile sts
+ Should Not Contain ${output} AccessDenied
+
+ # A ListBucket grant must not authorize ListObjectVersions
+ ${session_policy} = Set Variable
{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":"s3:ListBucket","Resource":"arn:aws:s3:::${ICEBERG_BUCKET_OBS}"}]}
+ 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=${ICEBERG_ALL_ACCESS_ROLE_OBS_ARN}
+ ${output} = Execute And Ignore Error aws s3api
--endpoint-url ${S3G_ENDPOINT_URL} list-object-versions --bucket
${ICEBERG_BUCKET_OBS} --profile sts
+ Should Contain ${output} AccessDenied
+
+ # A ListBucketVersions grant must not authorize ListObjects nor
ListObjectsV2
+ ${session_policy} = Set Variable
{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":"s3:ListBucketVersions","Resource":"arn:aws:s3:::${ICEBERG_BUCKET_OBS}"}]}
+ 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=${ICEBERG_ALL_ACCESS_ROLE_OBS_ARN}
+ ${output} = Execute And Ignore Error aws s3api
--endpoint-url ${S3G_ENDPOINT_URL} list-objects --bucket ${ICEBERG_BUCKET_OBS}
--profile sts
+ Should Contain ${output} AccessDenied
+ ${output} = Execute And Ignore Error aws s3api
--endpoint-url ${S3G_ENDPOINT_URL} list-objects-v2 --bucket
${ICEBERG_BUCKET_OBS} --profile sts
+ Should Contain ${output} AccessDenied
+
+ # Negative A: missing LIST (prefix upload so key READ is satisfied and
only bucket LIST is denied)
+ 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=${PARTIAL_BUCKET_READ_UPLOAD_PREFIX_ROLE_ARN}
+ ${output} = Execute And Ignore Error aws s3api
--endpoint-url ${S3G_ENDPOINT_URL} list-object-versions --bucket
${ICEBERG_BUCKET_OBS} --prefix upload --profile sts
+ Should Contain ${output} AccessDenied
+
+ # Negative B: missing READ
+ 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=${PARTIAL_BUCKET_LIST_ROLE_ARN}
+ ${output} = Execute And Ignore Error aws s3api
--endpoint-url ${S3G_ENDPOINT_URL} list-object-versions --bucket
${ICEBERG_BUCKET_OBS} --profile sts
+ Should Contain ${output} AccessDenied
+
STS session policy GetBucketAcl must require bucket READ and READ_ACL
# Positive control
${session_policy} = Set Variable
{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":"s3:GetBucketAcl","Resource":"arn:aws:s3:::${ICEBERG_BUCKET_OBS}"}]}
@@ -1604,6 +1635,7 @@ Expired STS temporary credentials must return
ExpiredToken on S3 APIs
Execute S3api Expect Expired Token Head Operation head-bucket
--bucket ${ICEBERG_BUCKET_OBS} HeadBucket
Execute S3api Expect Expired Token
list-objects-v2 --bucket ${ICEBERG_BUCKET_OBS} --output json
Execute S3api Expect Expired Token list-objects
--bucket ${ICEBERG_BUCKET_OBS} --output json
+ Execute S3api Expect Expired Token
list-object-versions --bucket ${ICEBERG_BUCKET_OBS} --output json
Execute S3api Expect Expired Token get-object
--bucket ${ICEBERG_BUCKET_OBS} --key ${ICEBERG_BUCKET_TESTFILE}
${TEMP_DIR}/expired-sts-token-get-object.out
Create File
${TEMP_DIR}/expired-sts-token-put-object-body.txt expired sts token put body
diff --git
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/audit/S3GAction.java
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/audit/S3GAction.java
index 0171d19f9a6..3d49d280e7e 100644
---
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/audit/S3GAction.java
+++
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/audit/S3GAction.java
@@ -24,6 +24,7 @@ public enum S3GAction implements AuditAction {
//BucketEndpoint
GET_BUCKET,
+ LIST_OBJECT_VERSIONS,
CREATE_BUCKET,
HEAD_BUCKET,
DELETE_BUCKET,
diff --git
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java
index db9d6a0cb30..c7cdfb3a981 100644
---
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java
+++
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java
@@ -105,6 +105,9 @@ public Response get(
@Override
Response handleGetRequest(S3RequestContext context, String bucketName)
throws IOException, OS3Exception {
+ if (isListObjectVersions()) {
+ context.setAction(S3GAction.LIST_OBJECT_VERSIONS);
+ }
final String continueToken = isListObjectVersions() ? null :
queryParams().get(QueryParams.CONTINUATION_TOKEN);
final String delimiter = queryParams().containsKey(QueryParams.DELIMITER) ?
queryParams().get(QueryParams.DELIMITER) : null;
diff --git
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3GActionIamMapper.java
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3GActionIamMapper.java
index 259325eb8be..6cacf0b6565 100644
---
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3GActionIamMapper.java
+++
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3GActionIamMapper.java
@@ -41,6 +41,8 @@ private S3GActionIamMapper() {
case GET_BUCKET:
case HEAD_BUCKET:
return "ListBucket";
+ case LIST_OBJECT_VERSIONS:
+ return "ListBucketVersions";
case CREATE_BUCKET:
return "CreateBucket";
case DELETE_BUCKET:
diff --git
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestS3ActionOverrideForOwnerVerification.java
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestS3ActionOverrideForOwnerVerification.java
index d4f4befbe73..36a8518c7ed 100644
---
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestS3ActionOverrideForOwnerVerification.java
+++
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestS3ActionOverrideForOwnerVerification.java
@@ -30,6 +30,7 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
@@ -38,6 +39,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import java.io.IOException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
@@ -47,6 +49,7 @@
import javax.ws.rs.core.Response;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.ozone.OzoneConfigKeys;
+import org.apache.hadoop.ozone.audit.S3GAction;
import org.apache.hadoop.ozone.client.ObjectStore;
import org.apache.hadoop.ozone.client.OzoneBucket;
import org.apache.hadoop.ozone.client.OzoneClient;
@@ -61,6 +64,7 @@
import org.apache.hadoop.ozone.s3.exception.OS3Exception;
import org.apache.hadoop.ozone.s3.metrics.S3GatewayMetrics;
import org.apache.hadoop.ozone.s3.signature.SignatureInfo;
+import org.apache.hadoop.ozone.s3.util.S3Consts.QueryParams;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
@@ -83,6 +87,30 @@ public static void setUp() {
S3GatewayMetrics.create(new OzoneConfiguration());
}
+ @Test
+ public void testListObjectVersionsUsesListBucketVersionsAction() throws
Exception {
+ assertEquals("ListBucketVersions", listBucketAction(true, true));
+ }
+
+ @Test
+ public void testListObjectsUsesListBucketAction() throws Exception {
+ assertEquals("ListBucket", listBucketAction(false, true));
+ }
+
+ @Test
+ public void testListObjectVersionsDoesNotSetActionWhenStsDisabled() throws
Exception {
+ assertNull(listBucketAction(true, false));
+ }
+
+ @Test
+ public void testListObjectVersionsUsesListObjectVersionsAuditAction() throws
Exception {
+ final AtomicReference<S3GAction> auditAction = new AtomicReference<>();
+ final BucketEndpoint endpoint = newBucketEndpoint(new AtomicReference<>(),
true, auditAction);
+ endpoint.queryParamsForTest().set(QueryParams.VERSIONS, "");
+ endpoint.get("bucket");
+ assertEquals(S3GAction.LIST_OBJECT_VERSIONS, auditAction.get());
+ }
+
@Test
public void
testUploadPartCopyUsesGetObjectActionForSourceBucketOwnerLookup() throws
Exception {
final AtomicReference<String> actionAtSourceBucketOwnerLookup = new
AtomicReference<>();
@@ -297,6 +325,65 @@ private static ObjectEndpoint
newGetObjectAttributesEndpoint(List<String> action
.build();
}
+ private static String listBucketAction(boolean listObjectVersions, boolean
isStsEnabled) throws Exception {
+ final AtomicReference<String> actionAtBucketLookup = new
AtomicReference<>();
+ final BucketEndpoint endpoint = newBucketEndpoint(actionAtBucketLookup,
isStsEnabled);
+ if (listObjectVersions) {
+ endpoint.queryParamsForTest().set(QueryParams.VERSIONS, "");
+ }
+ endpoint.get("bucket");
+ return actionAtBucketLookup.get();
+ }
+
+ private static BucketEndpoint newBucketEndpoint(AtomicReference<String>
actionAtBucketLookup,
+ boolean isStsEnabled) throws Exception {
+ return newBucketEndpoint(actionAtBucketLookup, isStsEnabled, null);
+ }
+
+ private static BucketEndpoint newBucketEndpoint(AtomicReference<String>
actionAtBucketLookup,
+ boolean isStsEnabled, AtomicReference<S3GAction> auditActionAtList)
throws Exception {
+ final OzoneClient client = mock(OzoneClient.class);
+ final ObjectStore objectStore = mock(ObjectStore.class);
+ final ClientProtocol clientProtocol = mock(ClientProtocol.class);
+ final OzoneVolume volume = mock(OzoneVolume.class);
+ final OzoneBucket bucket = mock(OzoneBucket.class);
+ final AtomicReference<S3Auth> s3AuthRef = new AtomicReference<>();
+
+ doAnswer(invocationOnMock -> {
+ s3AuthRef.set(invocationOnMock.getArgument(0));
+ return null;
+ }).when(clientProtocol).setThreadLocalS3Auth(any(S3Auth.class));
+
+ when(client.getObjectStore()).thenReturn(objectStore);
+ when(client.getProxy()).thenReturn(clientProtocol);
+ when(objectStore.getClientProxy()).thenReturn(clientProtocol);
+ when(objectStore.getS3Volume()).thenReturn(volume);
+ when(volume.getBucket("bucket")).thenAnswer(invocationOnMock -> {
+ final S3Auth s3Auth = s3AuthRef.get();
+ actionAtBucketLookup.set(s3Auth == null ? null : s3Auth.getS3Action());
+ return bucket;
+ });
+ when(bucket.listKeys(anyString(), any(),
anyBoolean())).thenReturn(Collections.emptyIterator());
+
+ final OzoneConfiguration conf = new OzoneConfiguration();
+ conf.setBoolean(OzoneConfigKeys.OZONE_S3G_STS_HTTP_ENABLED_KEY,
isStsEnabled);
+ final BucketEndpoint base = new BucketEndpoint() {
+ @Override
+ Response handleGetRequest(S3RequestContext context, String bucketName)
throws IOException, OS3Exception {
+ final Response response = super.handleGetRequest(context, bucketName);
+ if (auditActionAtList != null) {
+ auditActionAtList.set(context.getAction());
+ }
+ return response;
+ }
+ };
+ return EndpointBuilder.newBucketEndpointBuilder()
+ .setBase(base)
+ .setClient(client)
+ .setConfig(conf)
+ .build();
+ }
+
private static <T> T returnOrDeny(T result, boolean denyAccess) throws
OMException {
if (denyAccess) {
throw new OMException("Permission denied",
ResultCodes.PERMISSION_DENIED);
diff --git
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/util/TestS3GActionIamMapper.java
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/util/TestS3GActionIamMapper.java
index 338dcabfe11..bbb0f8fbd0b 100644
---
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/util/TestS3GActionIamMapper.java
+++
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/util/TestS3GActionIamMapper.java
@@ -30,6 +30,7 @@ public class TestS3GActionIamMapper {
public void mapsCoreObjectActions() {
assertEquals("ListBucket",
S3GActionIamMapper.toS3ActionString(S3GAction.GET_BUCKET));
assertEquals("ListBucket",
S3GActionIamMapper.toS3ActionString(S3GAction.HEAD_BUCKET));
+ assertEquals("ListBucketVersions",
S3GActionIamMapper.toS3ActionString(S3GAction.LIST_OBJECT_VERSIONS));
assertEquals("CreateBucket",
S3GActionIamMapper.toS3ActionString(S3GAction.CREATE_BUCKET));
assertEquals("DeleteBucket",
S3GActionIamMapper.toS3ActionString(S3GAction.DELETE_BUCKET));
assertEquals("GetBucketAcl",
S3GActionIamMapper.toS3ActionString(S3GAction.GET_ACL));
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]