我需要以域管理员的身份自动执行目标VM上的脚本。问题是,虚拟机没有公开。我也不应该重写脚本,因为它是由团队成员编写的,我宁愿为我的团队提供适用于他们的解决方案,并且是自动化的,而不是每次都重写它们的脚本。 当前进程看起来像THI从VSTS通过Azure PowerShell脚本到目标VM上的PowerShell脚本的双跳凭证
- VSTS启动与Azure的PowerShell脚本command1.ps1构建过程
- Command1.ps1目标安装Azure的自定义脚本扩展VM
- 自定义脚本扩展下载并执行命令2名为.ps1运行command3.ps1以域管理员
我遇到的问题是我无法从VSTS凭据传递到command2.ps1 请推荐我,我应该怎么办次妥善处理。 的选项,我发现:如果
不知道这是可能的VSTS https://blogs.technet.microsoft.com/ashleymcglone/2016/08/30/powershell-remoting-kerberos-double-hop-solved-securely/
添加IP公网地址到目标VM,配置WinRM的,执行command2.ps1,删除公网IP地址
我确定有这样做的更好的方法。 command1.ps1:
param
(
[Parameter(Mandatory)]
[String]$resourceGroupName,
[Parameter(Mandatory)]
[String]$targetVMname,
[Parameter(Mandatory)]
[String]$vmLocation,
[Parameter(Mandatory)]
[String]$FileUri,
[Parameter(Mandatory)]
[String]$nameOfTheScriptToRun,
[Parameter(Mandatory)]
[String]$customScriptExtensionName,
[Parameter(Mandatory)]
[String]$domainAdminName,
[Parameter(Mandatory)]
[String]$domainAdminPassword
)
$domainAdminPasswordSecureString = ConvertTo-SecureString -String $domainAdminPassword -AsPlainText -Force
$DomainCredentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $domainAdminName, $domainAdminPasswordSecureString
Set-AzureRmVMCustomScriptExtension -Argument "-DomainCredentials $DomainCredentials" `
-ResourceGroupName $resourceGroupName `
-VMName $targetVMname `
-Location $vmLocation `
-FileUri $FileUri `
-Run $nameOfTheScriptToRun `
-Name $customScriptExtensionName
Remove-AzureRmVMCustomScriptExtension -Force `
-ResourceGroupName $resourceGroupName `
-VMName $targetVMname `
-Name $customScriptExtensionName
command2.ps1:
param
(
[Parameter(Mandatory)]
[System.Management.Automation.PSCredential]$DomainCredentials
)
$url = "https://raw.githubusercontent.com/x/command2.ps1"
$output = "C:\command2.ps1"
Invoke-WebRequest -Uri $url -OutFile $output
Start-Process -FilePath powershell.exe -ArgumentList $output -Credential $DomainCredentials
您是否打算通过Azure自定义扩展从VSTS传递纯文本密码?我不认为这是个好主意。密码在C:\ Packages \ Plugins \ Microsoft.Compute.CustomScriptExtension \ 1.9 \ RuntimeSettings \ 0.settings – WinBoss
中显示为纯文本,之后您将删除扩展名,所以并不重要。那个地方会被清理干净。或者你可以使用受保护的设置,执行的命令将被编码。 https://docs.microsoft.com/en-us/azure/virtual-machines/windows/extensions-customscript – 4c74356b41
使用PowerShell传递受保护设置的任何方式?如果不是,你会怎么做?你觉得安全通过密码作为简单的字符串? – WinBoss