This is an automated email from the ASF dual-hosted git repository.
adoroszlai 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 e9ecea63b46 HDDS-17410. Record STS revocation cutoff when revoking
tenant access id (#11796)
e9ecea63b46 is described below
commit e9ecea63b463f7f2b03fd6286bb190a7e373e974
Author: Andy Huang <[email protected]>
AuthorDate: Tue Nov 10 21:24:08 2026 +0800
HDDS-17410. Record STS revocation cutoff when revoking tenant access id
(#11796)
---
.../security/ozone-secure-sts-multitenant.robot | 11 ++
.../om/TestOzoneManagerHATenantStsRevocation.java | 177 +++++++++++++++++++
.../tenant/OMTenantRevokeUserAccessIdRequest.java | 13 +-
.../tenant/OMTenantRevokeUserAccessIdResponse.java | 9 +-
.../TestOMTenantRevokeUserAccessIdRequest.java | 194 +++++++++++++++++++++
5 files changed, 402 insertions(+), 2 deletions(-)
diff --git
a/hadoop-ozone/dist/src/main/smoketest/security/ozone-secure-sts-multitenant.robot
b/hadoop-ozone/dist/src/main/smoketest/security/ozone-secure-sts-multitenant.robot
index 8c785b3d46d..0c09821150c 100644
---
a/hadoop-ozone/dist/src/main/smoketest/security/ozone-secure-sts-multitenant.robot
+++
b/hadoop-ozone/dist/src/main/smoketest/security/ozone-secure-sts-multitenant.robot
@@ -325,6 +325,17 @@ Multitenant Revocation Scenarios
Should contain ${output} Revoked
accessId '${TENANT_ONE}$${USER_A}'.
Get Object Should Fail ${TENANT_ONE_ICEBERG_BUCKET}
${ICEBERG_BUCKET_TESTFILE} AccessDenied
+ # Reassign the same access ID: the old token must stay revoked, while a
new token must work.
+ ${accessKeyId} ${secretKey} = Assign User To Tenant And Get Credentials
${USER_A} ${TENANT_ONE}
+ Should Be Equal ${accessKeyId}
${USER_A_T1_PERM_ACCESS_KEY_ID}
+ Get Object Should Fail ${TENANT_ONE_ICEBERG_BUCKET}
${ICEBERG_BUCKET_TESTFILE} AccessDenied
+ Refresh Ranger Policy Cache
+ Assume Role And Get Temporary Credentials
perm_access_key_id=${accessKeyId} perm_secret_key=${secretKey}
role_arn=${ROLE_ARN}
+ Configure STS Profile ${STS_ACCESS_KEY_ID} ${STS_SECRET_KEY}
${STS_SESSION_TOKEN}
+ Get Object Should Succeed ${TENANT_ONE_ICEBERG_BUCKET}
${ICEBERG_BUCKET_TESTFILE}
+ Configure STS Profile ${USER_A_T1_STS_ACCESS_KEY_ID}
${USER_A_T1_STS_SECRET_KEY} ${USER_A_T1_STS_SESSION_TOKEN}
+ Get Object Should Fail ${TENANT_ONE_ICEBERG_BUCKET}
${ICEBERG_BUCKET_TESTFILE} AccessDenied
+
Configure STS Profile ${USER_A_T2_STS_ACCESS_KEY_ID}
${USER_A_T2_STS_SECRET_KEY} ${USER_A_T2_STS_SESSION_TOKEN}
Get Object Should Succeed ${TENANT_TWO_ICEBERG_BUCKET}
${ICEBERG_BUCKET_TESTFILE}
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManagerHATenantStsRevocation.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManagerHATenantStsRevocation.java
new file mode 100644
index 00000000000..c69fee85853
--- /dev/null
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManagerHATenantStsRevocation.java
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om;
+
+import static
org.apache.hadoop.hdds.security.SecurityConfig.OZONE_TEST_AUTHORIZATION_ENABLED;
+import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ACL_AUTHORIZER_CLASS;
+import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_S3G_STS_HTTP_ENABLED_KEY;
+import static
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_MULTITENANCY_ENABLED;
+import static
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.REVOKED_TOKEN;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.IOException;
+import java.time.Instant;
+import java.util.UUID;
+import javax.crypto.spec.SecretKeySpec;
+import org.apache.commons.codec.binary.Hex;
+import
org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClientTestImpl;
+import org.apache.hadoop.ozone.client.ObjectStore;
+import org.apache.hadoop.ozone.client.SecretKeyTestClient;
+import org.apache.hadoop.ozone.client.protocol.ClientProtocol;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.AssumeRoleResponseInfo;
+import org.apache.hadoop.ozone.om.helpers.S3SecretValue;
+import org.apache.hadoop.ozone.om.protocol.S3Auth;
+import org.apache.hadoop.ozone.security.HmacSha256;
+import org.apache.hadoop.ozone.security.STSTokenSecretManager;
+import org.apache.hadoop.ozone.security.acl.AssumeRoleRequest;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
+import org.apache.hadoop.ozone.security.acl.IOzoneObj;
+import org.apache.hadoop.ozone.security.acl.RequestContext;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.ozone.test.GenericTestUtils;
+import org.apache.ozone.test.HddsWhiteboxTestUtils;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+
+/** Tests tenant STS revocation over RPC with replicated OM metadata and
leader failover. */
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+public class TestOzoneManagerHATenantStsRevocation extends
AbstractOzoneManagerHATest {
+ private static final String STRING_TO_SIGN =
"AWS4-HMAC-SHA256\n20150830T123600Z\n"
+ + "20150830/us-east-1/s3/aws4_request\n" + "0".repeat(64);
+
+ @BeforeAll
+ public void init() throws Exception {
+ // Use the secure OM test hook used by TestSecureOzoneRpcClient, without
an external KDC or Ranger.
+ OzoneManager.setTestSecureOmFlag(true);
+ initCluster(false, conf -> {
+ conf.setBoolean(OZONE_TEST_AUTHORIZATION_ENABLED, true);
+ conf.setBoolean(OZONE_OM_MULTITENANCY_ENABLED, true);
+ conf.setBoolean(OZONE_S3G_STS_HTTP_ENABLED_KEY, true);
+
conf.setBoolean(OMMultiTenantManagerImpl.OZONE_OM_TENANT_DEV_SKIP_RANGER, true);
+ conf.set(OZONE_ACL_AUTHORIZER_CLASS, TestAuthorizer.class.getName());
+ });
+ SecretKeyTestClient keys = new SecretKeyTestClient();
+ for (OzoneManager om : getCluster().getOzoneManagersList()) {
+ om.setCertClient(new CertificateClientTestImpl(om.getConfiguration()));
+ om.setSecretKeyClient(keys);
+ // STSTokenSecretManager keeps its own final signer reference in
addition to the inherited one.
+ HddsWhiteboxTestUtils.setInternalState(om, "stsTokenSecretManager", new
STSTokenSecretManager(keys));
+ om.startSecretManager();
+ }
+ }
+
+ @AfterAll
+ public static void resetSecureOmFlag() {
+ OzoneManager.setTestSecureOmFlag(false);
+ }
+
+ @Test
+ public void testRevokedTenantTokenStaysRevokedAfterReassignmentAndFailover()
throws Exception {
+ String tenant = "tenant-" + UUID.randomUUID();
+ String user = UserGroupInformation.getCurrentUser().getShortUserName();
+ String accessId = tenant + "$" + user;
+ ObjectStore store = getObjectStore();
+ ClientProtocol proxy = store.getClientProxy();
+ store.createTenant(tenant);
+ S3SecretValue original = store.tenantAssignUserAccessId(user, tenant,
accessId);
+ AssumeRoleResponseInfo oldToken;
+ try {
+ proxy.setThreadLocalS3Auth(auth(accessId, original.getAwsSecret(), user,
null));
+ oldToken = store.assumeRole("arn:aws:iam::123456789012:role/test-role",
"before-revoke", 900,
+ null, UUID.randomUUID().toString());
+ proxy.setThreadLocalS3Auth(auth(oldToken.getAccessKeyId(),
oldToken.getSecretAccessKey(), user,
+ oldToken.getSessionToken()));
+ assertEquals(tenant, store.getVolume(tenant).getName());
+ } finally {
+ proxy.clearThreadLocalS3Auth();
+ }
+
+ store.tenantRevokeUserAccessId(accessId);
+ Long cutoff =
getCluster().waitForLeaderOM().getMetadataManager().getS3RevokedStsTokenTable().get(accessId);
+ assertNotNull(cutoff);
+ for (OzoneManager om : getCluster().getOzoneManagersList()) {
+ GenericTestUtils.waitFor(() -> {
+ try {
+ return
cutoff.equals(om.getMetadataManager().getS3RevokedStsTokenTable().getSkipCache(accessId));
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }, 100, 30000);
+ }
+ S3SecretValue replacement = store.tenantAssignUserAccessId(user, tenant,
accessId);
+ assertRevoked(store, oldToken, user, tenant);
+
+ OzoneManager oldLeader = getCluster().waitForLeaderOM();
+ getCluster().stopOzoneManager(oldLeader.getOMNodeId());
+ OzoneManager newLeader = getCluster().waitForLeaderOM();
+ assertEquals(cutoff,
newLeader.getMetadataManager().getS3RevokedStsTokenTable().get(accessId));
+ assertRevoked(store, oldToken, user, tenant);
+ assertTrue(oldToken.getExpirationEpochSeconds() >
Instant.now().getEpochSecond());
+
+ try {
+ proxy.setThreadLocalS3Auth(auth(accessId, replacement.getAwsSecret(),
user, null));
+ AssumeRoleResponseInfo newToken =
store.assumeRole("arn:aws:iam::123456789012:role/test-role",
+ "after-revoke", 900, null, UUID.randomUUID().toString());
+ proxy.setThreadLocalS3Auth(auth(newToken.getAccessKeyId(),
newToken.getSecretAccessKey(), user,
+ newToken.getSessionToken()));
+ assertEquals(tenant, store.getVolume(tenant).getName());
+ } finally {
+ proxy.clearThreadLocalS3Auth();
+ }
+ }
+
+ private void assertRevoked(ObjectStore store, AssumeRoleResponseInfo token,
String user, String tenant)
+ throws Exception {
+ try {
+ store.getClientProxy().setThreadLocalS3Auth(auth(token.getAccessKeyId(),
token.getSecretAccessKey(), user,
+ token.getSessionToken()));
+ OMException ex = assertThrows(OMException.class, () ->
store.getVolume(tenant));
+ assertEquals(REVOKED_TOKEN, ex.getResult());
+ } finally {
+ store.getClientProxy().clearThreadLocalS3Auth();
+ }
+ }
+
+ private static S3Auth auth(String accessId, String secret, String user,
String token) throws Exception {
+ byte[] key = AWSV4AuthValidator.getSigningKey(secret, STRING_TO_SIGN);
+ String signature = Hex.encodeHexString(
+ HmacSha256.sign(new SecretKeySpec(key, HmacSha256.ALGORITHM),
STRING_TO_SIGN));
+ S3Auth auth = new S3Auth(STRING_TO_SIGN, signature, accessId, user);
+ auth.setSessionToken(token);
+ return auth;
+ }
+
+ /** Supplies a session policy without requiring an external Ranger service.
*/
+ public static class TestAuthorizer implements IAccessAuthorizer {
+ @Override
+ public boolean checkAccess(IOzoneObj obj, RequestContext context) {
+ return true;
+ }
+
+ @Override
+ public String generateAssumeRoleSessionPolicy(AssumeRoleRequest request) {
+ return "{}";
+ }
+ }
+}
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tenant/OMTenantRevokeUserAccessIdRequest.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tenant/OMTenantRevokeUserAccessIdRequest.java
index ec999440852..d20ff3756b8 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tenant/OMTenantRevokeUserAccessIdRequest.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tenant/OMTenantRevokeUserAccessIdRequest.java
@@ -22,6 +22,7 @@
import java.io.IOException;
import java.nio.file.InvalidPathException;
+import java.time.Clock;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@@ -42,6 +43,7 @@
import org.apache.hadoop.ozone.om.helpers.OmDBAccessIdInfo;
import org.apache.hadoop.ozone.om.helpers.OmDBUserPrincipalInfo;
import org.apache.hadoop.ozone.om.request.OMClientRequest;
+import org.apache.hadoop.ozone.om.request.s3.security.S3SecretRequestHelper;
import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
import org.apache.hadoop.ozone.om.response.OMClientResponse;
import
org.apache.hadoop.ozone.om.response.s3.tenant.OMTenantRevokeUserAccessIdResponse;
@@ -49,6 +51,7 @@
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest.Builder;
+import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.RevokeSTSTokenRequest;
import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.TenantRevokeUserAccessIdRequest;
import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.TenantRevokeUserAccessIdResponse;
import org.slf4j.Logger;
@@ -70,6 +73,8 @@ public class OMTenantRevokeUserAccessIdRequest extends
OMClientRequest {
private static final Logger LOG = LoggerFactory.getLogger(
OMTenantRevokeUserAccessIdRequest.class);
+ private static final Clock CLOCK = Clock.systemUTC();
+
public OMTenantRevokeUserAccessIdRequest(OMRequest omRequest) {
super(omRequest);
}
@@ -136,6 +141,9 @@ public OMRequest preExecute(OzoneManager ozoneManager)
throws IOException {
}
final Builder omRequestBuilder = omRequest.toBuilder()
+ .setRevokeSTSTokenRequest(RevokeSTSTokenRequest.newBuilder()
+ .setOriginalAccessKeyId(accessId)
+ .setRevocationTimeMillis(CLOCK.millis()))
.setTenantRevokeUserAccessIdRequest(
TenantRevokeUserAccessIdRequest.newBuilder()
.setAccessId(accessId)
@@ -210,13 +218,16 @@ public OMClientResponse
validateAndUpdateCache(OzoneManager ozoneManager, Execut
// Update tenant cache
multiTenantManager.getCacheOp().revokeUserAccessId(accessId, tenantId);
+ Long stsRevocationCutoff =
S3SecretRequestHelper.updateStsRevocationCutoff(
+ omMetadataManager, getOmRequest(), accessId, transactionLogIndex);
+
// Generate response
omResponse.setTenantRevokeUserAccessIdResponse(
TenantRevokeUserAccessIdResponse.newBuilder()
.build());
omClientResponse = new OMTenantRevokeUserAccessIdResponse(
omResponse.build(), accessId, userPrincipal, principalInfo,
- s3SecretManager);
+ s3SecretManager, stsRevocationCutoff);
} catch (IOException | InvalidPathException ex) {
exception = ex;
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/s3/tenant/OMTenantRevokeUserAccessIdResponse.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/s3/tenant/OMTenantRevokeUserAccessIdResponse.java
index 818b335c523..8b4f7b6c1d6 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/s3/tenant/OMTenantRevokeUserAccessIdResponse.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/s3/tenant/OMTenantRevokeUserAccessIdResponse.java
@@ -35,19 +35,22 @@ public class OMTenantRevokeUserAccessIdResponse extends
OMClientResponse {
private String principal, accessId;
private OmDBUserPrincipalInfo omDBUserPrincipalInfo;
private S3SecretManager s3SecretManager;
+ private Long stsRevocationCutoff;
@SuppressWarnings("checkstyle:parameternumber")
public OMTenantRevokeUserAccessIdResponse(@Nonnull OMResponse omResponse,
@Nonnull String accessId,
@Nonnull String principal,
@Nonnull OmDBUserPrincipalInfo omDBUserPrincipalInfo,
- @Nonnull S3SecretManager s3SecretManager
+ @Nonnull S3SecretManager s3SecretManager,
+ Long stsRevocationCutoff
) {
super(omResponse);
this.principal = principal;
this.accessId = accessId;
this.omDBUserPrincipalInfo = omDBUserPrincipalInfo;
this.s3SecretManager = s3SecretManager;
+ this.stsRevocationCutoff = stsRevocationCutoff;
}
/**
@@ -73,6 +76,10 @@ public void addToDBBatch(OMMetadataManager omMetadataManager,
}
}
+ if (stsRevocationCutoff != null) {
+
omMetadataManager.getS3RevokedStsTokenTable().putWithBatch(batchOperation,
accessId, stsRevocationCutoff);
+ }
+
omMetadataManager.getTenantAccessIdTable().deleteWithBatch(
batchOperation, accessId);
diff --git
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/s3/tenant/TestOMTenantRevokeUserAccessIdRequest.java
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/s3/tenant/TestOMTenantRevokeUserAccessIdRequest.java
new file mode 100644
index 00000000000..fe48d14fb89
--- /dev/null
+++
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/s3/tenant/TestOMTenantRevokeUserAccessIdRequest.java
@@ -0,0 +1,194 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.request.s3.tenant;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.TreeSet;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.utils.db.BatchOperation;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.audit.AuditLogger;
+import org.apache.hadoop.ozone.om.OMConfigKeys;
+import org.apache.hadoop.ozone.om.OMMetrics;
+import org.apache.hadoop.ozone.om.OMMultiTenantManager;
+import org.apache.hadoop.ozone.om.OmMetadataManagerImpl;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.S3SecretLockedManager;
+import org.apache.hadoop.ozone.om.S3SecretManager;
+import org.apache.hadoop.ozone.om.S3SecretManagerImpl;
+import org.apache.hadoop.ozone.om.TenantOp;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.OmDBAccessIdInfo;
+import org.apache.hadoop.ozone.om.helpers.OmDBUserPrincipalInfo;
+import org.apache.hadoop.ozone.om.helpers.S3SecretValue;
+import org.apache.hadoop.ozone.om.multitenant.AuthorizerLock;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.om.s3.S3SecretCacheProvider;
+import org.apache.hadoop.ozone.om.upgrade.OMVersionManager;
+import org.apache.hadoop.ozone.om.upgrade.OMVersionManagerTestUtils;
+import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Status;
+import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.TenantRevokeUserAccessIdRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Type;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/** Tests STS revocation when a tenant access id is revoked. */
+public class TestOMTenantRevokeUserAccessIdRequest {
+ private static final String ACCESS_ID = "tenant$user";
+ private static final String TENANT = "tenant";
+ private static final String USER = "user";
+
+ @TempDir
+ private Path folder;
+ private OzoneManager ozoneManager;
+ private OmMetadataManagerImpl metadataManager;
+ private OMMetrics metrics;
+ private S3SecretManager secretManager;
+
+ @BeforeEach
+ public void setup() throws Exception {
+ ozoneManager = mock(OzoneManager.class);
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.set(OMConfigKeys.OZONE_OM_DB_DIRS, folder.toString());
+ metadataManager = new OmMetadataManagerImpl(conf, ozoneManager);
+ metrics = OMMetrics.create(conf);
+ when(ozoneManager.getMetadataManager()).thenReturn(metadataManager);
+ when(ozoneManager.getMetrics()).thenReturn(metrics);
+ OMVersionManager versionManager =
OMVersionManagerTestUtils.mockFinalizedOmVersionManager();
+ when(ozoneManager.getVersionManager()).thenReturn(versionManager);
+ when(ozoneManager.getAuditLogger()).thenReturn(mock(AuditLogger.class));
+ secretManager = new S3SecretLockedManager(
+ new S3SecretManagerImpl(metadataManager,
S3SecretCacheProvider.IN_MEMORY.get(conf)), metadataManager.getLock());
+ when(ozoneManager.getS3SecretManager()).thenReturn(secretManager);
+ OMMultiTenantManager tenantManager = mock(OMMultiTenantManager.class);
+ when(ozoneManager.getMultiTenantManager()).thenReturn(tenantManager);
+ when(tenantManager.getTenantVolumeName(TENANT)).thenReturn(TENANT);
+
when(tenantManager.getAuthorizerLock()).thenReturn(mock(AuthorizerLock.class));
+ when(tenantManager.getAuthorizerOp()).thenReturn(mock(TenantOp.class));
+ when(tenantManager.getCacheOp()).thenReturn(mock(TenantOp.class));
+ metadataManager.getTenantAccessIdTable().put(ACCESS_ID, new
OmDBAccessIdInfo.Builder()
+
.setTenantId(TENANT).setUserPrincipal(USER).setIsAdmin(false).setIsDelegatedAdmin(false).build());
+ metadataManager.getPrincipalToAccessIdsTable().put(USER, new
OmDBUserPrincipalInfo.Builder()
+ .setAccessIds(new
TreeSet<>(Collections.singleton(ACCESS_ID))).build());
+ secretManager.storeSecret(ACCESS_ID, S3SecretValue.of(ACCESS_ID,
"old-secret"));
+ }
+
+ @AfterEach
+ public void tearDown() throws Exception {
+ metadataManager.stop();
+ metrics.unRegister();
+ }
+
+ @Test
+ public void testRevokeRecordsCutoffThatSurvivesNewSecret() throws Exception {
+ OMRequest request = new
OMTenantRevokeUserAccessIdRequest(revokeRequest()).preExecute(ozoneManager);
+ assertTrue(request.hasRevokeSTSTokenRequest());
+ long cutoff = request.getRevokeSTSTokenRequest().getRevocationTimeMillis();
+ assertTrue(cutoff > 0);
+ assertEquals(ACCESS_ID,
request.getRevokeSTSTokenRequest().getOriginalAccessKeyId());
+ revokeAndCommit(request);
+ assertEquals(cutoff,
metadataManager.getS3RevokedStsTokenTable().get(ACCESS_ID));
+ assertEquals(cutoff,
metadataManager.getS3RevokedStsTokenTable().getSkipCache(ACCESS_ID));
+ secretManager.storeSecret(ACCESS_ID, S3SecretValue.of(ACCESS_ID,
"new-secret"));
+ assertTrue(secretManager.hasS3Secret(ACCESS_ID));
+ assertEquals(cutoff,
metadataManager.getS3RevokedStsTokenTable().get(ACCESS_ID));
+ }
+
+ @Test
+ public void testRevokeKeepsHigherCutoff() throws Exception {
+ OMRequest request = new
OMTenantRevokeUserAccessIdRequest(revokeRequest()).preExecute(ozoneManager);
+ long existing =
request.getRevokeSTSTokenRequest().getRevocationTimeMillis() + 1000;
+ metadataManager.getS3RevokedStsTokenTable().addCacheEntry(new
CacheKey<>(ACCESS_ID), CacheValue.get(1L, existing));
+ revokeAndCommit(request);
+ assertEquals(existing,
metadataManager.getS3RevokedStsTokenTable().get(ACCESS_ID));
+ assertEquals(existing,
metadataManager.getS3RevokedStsTokenTable().getSkipCache(ACCESS_ID));
+ }
+
+ @Test
+ public void testReplayWithoutCutoff() throws Exception {
+ revokeAndCommit(revokeRequest());
+ assertNull(metadataManager.getS3RevokedStsTokenTable().get(ACCESS_ID));
+
assertNull(metadataManager.getS3RevokedStsTokenTable().getSkipCache(ACCESS_ID));
+ }
+
+ @Test
+ public void testFailedRevokeDoesNotRecordCutoff() throws Exception {
+ assertFailedRevokeKeepsCutoff(null);
+ }
+
+ @Test
+ public void testFailedRevokeKeepsExistingCutoff() throws Exception {
+ assertFailedRevokeKeepsCutoff(1L);
+ }
+
+ private void assertFailedRevokeKeepsCutoff(Long existing) throws Exception {
+ if (existing != null) {
+ metadataManager.getS3RevokedStsTokenTable().put(ACCESS_ID, existing);
+ metadataManager.getS3RevokedStsTokenTable().addCacheEntry(
+ new CacheKey<>(ACCESS_ID), CacheValue.get(1L, existing));
+ }
+ OMRequest request = new
OMTenantRevokeUserAccessIdRequest(revokeRequest()).preExecute(ozoneManager);
+ TenantOp cacheOp = ozoneManager.getMultiTenantManager().getCacheOp();
+ doThrow(new OMException("Tenant cache update failed",
OMException.ResultCodes.INTERNAL_ERROR))
+ .when(cacheOp).revokeUserAccessId(ACCESS_ID, TENANT);
+ OMClientResponse response = new OMTenantRevokeUserAccessIdRequest(request)
+ .validateAndUpdateCache(ozoneManager, 2L);
+ assertEquals(Status.INTERNAL_ERROR, response.getOMResponse().getStatus());
+ assertEquals(existing,
metadataManager.getS3RevokedStsTokenTable().get(ACCESS_ID));
+ try (BatchOperation batch =
metadataManager.getStore().initBatchOperation()) {
+ response.checkAndUpdateDB(metadataManager, batch);
+ metadataManager.getStore().commitBatchOperation(batch);
+ }
+ assertEquals(existing,
metadataManager.getS3RevokedStsTokenTable().getSkipCache(ACCESS_ID));
+ }
+
+ private OMRequest revokeRequest() {
+ return
OMRequest.newBuilder().setCmdType(Type.TenantRevokeUserAccessId).setClientId("client")
+
.setTenantRevokeUserAccessIdRequest(TenantRevokeUserAccessIdRequest.newBuilder()
+ .setAccessId(ACCESS_ID).setTenantId(TENANT)).build();
+ }
+
+ private void revokeAndCommit(OMRequest request) throws Exception {
+ OMClientResponse response = new OMTenantRevokeUserAccessIdRequest(request)
+ .validateAndUpdateCache(ozoneManager, 2L);
+ assertEquals(Status.OK, response.getOMResponse().getStatus());
+ assertFalse(secretManager.hasS3Secret(ACCESS_ID));
+ if (request.hasRevokeSTSTokenRequest()) {
+ assertTrue(metadataManager.getS3RevokedStsTokenTable().get(ACCESS_ID)
+ >= request.getRevokeSTSTokenRequest().getRevocationTimeMillis());
+ }
+ try (BatchOperation batch =
metadataManager.getStore().initBatchOperation()) {
+ response.checkAndUpdateDB(metadataManager, batch);
+ metadataManager.getStore().commitBatchOperation(batch);
+ }
+ assertNull(metadataManager.getSecret(ACCESS_ID));
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]