Skip to content

Commit 9588eaa

Browse files
Fixing VPN connectivity
1 parent 117a1c6 commit 9588eaa

2 files changed

Lines changed: 33 additions & 44 deletions

File tree

Connect/AzureStack.Connect.psm1

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ function Add-AzureStackVpnConnection {
187187
[parameter(HelpMessage="Azure Stack VPN Connection Name such as 'my-poc'")]
188188
[string] $ConnectionName = "azurestack",
189189

190-
[parameter(mandatory=$true, HelpMessage="External IP of the Azure Stack NAT VM such as '1.2.3.4'")]
190+
[parameter(mandatory=$true, HelpMessage="External IP of the Azure Stack Host such as '1.2.3.4'")]
191191
[string] $ServerAddress,
192192

193193
[parameter(mandatory=$true, HelpMessage="Administrator password used to deploy this Azure Stack instance")]
@@ -226,18 +226,14 @@ function Connect-AzureStackVpn {
226226
param (
227227
[parameter(HelpMessage="Azure Stack VPN Connection Name such as 'my-poc'")]
228228
[string] $ConnectionName = "azurestack",
229-
[Parameter(HelpMessage="The Domain suffix of the environment VMs")]
230-
[string] $DomainSuffix = 'azurestack.local',
231-
[parameter(HelpMessage="Certificate Authority computer name in this Azure Stack Instance")]
232-
[string] $Remote = "azs-ca01",
233229
[parameter(HelpMessage="Administrator user name of this Azure Stack Instance")]
234230
[string] $User = "administrator",
235231
[parameter(mandatory=$true, HelpMessage="Administrator password used to deploy this Azure Stack instance")]
236-
[securestring] $Password
232+
[securestring] $Password,
233+
[parameter(HelpMessage="Indicate whether to retrieve and trust certificates from the environment after establishing a VPN connection")]
234+
[bool] $RetrieveCertificates = $true
237235
)
238236

239-
$Domain = $DomainSuffix
240-
241237
Write-Verbose "Connecting to Azure Stack VPN using connection named $ConnectionName..." -Verbose
242238

243239
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password)
@@ -248,36 +244,41 @@ function Connect-AzureStackVpn {
248244

249245
$azshome = "$env:USERPROFILE\Documents\$ConnectionName"
250246

251-
Write-Verbose "Connection-specific files will be saved in $azshome" -Verbose
247+
if ($RetrieveCertificates){
248+
Write-Verbose "Connection-specific files will be saved in $azshome" -Verbose
252249

253-
New-Item $azshome -ItemType Directory -Force | Out-Null
250+
New-Item $azshome -ItemType Directory -Force | Out-Null
254251

255-
$UserCred = "$Domain\$User"
256-
$credential = New-Object System.Management.Automation.PSCredential -ArgumentList $UserCred, $Password
252+
$hostIP = (Get-VpnConnection -Name $ConnectionName).ServerAddress
257253

258-
Write-Verbose "Retrieving Azure Stack Root Authority certificate..." -Verbose
259-
$cert = Invoke-Command -ComputerName "$Remote.$Domain" -ScriptBlock { Get-ChildItem cert:\currentuser\root | where-object {$_.Subject -eq "CN=AzureStackCertificationAuthority, DC=AzureStack, DC=local"} } -Credential $credential
254+
$UserCred = ".\$User"
255+
$credential = New-Object System.Management.Automation.PSCredential -ArgumentList $UserCred, $Password
260256

261-
if($cert -ne $null) {
262-
if($cert.GetType().IsArray) {
263-
$cert = $cert[0] # take any that match the subject if multiple certs were deployed
264-
}
257+
Write-Verbose "Retrieving Azure Stack Root Authority certificate..." -Verbose
258+
$cert = Invoke-Command -ComputerName "$hostIP" -ScriptBlock { Get-ChildItem cert:\currentuser\root | where-object {$_.Subject -like "*AzureStackSelfSignedRootCert*"} } -Credential $credential
265259

266-
$certFilePath = "$azshome\CA.cer"
260+
if($cert -ne $null) {
261+
if($cert.GetType().IsArray) {
262+
$cert = $cert[0] # take any that match the subject if multiple certs were deployed
263+
}
267264

268-
Write-Verbose "Saving Azure Stack Root certificate in $certFilePath..." -Verbose
265+
$certFilePath = "$azshome\CA.cer"
269266

270-
Export-Certificate -Cert $cert -FilePath $certFilePath -Force | Out-Null
267+
Write-Verbose "Saving Azure Stack Root certificate in $certFilePath..." -Verbose
271268

272-
Write-Verbose "Installing Azure Stack Root certificate for the current user..." -Verbose
273-
274-
Write-Progress "LOOK FOR CERT ACCEPTANCE PROMPT ON YOUR SCREEN!"
269+
Export-Certificate -Cert $cert -FilePath $certFilePath -Force | Out-Null
275270

276-
Import-Certificate -CertStoreLocation cert:\currentuser\root -FilePath $certFilePath
277-
}
278-
else {
279-
Write-Error "Certificate has not been retrieved!"
271+
Write-Verbose "Installing Azure Stack Root certificate for the current user..." -Verbose
272+
273+
Write-Progress "LOOK FOR CERT ACCEPTANCE PROMPT ON YOUR SCREEN!"
274+
275+
Import-Certificate -CertStoreLocation cert:\currentuser\root -FilePath $certFilePath
276+
}
277+
else {
278+
Write-Error "Certificate has not been retrieved!"
279+
}
280280
}
281+
281282
}
282283

283284
Export-ModuleMember Connect-AzureStackVpn

Connect/README.md

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,13 @@ This allows your client computer to become part of the Azure Stack PoC network s
2424
The tool will also download root certificate of the targeted Azure Stack PoC instance locally to your client computer.
2525
This will ensure that SSL sites of the target Azure Stack installation are trusted by your client when accessed from the browser or from the command-line tools.
2626

27-
To connect to Azure Stack PoC via VPN, first locate the external BGP-NAT01 address of the target installation.
28-
If you specified a static IP for the BGP-NAT during deployment of the Azure Stack PoC, then use it in the connection example below.
27+
To connect to Azure Stack PoC via VPN, first locate the host IP address of the target installation.
2928

30-
If you did not specify a static IP then the BGP-NAT was configured with DHCP. In that case, **read the below section** to obtain your BGP-NAT VM IP by using the IP address of the Azure Stack PoC host (which should be known to you after deployment).
31-
32-
The commands below need to access the Azure Stack PoC host computer and Azure Stack CA, so they need to be trusted hosts in PowerShell. Run PowerShell as administrator and modify TrustedHosts as follows.
29+
The commands below need to access the Azure Stack PoC host computer, so it needs to be a trusted host in PowerShell. Run PowerShell as administrator and modify TrustedHosts as follows.
3330

3431
```powershell
3532
# Add Azure Stack PoC host to the trusted hosts on your client computer
36-
Set-Item wsman:\localhost\Client\TrustedHosts -Value "<Azure Stack host address>" -Concatenate
37-
Set-Item wsman:\localhost\Client\TrustedHosts -Value azs-ca01.azurestack.local -Concatenate
33+
Set-Item wsman:\localhost\Client\TrustedHosts -Value "<Azure Stack host IP address>" -Concatenate
3834
```
3935

4036
For the VPN connection, use the admin password provided at the time of the Azure Stack deployment.
@@ -47,20 +43,12 @@ Then connect your client computer to the environment as follows.
4743

4844
```powershell
4945
# Create VPN connection entry for the current user
50-
Add-AzureStackVpnConnection -ServerAddress <NAT IP> -Password $Password
46+
Add-AzureStackVpnConnection -ServerAddress <Host IP Address> -Password $Password
5147
5248
# Connect to the Azure Stack instance. This command can be used multiple times.
5349
Connect-AzureStackVpn -Password $Password
5450
```
5551

56-
## Obtain the NAT IP address with the Azure Stack PoC host address
57-
58-
This command is helpful if you do not immediately know the NAT IP of the Azure Stack PoC you are trying to connect to. You must know the host address of your Azure Stack PoC.
59-
60-
```powershell
61-
$natIp = Get-AzureStackNatServerAddress -HostComputer "<Azure Stack host address>" -Password $Password
62-
```
63-
6452

6553
# Configure Azure Stack PowerShell Environment
6654

0 commit comments

Comments
 (0)