Trouble using VPN with AppVeyor

adam's Avatar

adam

12 Mar, 2018 03:57 PM

I am trying to make a VPN connection using rasdial during a build and it seems to hang and crash the build when it tries to connect. I've tested this powershell script locally and everything works fine, but can't seem to get it to work on AppVeyor. Any ideas?

Script:

$name = ${env:WAREHOUSE_NAME}
$address = ${env:VPN_ADDRESS}
$username = ${env:VPN_USER}
$plainpassword = ${env:VPN_PASS}
$sharedkey = ${env:VPN_SHARED_KEY}
$baosusername = ${env:WAREHOUSE_USER}
$baospass = ${env:WAREHOUSE_PASS}


# Add VPN Connection echo "Adding VPN Connection..." Add-VpnConnection -Name $name -ServerAddress $address -TunnelType L2tp -EncryptionLevel Optional -AuthenticationMethod Pap -L2tpPsk $sharedkey ` -Force echo "$LASTEXITCODE"


# Connect to VPN rasdial $name $username $plainpassword echo "$LASTEXITCODE" if ( $LASTEXITCODE -gt 0) { exit $LASTEXITCODE }


# Edit etc/hosts echo "Editing etc/hosts..." write-output "192.168.128.103 $name" | ` out-file "${env:SystemRoot}\System32\drivers\etc\hosts" -Encoding ASCII -Append if ( $LASTEXITCODE -gt 0) { exit $LASTEXITCODE }


# Add network drive echo "Adding network drive..." net use \$name\Users /user:$baosusername $baospass if ( $LASTEXITCODE -gt 0) { exit $LASTEXITCODE }


echo "Done"

Output:

1Build started
2git clone -q --branch=appveyor git@github.com:xxxxx/yyyyyy.git C:\myproject
3git checkout -qf 873098469c79d55708ecc4768355962013ff4bf4
4Running Install scripts
5& "${env:APPVEYOR_BUILD_FOLDER}\appveyor\connectvpn.ps1"
6Adding VPN Connection...
7The currently selected encryption level requires EAP or MS-CHAPv2 logon security methods. Data encryption will not occur for Pap or Chap.
8
9Connecting to WAREHOUSE...
  1. Support Staff 1 Posted by Ilya Finkelshte... on 13 Mar, 2018 12:46 AM

    Ilya Finkelshteyn's Avatar

    Can you please try to connect to the build VM over RDP and run this script manually? Note that environment variables from the build are not available in the RDP session, so you need to reset them manually. This experiment will help us rule out (or blame) networking issues. If it works in RDP, next step will be to check if all variables are correct during the build. If not, will concentrate on networking part of the problem.

    Please let us know what you found.

  2. 2 Posted by adam on 13 Mar, 2018 03:39 PM

    adam's Avatar

    I've tried using the method described in that article to connect over RDP but haven't had success making it work (even with the VPN connect turned off). I've double checked a few variables, but what's strange to me is the output seems to just die after the rasdial command is called without any more output of what went wrong.

  3. Support Staff 3 Posted by Ilya Finkelshte... on 14 Mar, 2018 12:01 AM

    Ilya Finkelshteyn's Avatar

    Hi Adam,

    Can you try to create a VPN connection in UI to see if this works?

    If you could create test VPN user for me, I could investigate. You can make this conversation private or email to team at appveyor.com with VPN user and server details.

    Also we can enable you to set build worker clouds, e.g. datacenters where build VM is being provisioned for you to check if some specific datacenter works. But for that we need your AppVeyor account name.

  4. 4 Posted by adam on 14 Mar, 2018 06:43 PM

    adam's Avatar

    Hi Ilya,

    I'm not sure how to create a VPN connection using the UI in AppVeyor...is there a guide for this?

    My AppVeyor account is ARizzo35.

  5. Support Staff 5 Posted by Ilya Finkelshte... on 15 Mar, 2018 02:43 AM

    Ilya Finkelshteyn's Avatar

    Hi Adam,

    I did some research and I think that you are loosing the VM because connection is actually succeeded, but default gateway is being set to your VPN server private IP, so it is being lost for AppVeyor and public Internet in general because routing is broken.

    Add the following to your Add-VpnConnection command: -SplitTunneling $true.

    Also might be needed to add static route (with route add command) to 192.168.128.103 host.

    Let us know if this helps.

    P.S. To create VPN connection on AppVeyor with UI, you need to follow the same steps as on any Windows machine, using Control Panel > Network and Internet > Network and Sharing Center > Set up an new connection or network.

    Ilya.

  6. 6 Posted by adam on 15 Mar, 2018 04:08 PM

    adam's Avatar

    Thanks Ilya! I can see the connection complete successfully now if I use the SplitTunneling option. I'm still not able to get the network drive to connect properly but I will continue debugging this.

  7. Support Staff 7 Posted by Ilya Finkelshte... on 15 Mar, 2018 04:25 PM

    Ilya Finkelshteyn's Avatar

    Great!

    Regarding networking drive I would first ensure that IP routing works properly. I would do something like this route ADD 192.168.128.103 MASK 255.255.255.255 <VPN_SERVER_PRIVATE_IP> and then check that ping and tracert to 192.168.128.103 work properly (assuming that ICMP is allowed on VPN server and on target servers firewall).

    VPN_SERVER_PRIVATE_IP can be tricky and not what it seems from the first look. You can check on your local machine by typing ipconfig and route print before and after VPN connection made without split tunneling. New default gateway appeared after connection was made is that IP.

  8. 8 Posted by adam on 15 Mar, 2018 08:49 PM

    adam's Avatar

    Ilya, much thanks for your help! I was finally able to get this working after adding the right entry in the routing table.

  9. Support Staff 9 Posted by Ilya Finkelshte... on 15 Mar, 2018 08:53 PM

    Ilya Finkelshteyn's Avatar

    Good, thanks for update :)

  10. Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 02:27 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac