121 Commits

Author SHA1 Message Date
Jayapal
da8a3567a3 CLOUDSTACK-9848: Added exit status checking for the iptables commands 2017-05-09 17:40:02 +05:30
Will Stevens
45a96a7f95 remove unnecessary VPN drops 2017-04-27 13:19:25 -04:00
Rajani Karuturi
13bfdd71e6 Merge pull request #1741 from swill/strongswanvpn
Updated StrongSwan VPN ImplementationThis PR is a merge of @jayapalu changes in #872 and the changes I had to make to get the functionality working.

I have done pretty extensive testing of this code so far and we are looking to be in pretty good shape.  One thing to note is that a `Diffie-Hellman` group **is required** in order for this feature to work correctly.  It is not highlighted in the tests below, but I have shown that the `PFS` is not required for this feature to work.  In #872 I have shown a more exhaustive set of tests of this code, but I have limited this set of tests to a recommended `IKE` and `ESP` configuration in order to reduce the noise and test the other areas of functionality.

**Test Results**
I am testing this functionality by creating two VPCs with VMs in each and creating a S2S VPN connection between the two VPCs. Then I SSH into a VM in one VPC and I ping the private IP of a VM in the other VPC. Then I tear it down and try a different configuration.

_Setup_

```
VPC 1                          VPC 2
=====                          =====
VPN Gateway                    VPN Gateway
VPN Customer Gateway           VPN Customer Gateway
VPN Connection        <--->    VPN Connection
 - Passive = True               - Passive = False
```

_Legend_
`SKIP` => At least one of the VPN Connections did not come up, so no test was run.
`OK` => The ping test was successful over the S2S VPN connection.
`FAIL` => The ping test failed over the S2S VPN connection.

`Passive` => Specifies if either the `<vpc_1> : <vpc_2>` sides of the VPN Connection is set to passive.
`Conn State` => Specifies the connection status of the `<vpc_1> : <vpc_2>` VPN Connection in the UI.
`Requires Reset` => If the ping test does not result in an `OK`, then a VPN Connection Reset is performed on either `<vpc_1> : <vpc_2>` sides of the VPN Connection based on which side is not showing `Connected`.  The results in the `Status` column is the final result after the reset is performed.

_Results_

```
+--------+----------------------+-------+-------+----------+----------+---------------+-----------------------------+----------------+
| Status | IKE & ESP            | DPD   | Encap | IKE Life | ESP Life | Passive       | Conn State                  | Requires Reset |
+========+======================+=======+=======+==========+==========+===============+=============================+================+
| OK     | aes128-sha1;modp1536 | True  | False | 86400    | 3600     | True : False  | Disconnected : Connected    | False : False  |
+--------+----------------------+-------+-------+----------+----------+---------------+-----------------------------+----------------+
| OK     | aes128-sha1;modp1536 | True  | True  | 86400    | 3600     | True : False  | Disconnected : Connected    | False : False  |
+--------+----------------------+-------+-------+----------+----------+---------------+-----------------------------+----------------+
| OK     | aes128-sha1;modp1536 | True  | False |          | 3600     | True : False  | Disconnected : Connected    | False : False  |
+--------+----------------------+-------+-------+----------+----------+---------------+-----------------------------+----------------+
| OK     | aes128-sha1;modp1536 | True  | False | 86400    |          | True : False  | Disconnected : Connected    | False : False  |
+--------+----------------------+-------+-------+----------+----------+---------------+-----------------------------+----------------+
| OK     | aes128-sha1;modp1536 | True  | False |          |          | True : False  | Disconnected : Connected    | False : False  |
+--------+----------------------+-------+-------+----------+----------+---------------+-----------------------------+----------------+
| OK     | aes128-sha1;modp1536 | True  | False | 86400    | 3600     | False : False | Connected : Connected       | False : False  |
+--------+----------------------+-------+-------+----------+----------+---------------+-----------------------------+----------------+
| OK     | aes128-sha1;modp1536 | True  | False | 86400    | 3600     | True : True   | Disconnected : Disconnected | False : False  |
+--------+----------------------+-------+-------+----------+----------+---------------+-----------------------------+----------------+
| OK     | aes128-sha1;modp1536 | True  | False | 86400    | 3600     | False : True  | Connected : Disconnected    | False : False  |
+--------+----------------------+-------+-------+----------+----------+---------------+-----------------------------+----------------+
| OK     | aes128-sha1;modp1536 | False | False | 86400    | 3600     | False : False | Connected : Connected       | False : False  |
+--------+----------------------+-------+-------+----------+----------+---------------+-----------------------------+----------------+
| OK     | aes128-sha1;modp1536 | False | False | 86400    | 3600     | True : False  | Disconnected : Connected    | False : False  |
+--------+----------------------+-------+-------+----------+----------+---------------+-----------------------------+----------------+
| OK     | aes128-sha1;modp1536 | False | False | 86400    | 3600     | True : True   | Disconnected : Disconnected | False : False  |
+--------+----------------------+-------+-------+----------+----------+---------------+-----------------------------+----------------+
| OK     | aes128-sha1;modp1536 | False | False | 86400    | 3600     | False : True  | Connected : Disconnected    | False : False  |
+--------+----------------------+-------+-------+----------+----------+---------------+-----------------------------+----------------+
| SKIP   | aes128-sha1          | True  | False | 86400    | 3600     | True : False  | Disconnected : Error        | True : False   |
+--------+----------------------+-------+-------+----------+----------+---------------+-----------------------------+----------------+
| SKIP   | aes128-sha1          | False | False | 86400    | 3600     | True : False  | Disconnected : Error        | True : False   |
+--------+----------------------+-------+-------+----------+----------+---------------+-----------------------------+----------------+
| FAIL   | aes128-sha1          | True  | False | 86400    | 3600     | True : True   | Disconnected : Disconnected | True : True    |
+--------+----------------------+-------+-------+----------+----------+---------------+-----------------------------+----------------+
| SKIP   | aes128-sha1          | True  | False | 86400    | 3600     | False : False | Connected : Error           | False : False  |
+--------+----------------------+-------+-------+----------+----------+---------------+-----------------------------+----------------+
```

* pr/1741:
  complete implementation of the StrongSwan VPN feature

Signed-off-by: Rajani Karuturi <rajani.karuturi@accelerite.com>
2017-02-14 17:59:17 +05:30
Will Stevens
f045d65b90 complete implementation of the StrongSwan VPN feature 2017-02-02 16:18:06 -05:00
Wei Zhou
16c2cd0244 FIX issue on preshared key if we disable/enable remote access vpn
Way to reproduce the issue
(1) enable remote access vpn
root@r-8349-VM:~# cat /etc/ipsec.d/ipsec.any.secrets
: PSK "mVSx5KDXCPYX7X5DGb2W8yNW"

(2) disable/enable vpn
root@r-8349-VM:~# cat /etc/ipsec.d/ipsec.any.secrets
: PSK "mVSx5KDXCPYX7X5DGb2W8yNW"
: PSK "HeV3dHZpZXt4chhfvhx8D83C"

Expected configuration:
root@r-8349-VM:~# cat /etc/ipsec.d/ipsec.any.secrets
: PSK "HeV3dHZpZXt4chhfvhx8D83C"
2017-01-05 12:14:13 +01:00
Jayapalu
fed58eebdd CLOUDSTACK-9615: Fixed applying ingress rules without ports 2016-12-12 11:11:02 +05:30
Murali Reddy
6749785cab CLOUDSTACK-9339 Virtual Routers don't handle Multiple Public Interfaces correctly
-when processing static nat rule, add a mangle table rule, to mark the traffic
   from the guest vm when it has associated static nat rule so that traffic gets
   routed using the route tabe of the device which has public ip associated

  -fix the case where nic_device_id is empty when ip is getting disassociated
   resulting in empty deviceid in ips.json

  -add utility methods in CsRule, and CsRoute to add 'ip rule' and 'ip route' rules respectivley

  -ensure traffic from all public interfaces are connection marked with device number, and restored
   for the reverse traffic. use the connection marked number to do device specific routing table lookup
   fill the device specific routing table with default route

  -component tests for testing multiple public interfaces of VR
2016-12-07 14:33:24 +05:30
Murali Reddy
a43abbe47b fix egress rule incorrect behavior
CLOUDSTACK-9480: Egress Firewall: Incorrect use of Allow/Deny for ICMP

     fix ensures, ICMP, TCP, UDP are handled similalry w.r.t egress rule action

CLOUDSTACK-9495: Egress rules functionalty broken when protocol=all specified

     when protocol=all specified, CIDR was ignored. Fix ensures if CIDR is specified
     its always used in configuring iptable rules

 2 new test cased to test /32 CIDR
2016-09-20 16:56:06 +05:30
Will Stevens
d302269fe5 CLOUDSTACK-9437: Create egress chain on upgrade and cleanup for allow all traffic
- Ensure that FW_EGRESS_RULE chain exists after upgrading the router
- Flush allow all egress rule on 0.0.0.0/0, if such a rule exists in the config
  it will be added later (CLOUDSTACK-9437)
2016-07-25 16:44:38 -04:00
Patrick Dube
9ab676206a Added missing rules on router config, fixed ordering of multiple rules, removed duplicate rules, added fix for network stats, added a check for b64 decoding (to pad incorrect b64). Also added a catch exception to be logged on the configure main. 2016-07-22 15:32:20 -04:00
Will Stevens
49df7f283c Merge release branch 4.8 to master
* 4.8:
  CLOUDSTACK-9342: Site to Site VPN PFS not being set correctly
2016-07-18 14:07:09 -04:00
Will Stevens
adaf410109 Merge pull request #1480 from Slair1/S2S-VPN-PFS-Setting
CLOUDSTACK-9342: Site to Site VPN PFS not being set correctlyBug in code set PFS to the same value (yes/no) as DPD.

file.addeq(" pfs=%s" % CsHelper.bool_to_yn(obj['dpd']))

* pr/1480:
  CLOUDSTACK-9342: Site to Site VPN PFS not being set correctly

Signed-off-by: Will Stevens <williamstevens@gmail.com>
2016-07-18 14:05:18 -04:00
Syed
26227768a1 [CLOUDSTACK-9296] Start ipsec for client VPN 2016-05-26 11:25:09 -04:00
Remi Bergsma
74f60df828 Revert "Merge pull request #1482 from remibergsma/iptables-fix"
Seems to have a license issue so reverting for now.

This reverts commit 9a20ab8bcbbd39aa012a0ec5a65e66bcc737ee0e, reversing
changes made to 7a0b37a29a8be14011427dcf61bf3ea86e47dbf4.
2016-05-19 11:04:46 +02:00
Will Stevens
9a20ab8bcb Merge pull request #1482 from remibergsma/iptables-fix
Restore iptables at once using iptables-restore instead of calling iptables numerous timesThis makes handling the firewall rules about 50-60 times faster because it is generated in memory and then loaded once. It's work by @borisroman see PR #1400. Reopened it here because I think this is a great improvement.

* pr/1482:
  Resolve conflict as forceencap is already in master
  Split the cidr lists so we won't hit the iptables-resture limits
  Check the existence of 'forceencap' parameter before use
  Do not load previous firewall rules as we replace everyhing anyway
  Wait for dnsmasq to finish restart
  Remove duplicate spaces, and thus duplicate rules.
  Restore iptables at once using iptables-restore instead of calling iptables numerous times
  Add iptables copnversion script.

Signed-off-by: Will Stevens <williamstevens@gmail.com>
2016-05-18 15:50:20 -04:00
Will Stevens
919660d093 Merge pull request #1472 from remibergsma/47_fix_static_router_master_change
Apply static routes on change to master stateRefactored static routes for private gateways so they also get loaded when the router switches to master state. Otherwise they're lost and connections drop after fail over.

* pr/1472:
  apply static routes on change to master state

Signed-off-by: Will Stevens <williamstevens@gmail.com>
2016-05-12 11:01:55 -04:00
Will Stevens
309a60ea71 Merge pull request #1483 from remibergsma/pr1413-wilder-47
CLOUDSTACK-9287 - Fix unique mac address per rVPC routerThis is work by @wilderrodrigues, see PR #1413 It contains important fixes and I think it needs to be included so I send the PR again.

* pr/1483:
  CLOUDSTACK-9287 - Improve test by checking if pvt gw is removed and fix typos
  CLOUDSTACK-9287 - Fix RVR public interface
  CLOUDSTACK-9287 - Add integration test to cover the private gateway related changes
  CLOUDSTACK-9287 - Refactor the interface state configuration
  CLOUDSTACK-9287 - Check if the nic profile has already been removed from a certain router
  CLOUDSTACK-9287 - Bring up the private gw interface on state change to master
  CLOUDSTACK-9287 - Make sure private gw interface is not used for default gw
  CLOUDSTACK-9287 - Add integration test to cover the private gw interface/mac address issues
  CLOUDSTACK-9287 - Put private gateway interface down on backup router
  CLOUDSTACK-9287 - Generate new mac address if router is redundant and nic profile exists

Signed-off-by: Will Stevens <williamstevens@gmail.com>
2016-05-12 11:00:40 -04:00
Remi Bergsma
ebb7cb690d Resolve conflict as forceencap is already in master 2016-04-30 21:09:33 +02:00
Will Stevens
a7fef86bb3 Merge pull request #1402 from remibergsma/forceencap_check
Check the existence of 'forceencap' parameter before useCheck the existence of 'forceencap' parameter before use.

Error seen:

```
Traceback (most recent call last):
  File "/opt/cloud/bin/update_config.py", line 140, in <module>
    process_file()
  File "/opt/cloud/bin/update_config.py", line 54, in process_file
    finish_config()
  File "/opt/cloud/bin/update_config.py", line 44, in finish_config
    returncode = configure.main(sys.argv)
  File "/opt/cloud/bin/configure.py", line 1003, in main
    vpns.process()
  File "/opt/cloud/bin/configure.py", line 488, in process
    self.configure_ipsec(self.dbag[vpn])
  File "/opt/cloud/bin/configure.py", line 544, in configure_ipsec
    file.addeq(" forceencaps=%s" % CsHelper.bool_to_yn(obj['encap']))
KeyError: 'encap'
```

* pr/1402:
  Check the existence of 'forceencap' parameter before use

Signed-off-by: Will Stevens <williamstevens@gmail.com>
2016-04-21 16:30:16 -04:00
Remi Bergsma
53de78f642 Check the existence of 'forceencap' parameter before use 2016-04-19 11:11:19 +02:00
Slair1
7b9b328f30 CLOUDSTACK-9342: Site to Site VPN PFS not being set correctly
Bug in code set PFS to the same value (yes/no) as DPD.

file.addeq(" pfs=%s" % CsHelper.bool_to_yn(obj['dpd']))
2016-04-15 12:00:16 -05:00
kollyma
0a01e82c23 speedup iptables by prefetching the variables 2016-04-11 20:58:03 +02:00
Wilder Rodrigues
c41edc1fe6 CLOUDSTACK-9287 - Refactor the interface state configuration
- This also refactors the CsAddress in order to offer better readability in a couple of methods.
2016-04-09 21:14:25 +02:00
Remi Bergsma
b9feb39e17 apply static routes on change to master state 2016-04-07 20:57:58 +02:00
Boris Schrijver
30741a3309 Split the cidr lists so we won't hit the iptables-resture limits 2016-02-05 21:11:59 +01:00
Boris Schrijver
709be45cf0 Check the existence of 'forceencap' parameter before use 2016-02-05 21:06:53 +01:00
Boris Schrijver
18d5cd2855 Do not load previous firewall rules as we replace everyhing anyway 2016-02-05 21:04:06 +01:00
Boris Schrijver
b857f79fcb Restore iptables at once using iptables-restore instead of calling iptables numerous times 2016-02-05 12:02:57 +01:00
Remi Bergsma
78c43669e5 CLOUDSTACK-9264: Make /32 static routes for private gw work 2016-01-29 19:25:29 +01:00
Boris Schrijver
3eceb60f5c More VR performance! 2016-01-21 11:51:03 +01:00
Boris Schrijver
73c0242df3 Enhance VR performance by selectively executing tasks instead of brute-forcing 2016-01-18 11:40:59 +01:00
Remi Bergsma
5fdc77e16c Merge pull request #1276 from michaelandersen/fix/site2sitevpn
[4.7] FIX Site2SiteVPN on redundant VPCThis PR:
- fixes the inability to setup more than one Site2Site VPN connection from a VPC
- fixes starting of Site2Site VPN on redundant VPC
- fixes Site2Site VPN state checking on redundant VPC
- improves the vpc_vpn test to allow multple hypervisors
- adds an integration test for Site2Site VPN on redundant VPC

Tested it on 4.7 single Xen server zone:

command:
```
nosetests --with-marvin --marvin-config=/data/shared/marvin/mct-zone1-xen1.cfg -a tags=advanced,required_hardware=true /tmp/test_vpc_vpn.py
```

results:
```
Test Site 2 Site VPN Across redundant VPCs ... === TestName: test_01_redundant_vpc_site2site_vpn | Status : SUCCESS ===
ok
Test Remote Access VPN in VPC ... === TestName: test_01_vpc_remote_access_vpn | Status : SUCCESS ===
ok
Test Site 2 Site VPN Across VPCs ... === TestName: test_01_vpc_site2site_vpn | Status : SUCCESS ===
ok

----------------------------------------------------------------------
Ran 3 tests in 1490.076s

OK
```

also performed numerous manual inspections of state of VPN connections and connectivity between VPC's

* pr/1276:
  Fix unable to setup more than one Site2Site VPN Connection
  FIX S2S VPN rVPC: Check only redundant routers in state MASTER
  PEP8 of integration/smoke/test_vpc_vpn
  Add S2S VPN test for Redundant VPC
  Make integration/smoke/test_vpc_vpn Hypervisor independant
  FIX VPN: non-working ipsec commands

Signed-off-by: Remi Bergsma <github@remi.nl>
2016-01-16 19:51:46 +01:00
Michael Andersen
435a98cd3f Fix unable to setup more than one Site2Site VPN Connection 2016-01-12 11:24:35 +01:00
Michael Andersen
dfa924bdee FIX VPN: non-working ipsec commands 2016-01-12 11:24:34 +01:00
Michael Andersen
21acc95d57 [ROUTER] Add forceencaps field to python router ipsec config method 2016-01-07 19:27:42 +01:00
Wilder Rodrigues
6d9a3d82f9 CLOUDSTACK-9075 - Uses the same vlan since it should have been already released
- After the first test is done, the clean up will delete the whole VPC, also releasing the VLAN that was in use.
2015-12-02 10:36:53 +01:00
Wilder Rodrigues
a17fa48de1 CLOUDSTACK-9075 - Adds VPC static routes test
- Adds redundant VPC tests
   - Adds support to Static Routes on VPC private gatways
   - Removes the route configuration in case static route is deleted.
2015-12-02 10:36:52 +01:00
Wilder Rodrigues
cd05a252fb CLOUDSTACK-9015 - Make sure the Backup router can talk to the Master router after a stop/start/reboot
- Stop KeepaliveD/ConntrackD if the eth2 (guest) interface is not configured and UP
   - Only setup the redundancy after all the router configuration is done
   - Open the FW for the VRRP communitation
     - 224.0.0.18 and 225.0.0.50
   - Set keepalived.conf.templ by default to use interface eth2 (guest)
     - It will be reconfigured anyway, but having eth2 there is more clear
2015-11-12 18:13:51 +01:00
Wilder Rodrigues
79dabfdae4 CLOUDSTACK-8925 - Implement the default egress DENY/ALLOW properly
- Make tests work with right IP and rules
   - Add egress rule for port 53 protocol UDP when testing default egress DENY on RVR
2015-11-04 13:48:04 +01:00
Wilder Rodrigues
caa0b4071c CLOUDSTACK-8925 - Drop the traffic when default egress is set to false
- The DROP rule should be appended and the other rules inserted.
2015-11-02 21:45:03 +01:00
Wei Zhou
9f7f42330a CLOUDSTACK-9013: Virtual router failed to start on KVM
This fix a typo of commit 4a177031b055f3649e3b4a00c80eddb5cafa1dd7
2015-10-30 20:04:56 +01:00
Wilder Rodrigues
b2aa1f8417 CLOUDSTACK-8957 - Implement password server in configure.py 2015-10-29 07:14:51 +01:00
Wilder Rodrigues
2b286ecd73 CLOUDSTACK-8952 - Make sure the calls to CsFile use the new logic of commit/is_changed methods
- We now have to check if the file changed before commiting. Doesn't make sense to write on disk if there was nono change.
2015-10-17 12:20:40 +02:00
Wilder Rodrigues
4a177031b0 CLOUDSTACK-8947 - Avoid multiple entries in the FW_EGRESS_RULES table 2015-10-14 07:44:38 +02:00
Wilder Rodrigues
cbd6464b88 CLOUDSTACK-8947 - FW_EGRESS should be added only to filter table 2015-10-14 07:44:37 +02:00
Wilder Rodrigues
cd8c3e97f5 CLOUDSTACK-8934 - Fix the AclIP class to make it configure the default FW policy 2015-10-11 14:57:33 +02:00
Wilder Rodrigues
b4dc392bfd CLOUDSTACK-8934 - Fix default EGRESS rules for isolated networks
- The default is Accept and will be changed based on the configuration of the offering.

CLOUDSTACK-8934 - The default egress is set as Deny in the router.

   - We had to change it on the Java side in order to make the apply it once the default is defined as allowed on the net offering
2015-10-11 14:57:32 +02:00
Wilder Rodrigues
0c752eab60 CLOUDSTACK-8915 - Rearrenging a bit the default route code in order to make it more clear 2015-10-06 16:41:13 +02:00
Remi Bergsma
4420f48e3e Merge pull request #882 from jayapalu/CLOUDSTACK-8881
CLOUDSTACK-8881: Fixed Static and PF configuration issue1. For static nat filter rules are not configured in VR.
2. Corrected vm ip in PF rule.

* pr/882:
  CLOUDSTACK-8881: Fixed Static and PF configuration issue

Signed-off-by: Remi Bergsma <github@remi.nl>
2015-09-24 15:36:18 +02:00
Remi Bergsma
649a4bdc76 Merge pull request #881 from jayapalu/CLOUDSTACK-8905
CLOUDSTACK-8905: Fixed hooking egress rulesAdded hooking the FIREWALL_EGRESS_RULES chain into FW_OUTBOUND chain.
With this egress rules will effective.

* pr/881:
  CLOUDSTACK-8905: Fixed hooking egress rules

Signed-off-by: Remi Bergsma <github@remi.nl>
2015-09-24 15:36:04 +02:00