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 d6628f25adc HDDS-17654. Avoid wait for expired token in STS tests 
(#12102)
d6628f25adc is described below

commit d6628f25adcedb50b8e23028177e25b82b72baf4
Author: fmorg-git <[email protected]>
AuthorDate: Sat Nov 21 10:46:39 2026 -0800

    HDDS-17654. Avoid wait for expired token in STS tests (#12102)
---
 .../apache/hadoop/ozone/om/helpers/S3STSUtils.java | 57 ++++++++++++++++++--
 .../hadoop/ozone/om/helpers/TestS3STSUtils.java    | 61 ++++++++++++++++++++++
 .../src/main/compose/ozonesecure-ha/docker-config  |  2 +
 .../smoketest/security/ozone-secure-sts.resource   | 32 +++++-------
 .../main/smoketest/security/ozone-secure-sts.robot | 14 ++---
 .../org/apache/hadoop/ozone/om/OzoneManager.java   | 12 +++++
 .../request/s3/security/S3AssumeRoleRequest.java   |  2 +-
 .../s3/security/TestS3AssumeRoleRequest.java       | 43 +++++++++++++++
 .../apache/hadoop/ozone/s3/S3STSHttpServer.java    |  3 ++
 .../hadoop/ozone/s3sts/S3STSDurationConfig.java    | 41 +++++++++++++++
 .../apache/hadoop/ozone/s3sts/S3STSEndpoint.java   | 10 +++-
 .../hadoop/ozone/s3/TestS3GatewayHttpServers.java  | 48 +++++++++++++++++
 .../hadoop/ozone/s3sts/TestS3STSEndpoint.java      | 41 +++++++++++++++
 13 files changed, 334 insertions(+), 32 deletions(-)

diff --git 
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/S3STSUtils.java
 
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/S3STSUtils.java
index 96627a1b9ea..4a13550e384 100644
--- 
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/S3STSUtils.java
+++ 
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/S3STSUtils.java
@@ -19,9 +19,11 @@
 
 import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.INVALID_REQUEST;
 
+import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import java.util.Map;
 import net.jcip.annotations.Immutable;
+import org.apache.hadoop.hdds.conf.ConfigurationSource;
 import org.apache.hadoop.ozone.om.exceptions.OMException;
 
 /**
@@ -34,6 +36,12 @@ public final class S3STSUtils {
   public static final int MAX_DURATION_SECONDS = 43200;       // 12 hours
   public static final int MIN_DURATION_SECONDS = 900;         // 15 minutes
 
+  /**
+   * Test-only: override the minimum AssumeRole {@code DurationSeconds} 
accepted by OM and S3 Gateway STS.
+   * Values may only lower the AWS-compatible minimum of 900 seconds.  Valid 
range is 1-900.
+   */
+  public static final String OZONE_S3G_STS_TEST_MIN_DURATION_SECONDS_KEY = 
"ozone.s3g.sts.test.min.duration.seconds";
+
   public static final int ASSUME_ROLE_SESSION_NAME_MIN_LENGTH = 2;
   public static final int ASSUME_ROLE_SESSION_NAME_MAX_LENGTH = 64;
 
@@ -99,6 +107,17 @@ public static void addAssumeRoleAuditParams(Map<String, 
String> auditParams, Str
     auditParams.put("requestId", requestId);
   }
 
+  /**
+   * Returns the minimum AssumeRole duration in seconds: either the AWS 
default 900, or the test-only override when set.
+   */
+  public static int getMinDurationSeconds(ConfigurationSource conf) {
+    final int configured = 
conf.getInt(OZONE_S3G_STS_TEST_MIN_DURATION_SECONDS_KEY, MIN_DURATION_SECONDS);
+    Preconditions.checkArgument(
+        configured >= 1 && configured <= MIN_DURATION_SECONDS, "%s must be 
between 1 and %s, but was %s",
+        OZONE_S3G_STS_TEST_MIN_DURATION_SECONDS_KEY, MIN_DURATION_SECONDS, 
configured);
+    return configured;
+  }
+
   /**
    * Validates the duration in seconds.
    * @param durationSeconds duration in seconds
@@ -106,8 +125,19 @@ public static void addAssumeRoleAuditParams(Map<String, 
String> auditParams, Str
    * @throws OMException if duration is invalid
    */
   public static int validateDuration(int durationSeconds) throws OMException {
-    if (durationSeconds < MIN_DURATION_SECONDS || durationSeconds > 
MAX_DURATION_SECONDS) {
-      throw new OMException(DURATION_VALIDATION_ERROR_MESSAGE, 
INVALID_REQUEST);
+    return validateDuration(durationSeconds, MIN_DURATION_SECONDS);
+  }
+
+  /**
+   * Validates the duration in seconds against the supplied minimum.
+   * @param durationSeconds duration in seconds
+   * @param minDurationSeconds minimum allowed duration
+   * @return validated duration
+   * @throws OMException if duration is invalid
+   */
+  public static int validateDuration(int durationSeconds, int 
minDurationSeconds) throws OMException {
+    if (durationSeconds < minDurationSeconds || durationSeconds > 
MAX_DURATION_SECONDS) {
+      throw new 
OMException(durationValidationErrorMessage(minDurationSeconds), 
INVALID_REQUEST);
     }
 
     return durationSeconds;
@@ -120,6 +150,17 @@ public static int validateDuration(int durationSeconds) 
throws OMException {
    * @throws OMException if duration is invalid
    */
   public static int validateDuration(String durationSeconds) throws 
OMException {
+    return validateDuration(durationSeconds, MIN_DURATION_SECONDS);
+  }
+
+  /**
+   * Validates the duration in seconds from a raw request value against the 
supplied minimum.
+   * @param durationSeconds duration in seconds as a string
+   * @param minDurationSeconds minimum allowed duration
+   * @return validated duration
+   * @throws OMException if duration is invalid
+   */
+  public static int validateDuration(String durationSeconds, int 
minDurationSeconds) throws OMException {
     if (durationSeconds == null) {
       return DEFAULT_DURATION_SECONDS;
     }
@@ -128,9 +169,9 @@ public static int validateDuration(String durationSeconds) 
throws OMException {
     try {
       value = Integer.parseInt(durationSeconds);
     } catch (NumberFormatException e) {
-      throw new OMException(DURATION_VALIDATION_ERROR_MESSAGE, 
INVALID_REQUEST);
+      throw new 
OMException(durationValidationErrorMessage(minDurationSeconds), 
INVALID_REQUEST);
     }
-    return validateDuration(value);
+    return validateDuration(value, minDurationSeconds);
   }
 
   /**
@@ -212,6 +253,14 @@ public static String toAssumedRoleUserArn(String 
validRoleArn, String roleSessio
     return stringBuilder.toString();
   }
 
+  private static String durationValidationErrorMessage(int minDurationSeconds) 
{
+    if (minDurationSeconds == MIN_DURATION_SECONDS) {
+      return DURATION_VALIDATION_ERROR_MESSAGE;
+    }
+    return "Invalid Value: DurationSeconds must be a number between " + 
minDurationSeconds + " and " +
+        MAX_DURATION_SECONDS + " seconds";
+  }
+
   private static String[] splitRoleArnWithoutRegex(String roleArn) {
     final String[] parts = new String[6];
     int start = 0;
diff --git 
a/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestS3STSUtils.java
 
b/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestS3STSUtils.java
index 9fb7b0eb3f1..a9db0b026b7 100644
--- 
a/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestS3STSUtils.java
+++ 
b/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestS3STSUtils.java
@@ -17,10 +17,12 @@
 
 package org.apache.hadoop.ozone.om.helpers;
 
+import static 
org.apache.hadoop.ozone.om.helpers.S3STSUtils.OZONE_S3G_STS_TEST_MIN_DURATION_SECONDS_KEY;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
 import org.apache.hadoop.ozone.om.exceptions.OMException;
 import org.junit.jupiter.api.Test;
 
@@ -95,4 +97,63 @@ public void testValidateDurationIntOutOfRange() {
     final OMException tooLong = assertThrows(OMException.class, () -> 
S3STSUtils.validateDuration(43201));
     
assertThat(tooLong.getMessage()).isEqualTo(DURATION_VALIDATION_ERROR_MESSAGE);
   }
+
+  @Test
+  public void testGetMinDurationSecondsDefault() {
+    final OzoneConfiguration conf = new OzoneConfiguration();
+    assertEquals(900, S3STSUtils.getMinDurationSeconds(conf));
+  }
+
+  @Test
+  public void testGetMinDurationSecondsOverride() {
+    final OzoneConfiguration conf = new OzoneConfiguration();
+    conf.setInt(OZONE_S3G_STS_TEST_MIN_DURATION_SECONDS_KEY, 5);
+    assertEquals(5, S3STSUtils.getMinDurationSeconds(conf));
+
+    conf.setInt(OZONE_S3G_STS_TEST_MIN_DURATION_SECONDS_KEY, 1);
+    assertEquals(1, S3STSUtils.getMinDurationSeconds(conf));
+
+    conf.setInt(OZONE_S3G_STS_TEST_MIN_DURATION_SECONDS_KEY, 
S3STSUtils.MIN_DURATION_SECONDS);
+    assertEquals(900, S3STSUtils.getMinDurationSeconds(conf));
+  }
+
+  @Test
+  public void testGetMinDurationSecondsRejectsOutOfRange() {
+    final OzoneConfiguration conf = new OzoneConfiguration();
+    conf.setInt(OZONE_S3G_STS_TEST_MIN_DURATION_SECONDS_KEY, 0);
+    final IllegalArgumentException tooSmall = assertThrows(
+        IllegalArgumentException.class, () -> 
S3STSUtils.getMinDurationSeconds(conf));
+    assertEquals(
+        "ozone.s3g.sts.test.min.duration.seconds must be between 1 and 900, 
but was 0",
+        tooSmall.getMessage());
+
+    conf.setInt(OZONE_S3G_STS_TEST_MIN_DURATION_SECONDS_KEY, 901);
+    final IllegalArgumentException tooLarge = assertThrows(
+        IllegalArgumentException.class, () -> 
S3STSUtils.getMinDurationSeconds(conf));
+    assertEquals(
+        "ozone.s3g.sts.test.min.duration.seconds must be between 1 and 900, 
but was 901",
+        tooLarge.getMessage());
+  }
+
+  @Test
+  public void testValidateDurationWithCustomMinimum() throws OMException {
+    assertEquals(5, S3STSUtils.validateDuration(5, 5));
+
+    final OMException tooShort = assertThrows(OMException.class, () -> 
S3STSUtils.validateDuration(4, 5));
+    assertEquals(
+        "Invalid Value: DurationSeconds must be a number between 5 and 43200 
seconds", tooShort.getMessage());
+  }
+
+  @Test
+  public void testValidateDurationStringWithCustomMinimum() throws OMException 
{
+    assertEquals(5, S3STSUtils.validateDuration("5", 5));
+
+    final OMException tooShort = assertThrows(OMException.class, () -> 
S3STSUtils.validateDuration("4", 5));
+    assertEquals(
+        "Invalid Value: DurationSeconds must be a number between 5 and 43200 
seconds", tooShort.getMessage());
+
+    final OMException nonNumeric = assertThrows(OMException.class, () -> 
S3STSUtils.validateDuration("abc", 5));
+    assertEquals(
+        "Invalid Value: DurationSeconds must be a number between 5 and 43200 
seconds", nonNumeric.getMessage());
+  }
 }
diff --git a/hadoop-ozone/dist/src/main/compose/ozonesecure-ha/docker-config 
b/hadoop-ozone/dist/src/main/compose/ozonesecure-ha/docker-config
index 25ffe353421..079908e4730 100644
--- a/hadoop-ozone/dist/src/main/compose/ozonesecure-ha/docker-config
+++ b/hadoop-ozone/dist/src/main/compose/ozonesecure-ha/docker-config
@@ -106,6 +106,8 @@ 
OZONE-SITE.XML_ozone.http.filter.initializers=org.apache.hadoop.security.Authent
 
 # Enable S3 Gateway STS (AWS STS compatible) endpoint on s3g (http://s3g:9880)
 OZONE-SITE.XML_ozone.s3g.sts.http.enabled=true
+# Test-only: allow short AssumeRole DurationSeconds for STS expired-token 
acceptance tests
+OZONE-SITE.XML_ozone.s3g.sts.test.min.duration.seconds=5
 
 OZONE-SITE.XML_ozone.om.http.auth.type=kerberos
 OZONE-SITE.XML_hdds.scm.http.auth.type=kerberos
diff --git 
a/hadoop-ozone/dist/src/main/smoketest/security/ozone-secure-sts.resource 
b/hadoop-ozone/dist/src/main/smoketest/security/ozone-secure-sts.resource
index e125e44e3e9..9c6c6fbbac1 100644
--- a/hadoop-ozone/dist/src/main/smoketest/security/ozone-secure-sts.resource
+++ b/hadoop-ozone/dist/src/main/smoketest/security/ozone-secure-sts.resource
@@ -101,10 +101,9 @@ Assume Role And Get Temporary Credentials
     ${cmd} =                      Set Variable If               
'${duration_seconds}' != '${EMPTY}'    ${cmd} --duration-seconds 
${duration_seconds}    ${cmd}
     ${cmd} =                      Set Variable If               
'${policy_json}' != '${EMPTY}'    ${cmd} --policy '${policy_json}'    ${cmd}
 
+    ${before} =                   Get Current Date              time_zone=UTC
     ${json} =                     Execute                       ${cmd}
-
-    # Don't include the latency of the AssumeRole call when checking the 
expiration
-    ${now} =                      Get Current Date              time_zone=UTC
+    ${after} =                    Get Current Date              time_zone=UTC
 
     Should Contain                ${json}                       Credentials
 
@@ -126,20 +125,23 @@ Assume Role And Get Temporary Credentials
     ${minimum_expected} =         Evaluate                      
int(${expected_duration}) - 2
     ${maximum_expected} =         Evaluate                      
int(${expected_duration}) + 2
 
-    # Verify Expiration based on requested duration (or default 1h), with 
small grace (plus or minus 2 seconds) for clock skew.
+    # Expiration must fall within the requested duration window with a small 
grace (+/- 2 seconds) for clock skew and second truncation.
     ${expiration} =               Execute                       echo '${json}' 
| jq -r '.Credentials.Expiration'
-    ${time_diff} =                Subtract Date From Date       ${expiration}  
  ${now}
-    Should Be True                ${time_diff} >= ${minimum_expected}          
 Expected expiration to be at least ${minimum_expected}s in the future, but was 
${time_diff}s
-    Should Be True                ${time_diff} <= ${maximum_expected}          
 Expected expiration to be at most ${maximum_expected}s in the future, but was 
${time_diff}s
+    ${time_diff_from_before} =    Subtract Date From Date       ${expiration}  
  ${before}
+    ${time_diff_from_after} =     Subtract Date From Date       ${expiration}  
  ${after}
+    Should Be True                ${time_diff_from_before} >= 
${minimum_expected}    Expected expiration to be at least ${minimum_expected}s 
after request start, but was ${time_diff_from_before}s
+    Should Be True                ${time_diff_from_after} <= 
${maximum_expected}     Expected expiration to be at most ${maximum_expected}s 
after request end, but was ${time_diff_from_after}s
 
 Assume Role And Store Expired STS Token Credentials
-    # Issue a 900s STS credential and store it in EXPIRED_STS_TOKEN_* globals 
only (it should never be used/modified until the "Expired STS temporary 
credentials return ExpiredToken on S3 APIs" test).
-    [Arguments]                   ${perm_access_key_id}  ${perm_secret_key}  
${role_arn}  ${duration_seconds}=900
-    Configure AWS Profile         permanent  ${perm_access_key_id}  
${perm_secret_key}
+    # Issue a short-lived STS credential (default 5s) and store it in 
EXPIRED_STS_TOKEN_* globals only (unused until the expired-token S3 API test).
+    # Profile expired_sts_token_issuer disables botocore parameter_validation 
so DurationSeconds can be below 900.
+    [Arguments]                   ${perm_access_key_id}  ${perm_secret_key}  
${role_arn}  ${duration_seconds}=5
+    Configure AWS Profile         expired_sts_token_issuer  
${perm_access_key_id}  ${perm_secret_key}
+    Execute                       aws configure set parameter_validation false 
--profile expired_sts_token_issuer
     ${suffix} =                   Generate Random String        8    [LOWER]
     ${role_session_name} =        Set Variable                  
expired-sts-token-${suffix}
 
-    ${cmd} =                      Set Variable                  aws sts 
assume-role --endpoint-url ${STS_ENDPOINT_URL} --role-arn ${role_arn} 
--role-session-name ${role_session_name} --duration-seconds ${duration_seconds} 
--output json --profile permanent
+    ${cmd} =                      Set Variable                  aws sts 
assume-role --endpoint-url ${STS_ENDPOINT_URL} --role-arn ${role_arn} 
--role-session-name ${role_session_name} --duration-seconds ${duration_seconds} 
--output json --profile expired_sts_token_issuer
 
     ${json} =                     Execute                       ${cmd}
     Should Contain                ${json}                       Credentials
@@ -160,14 +162,6 @@ Expired STS Token Credentials Should Be Available
     Should Not Be Empty           ${EXPIRED_STS_TOKEN_SECRET_ACCESS_KEY}     
Expired STS token secret key is unavailable.
     Should Not Be Empty           ${EXPIRED_STS_TOKEN_SESSION_TOKEN}         
Expired STS token session token is unavailable.
 
-Wait Until Expired STS Token Expiration Elapsed
-    # Matches the +/-2s skew tolerance used for AssumeRole duration checks.
-    Expired STS Token Credentials Should Be Available
-    ${now} =                      Get Current Date              time_zone=UTC
-    ${secondsUntilExpiration} =   Subtract Date From Date       
${EXPIRED_STS_TOKEN_EXPIRATION}    ${now}
-    ${remaining} =                Evaluate                      
${secondsUntilExpiration} + 2
-    Run Keyword If                ${remaining} > 0              Sleep  
${remaining}
-
 Configure Expired STS Token S3 Profile
     Expired STS Token Credentials Should Be Available
     Configure AWS Profile         ${EXPIRED_STS_TOKEN_PROFILE}  
${EXPIRED_STS_TOKEN_ACCESS_KEY_ID}  ${EXPIRED_STS_TOKEN_SECRET_ACCESS_KEY}  
${EXPIRED_STS_TOKEN_SESSION_TOKEN}
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 2deaca7af85..10105c84333 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
@@ -477,7 +477,7 @@ Get S3 Credentials for Service Catalog Principal, Create 
Iceberg Buckets, and Up
     Set Global Variable           ${PERMANENT_ACCESS_KEY_ID}    ${accessKeyId}
     Set Global Variable           ${PERMANENT_SECRET_KEY}       ${secretKey}
 
-    # Long-lived 15-minute STS credential to test STS token expiration and 
proper error message
+    # Short-lived STS credential (stored until the expired-token S3 API test 
runs later in the suite)
     Assume Role And Store Expired STS Token Credentials         
perm_access_key_id=${PERMANENT_ACCESS_KEY_ID}  
perm_secret_key=${PERMANENT_SECRET_KEY}  
role_arn=${ICEBERG_ALL_ACCESS_ROLE_OBS_ARN}
 
     # Create buckets as a different user so the permanent credential principal 
isn't the bucket owner.
@@ -743,11 +743,13 @@ Assume Role Should Fail For Too Short Role Session Name
 
 Assume Role Should Fail For Invalid Duration
     # AWS CLI rejects out-of-range DurationSeconds before the request is sent, 
so use curl.
-    Assume Role Should Fail Using Curl  
perm_access_key_id=${PERMANENT_ACCESS_KEY_ID}  
perm_secret_key=${PERMANENT_SECRET_KEY}  expected_error=ValidationError  
expected_http_code=400  role_arn=${ICEBERG_ALL_ACCESS_ROLE_OBS_ARN}  
duration_seconds=43201  expected_message=must be a number between 900 and 43200 
seconds
+    # The minimum is 5 seconds (not the AWS default of 900) because 
ozonesecure-ha sets ozone.s3g.sts.test.min.duration.seconds=5.
+    Assume Role Should Fail Using Curl  
perm_access_key_id=${PERMANENT_ACCESS_KEY_ID}  
perm_secret_key=${PERMANENT_SECRET_KEY}  expected_error=ValidationError  
expected_http_code=400  role_arn=${ICEBERG_ALL_ACCESS_ROLE_OBS_ARN}  
duration_seconds=4  expected_message=DurationSeconds must be a number between 5 
and 43200 seconds
+    Assume Role Should Fail Using Curl  
perm_access_key_id=${PERMANENT_ACCESS_KEY_ID}  
perm_secret_key=${PERMANENT_SECRET_KEY}  expected_error=ValidationError  
expected_http_code=400  role_arn=${ICEBERG_ALL_ACCESS_ROLE_OBS_ARN}  
duration_seconds=43201  expected_message=DurationSeconds must be a number 
between 5 and 43200 seconds
     # Check duration that overflows integer as well
-    Assume Role Should Fail Using Curl  
perm_access_key_id=${PERMANENT_ACCESS_KEY_ID}  
perm_secret_key=${PERMANENT_SECRET_KEY}  expected_error=ValidationError  
expected_http_code=400  role_arn=${ICEBERG_ALL_ACCESS_ROLE_OBS_ARN}  
duration_seconds=43200100000  expected_message=must be a number between 900 and 
43200 seconds
+    Assume Role Should Fail Using Curl  
perm_access_key_id=${PERMANENT_ACCESS_KEY_ID}  
perm_secret_key=${PERMANENT_SECRET_KEY}  expected_error=ValidationError  
expected_http_code=400  role_arn=${ICEBERG_ALL_ACCESS_ROLE_OBS_ARN}  
duration_seconds=43200100000  expected_message=DurationSeconds must be a number 
between 5 and 43200 seconds
     # Whitespace-only DurationSeconds must be rejected
-    Assume Role Should Fail Using Curl  
perm_access_key_id=${PERMANENT_ACCESS_KEY_ID}  
perm_secret_key=${PERMANENT_SECRET_KEY}  expected_error=ValidationError  
expected_http_code=400  role_arn=${ICEBERG_ALL_ACCESS_ROLE_OBS_ARN}  
duration_seconds=${SPACE}${SPACE}${SPACE}${SPACE}${SPACE}  
expected_message=must be a number between 900 and 43200 seconds
+    Assume Role Should Fail Using Curl  
perm_access_key_id=${PERMANENT_ACCESS_KEY_ID}  
perm_secret_key=${PERMANENT_SECRET_KEY}  expected_error=ValidationError  
expected_http_code=400  role_arn=${ICEBERG_ALL_ACCESS_ROLE_OBS_ARN}  
duration_seconds=${SPACE}${SPACE}${SPACE}${SPACE}${SPACE}  
expected_message=DurationSeconds must be a number between 5 and 43200 seconds
 
 Assume Role With ExternalId Should Fail As UnsupportedOperation
     Assume Role Should Fail       
perm_access_key_id=${PERMANENT_ACCESS_KEY_ID}  
perm_secret_key=${PERMANENT_SECRET_KEY}  expected_error=UnsupportedOperation  
expected_http_code=501  role_arn=${ICEBERG_ALL_ACCESS_ROLE_OBS_ARN}  
extra_cli_args=--external-id test-external-id
@@ -1622,11 +1624,9 @@ Get Caller Identity Rejects Invalid Version
     Get Caller Identity Should Fail                             InvalidAction  
  api_version=2020-01-01
 
 Expired STS temporary credentials must return ExpiredToken on S3 APIs
-    # Increase timeout to account for 15 minute STS token expiration plus the 
time to execute the api calls
-    [Timeout]                     25 minutes
     ${dummy_mpu_upload_id} =      Set Variable                  
dummyExpiredStsMpuUploadId01
 
-    Wait Until Expired STS Token Expiration Elapsed
+    Expired STS Token Credentials Should Be Available
     Configure Expired STS Token S3 Profile
 
     Execute S3api Expect Expired Token                          list-buckets 
--output json
diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
index cc2f2845f60..c120d2cfb35 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
@@ -290,6 +290,7 @@
 import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
 import org.apache.hadoop.ozone.om.helpers.OzoneFileStatus;
 import org.apache.hadoop.ozone.om.helpers.OzoneFileStatusLight;
+import org.apache.hadoop.ozone.om.helpers.S3STSUtils;
 import org.apache.hadoop.ozone.om.helpers.S3VolumeContext;
 import org.apache.hadoop.ozone.om.helpers.ServiceInfo;
 import org.apache.hadoop.ozone.om.helpers.ServiceInfoEx;
@@ -518,6 +519,7 @@ public final class OzoneManager extends 
ServiceRuntimeInfoImpl
   private final boolean isS3MultiTenancyEnabled;
   private final boolean isStrictS3;
   private final boolean isS3STSEnabled;
+  private final int s3StsMinDurationSeconds;
   private ExitManager exitManager;
   /** Test-only hook to fail a checkpoint-install DB backup part way through. 
*/
   private FaultInjector checkpointBackupInjector;
@@ -768,6 +770,9 @@ private OzoneManager(OzoneConfiguration conf, StartupOption 
startupOption)
     this.isS3STSEnabled = conf.getBoolean(
         OzoneConfigKeys.OZONE_S3G_STS_HTTP_ENABLED_KEY,
         OzoneConfigKeys.OZONE_S3G_STS_HTTP_ENABLED_DEFAULT);
+    // Invalid AssumeRole min duration with STS feature flag off must not 
break startup
+    this.s3StsMinDurationSeconds = isS3STSEnabled ? 
S3STSUtils.getMinDurationSeconds(conf) :
+        S3STSUtils.MIN_DURATION_SECONDS;
 
     metrics = OMMetrics.create(conf);
     omSnapshotIntMetrics = OmSnapshotInternalMetrics.create(getOMServiceId(),
@@ -1217,6 +1222,13 @@ public boolean isS3STSEnabled() {
     return isS3STSEnabled;
   }
 
+  /**
+   * Returns the minimum valid AssumeRole {@code DurationSeconds}, including 
any test-only override.
+   */
+  public int getS3StsMinDurationSeconds() {
+    return s3StsMinDurationSeconds;
+  }
+
   /**
    * Throws OMException FEATURE_NOT_ENABLED if S3 multi-tenancy is not enabled.
    */
diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/security/S3AssumeRoleRequest.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/security/S3AssumeRoleRequest.java
index 173ae19461f..22cc7e98f1b 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/security/S3AssumeRoleRequest.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/security/S3AssumeRoleRequest.java
@@ -132,7 +132,7 @@ public OMRequest preExecute(OzoneManager ozoneManager) 
throws IOException {
       // The original AssumeRole request is converted to an 
UpdateAssumeRoleRequest with the generated
       // values. This update request will be submitted to Ratis and replicated 
across all OMs.
       // All OMs in HA mode therefore will have identical audit logs with the 
same tempAccessKeyId.
-      S3STSUtils.validateDuration(durationSeconds);
+      S3STSUtils.validateDuration(durationSeconds, 
ozoneManager.getS3StsMinDurationSeconds());
       S3STSUtils.validateRoleSessionName(roleSessionName);
       final String targetRoleName = 
AwsRoleArnValidator.validateAndExtractRoleNameFromArn(roleArn);
 
diff --git 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/s3/security/TestS3AssumeRoleRequest.java
 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/s3/security/TestS3AssumeRoleRequest.java
index 3d073c7b71e..99c1b07ceec 100644
--- 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/s3/security/TestS3AssumeRoleRequest.java
+++ 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/s3/security/TestS3AssumeRoleRequest.java
@@ -19,6 +19,7 @@
 
 import static java.util.Collections.emptySet;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
@@ -123,6 +124,7 @@ public void setup() throws IOException {
 
     final OzoneConfiguration configuration = new OzoneConfiguration();
     when(ozoneManager.getConfiguration()).thenReturn(configuration);
+    when(ozoneManager.getS3StsMinDurationSeconds()).thenReturn(900);
     when(ozoneManager.isS3MultiTenancyEnabled()).thenReturn(false);
 
     final SecretKeySignerClient secretKeyClient = 
mock(SecretKeySignerClient.class);
@@ -248,6 +250,47 @@ public void testValidDurationMinBoundary() throws 
IOException {
     assertMarkForAuditCalled(requestWithCredentials);
   }
 
+  @Test
+  public void testValidDurationWithTestMinOverride() throws IOException {
+    when(ozoneManager.getS3StsMinDurationSeconds()).thenReturn(5);
+
+    final OMRequest omRequest = baseOmRequestBuilder()
+        .setAssumeRoleRequest(
+            AssumeRoleRequest.newBuilder()
+                .setRoleArn(ROLE_ARN_1)
+                .setRoleSessionName(SESSION_NAME)
+                .setDurationSeconds(5)
+                .setRequestId(REQUEST_ID)
+        ).build();
+
+    final S3AssumeRoleRequest request = new S3AssumeRoleRequest(omRequest, 
CLOCK);
+    final OMRequest preExecutedRequest = request.preExecute(ozoneManager);
+
+    assertLeaderGeneratedAssumeRoleFields(preExecutedRequest, 5);
+  }
+
+  @Test
+  public void testInvalidDurationBelowTestMinOverride() {
+    when(ozoneManager.getS3StsMinDurationSeconds()).thenReturn(5);
+
+    final OMRequest omRequest = baseOmRequestBuilder()
+        .setAssumeRoleRequest(
+            AssumeRoleRequest.newBuilder()
+                .setRoleArn(ROLE_ARN_1)
+                .setRoleSessionName(SESSION_NAME)
+                .setDurationSeconds(4)
+                .setRequestId(REQUEST_ID)
+        ).build();
+
+    final S3AssumeRoleRequest request = new S3AssumeRoleRequest(omRequest, 
CLOCK);
+    final OMException exception = assertThrows(OMException.class, () -> 
request.preExecute(ozoneManager));
+
+    
assertThat(exception.getResult()).isEqualTo(OMException.ResultCodes.INVALID_REQUEST);
+    assertEquals(
+        "Invalid Value: DurationSeconds must be a number between 5 and 43200 
seconds", exception.getMessage());
+    assertMarkForAuditCalled(request);
+  }
+
   @Test
   public void testMissingS3Authentication() {
     final OMRequest omRequest = OMRequest.newBuilder()  // note: not using 
baseOMRequestBuilder that has S3 auth
diff --git 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/S3STSHttpServer.java
 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/S3STSHttpServer.java
index 7a6d9eee24d..cb53221c14b 100644
--- 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/S3STSHttpServer.java
+++ 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/S3STSHttpServer.java
@@ -33,6 +33,7 @@
 import java.io.IOException;
 import org.apache.hadoop.hdds.conf.MutableConfigurationSource;
 import org.apache.hadoop.hdds.server.http.BaseHttpServer;
+import org.apache.hadoop.ozone.om.helpers.S3STSUtils;
 
 /**
  * HTTP server for the S3 Gateway STS endpoint.
@@ -42,6 +43,8 @@ public class S3STSHttpServer extends BaseHttpServer {
   S3STSHttpServer(MutableConfigurationSource conf, String name) throws 
IOException {
     super(conf, name);
     if (isEnabled()) {
+      // Fail fast if the test override property is invalid
+      S3STSUtils.getMinDurationSeconds(conf);
       WeldCdiIntegration.enable(getWebAppContext());
     }
   }
diff --git 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3sts/S3STSDurationConfig.java
 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3sts/S3STSDurationConfig.java
new file mode 100644
index 00000000000..2528ab74475
--- /dev/null
+++ 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3sts/S3STSDurationConfig.java
@@ -0,0 +1,41 @@
+/*
+ * 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.s3sts;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.om.helpers.S3STSUtils;
+
+/**
+ * Immutable STS duration configuration shared by all STS endpoint instances.
+ */
+@Singleton
+public final class S3STSDurationConfig {
+
+  private final int minDurationSeconds;
+
+  @Inject
+  S3STSDurationConfig(OzoneConfiguration conf) {
+    minDurationSeconds = S3STSUtils.getMinDurationSeconds(conf);
+  }
+
+  int getMinDurationSeconds() {
+    return minDurationSeconds;
+  }
+}
diff --git 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3sts/S3STSEndpoint.java
 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3sts/S3STSEndpoint.java
index 5d7d8785df8..d2a99223eab 100644
--- 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3sts/S3STSEndpoint.java
+++ 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3sts/S3STSEndpoint.java
@@ -124,11 +124,19 @@ public class S3STSEndpoint extends S3STSEndpointBase {
   @Inject
   private RequestIdentifier requestIdentifier;
 
+  @Inject
+  private S3STSDurationConfig stsDurationConfig;
+
   @VisibleForTesting
   public void setRequestIdentifier(RequestIdentifier requestIdentifier) {
     this.requestIdentifier = requestIdentifier;
   }
 
+  @VisibleForTesting
+  public void setS3STSDurationConfig(S3STSDurationConfig config) {
+    this.stsDurationConfig = config;
+  }
+
   /**
    * STS endpoint that handles GET requests with query parameters.
    * AWS STS supports both GET and POST requests.
@@ -225,7 +233,7 @@ private Response handleAssumeRole(Set<String> 
paramNamesToValidate, String roleA
     int duration = S3STSUtils.DEFAULT_DURATION_SECONDS;
     String durationValidationError = null;
     try {
-      duration = S3STSUtils.validateDuration(durationSeconds);
+      duration = S3STSUtils.validateDuration(durationSeconds, 
stsDurationConfig.getMinDurationSeconds());
     } catch (OMException e) {
       durationValidationError = e.getMessage();
     }
diff --git 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/TestS3GatewayHttpServers.java
 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/TestS3GatewayHttpServers.java
index 9dd90214c70..714efb7130a 100644
--- 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/TestS3GatewayHttpServers.java
+++ 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/TestS3GatewayHttpServers.java
@@ -17,9 +17,14 @@
 
 package org.apache.hadoop.ozone.s3;
 
+import static 
org.apache.hadoop.ozone.om.helpers.S3STSUtils.OZONE_S3G_STS_TEST_MIN_DURATION_SECONDS_KEY;
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.fail;
 
 import java.io.IOException;
 import java.nio.file.Path;
@@ -115,6 +120,49 @@ void disabledStsServerIsCreatedWithoutCdiIntegration() {
     assertDoesNotThrow(() -> new S3STSHttpServer(conf, "s3g-sts"));
   }
 
+  @Test
+  void disabledStsServerIgnoresInvalidMinDurationConfig() {
+    final OzoneConfiguration conf = newConf();
+    conf.setInt(OZONE_S3G_STS_TEST_MIN_DURATION_SECONDS_KEY, 0);
+
+    assertDoesNotThrow(
+        () -> {
+          try (S3STSHttpServer server = new S3STSHttpServer(conf, "s3g-sts")) {
+            assertNull(server.getHttpAddress());
+          }
+        });
+  }
+
+  @Test
+  void enabledStsServerRejectsInvalidMinDurationConfig() {
+    final OzoneConfiguration conf = newConf();
+    conf.setBoolean(S3STSConfigKeys.OZONE_S3G_STS_HTTP_ENABLED_KEY, true);
+    conf.set(S3STSConfigKeys.OZONE_S3G_STS_HTTP_ADDRESS_KEY, 
PortAllocator.localhostWithFreePort());
+    conf.setInt(OZONE_S3G_STS_TEST_MIN_DURATION_SECONDS_KEY, 0);
+
+    assertThrows(
+        IllegalArgumentException.class, () -> {
+          try (S3STSHttpServer ignored = new S3STSHttpServer(conf, "s3g-sts")) 
{
+            fail("Expected invalid minimum duration configuration to be 
rejected");
+          }
+        });
+  }
+
+  @Test
+  void enabledStsServerAcceptsValidMinDurationConfig() {
+    final OzoneConfiguration conf = newConf();
+    conf.setBoolean(S3STSConfigKeys.OZONE_S3G_STS_HTTP_ENABLED_KEY, true);
+    conf.set(S3STSConfigKeys.OZONE_S3G_STS_HTTP_ADDRESS_KEY, 
PortAllocator.localhostWithFreePort());
+    conf.setInt(OZONE_S3G_STS_TEST_MIN_DURATION_SECONDS_KEY, 10);
+
+    assertDoesNotThrow(
+        () -> {
+          try (S3STSHttpServer server = new S3STSHttpServer(conf, "s3g-sts")) {
+            assertNotNull(server.getHttpAddress());
+          }
+        });
+  }
+
   /**
    * The secret endpoint expands {@code _HOST} in its SPNEGO principal from the
    * advertised web admin address, not from the bind host, which here is the
diff --git 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3sts/TestS3STSEndpoint.java
 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3sts/TestS3STSEndpoint.java
index 6eea1c06594..22e666027b4 100644
--- 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3sts/TestS3STSEndpoint.java
+++ 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3sts/TestS3STSEndpoint.java
@@ -18,6 +18,7 @@
 package org.apache.hadoop.ozone.s3sts;
 
 import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_S3_ADMINISTRATORS;
+import static 
org.apache.hadoop.ozone.om.helpers.S3STSUtils.OZONE_S3G_STS_TEST_MIN_DURATION_SECONDS_KEY;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -52,6 +53,7 @@
 import org.apache.hadoop.ozone.om.exceptions.OMException;
 import org.apache.hadoop.ozone.om.helpers.AssumeRoleResponseInfo;
 import org.apache.hadoop.ozone.om.helpers.CallerIdentityInfo;
+import org.apache.hadoop.ozone.om.helpers.S3STSUtils;
 import org.apache.hadoop.ozone.s3.OzoneConfigurationHolder;
 import org.apache.hadoop.ozone.s3.RequestIdentifier;
 import org.apache.hadoop.ozone.s3.exception.OSTSException;
@@ -114,6 +116,7 @@ public void setup() throws Exception {
     when(clientStub.getObjectStore()).thenReturn(objectStore);
 
     endpoint = new S3STSEndpoint();
+    endpoint.setS3STSDurationConfig(new S3STSDurationConfig(config));
     endpoint.setClient(clientStub);
     endpoint.setContext(context);
     auditLogger = mock(AuditLogger.class);
@@ -346,6 +349,44 @@ public void testStsAssumeRoleValidForGetMethod() throws 
Exception {
     assertEquals(ROLE_USER_ARN, arn);
   }
 
+  @Test
+  public void testStsAssumeRoleAllowsShortDurationWithTestMinOverride() throws 
Exception {
+    final OzoneConfiguration shortMinConf = new OzoneConfiguration();
+    shortMinConf.setInt(OZONE_S3G_STS_TEST_MIN_DURATION_SECONDS_KEY, 5);
+    endpoint.setS3STSDurationConfig(new S3STSDurationConfig(shortMinConf));
+    shortMinConf.setInt(OZONE_S3G_STS_TEST_MIN_DURATION_SECONDS_KEY, 
S3STSUtils.MIN_DURATION_SECONDS);
+
+    final Response response = endpoint.get("AssumeRole", ROLE_ARN, 
ROLE_SESSION_NAME, "5", "2011-06-15", null);
+
+    assertEquals(200, response.getStatus());
+    verify(auditLogger).logWriteSuccess(any(AuditMessage.class));
+    verify(auditLogger, never()).logWriteFailure(any(AuditMessage.class));
+
+    final ArgumentCaptor<Integer> durationCaptor = 
ArgumentCaptor.forClass(Integer.class);
+    verify(objectStore).assumeRole(anyString(), anyString(), 
durationCaptor.capture(), any(), anyString());
+    assertEquals(5, durationCaptor.getValue());
+  }
+
+  @Test
+  public void testStsAssumeRoleRejectsDurationBelowTestMinOverride() throws 
Exception {
+    final OzoneConfiguration shortMinConf = new OzoneConfiguration();
+    shortMinConf.setInt(OZONE_S3G_STS_TEST_MIN_DURATION_SECONDS_KEY, 5);
+    endpoint.setS3STSDurationConfig(new S3STSDurationConfig(shortMinConf));
+
+    final OSTSException ex = assertThrows(
+        OSTSException.class, () -> endpoint.get("AssumeRole", ROLE_ARN, 
ROLE_SESSION_NAME, "4", "2011-06-15", null));
+
+    assertEquals(400, ex.getHttpCode());
+    verify(auditLogger).logWriteFailure(any(AuditMessage.class));
+    verify(auditLogger, never()).logWriteSuccess(any(AuditMessage.class));
+    verify(objectStore, never()).assumeRole(anyString(), anyString(), 
anyInt(), any(), anyString());
+
+    ex.setRequestId(REQUEST_ID);
+    assertStsErrorXml(
+        ex.toXml(), STS_NS, "Sender", "ValidationError",
+        "Invalid Value: DurationSeconds must be a number between 5 and 43200 
seconds");
+  }
+
   @Test
   public void testStsAssumeRoleValidForPostMethod() throws Exception {
     setBaseAssumeRoleFormParameters();


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

Reply via email to