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

Basic auth not working - Orleans 7 #393

Open
iamsamcoder opened this issue Mar 6, 2023 · 7 comments
Open

Basic auth not working - Orleans 7 #393

iamsamcoder opened this issue Mar 6, 2023 · 7 comments

Comments

@iamsamcoder
Copy link

Hello,

I've recently upgraded to Orleans 7.1.0 and I've updated Dashboard to 7. 2.0. I've configured the dashboard to use basic auth with username and password.

Program.cs configuration

siloBuilder.UseDashboard(options =>
                {
                    options.Username = "username";
                    options.Password = "password";
                });

Startup.cs configuration

app.Map("/dashboard", x => x.UseOrleansDashboard());

Dashboard works, but doesn't require the password. I'm running this locally in docker and live in Azure container apps.

Am I missing something for the configuration to require username and password?

@richorama
Copy link
Member

I have just tried Orleans 7.1.0 with dashboard 7.2.0 and I can't reproduce the fault. This is my config:

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Orleans;
using Orleans.Configuration;
using Orleans.Hosting;
using System.Net;
using TestGrains;

namespace TestHost
{
    public static class Program
    {
        private static readonly int GatewayPort = 30000;
        private static readonly int SiloPort = 11111;
        private static readonly IPAddress SiloAddress = IPAddress.Loopback;

        public static void Main(string[] args)
        {
            //
            // In this sample we let the dashboard host kestrel and the backend services.
            // 
            Host.CreateDefaultBuilder(args)
                .UseOrleans((_, builder) =>
                {
                    builder.UseDevelopmentClustering(options => options.PrimarySiloEndpoint = new IPEndPoint(SiloAddress, SiloPort));
                    builder.UseInMemoryReminderService();
                    builder.AddMemoryGrainStorageAsDefault();
                    builder.ConfigureEndpoints(SiloAddress, SiloPort, GatewayPort);
                    builder.Configure<ClusterOptions>(options =>
                    {
                        options.ClusterId = "helloworldcluster";
                        options.ServiceId = "1";
                    });

                    builder.UseDashboard(options =>
                    {
                        options.HostSelf = true;
                        options.Username = "test";
                        options.Password = "test";
                    });
                })
                .ConfigureServices(services =>
                {
                    services.AddSingleton<IHostedService, TestGrainsHostedService>();
                })
                .Build()
                .Run();
        }
    }
}

Are you able to provide a failing example?

@clement128
Copy link

I think the problem is only happen if we disable self hosting

@iamsamcoder
Copy link
Author

iamsamcoder commented May 1, 2023 via email

@clement128
Copy link

You can not use app.Map("/dashboard", x => x.UseOrleansDashboard()); as it will go to your application request pipeline, it is not self hosting

@iamsamcoder
Copy link
Author

iamsamcoder commented Jul 27, 2023

Hello @clement128 and @richorama

I'm sorry for not responding sooner, I had other aspects of our Orleans project prioritized. I'm back to trying to get basic auth working for Orleans.

I'm still not able to get basic auth working locally. I'm trying the following as a simple spike to test it out, but I'm still able to access the dashboard without a prompt for authentication. I access dashboard at the application port https://localhost:44393/dashboard.

"OrleansDashboard" Version="7.2.2"
"Microsoft.Orleans.Core" Version="7.2.1"

var builder = WebApplication.CreateBuilder(args);

builder.Host.UseOrleans(siloBuilder =>
{
    siloBuilder.UseLocalhostClustering();
    siloBuilder.UseDashboard(options =>
    {
        options.HostSelf = true;
        options.Username = "test";
        options.Password = "test";
    });
});

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

app.Map("/dashboard", x => x.UseOrleansDashboard());

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

//app.UseHttpsRedirection();

//app.UseAuthorization();

app.MapControllers();

app.Run();

I've tried also with HostSelf = false and without app.Map("/dashboard", x => x.UseOrleansDashboard()); but the page is not accessible.

@iamsamcoder
Copy link
Author

You can not use app.Map("/dashboard", x => x.UseOrleansDashboard()); as it will go to your application request pipeline, it is not self hosting

Sorry @clement128, were you saying basic auth doesn't work when you use app.Map()?

I was able to get basic auth without using app.Map().

@jsteff
Copy link

jsteff commented Aug 9, 2024

@richorama

I am experiencing the same issue with Orleans 8.2.0 on .NET 8

    var builder = WebApplication.CreateBuilder(args);

    builder.Host.UseOrleans((ctx, orleansBuilder) =>
    {
        if (ctx.HostingEnvironment.IsDevelopment())
        {
            orleansBuilder
                .UseLocalhostClustering()
                .AddMemoryGrainStorage("grains")
                .UseDashboard(options =>
                {
                    options.HostSelf = false;
                }); 
        }
    });

    builder.Services.AddControllers();

    var app = builder.Build();

    app.UseAuthorization();

    app.UseStaticFiles();

    app.MapControllers();

    app.UseOrleansDashboard(new OrleansDashboard.DashboardOptions
    {
        BasePath = "/orleans/dashboard",
        Username = "test",
        Password = "test"
    });

    app.Run();

It seems that UseOrleansDashboard is using the DashboardMiddleware which doesn't check the username and password at all. When the dashboard is self-hosted it is working as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants