Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service specific endpoints don't work with SSO profiles #3538

Open
1 task
drjaydenm opened this issue Nov 1, 2024 · 1 comment
Open
1 task

Service specific endpoints don't work with SSO profiles #3538

drjaydenm opened this issue Nov 1, 2024 · 1 comment
Labels
bug This issue is a bug. credentials p2 This is a standard priority issue queued

Comments

@drjaydenm
Copy link

drjaydenm commented Nov 1, 2024

Describe the bug

I'm seeing an issue where specifying service specific endpoints as per the documentation is not working when using a profile with SSO.

Regression Issue

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

Expected Behavior

Service specific configuration works correctly with SSO profiles.

Current Behavior

Service specific configuration like endpoint URL's aren't available to the client services (i.e. SQS) when setup on a profile using SSO.

Adding the service specific configuration to the default profile however works correctly.

Reproduction Steps

~/.aws/config file:

[default]
region = ap-southeast-2

[sso-session app-sso]
sso_start_url = https://appsso.awsapps.com/start
sso_region = ap-southeast-2

[profile app-dev]
sso_session = app-sso
sso_account_id = 1234565768
sso_role_name = AWSAdministratorAccess
services = app-services

[services app-services]
sqs = 
  endpoint_url = http://localhost:9324

appsettings.json file:

"AWS": {
  "Region": "ap-southeast-2",
  "Profile": "app-dev"
}

Program.cs file:

builder.Services.AddDefaultAWSOptions(builder.Configuration.GetAWSOptions());
builder.Services.AddAWSService<IAmazonSQS>();

Possible Solution

I've stepped through the SDK a bit and it seems like the SharedCredentialsFile for the app-dev profile initially loads (which has the services NestedProperties available), but then gets swapped to the default profile further down the line by the time it makes its way to the SQS client.

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

Targeted .NET Platform

.NET 8

Operating System and version

Windows 11

@drjaydenm drjaydenm added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 1, 2024
@bhoradc bhoradc added needs-reproduction This issue needs reproduction. credentials p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Nov 3, 2024
@bhoradc
Copy link

bhoradc commented Nov 5, 2024

Hello @drjaydenm,

Thank you for reporting the issue. I am able to reproduce the scenario where the Service specific endpoint doesn't work with SSO profiles. Below is the minimal code sample (ASP.NET MVC web app) and configuration used for the same.

Program.cs:
using Amazon.SQS;
using Amazon.SSO;
namespace SSO_Issue
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);
            builder.Services.AddControllersWithViews();
            builder.Services.AddDefaultAWSOptions(builder.Configuration.GetAWSOptions());
            builder.Services.AddAWSService<IAmazonSQS>();
            builder.Services.AddAWSService<IAmazonSSO>();
            var app = builder.Build();
            if (!app.Environment.IsDevelopment())
            {
                app.UseExceptionHandler("/Service/Error");
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseRouting();
            app.UseAuthorization();
            app.MapControllerRoute(
                name: "default",
                pattern: "{controller=Service}/{action=Index}/{id?}");
            app.Run();
        }
    }
}
ServiceController.cs:
using Amazon.SQS;
using Microsoft.AspNetCore.Mvc;
using SSO_Issue.Models;
using System.Diagnostics;

namespace SSO_Issue.Controllers
{
    public class ServiceController : Controller
    {
        private IAmazonSQS SQSClient { get; set; }
        public ServiceController(IAmazonSQS sqsClient)
        {
            this.SQSClient = sqsClient;
        }
        public async Task<IActionResult> Index()
        {
            string queueName = "MyQueueName";
            var response = await SQSClient.GetQueueUrlAsync(queueName);
            string queueUrl = response.QueueUrl;
            Console.WriteLine($"The URL for {queueName} is: {response.QueueUrl}");
            this.ViewBag.QueueUrl = queueUrl;
            return View();
        }
        public IActionResult Privacy()
        {
            return View();
        }
        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
Index.cshtml:
@{
    ViewData["Title"] = "Home Page";
}
<div class="text-center">
    <h1 class="display-4">SSO Issue page</h1>
    QueueUrl: @ViewBag.QueueUrl
</div>
appsettings.json:
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "AWS": {
    "Region": "us-east-1",
    "Profile": "app-dev"
  }
}
aws config file:
[default]
region = us-east-1
#services = app-services
[sso-session app-sso]
sso_start_url = https://d-****.awsapps.com/start
sso_region = us-east-1
[profile app-dev]
sso_session = app-sso
sso_account_id = account_id
sso_role_name = Squad**
services = app-services
[services app-services]
sqs = 
    endpoint_url = https://sqs.us-east-2.amazonaws.com:443
Packages used:
AWSSDK.Extensions.NETCore.Setup - 3.7.301
AWSSDK.SQS - 3.7.400.45
AWSSDK.SSO - 3.7.400.45
AWSSDK.SSOOIDC - 3.7.400.45

As you mentioned, I can also confirm that setting the service endpoint url works with the default profile. I will review this issue with the .NET SDK team to further investigate and root cause.

Regards,
Chaitanya

@bhoradc bhoradc added needs-review queued and removed needs-reproduction This issue needs reproduction. needs-review labels Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. credentials p2 This is a standard priority issue queued
Projects
None yet
Development

No branches or pull requests

2 participants