Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# docker中的ASP.NET Core kestrel windows身份验证识别错误的用户_C#_Docker_Asp.net Core_Windows Authentication_Traefik - Fatal编程技术网

C# docker中的ASP.NET Core kestrel windows身份验证识别错误的用户

C# docker中的ASP.NET Core kestrel windows身份验证识别错误的用户,c#,docker,asp.net-core,windows-authentication,traefik,C#,Docker,Asp.net Core,Windows Authentication,Traefik,我正在使用docker(windows nanoserver)、traefik、asp.net core 3.1和windows身份验证/协商。如果用户连接到容器,他或她将登录,并将其用户绑定到httpcontext。如果其他用户在此之后连接,则第一个用户仍然绑定到上下文 这是我的设置代码: docker compose.yml 版本:“3.7” 服务: 网络应用程序: 图片:/webapplication:8-1 网络: 网络应用网络: 别名: -网络应用 特拉菲克: 别名: -traefik

我正在使用docker(windows nanoserver)、traefik、asp.net core 3.1和windows身份验证/协商。如果用户连接到容器,他或她将登录,并将其用户绑定到httpcontext。如果其他用户在此之后连接,则第一个用户仍然绑定到上下文

这是我的设置代码:

docker compose.yml

版本:“3.7”
服务:
网络应用程序:
图片:/webapplication:8-1
网络:
网络应用网络:
别名:
-网络应用
特拉菲克:
别名:
-traefik Web应用程序
凭证规格:
文件:webapp({GMSA_ACCOUNT})\u credential.json
秘密:
-资料来源:config_secrets
目标:C:/app/appsettings.json
部署:
模式:复制
副本:1份
重新启动\u策略:
条件:故障时
延迟:5秒
最多尝试次数:10次
窗口:30秒
标签:
-applicationname=({applicationname})
-“traefik.enable=true”
-“traefik.http.routers.({APPLICATIONNAME})-webapplication.rule=Host(`({APPLICATIONNAME})-webapplication.({DOMAIN})`)”
-“traefik.http.routers({APPLICATIONNAME})-webapplication.service=({APPLICATIONNAME})-webapplication”
-“traefik.http.routers({APPLICATIONNAME})-webapplication.entrypoints=https”
-“traefik.http.routers({APPLICATIONNAME})-webapplication.tls=true”
-“traefik.http.services({APPLICATIONNAME})-webapplication.loadbalancer.server.scheme=http”
-“traefik.http.services({APPLICATIONNAME})-webapplication.loadbalancer.server.port=80”
#将http重定向到https
-traefik.http.middleware({APPLICATIONNAME})-webapplication不安全重定向secure.redirectscheme.scheme=https
-traefik.http.routers({APPLICATIONNAME})-webapplication unsecure.middleware=({APPLICATIONNAME})-webapplication unsecure重定向安全
-traefik.http.routers.({APPLICATIONNAME})-webapplication unsecure.rule=Host(`({APPLICATIONNAME})-webapplication.({DOMAIN})`)
-路由器({APPLICATIONNAME})-webapplication不安全。入口点=http
#尝试通过TCP使Windows身份验证工作
-“traefik.tcp.routers.({APPLICATIONNAME})-webapplication.rule=HostSNI(`({APPLICATIONNAME})-webapplication.({DOMAIN})`)”
-“traefik.tcp.routers({APPLICATIONNAME})-webapplication.service=({APPLICATIONNAME})-webapplication”
-“traefik.tcp.routers({APPLICATIONNAME})-webapplication.tls=true”
-“traefik.tcp.services({APPLICATIONNAME})-webapplication.loadbalancer.server.port=80”
-“traefik.http.services({APPLICATIONNAME})-webapplication.loadbalancer.sticky=true”
Dockerfile Web应用程序windows netcore基础

# escape=`
FROM mcr.microsoft.com/windows/servercore:ltsc2019 AS installer
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

# Retrieve .NET Core Runtime
RUN $dotnet_version = '3.1.3'; `
    Invoke-WebRequest -OutFile dotnet.zip https://dotnetcli.azureedge.net/dotnet/Runtime/$dotnet_version/dotnet-runtime-$dotnet_version-win-x64.zip; `
    $dotnet_sha512 = '62a18838664afd6f08cdb9a90a96a67626743aab1f0de0065eadfd7d1df31681c90f96744ccb5b7e40834c9e3c4952125c8c83625867c500692050cdd113ff50'; `
    if ((Get-FileHash dotnet.zip -Algorithm sha512).Hash -ne $dotnet_sha512) { `
        Write-Host 'CHECKSUM VERIFICATION FAILED!'; `
        exit 1; `
    }; `
    `
    Expand-Archive dotnet.zip -DestinationPath dotnet; `
    Remove-Item -Force dotnet.zip; `
# Install ASP.NET Core Runtime
    $aspnetcore_version = '3.1.3'; `
    Invoke-WebRequest -OutFile aspnetcore.zip https://dotnetcli.azureedge.net/dotnet/aspnetcore/Runtime/$aspnetcore_version/aspnetcore-runtime-$aspnetcore_version-win-x64.zip; `
    $aspnetcore_sha512 = '6d8a21a7420db9091fc05613ef0a923c7b86cc995360c9f0133d632020e042db0efac0343ee6516a28feb2c1dd004b33b74bfdcc1a687efdefa9db1a486c1ca2'; `
    if ((Get-FileHash aspnetcore.zip -Algorithm sha512).Hash -ne $aspnetcore_sha512) { `
        Write-Host 'CHECKSUM VERIFICATION FAILED!'; `
        exit 1; `
    }; `
    `
    Expand-Archive aspnetcore.zip -DestinationPath dotnet -Force; `
    Remove-Item -Force aspnetcore.zip
# Runtime image
FROM mcr.microsoft.com/windows/servercore:ltsc2019

ENV `
    # Configure web servers to bind to port 80 when present
    ASPNETCORE_URLS=http://+:80 `
    # Enable detection of running in a container
    DOTNET_RUNNING_IN_CONTAINER=true

WORKDIR C:\app
USER ContainerAdministrator
RUN setx /M PATH "%PATH%;C:\Program Files\dotnet" && `
    REG ADD HKLM\SYSTEM\CurrentControlSet\Control\FileSystem /v LongPathsEnabled /t REG_DWORD /d 1 -f
COPY --from=installer ["/dotnet", "/Program Files/dotnet"]
Dockerfile Web应用程序

# escape=`
##### Runtime #####
ARG baseImageVersie
ARG buildNumber
ARG release
FROM <repository>/webapplication-build:$release-$buildNumber AS buildtools
FROM webapplication-windows-netcore-base:$baseImageVersie 
ENV DOTNET_RUNNING_IN_CONTAINER=true
ENTRYPOINT ["dotnet", "webapplication.dll"]
COPY --from=buildtools C:/publish .
发生了什么 -用户1通过填写其凭证登录(使用匿名模式) -用户1调用/api/connect/User并返回“用户1” -用户2打开webapplication,无需提供任何凭据 -用户2调用/api/connect/User,它仍然返回“用户1”

问题:
如何防止asp.net核心应用程序返回错误的windows身份验证用户?

我使用traefik TLS passthrough使其正常工作。因此,我不得不将应用程序更改为服务于https本身,而不是让traefik进行SSL终止。我的应用程序的撰写文件现在如下所示:

docker compose.yml

版本:“3.7”
服务:
网络应用程序:
图片:/webapplication:8-1
环境:
-ASPNETCORE\u Kestrel\u证书\u默认\u路径=通配符\u证书.pfx
网络:
网络应用网络:
别名:
-网络应用
特拉菲克:
别名:
-traefik Web应用程序
凭证规格:
文件:webapp({GMSA_ACCOUNT})\u credential.json
秘密:
-资料来源:config_secrets
目标:C:/app/appsettings.json
-来源:通配符\u证书\u pfx
目标:c:\certificates\wildcard\u certificate.pfx
部署:
模式:复制
副本:1份
重新启动\u策略:
条件:故障时
延迟:5秒
最多尝试次数:10次
窗口:30秒
标签:
-applicatenaam=({applicatenaam})
-“traefik.enable=true”
-“traefik.http.routers.({applicationaam})-webapplication.rule=Host(`({applicationaam})-webapplication.({DOMAIN})`)”
-“traefik.http.routers({applicationaam})-webapplication.entrypoints=https”
-“traefik.http.routers({applicationaam})-webapplication.tls=true”
-“traefik.http.services({applicationaam})-webapplication.loadbalancer.server.scheme=https”
-“traefik.http.services({applicationaam})-webapplication.loadbalancer.server.port=443”
#Windows身份验证通过TCP工作
#TLS通过,因为否则windows身份验证将不支持多个用户
-“traefik.tcp.routers({applicationaam})-webapplication.tls=true”
-“traefik.tcp.routers({applicationaam})-webapplication.tls.options=default”
-“traefik.tcp.routers({applicationaam})-webapplication.tls.passthrough=true”
-“traefik.tcp.routers.({applicationaam})-webapplication.rule=HostSNI(`({applicationaam})-webapplication.({DOMAIN})`)”
-“traefik.tcp.routers({applicationaam})-webapplication.entrypoints=https”
-“traefik.tcp.services({applicationaam})-webapplication.loadbalancer.server.port=443”
我认为第一个登录的用户是绑定到traefik连接的,所以所有下一个用户都将使用第一个用户会话,但我不确定。我只知道上面的解决方案可以防止混淆用户会话

我还必须对dockerfile进行更改,使其成为https f
# escape=`
##### Runtime #####
ARG baseImageVersie
ARG buildNumber
ARG release
FROM <repository>/webapplication-build:$release-$buildNumber AS buildtools
FROM webapplication-windows-netcore-base:$baseImageVersie 
ENV DOTNET_RUNNING_IN_CONTAINER=true

# The copy is done, because wildcard_certificate.pfx is put into the container using docker secrets, which makes it a symlink. 
# Reading a certificate as a symlink is not supported at this moment: https://stackoverflow.com/q/43955181/1608705
# After doing a copy, the copied version is not a symlink anymore.
ENTRYPOINT (IF EXIST "c:\certificates\wildcard_certificate.pfx" (copy c:\certificates\wildcard_certificate.pfx c:\app\wildcard_certificate.pfx)) && dotnet webapplication.dll

COPY --from=buildtools C:/publish .