sql-server - 由于双跳失败、受约束的委派,远程 powershell 请求中的 SSPI sql 访问失败
问题描述
我们正在尝试从远程 serverB 上的 serverA 运行自动安装,该安装需要使用 windows 身份验证与 sql serverC 对话。
Invoke-Command -ComputerName serverB -ScriptBlock {
$conn = new-object System.Data.SqlClient.SqlConnection 'Data Source=ServerC;Initial Catalog=master;Integrated Security=SSPI'
try
{
$conn.open()
} finally {
$conn | Remove-SQLConnection
}
} -Credential $cred
但是它无法返回:
使用“0”参数调用“打开”的异常:“用户 'NT AUTHORITY\ANONYMOUS LOGON' 登录失败。”
我们使用以下方法解决了这个问题:
Invoke-Command -ComputerName serverB -ScriptBlock { Register-PSSessionConfiguration -Name Ipswitch -RunAsCredential $using:cred -Force } -Credential $cred
但我们更愿意使用受约束的 kerberos 委托:
我们尝试使用以下步骤执行 kerberos 委派:
##########################
#run on serverC
##########################
Add-WindowsFeature RSAT-AD-PowerShell
Import-Module ActiveDirectory
$serverB = Get-ADComputer serverB
$serverC = Get-ADComputer serverC
# Grant resource-based Kerberos constrained delegation
Set-ADComputer -Identity $serverC -PrincipalsAllowedToDelegateToAccount $serverB
# Check the value of the attribute directly
$x = Get-ADComputer -Identity $serverC -Properties msDS-AllowedToActOnBehalfOfOtherIdentity
$x.'msDS-AllowedToActOnBehalfOfOtherIdentity'.Access
# Check the value of the attribute indirectly
Get-ADComputer -Identity $serverC -Properties PrincipalsAllowedToDelegateToAccount
# purge kerberose cache
Invoke-Command -ComputerName $serverB.Name -Credential $cred -ScriptBlock {
klist purge -li 0x3e7
}
完成后,这两个测试通过:
Invoke-Command -ComputerName serverB -ScriptBlock {
Invoke-Command -ComputerName serverC -ScriptBlock {'hello world'} -Credential $using:cred
} -Credential $cred
Invoke-Command -ComputerName serverB -ScriptBlock {
Copy-Item '\\serverC\c$\file'
} -Credential $cred
但是 sql 命令仍然失败,我们还没有找到解决方案。
我们在 github 上发现了同样的问题,看起来相同,但没有答案: https ://github.com/PowerShell/PowerShell/issues/9331
解决方案
请务必使用 SetSPN –A MSSQLSvc/.:1433 为 SQL 服务帐户注册 SPN
推荐阅读
- python - 如何在熊猫中按一个月的最后一个日期分组
- python - 了解 z3 中的量词
- php - PHP中的字体真棒问题
- hdfs - Datanodes 无法使用 HDFS / YARN 连接 Namenode
- javascript - 在Vuejs中包含“活动”类时如何切换图标
- mongodb - MongoDB 更新数组内许多对象的某些字段
- c# - 构建/发布 web .netcore api:我无法访问他们从邮递员返回 500 的任何端点
- javascript - 如何将base64数据解码为图像django-js
- excel - 使用 Application.Quit 后 Excel.exe 仍在运行
- node.js - 合作伙伴仪表板中的 Node-React 应用程序抛出错误“由于浏览器 cookie 的问题,此应用程序无法加载