由匿名用户执行的远程PowerShell脚本

Joh*_*gue 5 sql-server powershell

我们正在使用pstrami运行部署脚本.部署部分是执行数据库迁移.迁移使用具有集成安全性的连接字符串.

当脚本在远程计算机上执行时,迁移失败,并显示sql错误,指出用户'NT AUTHORITY\ANONYMOUS LOGON'登录失败

执行脚本的人是域管理员.我们运行的其他部署与启动该进程的用户执行远程脚本.

Fre*_*ake 12

问题是凭据不会跳转到SQL Server以实现集成安全性.您需要执行以下操作:

在服务器(进行SQL Server连接的服务器上,以管理员身份运行:

Enable-WSManCredSSP -Role server
Run Code Online (Sandbox Code Playgroud)

在客户端计算机上,以管理员身份运行:

Enable-WSManCredSSP -Role client -DelegateComputer YOUR_SERVER_NAME
Run Code Online (Sandbox Code Playgroud)

要将其打开到所有服务器,您可以运行:

Enable-WSManCredSSP -Role client -DelegateComputer *
Run Code Online (Sandbox Code Playgroud)

最后,您的invoke命令确保您运行-authentication credssp.一个例子:

invoke-command -computername $remoteServer -authentication credssp -scriptblock { write-host "hello!" } -credential $credentials
Run Code Online (Sandbox Code Playgroud)


Vic*_*cia 2

场景如下:
您从桌面 A 运行 pstrami(部署)脚本。该脚本将您的安装文件推送到 serverA。然后,在服务器 A 上,脚本将作为从桌面 A 启动脚本的人员远程运行。步骤之一是使用“集成安全性”的连接字符串参数通过 FluentMigrator 运行 sql 数据库更新,并且数据库位于 serverB 上。

连接字符串示例:

$migration_db_connection = Data Source=serverB;Initial Catalog=PropertyDb;Integrated Security=SSPI; 
.\migrate.exe /conn "$migration_db_connection" /db SqlServer /a $migration_assembly /profile DEBUG
Run Code Online (Sandbox Code Playgroud)

Pstrami 使用 powershell 命令 invoke-command ,该命令使用您运行脚本的帐户作为默认用户。因此,当您以“jonDoe”身份从desktopA 运行脚本时,它会在serverA 上进行身份验证。因此,您的 pstrami 脚本在 serverA 上的“jonDoe”下运行。当您在 serverA 上以“jonDoe”执行 Fluentmigrator 脚本时,Fluentmigrator 返回错误“用户‘NT AUTHORITY\ANONYMOUS LOGON’登录失败”。在 IIS 中,当您需要访问 IIS 服务器之外的另一个资源时,您会遇到一个有趣的情况,并且会发生某些相当常见的情况。使用集成安全性时,匿名访问被禁用,模拟被打开,Windows 安全措施将启动,并且不允许您的站点访问任何网络服务器上的资源。(http://weblogs.asp.net/owscott/archive/2008/08/22/iis-windows-authentication-and-the-double-hop-issue.aspx

这就是我解决 Windows 身份验证和遇到的双跳问题的方法。直接在 SQL 数据库服务器上运行迁移脚本,并将其作为服务器目标包含在 pstrami 环境中。

例子:

Environment "dev" -servers @(
    Server "serverA" @("InstallWeb") 
    Server "serverB" @("RunMigrations")
    ) 
Run Code Online (Sandbox Code Playgroud)

更多关于双跳