mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-12-28 11:21:12 +08:00
[vcpkg] Use SSH keys instead of password authentication when minting Linux scale sets (#11999)
This commit is contained in:
parent
ee17a68508
commit
2bf1f30deb
@ -14,6 +14,8 @@ for more information.
|
|||||||
This script assumes you have installed Azure tools into PowerShell by following the instructions
|
This script assumes you have installed Azure tools into PowerShell by following the instructions
|
||||||
at https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-3.6.1
|
at https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-3.6.1
|
||||||
or are running from Azure Cloud Shell.
|
or are running from Azure Cloud Shell.
|
||||||
|
|
||||||
|
This script assumes you have installed the OpenSSH Client optional Windows component.
|
||||||
#>
|
#>
|
||||||
|
|
||||||
$Location = 'westus2'
|
$Location = 'westus2'
|
||||||
@ -24,11 +26,26 @@ $LiveVMPrefix = 'BUILD'
|
|||||||
$ErrorActionPreference = 'Stop'
|
$ErrorActionPreference = 'Stop'
|
||||||
|
|
||||||
$ProgressActivity = 'Creating Scale Set'
|
$ProgressActivity = 'Creating Scale Set'
|
||||||
$TotalProgress = 10
|
$TotalProgress = 11
|
||||||
$CurrentProgress = 1
|
$CurrentProgress = 1
|
||||||
|
|
||||||
Import-Module "$PSScriptRoot/../create-vmss-helpers.psm1" -DisableNameChecking
|
Import-Module "$PSScriptRoot/../create-vmss-helpers.psm1" -DisableNameChecking
|
||||||
|
|
||||||
|
####################################################################################################
|
||||||
|
Write-Progress `
|
||||||
|
-Activity $ProgressActivity `
|
||||||
|
-Status 'Creating SSH key' `
|
||||||
|
-PercentComplete (100 / $TotalProgress * $CurrentProgress++)
|
||||||
|
|
||||||
|
$sshDir = [System.IO.Path]::GetTempPath() + [System.IO.Path]::GetRandomFileName()
|
||||||
|
mkdir $sshDir
|
||||||
|
try {
|
||||||
|
ssh-keygen.exe -q -b 2048 -t rsa -f "$sshDir/key" -P [string]::Empty
|
||||||
|
$sshPublicKey = Get-Content "$sshDir/key.pub"
|
||||||
|
} finally {
|
||||||
|
Remove-Item $sshDir -Recurse -Force
|
||||||
|
}
|
||||||
|
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
Write-Progress `
|
Write-Progress `
|
||||||
-Activity $ProgressActivity `
|
-Activity $ProgressActivity `
|
||||||
@ -174,7 +191,8 @@ $VM = Set-AzVMOperatingSystem `
|
|||||||
-VM $VM `
|
-VM $VM `
|
||||||
-Linux `
|
-Linux `
|
||||||
-ComputerName $ProtoVMName `
|
-ComputerName $ProtoVMName `
|
||||||
-Credential $Credential
|
-Credential $Credential `
|
||||||
|
-DisablePasswordAuthentication
|
||||||
|
|
||||||
$VM = Add-AzVMNetworkInterface -VM $VM -Id $Nic.Id
|
$VM = Add-AzVMNetworkInterface -VM $VM -Id $Nic.Id
|
||||||
$VM = Set-AzVMSourceImage `
|
$VM = Set-AzVMSourceImage `
|
||||||
@ -185,6 +203,12 @@ $VM = Set-AzVMSourceImage `
|
|||||||
-Version latest
|
-Version latest
|
||||||
|
|
||||||
$VM = Set-AzVMBootDiagnostic -VM $VM -Disable
|
$VM = Set-AzVMBootDiagnostic -VM $VM -Disable
|
||||||
|
|
||||||
|
$VM = Add-AzVMSshPublicKey `
|
||||||
|
-VM $VM `
|
||||||
|
-KeyData $sshPublicKey `
|
||||||
|
-Path "/home/AdminUser/.ssh/authorized_keys"
|
||||||
|
|
||||||
New-AzVm `
|
New-AzVm `
|
||||||
-ResourceGroupName $ResourceGroupName `
|
-ResourceGroupName $ResourceGroupName `
|
||||||
-Location $Location `
|
-Location $Location `
|
||||||
@ -269,11 +293,16 @@ $Vmss = Add-AzVmssNetworkInterfaceConfiguration `
|
|||||||
-NetworkSecurityGroupId $NetworkSecurityGroup.Id `
|
-NetworkSecurityGroupId $NetworkSecurityGroup.Id `
|
||||||
-Name $NicName
|
-Name $NicName
|
||||||
|
|
||||||
|
$VmssPublicKey = New-Object -TypeName 'Microsoft.Azure.Management.Compute.Models.SshPublicKey' `
|
||||||
|
-ArgumentList @('/home/AdminUser/.ssh/authorized_keys', $sshPublicKey)
|
||||||
|
|
||||||
$Vmss = Set-AzVmssOsProfile `
|
$Vmss = Set-AzVmssOsProfile `
|
||||||
-VirtualMachineScaleSet $Vmss `
|
-VirtualMachineScaleSet $Vmss `
|
||||||
-ComputerNamePrefix $LiveVMPrefix `
|
-ComputerNamePrefix $LiveVMPrefix `
|
||||||
-AdminUsername AdminUser `
|
-AdminUsername AdminUser `
|
||||||
-AdminPassword $AdminPW
|
-AdminPassword $AdminPW `
|
||||||
|
-LinuxConfigurationDisablePasswordAuthentication $true `
|
||||||
|
-PublicKey @($VmssPublicKey)
|
||||||
|
|
||||||
$Vmss = Set-AzVmssStorageProfile `
|
$Vmss = Set-AzVmssStorageProfile `
|
||||||
-VirtualMachineScaleSet $Vmss `
|
-VirtualMachineScaleSet $Vmss `
|
||||||
|
@ -195,7 +195,7 @@ New-AzVm `
|
|||||||
####################################################################################################
|
####################################################################################################
|
||||||
Write-Progress `
|
Write-Progress `
|
||||||
-Activity $ProgressActivity `
|
-Activity $ProgressActivity `
|
||||||
-Status 'Running provisioning script provision-image.ps1 in VM' `
|
-Status 'Running provisioning script provision-image.txt (as a .ps1) in VM' `
|
||||||
-PercentComplete (100 / $TotalProgress * $CurrentProgress++)
|
-PercentComplete (100 / $TotalProgress * $CurrentProgress++)
|
||||||
|
|
||||||
Invoke-AzVMRunCommand `
|
Invoke-AzVMRunCommand `
|
||||||
|
Loading…
x
Reference in New Issue
Block a user