我正在使用以下 SSH 任务通过 powershell 执行我的 sql 脚本,但任务失败并出现错误:
用户“NT AUTHORITY\ANONYMOUS LOGON”登录失败
相同的任务在主 sql 节点上成功,仅在辅助 sql 节点上失败
我还尝试从我的 devops 代理手动 ssh 到辅助 sql 服务器,这是相同的响应。
- task: SSH@0
displayName: 'Create Scheduled Job'
inputs:
sshEndpoint: 'ssh_Server2' # Replace with your SSH service connection name
runOptions: 'commands'
commands: |
pwsh -File "$(PackagePath)\RunSQLScripts.ps1" -dbName msdb -dbServer Server2 -sqlScript "$(PackagePath)\Scripts\Create_Scheduled_Job.sql"
SSH 服务作为本地系统帐户运行。仅使用 publicKeyAuthentication,passwordauth 被禁用。事实上,CopyFilesOverSSH@0 在同一服务器上工作没有任何问题。
问题仅当我使用 ssh 从代理到 sql server,以任何用户身份在 sql server 上运行脚本时,脚本才能成功执行。
RunSQLScripts.ps1
param
(
[Parameter(Position=0,Mandatory=$true, HelpMessage="Database name")]
[string]$dbName,
[Parameter(Position=1,Mandatory=$true, HelpMessage="Database server name and instance")]
[string]$dbServer,
[Parameter(Position=2,Mandatory=$true, HelpMessage="Path to sql script")]
[string]$sqlScript
)
$ErrorActionPreference = "Stop"
Write-Output "################## Execute SQL Script Task ##############"
Write-Output "Database Server: $dbServer"
Write-Output "Database Name: $dbName"
Write-Output "Script: $sqlScript"
try
{
Write-Output "########## Executing Script on SQL Server - $dbServer\\$dbName,"
invoke-sqlcmd -inputfile "$sqlScript" -serverinstance "$dbServer" -database "$dbName" -TrustServerCertificate | Out-String
Write-Output "########## Executed $sqlScript on SQL Server - $dbServer\\$dbName"
}
catch
{
Write-Warning -Message "########## Error while Executing SQL Script - $assemblyName from location - $assemblyPath"
Write-Error -Message "$($_.Exception.Message)"
}
Write-Output "################## End ##############"
使用SQL Server进行身份验证时出现错误信息
Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'
,表示SSH连接成功,命令开始运行。这不是 DevOps 的问题。
经确认,问题出在 SQL 脚本中,该脚本引用主节点,导致辅助节点上 ssh 执行 sql 脚本失败,并显示“NT AUTHORITY\ANONYMOUS LOGON”。这是 SQL 上的跃点问题。