fmorg-git commented on code in PR #9344:
URL: https://github.com/apache/ozone/pull/9344#discussion_r2566039843
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/security/STSTokenIdentifier.java:
##########
@@ -161,12 +161,58 @@ public void fromProtoBuf(OMTokenProto token) throws
IOException {
"Invalid secretKeyId format in STS token: " +
token.getSecretKeyId(), e);
}
}
+ // Note: secretKeyId must be set before attempting to decrypt
secretAccessKey
+ if (token.hasSecretAccessKey()) {
+ this.secretAccessKey = decryptSensitiveField(token.getSecretAccessKey());
+ }
if (token.hasSessionPolicy()) {
this.sessionPolicy = token.getSessionPolicy();
}
}
+ /**
+ * Encrypt a sensitive field using the configured encryption key.
+ */
+ private String encryptSensitiveField(String value) {
+ if (encryptionKey == null) {
+ throw new IllegalStateException("Encryption key must be set before
encrypting sensitive fields");
+ }
+
+ try {
+ final byte[] aad = computeAadBytes();
+ return STSTokenEncryption.encrypt(value, encryptionKey, aad);
+ } catch (STSTokenEncryption.STSTokenEncryptionException e) {
+ throw new RuntimeException("Token encryption failed", e);
+ }
+ }
+
+ /**
+ * Decrypt a sensitive field using the configured encryption key.
+ */
+ private String decryptSensitiveField(String encryptedValue) {
+ if (encryptionKey == null) {
+ throw new IllegalStateException("Encryption key must be set before
decrypting sensitive fields");
+ }
+
+ try {
+ final byte[] aad = computeAadBytes();
+ return STSTokenEncryption.decrypt(encryptedValue, encryptionKey, aad);
+ } catch (STSTokenEncryption.STSTokenEncryptionException e) {
+ throw new RuntimeException("Token decryption failed", e);
+ }
+ }
+
+ /**
+ * Compute additional authenticated data to bind token context to encryption.
+ * Includes token type, ownerId, expiry millis, and secretKeyId.
+ */
+ private byte[] computeAadBytes() {
+ final String aad = "v1|S3_STS_TOKEN|" + getOwnerId() + "|" +
getExpiry().toEpochMilli() + "|" +
Review Comment:
updated
--
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]