@@ -15,7 +15,6 @@ import (
1515 "net/http"
1616 "net/url"
1717 "os"
18- "strconv"
1918 "strings"
2019 "sync"
2120 "testing"
@@ -142,8 +141,8 @@ func getS3Credentials(t *testing.T) aws.CredentialsProvider {
142141}
143142
144143// setupS3Compat configures the cluster for S3 compatibility tests
145- // If auth is enabled, it automatically enables S3 reverse proxy and JWT token compat mode
146- // Returns a cleanup function that restores original settings
144+ // If auth is enabled, it enables S3 reverse proxy feature.
145+ // S3 JWT authentication (via X-Amz-Security-Token) will be checked as a fallback if no Authorization header is present.
147146func setupS3Compat (t * testing.T ) {
148147 config , err := api .GetClusterConfig (tools .BaseAPIParams ())
149148 tassert .CheckFatal (t , err )
@@ -153,19 +152,16 @@ func setupS3Compat(t *testing.T) {
153152 return
154153 }
155154
156- // Auth is enabled - ensure S3 JWT compat mode is enabled
155+ // Auth is enabled - ensure S3 reverse proxy is enabled
157156 originalFeatures := config .Features .String ()
158- originalS3TokenCompat := strconv .FormatBool (config .Auth .AllowS3TokenCompat )
159157
160158 tools .SetClusterConfig (t , cos.StrKVs {
161- "features" : feat .S3ReverseProxy .String (),
162- "auth.allow_s3_token_compat" : "true" ,
159+ "features" : feat .S3ReverseProxy .String (),
163160 })
164161
165162 t .Cleanup (func () {
166163 tools .SetClusterConfig (t , cos.StrKVs {
167- "features" : originalFeatures ,
168- "auth.allow_s3_token_compat" : originalS3TokenCompat ,
164+ "features" : originalFeatures ,
169165 })
170166 })
171167}
@@ -712,13 +708,6 @@ func TestS3JWTAuth(t *testing.T) {
712708 // Create test bucket
713709 tools .CreateBucket (t , proxyURL , bck , nil , true /*cleanup*/ )
714710
715- // VERIFY: S3 JWT compat is enabled
716- updatedConfig , err := api .GetClusterConfig (authBP )
717- tassert .CheckFatal (t , err )
718- tassert .Fatalf (t , updatedConfig .Auth .AllowS3TokenCompat ,
719- "S3 JWT compat mode should be enabled but got: %v" , updatedConfig .Auth .AllowS3TokenCompat )
720- tlog .Logfln ("✓ S3 JWT compatibility mode enabled" )
721-
722711 // Get a valid JWT token from the authenticated BaseParams
723712 testJWT := authBP .Token
724713 tassert .Fatalf (t , testJWT != "" , "Expected valid auth token from tools.BaseAPIParams()" )
@@ -816,19 +805,9 @@ func TestS3JWTAuthFailures(t *testing.T) {
816805 bck = cmn.Bck {Name : "test-s3-jwt-fail-" + trand .String (6 ), Provider : apc .AIS }
817806 )
818807
819- // Get authenticated BaseParams
820- authBP := tools .BaseAPIParams ()
821-
822808 // Create test bucket
823809 tools .CreateBucket (t , proxyURL , bck , nil , true /*cleanup*/ )
824810
825- // VERIFY: S3 JWT compat is enabled
826- updatedConfig , err := api .GetClusterConfig (authBP )
827- tassert .CheckFatal (t , err )
828- tassert .Fatalf (t , updatedConfig .Auth .AllowS3TokenCompat ,
829- "S3 JWT compat mode should be enabled but got: %v" , updatedConfig .Auth .AllowS3TokenCompat )
830- tlog .Logfln ("✓ S3 JWT compatibility mode enabled" )
831-
832811 // Test 1: Request with NO credentials at all
833812 tlog .Logln ("Test 1: Request with NO credentials should fail..." )
834813 noCfg , err := config .LoadDefaultConfig (
@@ -914,77 +893,3 @@ func TestS3JWTAuthFailures(t *testing.T) {
914893 tassert .Fatalf (t , err != nil , "Expected request with malformed JWT to fail, but it succeeded" )
915894 tlog .Logfln ("✓ Malformed JWT signature failed as expected: %v" , err )
916895}
917-
918- // TestS3JWTAuthDisabledByDefault validates backward compatibility:
919- // When auth is enabled but allow_s3_token_compat is false (default),
920- // valid JWT tokens in X-Amz-Security-Token should be rejected
921- func TestS3JWTAuthDisabledByDefault (t * testing.T ) {
922- tools .CheckSkip (t , & tools.SkipTestArgs {RequiresAuth : true })
923-
924- var (
925- proxyURL = tools .GetPrimaryURL ()
926- bck = cmn.Bck {Name : "test-s3-jwt-disabled-" + trand .String (6 ), Provider : apc .AIS }
927- )
928-
929- // Get authenticated BaseParams
930- authBP := tools .BaseAPIParams ()
931-
932- // Get current config
933- clusterConfig , err := api .GetClusterConfig (authBP )
934- tassert .CheckFatal (t , err )
935- originalFeatures := clusterConfig .Features .String ()
936- originalS3TokenCompat := strconv .FormatBool (clusterConfig .Auth .AllowS3TokenCompat )
937-
938- // Create test bucket
939- tools .CreateBucket (t , proxyURL , bck , nil , true /*cleanup*/ )
940-
941- // Enable S3 reverse proxy but keep allow_s3_token_compat disabled (false)
942- tlog .Logln ("Enabling S3 reverse proxy with JWT auth mode DISABLED..." )
943- tools .SetClusterConfig (t , cos.StrKVs {
944- "features" : feat .S3ReverseProxy .String (),
945- "auth.allow_s3_token_compat" : "false" ,
946- })
947- t .Cleanup (func () {
948- // Restore original config values
949- tools .SetClusterConfig (t , cos.StrKVs {
950- "features" : originalFeatures ,
951- "auth.allow_s3_token_compat" : originalS3TokenCompat ,
952- })
953- })
954-
955- // VERIFY: S3 JWT compat is disabled
956- updatedConfig , err := api .GetClusterConfig (authBP )
957- tassert .CheckFatal (t , err )
958- tassert .Fatalf (t , ! updatedConfig .Auth .AllowS3TokenCompat ,
959- "S3 JWT compat mode should be disabled but got: %v" , updatedConfig .Auth .AllowS3TokenCompat )
960- tlog .Logfln ("✓ S3 JWT compatibility mode is disabled (backward compatibility mode)" )
961-
962- // Get a valid JWT token
963- testJWT := authBP .Token
964- tassert .Fatalf (t , testJWT != "" , "Expected valid auth token from tools.BaseAPIParams()" )
965- tlog .Logfln ("Attempting S3 request with valid JWT token (length: %d bytes)" , len (testJWT ))
966-
967- // Create AWS SDK client with JWT as SessionToken
968- cfg , err := config .LoadDefaultConfig (
969- context .Background (),
970- config .WithCredentialsProvider (
971- credentials .NewStaticCredentialsProvider (
972- "dummy-access-key" ,
973- "dummy-secret-key" ,
974- testJWT , // Valid JWT in X-Amz-Security-Token header
975- ),
976- ),
977- config .WithRegion (env .AwsDefaultRegion ()),
978- )
979- tassert .CheckFatal (t , err )
980-
981- cfg .HTTPClient = newS3Client (false )
982- cfg .BaseEndpoint = aws .String (proxyURL + "/s3" )
983- s3Client := s3 .NewFromConfig (cfg )
984-
985- // Attempt S3 request - should FAIL because allow_s3_token_compat is disabled
986- tlog .Logln ("Testing that valid JWT is rejected when feature is disabled..." )
987- _ , err = s3Client .ListBuckets (context .Background (), & s3.ListBucketsInput {})
988- tassert .Fatalf (t , err != nil , "Expected request to fail when allow_s3_token_compat=false, but it succeeded" )
989- tlog .Logfln ("✓ Valid JWT was correctly rejected (backward compatibility preserved): %v" , err )
990- }
0 commit comments