Skip to content

SSOAWSCredentials does not work behind an authenticated proxy #4027

@Evolva

Description

@Evolva

Describe the bug

Unable to call any AWS services using SSOAWSCredentials behind an authenticated proxy

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

Code in Reproduction Steps should be able to call S3

Current Behavior

Code in Reproduction Steps throw a System.Net.Http.HttpRequestException : The proxy tunnel request to proxy 'http://your-authenticated-proxy//' failed with status code '407'."

Reproduction Steps

⚠️ Delete existing sso cache files in folder %USERPROFILE%\.aws\sso\cache if any ⚠️

var proxy = new WebProxy
{
    Address = new Uri("http://your-authenticated-proxy/"),
    UseDefaultCredentials = true
};

AWSConfigs.LoggingConfig.LogTo = LoggingOptions.Console;

var s3Client = new AmazonS3Client(
    new SSOAWSCredentials(
        accountId: "your-account-id",
        region: "eu-west-1",
        roleName: "your-role-name",
        startUrl: "your-start-url",
        options: new SSOAWSCredentialsOptions
        {
            ClientName = "test-sso-aws-creds",
            ProxySettings = proxy,
            SupportsGettingNewToken = true,
            SsoVerificationCallback = arg =>
            {
                Process.Start(new ProcessStartInfo(arg.VerificationUriComplete)
                {
                    UseShellExecute = true
                });
            },
        }
    ),
    new AmazonS3Config
    {
        RegionEndpoint = RegionEndpoint.EUWest1,
        ProxyHost = proxy.Address.Host,
        ProxyPort = proxy.Address.Port,
        ProxyCredentials = proxy.Credentials
    });

    var result = await s3Client.ListBucketsAsync();

Possible Solution

Using the GlobalRuntimeDependencyRegistry (as below) is a workaround for the issue

GlobalRuntimeDependencyRegistry.Instance.RegisterSSOOIDCClient(
    new AmazonSSOOIDCClient(
        new AmazonSSOOIDCConfig
        {
            RegionEndpoint = RegionEndpoint.EUWest1,
            ProxyHost = proxy.Address.Host,
            ProxyPort = proxy.Address.Port,
            ProxyCredentials = proxy.Credentials
        }));

The root cause seems to be because

protected virtual ICoreAmazonSSOOIDC_V2 CreateSSOOIDC_V2Client(string region,
#if BCL
WebProxy proxySettings = null
#elif NETSTANDARD
IWebProxy proxySettings = null
#endif
)
{
return SSOServiceClientHelpers.BuildSSOIDC_V2Client(RegionEndpoint.GetBySystemName(region), proxySettings);
}

is never called with a proxySettings

var ssooidc_V2Client = CreateSSOOIDC_V2Client(options.Region);

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

AWSSDK.SSO 4.0.1.6
AWSSDK.SSOOIDC 4.0.2.3

Targeted .NET Platform

.NET 8

Operating System and version

Windows 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions