Skip to content

HDDS-13961. [STS] Encrypt secretAccessKey in session token#9344

Merged
sodonnel merged 5 commits intoapache:HDDS-13323-stsfrom
fmorg-git:HDDS-13961
Dec 2, 2025
Merged

HDDS-13961. [STS] Encrypt secretAccessKey in session token#9344
sodonnel merged 5 commits intoapache:HDDS-13323-stsfrom
fmorg-git:HDDS-13961

Conversation

@fmorg-git
Copy link
Contributor

Please describe your PR in detail:

  • Encrypt secretAccessKey in session token.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-13961

How was this patch tested?

unit tests

@fmorg-git fmorg-git changed the base branch from master to HDDS-13323-sts November 21, 2025 22:06
@fmorg-git fmorg-git force-pushed the HDDS-13961 branch 2 times, most recently from 09ab4da to b6f8f5e Compare November 21, 2025 22:42
@ivandika3 ivandika3 added the sts Changes for Ozone's S3 Security Token Service label Nov 22, 2025
@swamirishi
Copy link
Contributor

@yandrey321 do you wanna look at this patch?

return sessionPolicy;
}

public void setEncryptionKey(byte[] encryptionKey) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how are we protecting key in memory? how long would it be stored in memory? We zeroing out buffers but do nothing with key, which is more sensitive.

Copy link
Contributor Author

@fmorg-git fmorg-git Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the keys are loaded by OM on startup and cached in memory until restart, and are periodically background refreshed. I updated to remove unnecessary zero filling.

// AES-GCM parameters
private static final int GCM_IV_LENGTH = 12; // 96 bits

private static final SecureRandom SECURE_RANDOM = new SecureRandom();
Copy link

@yandrey321 yandrey321 Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use non-blocking provider like NativePRNGNonBlocking ?


// Initialize AES-GCM cipher
final Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", BC_PROVIDER);
final GCMParameterSpec spec = new GCMParameterSpec(128, iv);
Copy link

@yandrey321 yandrey321 Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

128 should be a named constant

Copy link
Contributor Author

@fmorg-git fmorg-git Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated (I updated the transformation and algorithm to be constants also.) Also I updated to use non-blocking provider where available.

* Encrypt a sensitive field using the configured encryption key.
*/
private String encryptSensitiveField(String value) {
if (value == null || value.isEmpty()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be a part of STSTokenEncryption.encrypt() contract?

in this case we dont need this logic in all the client calls

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

* Decrypt a sensitive field using the configured encryption key.
*/
private String decryptSensitiveField(String encryptedValue) {
if (encryptedValue == null || encryptedValue.isEmpty()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't it be the part of STSTokenEncryption.decrypt() contract?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how would it work with JDK 11/17/21?

Copy link
Contributor Author

@fmorg-git fmorg-git Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to Maven, this dependency would work on Java 1.8 and later

private static final String AES_CIPHER_TRANSFORMATION = "AES/GCM/NoPadding";

private static final SecureRandom SECURE_RANDOM;
private static final BouncyCastleProvider BC_PROVIDER = new BouncyCastleProvider();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason to use BC provider vs native JDK implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my understanding is we need to code for Java 1.8, and native JDK doesn't add support for HKDF until Java 11. HKDF is recommended by NIST and used by TLS 1.3.

* Includes token type, ownerId, expiry millis, and secretKeyId.
*/
private byte[] computeAadBytes() {
final String aad = "v1|S3_STS_TOKEN|" + getOwnerId() + "|" + getExpiry().toEpochMilli() + "|" +

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stringbuilder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Copy link
Contributor

@sodonnel sodonnel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. We can commit if we get green CI and @yandrey321 is happy.

Copy link

@yandrey321 yandrey321 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sodonnel sodonnel merged commit c63f444 into apache:HDDS-13323-sts Dec 2, 2025
83 of 84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sts Changes for Ozone's S3 Security Token Service

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Comments