Skip to content

Commit 77ae30f

Browse files
committed
feat: add authentication scheme preference configuration
1 parent 92c4d9f commit 77ae30f

File tree

12 files changed

+841
-9
lines changed

12 files changed

+841
-9
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"core": {
3+
"changeLogMessages": [
4+
"Added ability to configure authentication scheme preferences (e.g., prioritize SigV4a over SigV4)",
5+
"Added support for AWS_AUTH_SCHEME_PREFERENCE environment variable and auth_scheme_preference configuration file setting",
6+
"Improved authentication scheme resolution to support multiple authentication methods per service"
7+
],
8+
"type": "minor",
9+
"updateMinimum": true
10+
}
11+
}

sdk/src/Core/AWSConfigs.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,64 @@ public static bool DisableLegacyPersistenceStore
402402

403403
#endregion
404404

405+
#region Authentication Scheme Preference
406+
407+
/// <summary>
408+
/// Key for the AuthSchemePreference property.
409+
/// <seealso cref="Amazon.AWSConfigs.AuthSchemePreference"/>
410+
/// </summary>
411+
public const string AuthSchemePreferenceKey = "AWSAuthSchemePreference";
412+
413+
/// <summary>
414+
/// Gets or sets the global authentication scheme preference for all AWS service clients.
415+
/// <para>
416+
/// This property allows you to specify a preference list of authentication schemes
417+
/// that will be used to reprioritize the supported authentication schemes globally.
418+
/// Individual client configurations can override this global setting.
419+
/// </para>
420+
/// <para>
421+
/// This setting can be configured through environment variables or configuration files:
422+
/// - Environment variable: AWS_AUTH_SCHEME_PREFERENCE
423+
/// - Configuration file: auth_scheme_preference
424+
/// </para>
425+
/// </summary>
426+
public static string AuthSchemePreference
427+
{
428+
get { return _rootConfig.AuthSchemePreference; }
429+
set { _rootConfig.AuthSchemePreference = value; }
430+
}
431+
432+
#endregion
433+
434+
#region SigV4a Region Set Configuration
435+
436+
/// <summary>
437+
/// Key for the SigV4aSigningRegionSet property.
438+
/// <seealso cref="Amazon.AWSConfigs.SigV4aSigningRegionSet"/>
439+
/// </summary>
440+
public const string SigV4aSigningRegionSetKey = "AWSSigV4aRegionSet";
441+
442+
/// <summary>
443+
/// Gets or sets the global SigV4a signing region set configuration for all AWS service clients.
444+
/// <para>
445+
/// This property allows you to specify the region set that will be used for SigV4a signing globally.
446+
/// The region set determines which regions the signed request is valid for.
447+
/// Individual client configurations can override this global setting.
448+
/// </para>
449+
/// <para>
450+
/// This setting can be configured through environment variables or configuration files:
451+
/// - Environment variable: AWS_SIGV4A_SIGNING_REGION_SET
452+
/// - Configuration file: sigv4a_signing_region_set
453+
/// </para>
454+
/// </summary>
455+
public static string SigV4aSigningRegionSet
456+
{
457+
get { return _rootConfig.SigV4aSigningRegionSet; }
458+
set { _rootConfig.SigV4aSigningRegionSet = value; }
459+
}
460+
461+
#endregion
462+
405463
#region AWS Config Sections
406464

407465
/// <summary>

sdk/src/Core/Amazon.Runtime/ClientConfig.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,28 @@ public TelemetryProvider TelemetryProvider
11851185
set { this.telemetryProvider = value; }
11861186
}
11871187

1188+
/// <summary>
1189+
/// Gets or sets the authentication scheme preference for this client configuration.
1190+
/// <para>
1191+
/// This property allows you to specify a comma-separated preference list of authentication schemes
1192+
/// (e.g., "sigv4a,sigv4") that will be used to reprioritize the supported authentication schemes for this client.
1193+
/// If not set, the client will use environment variables, configuration files,
1194+
/// or fall back to the default model-based authentication scheme resolution.
1195+
/// </para>
1196+
/// </summary>
1197+
public string AuthSchemePreference { get; set; }
1198+
1199+
/// <summary>
1200+
/// Gets or sets the SigV4a signing region set for this client.
1201+
/// <para>
1202+
/// This property allows you to specify a comma-separated list of regions (e.g., "us-east-1,us-west-2")
1203+
/// that will be used for SigV4a signing. The region set determines which regions the signed request is valid for.
1204+
/// If not set, the client will use environment variables, configuration files,
1205+
/// endpoints metadata, or fall back to the client's configured region.
1206+
/// </para>
1207+
/// </summary>
1208+
public string SigV4aSigningRegionSet { get; set; }
1209+
11881210
/// <summary>
11891211
/// Determines the behavior for calculating checksums for request payloads.
11901212
/// By default it is set to <see cref="RequestChecksumCalculation.WHEN_SUPPORTED"/>.

sdk/src/Core/Amazon.Runtime/Credentials/Internal/AuthSchemeOption.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,33 @@ public class AuthSchemeOption : IAuthSchemeOption
2323
/// <inheritdoc/>
2424
public string SchemeId { get; set; }
2525

26+
/// <summary>
27+
/// Gets the short name of the authentication scheme (e.g., "sigv4" from "aws.auth#sigv4").
28+
/// This is used for configuration purposes.
29+
/// </summary>
30+
public string Name => GetNameFromSchemeId(SchemeId);
31+
2632
internal const string SigV4 = "aws.auth#sigv4";
2733
internal const string SigV4A = "aws.auth#sigv4a";
2834
internal const string Bearer = "smithy.api#httpBearerAuth";
2935
internal const string NoAuth = "smithy.api#noAuth";
3036

37+
/// <summary>
38+
/// Extracts the short name from a fully qualified scheme ID.
39+
/// </summary>
40+
/// <param name="schemeId">The fully qualified scheme ID (e.g., "aws.auth#sigv4").</param>
41+
/// <returns>The short name (e.g., "sigv4") or the original schemeId if no '#' is present.</returns>
42+
public static string GetNameFromSchemeId(string schemeId)
43+
{
44+
if (string.IsNullOrEmpty(schemeId))
45+
return schemeId;
46+
47+
int hashIndex = schemeId.IndexOf('#');
48+
return hashIndex >= 0 && hashIndex < schemeId.Length - 1
49+
? schemeId.Substring(hashIndex + 1)
50+
: schemeId;
51+
}
52+
3153
/// <summary>
3254
/// Default auth scheme options for services / operations that only support SigV4.
3355
/// </summary>

sdk/src/Core/Amazon.Runtime/IClientConfig.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,28 @@ public partial interface IClientConfig
397397
/// </summary>
398398
ResponseChecksumValidation ResponseChecksumValidation { get; }
399399

400+
/// <summary>
401+
/// Gets or sets the authentication scheme preference for this client configuration.
402+
/// <para>
403+
/// This property allows you to specify a comma-separated preference list of authentication schemes
404+
/// (e.g., "sigv4a,sigv4") that will be used to reprioritize the supported authentication schemes for this client.
405+
/// If not set, the client will use environment variables, configuration files,
406+
/// or fall back to the default model-based authentication scheme resolution.
407+
/// </para>
408+
/// </summary>
409+
string AuthSchemePreference { get; }
410+
411+
/// <summary>
412+
/// Gets or sets the SigV4a signing region set for this client.
413+
/// <para>
414+
/// This property allows you to specify a comma-separated list of regions (e.g., "us-east-1,us-west-2")
415+
/// that will be used for SigV4a signing. The region set determines which regions the signed request is valid for.
416+
/// If not set, the client will use environment variables, configuration files,
417+
/// endpoints metadata, or fall back to the client's configured region.
418+
/// </para>
419+
/// </summary>
420+
string SigV4aSigningRegionSet { get; }
421+
400422
/// <summary>
401423
/// Controls whether the resolved endpoint will include the account id. This allows for direct routing of traffic
402424
/// to the cell responsible for a given account, which avoids the additional latency of extra backend hops and reduces

sdk/src/Core/Amazon.Runtime/Internal/InternalConfiguration.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ public class InternalConfiguration
114114
/// Determines the behavior for validating checksums on response payloads.
115115
/// </summary>
116116
public ResponseChecksumValidation? ResponseChecksumValidation { get; set; }
117+
118+
/// <summary>
119+
/// Comma-separated list of authentication scheme preferences (e.g., "sigv4a,sigv4").
120+
/// </summary>
121+
public string AuthSchemePreference { get; set; }
122+
123+
/// <summary>
124+
/// Comma-separated list of regions for SigV4a signing (e.g., "us-east-1,us-west-2").
125+
/// </summary>
126+
public string SigV4aSigningRegionSet { get; set; }
117127
}
118128

119129
#if BCL || NETSTANDARD
@@ -140,6 +150,8 @@ public class EnvironmentVariableInternalConfiguration : InternalConfiguration
140150
public const string ENVIRONMENT_VARAIBLE_AWS_ACCOUNT_ID_ENDPOINT_MODE = "AWS_ACCOUNT_ID_ENDPOINT_MODE";
141151
public const string ENVIRONMENT_VARIABLE_AWS_REQUEST_CHECKSUM_CALCULATION = "AWS_REQUEST_CHECKSUM_CALCULATION";
142152
public const string ENVIRONMENT_VARIABLE_AWS_RESPONSE_CHECKSUM_VALIDATION = "AWS_RESPONSE_CHECKSUM_VALIDATION";
153+
public const string ENVIRONMENT_VARIABLE_AWS_AUTH_SCHEME_PREFERENCE = "AWS_AUTH_SCHEME_PREFERENCE";
154+
public const string ENVIRONMENT_VARIABLE_AWS_SIGV4A_SIGNING_REGION_SET = "AWS_SIGV4A_SIGNING_REGION_SET";
143155
public const int AWS_SDK_UA_APP_ID_MAX_LENGTH = 50;
144156

145157
/// <summary>
@@ -165,6 +177,10 @@ public EnvironmentVariableInternalConfiguration()
165177
RequestChecksumCalculation = GetEnvironmentVariable<RequestChecksumCalculation>(ENVIRONMENT_VARIABLE_AWS_REQUEST_CHECKSUM_CALCULATION);
166178
ResponseChecksumValidation = GetEnvironmentVariable<ResponseChecksumValidation>(ENVIRONMENT_VARIABLE_AWS_RESPONSE_CHECKSUM_VALIDATION);
167179
ClientAppId = GetClientAppIdEnvironmentVariable();
180+
TryGetEnvironmentVariable(ENVIRONMENT_VARIABLE_AWS_AUTH_SCHEME_PREFERENCE, out var authPref);
181+
AuthSchemePreference = authPref;
182+
TryGetEnvironmentVariable(ENVIRONMENT_VARIABLE_AWS_SIGV4A_SIGNING_REGION_SET, out var regionSet);
183+
SigV4aSigningRegionSet = regionSet;
168184
}
169185

170186
private bool GetEnvironmentVariable(string name, bool defaultValue)
@@ -340,6 +356,16 @@ private void Setup(ICredentialProfileSource source, string profileName)
340356
AccountIdEndpointMode = profile.AccountIdEndpointMode;
341357
RequestChecksumCalculation = profile.RequestChecksumCalculation;
342358
ResponseChecksumValidation = profile.ResponseChecksumValidation;
359+
360+
// Auth scheme properties are stored in the Properties dictionary
361+
if (profile.Properties.TryGetValue("auth_scheme_preference", out string authSchemePreference))
362+
{
363+
AuthSchemePreference = string.IsNullOrWhiteSpace(authSchemePreference) ? null : authSchemePreference.Trim();
364+
}
365+
if (profile.Properties.TryGetValue("sigv4a_signing_region_set", out string sigv4aRegionSet))
366+
{
367+
SigV4aSigningRegionSet = string.IsNullOrWhiteSpace(sigv4aRegionSet) ? null : sigv4aRegionSet.Trim();
368+
}
343369
}
344370
else
345371
{
@@ -365,6 +391,8 @@ private void Setup(ICredentialProfileSource source, string profileName)
365391
new KeyValuePair<string, object>("account_id_endpoint_mode", profile.AccountIdEndpointMode),
366392
new KeyValuePair<string, object>("request_checksum_calculation", profile.RequestChecksumCalculation),
367393
new KeyValuePair<string, object>("response_checksum_validation", profile.ResponseChecksumValidation),
394+
new KeyValuePair<string, object>("auth_scheme_preference", AuthSchemePreference),
395+
new KeyValuePair<string, object>("sigv4a_signing_region_set", SigV4aSigningRegionSet),
368396
};
369397

370398
foreach(var item in items)
@@ -436,6 +464,8 @@ public static void Reset()
436464
_cachedConfiguration.AccountIdEndpointMode = SeekValue(standardGenerators,(c) => c.AccountIdEndpointMode);
437465
_cachedConfiguration.RequestChecksumCalculation = SeekValue(standardGenerators, (c) => c.RequestChecksumCalculation);
438466
_cachedConfiguration.ResponseChecksumValidation = SeekValue(standardGenerators, (c) => c.ResponseChecksumValidation);
467+
_cachedConfiguration.AuthSchemePreference = SeekString(standardGenerators, (c) => c.AuthSchemePreference, defaultValue: null);
468+
_cachedConfiguration.SigV4aSigningRegionSet = SeekString(standardGenerators, (c) => c.SigV4aSigningRegionSet, defaultValue: null);
439469
}
440470

441471
private static T? SeekValue<T>(List<ConfigGenerator> generators, Func<InternalConfiguration, T?> getValue) where T : struct
@@ -634,5 +664,27 @@ public static ResponseChecksumValidation? ResponseChecksumValidation
634664
return _cachedConfiguration.ResponseChecksumValidation;
635665
}
636666
}
667+
668+
/// <summary>
669+
/// Gets the authentication scheme preference from environment or config files.
670+
/// </summary>
671+
public static string AuthSchemePreference
672+
{
673+
get
674+
{
675+
return _cachedConfiguration.AuthSchemePreference;
676+
}
677+
}
678+
679+
/// <summary>
680+
/// Gets the SigV4a signing region set from environment or config files.
681+
/// </summary>
682+
public static string SigV4aSigningRegionSet
683+
{
684+
get
685+
{
686+
return _cachedConfiguration.SigV4aSigningRegionSet;
687+
}
688+
}
637689
}
638690
}

sdk/src/Core/Amazon.Runtime/Internal/Settings/SettingsConstants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public static class SettingsConstants
5757
public const string Services = "services";
5858
public const string EndpointUrl = "endpoint_url";
5959
public const string AwsAccountId = "aws_account_id";
60+
public const string AuthSchemePreference = "auth_scheme_preference";
61+
public const string SigV4aSigningRegionSet = "sigv4a_signing_region_set";
6062

6163
// present in endpoint definitions in SAMLEndpoints.json file
6264
public const string EndpointField = "Endpoint";

0 commit comments

Comments
 (0)