我目前正在尝试对一些旧的(即将淘汰)基础结构进行一些改进,以准备迁移到.NET Core。我们有一个小的反馈表格,该表格使用SQLOLEDB连接字符串写入SQL表。这些字符串与以明文定义的用户名/密码一起使用时效果很好,尽管我希望脱离此方法,而转向集成身份验证。
我已经做了很多工作去到达自己的位置:
目前,我已经完成了Windows容器指南(https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/manage-serviceaccounts)上MS的gMSA中的所有步骤。测试签出后,我可以毫无问题地在https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/gmsa-troubleshooting#check-the-container中运行所有测试,但是当我尝试使用连接字符串进行连接时,我的日志中显示了一条错误,显示:
2020-09-28 19:36:43 172.17.173.120 POST /Default.asp |42|80040e4d|Login_failed_for_user_'NT_AUTHORITY\ANONYMOUS_LOGON'.
对我来说,这没有多大意义,因为应用程序池标识设置为网络,并且测试在容器上签出。
现在我已经尝试了一些操作,例如编辑web.config以将假冒设置为true / false,通过Windows进行身份验证,但我还是有些困惑。我已设置允许主机通过Kerberos委派任何服务。
我还尝试使用以下方式登录:
docker exec -it --user "NT AUTHORITY\NETWORK SERVICE" cb4 powershell
然后运行:
$connectionString = 'Data Source=serverhostname.domain.local;database=databasename;Integrated Security = True;'
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $connectionString
$sqlConnection.Open()
$sqlConnection | select *
这将导致数据库连接处于打开状态。
使用NetworkService身份设置应用程序池
Get-ItemProperty IIS:\AppPools\domain.co.uk\ -Name processModel
identityType : NetworkService
userName :
password :
loadUserProfile : False
setProfileEnvironment : True
logonType : LogonBatch
manualGroupMembership : False
idleTimeout : 00:20:00
idleTimeoutAction : Terminate
maxProcesses : 1
shutdownTimeLimit : 00:01:30
startupTimeLimit : 00:01:30
pingingEnabled : True
pingInterval : 00:00:30
pingResponseTime : 00:01:30
logEventOnProcessModel : IdleTimeout
PSPath : WebAdministration::\\413E8843BBEF\AppPools\domain.co.uk\
PSParentPath : WebAdministration::\\413E8843BBEF\AppPools
PSChildName : domain.co.uk\
PSDrive : IIS
PSProvider : WebAdministration
Attributes : {identityType, userName, password, loadUserProfile...}
ChildElements : {}
ElementTagName : processModel
Methods :
Schema : Microsoft.IIs.PowerShell.Framework.ConfigurationElementSchema
任何建议将不胜感激!
答案 0 :(得分:1)
好吧,所以我弄清楚了这一点,并将我的发现发布在了公开的Gist上:
https://gist.github.com/jimbo8098/48fa8d1cd05a61b35534aa107decb3e3
基本上,问题在于,虽然应用程序池标识设置为“网络”,但站点未设置,但它使用的似乎是IUSR。鉴于此,我没有将gMSA帐户中继到ASP的脚本,因此无法使用集成身份验证。解决方案是运行:
Set-WebConfigurationProperty system.webServer/security/authentication/anonymousAuthentication -Name "userName" -Value ""; if ($?) {
Set-WebConfigurationProperty system.webServer/security/authentication/anonymousAuthentication -Name "password" -Value ""; if ($?) {
Set-WebConfigurationProperty system.webServer/security/authentication/anonymousAuthentication -Name "logonMethod" -Value 2;}}
这样做是将用户名和密码设置为空白,将登录方法设置为网络。这是完美的,因为这意味着应用程序池和站点都使用了预期的帐户,即gMSA帐户。
我发现深入了解这一点的一种非常有用的方法是制作一个测试脚本:
<%
Set objNetwork = CreateObject("WScript.Network")
strNAME = objNetwork.computername
response.write("Value of strNAME variable: " & strNAME & "<br>")
response.write("Domain = " & objNetwork.UserDomain & "<br/>")
response.write("ComputerName = " & objNetwork.ComputerName & "<br/>")
response.write("UserName = " & objNetwork.UserName & "<br/>")
%>
在解决方案之前,这表明IUSR,这是我解决该问题的重要线索。解决方案完成后,UserName读取了具有预期域的app$
(其中app是gMSA的名称)。
答案 1 :(得分:-1)
连接到数据库时,您需要注意一些服务器方面的事情。
更多详细信息,请参阅此thread's answer。