fmorg-git commented on code in PR #11095:
URL: https://github.com/apache/ozone/pull/11095#discussion_r3848944475


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/security/S3RevokeSTSTokenRequest.java:
##########
@@ -61,48 +70,94 @@ public S3RevokeSTSTokenRequest(OMRequest omRequest) {
   @Override
   public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
     final OMRequest omRequest = super.preExecute(ozoneManager);
-    final OzoneManagerProtocolProtos.RevokeSTSTokenRequest revokeReq =
-        omRequest.getRevokeSTSTokenRequest();
+    final RevokeSTSTokenRequest revokeReq = 
omRequest.getRevokeSTSTokenRequest();
+    validateRevokeRequestFields(revokeReq);
 
-    // Get the original (long-lived) access key id from the session token
-    // and enforce the same permission model that is used for S3 secret
+    // Use the original (long-lived) access key ID from the request and enforce
+    // the same permission model that is used for S3 secret
     // operations (get/set/revoke). Only the owner of the original access
     // key (i.e. the creator of the STS token) or an S3 / tenant admin is 
allowed
     // to revoke its temporary STS credentials.
-    final String sessionToken = revokeReq.getSessionToken();
-    final STSTokenIdentifier stsTokenIdentifier = 
STSSecurityUtil.constructValidateAndDecryptSTSToken(
-        sessionToken, ozoneManager.getSecretKeyClient(), CLOCK);
-    final String originalAccessKeyId = 
stsTokenIdentifier.getOriginalAccessKeyId();
+    final String originalAccessKeyId = revokeReq.getOriginalAccessKeyId();
 
     final UserGroupInformation ugi = 
S3SecretRequestHelper.getOrCreateUgi(originalAccessKeyId);
     S3SecretRequestHelper.checkAccessIdSecretOpPermission(ozoneManager, ugi, 
originalAccessKeyId);
 
-    return omRequest;
+    if (!ozoneManager.getS3SecretManager().hasS3Secret(originalAccessKeyId)) {
+      throw new OMException("originalAccessKeyId does not exist: " + 
originalAccessKeyId, INVALID_REQUEST);
+    }
+
+    final long revocationTimeMillis = CLOCK.millis();
+    final UpdateRevokeSTSTokenRequest updateRevokeSTSTokenRequest = 
UpdateRevokeSTSTokenRequest.newBuilder()
+        .setOriginalAccessKeyId(originalAccessKeyId)
+        .setRevocationTimeMillis(revocationTimeMillis)
+        .build();
+
+    return omRequest.toBuilder()
+        .setUpdateRevokeSTSTokenRequest(updateRevokeSTSTokenRequest)
+        .build();
   }
 
   @Override
   public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, 
ExecutionContext context) {
     final OMResponse.Builder omResponse = 
OmResponseUtil.getOMResponseBuilder(getOmRequest());
+    IOException exception = null;
+    OMClientResponse omClientResponse;
+    String originalAccessKeyId = null;
+
+    try {
+      validateReplicatedRevokeRequestFields(getOmRequest());
+      final UpdateRevokeSTSTokenRequest updateRevokeSTSTokenRequest = 
getOmRequest().getUpdateRevokeSTSTokenRequest();
+      originalAccessKeyId = 
updateRevokeSTSTokenRequest.getOriginalAccessKeyId();
+      final long revocationTimeMillis = 
updateRevokeSTSTokenRequest.getRevocationTimeMillis();
 
-    final OzoneManagerProtocolProtos.RevokeSTSTokenRequest revokeReq = 
getOmRequest().getRevokeSTSTokenRequest();
-    final String sessionToken = revokeReq.getSessionToken();
+      // All actual DB mutations are done in the response's addToDBBatch().
+      omClientResponse = new S3RevokeSTSTokenResponse(originalAccessKeyId, 
revocationTimeMillis, omResponse.build());
 
-    // All actual DB mutations are done in the response's addToDBBatch().
-    final OMClientResponse omClientResponse = new S3RevokeSTSTokenResponse(
-        sessionToken, omResponse.build());
+      // Update the cache immediately so subsequent validation checks see the 
revocation
+      
ozoneManager.getMetadataManager().getS3RevokedStsTokenTable().addCacheEntry(
+          new CacheKey<>(originalAccessKeyId), 
CacheValue.get(context.getIndex(), revocationTimeMillis));
+
+      LOG.info(
+          "Marked STS tokens as revoked for originalAccessKeyId={} with cutoff 
time {}.",
+          originalAccessKeyId, revocationTimeMillis);
+    } catch (IOException ex) {
+      exception = ex;
+      omClientResponse = new S3RevokeSTSTokenResponse(null, 0L, 
createErrorOMResponse(omResponse, ex));
+    }
 
     // Audit log
     final Map<String, String> auditMap = new HashMap<>();
     final OzoneManagerProtocolProtos.UserInfo userInfo = 
getOmRequest().getUserInfo();
     auditMap.put(OzoneConsts.S3_REVOKESTSTOKEN_USER, userInfo.getUserName());

Review Comment:
   updated - 
https://github.com/apache/ozone/pull/11095/changes/3bcbe0348e1f0c7a013e05bf48d9f9deeb2fa357



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to