I'm trying to create a asp.net core web app that runs on docker and has windows authentication, by following the steps on this answer.
I've uploaded the project to google drive, in case you want to download it: google drive link
Project Info:
- ASP.Net core web app
- .net 5.0 framework
- windows authentication
- docker support (linux)
- Created with Visual Studio 2019 community (16.10.2) on windows 10.
My Steps:
- Added HomeController + views
- Installed
Microsoft.AspNetCore.Authentication.Negotiate
package - Added
services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();
toConfigureServices
- Added
app.UseAuthentication();
toConfigure
Behavior (debug mode, docker):
I could enter the application without entering my credentials and User.Identity.Name
was null.
I added the Microsoft.AspNetCore.Authorization.AuthorizeAttribute
attribute on the home controller, so now I can enter my credentials, but once I do get the following error:
GssApiException: GSSAPI operation failed with error - Unspecified GSS failure. Minor code may provide more information (Keytab FILE:/etc/krb5.keytab is nonexistent or empty).
Microsoft.AspNetCore.Authentication.Negotiate.NegotiateHandler.HandleRequestAsync() Microsoft.AspNetCore.Authentication.Negotiate.NegotiateHandler.HandleRequestAsync() Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
I'm not sure what the problem is (or if this is the correct approach to begin with), so I would appreciate some points on how to do this. I've included the relevant files of the project below.
Startup.cs
using Microsoft.AspNetCore.Authentication.Negotiate;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace DockerTest {
public class Startup {
public Startup(IConfiguration configuration) {
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services) {
services.AddRazorPages();
services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
app.UseDeveloperExceptionPage(); // removed other case to save space
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints => {
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
Program.cs
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
namespace DockerTest {
public class Program {
public static void Main(string[] args) {
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
}
}
HomeController.cs
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace DockerTest.Controllers {
[Route("[controller]")]
[Authorize]
public class HomeController : Controller {
[Route("/")]
[Route("/Home")]
[Route("/Home/Index")]
public IActionResult Index() {
return View();
}
}
}
DockerFile (as created by vs)
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["DockerTest/DockerTest.csproj", "DockerTest/"]
RUN dotnet restore "DockerTest/DockerTest.csproj"
COPY . .
WORKDIR "/src/DockerTest"
RUN dotnet build "DockerTest.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "DockerTest.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "DockerTest.dll"]