1 # This strongswan-swanctl test is based on:
2 # https://www.strongswan.org/testing/testresults/swanctl/rw-psk-ipv4/index.html
3 # https://github.com/strongswan/strongswan/tree/master/testing/tests/swanctl/rw-psk-ipv4
5 # The roadwarrior carol sets up a connection to gateway moon. The authentication
6 # is based on pre-shared keys and IPv4 addresses. Upon the successful
7 # establishment of the IPsec tunnels, the specified updown script automatically
8 # inserts iptables-based firewall rules that let pass the tunneled traffic. In
9 # order to test both tunnel and firewall, carol pings the client alice behind
13 # eth1------vlan_0------eth1 eth2------vlan_1------eth1
14 # 192.168.0.1 192.168.0.3 192.168.1.3 192.168.1.2
16 # See the NixOS manual for how to run this test:
17 # https://nixos.org/nixos/manual/index.html#sec-running-nixos-tests-interactively
19 import ./make-test-python.nix ({ pkgs, ...} :
22 allowESP = "iptables --insert INPUT --protocol ESP --jump ACCEPT";
24 # Shared VPN settings:
25 vlan0 = "192.168.0.0/24";
26 carolIp = "192.168.1.2";
27 moonIp = "192.168.1.3";
29 secret = "0sFpZAZqEN6Ti9sqt4ZP5EWcqx";
30 esp_proposals = [ "aes128gcm128-x25519" ];
31 proposals = [ "aes128-sha256-x25519" ];
33 name = "strongswan-swanctl";
34 meta.maintainers = with pkgs.lib.maintainers; [ basvandijk ];
38 virtualisation.vlans = [ 0 ];
40 dhcpcd.enable = false;
41 defaultGateway = "192.168.0.3";
45 moon = { config, ...} :
46 let strongswan = config.services.strongswan-swanctl.package;
48 virtualisation.vlans = [ 0 1 ];
50 dhcpcd.enable = false;
52 allowedUDPPorts = [ 4500 500 ];
53 extraCommands = allowESP;
57 internalIPs = [ vlan0 ];
58 internalInterfaces = [ "eth1" ];
60 externalInterface = "eth2";
63 environment.systemPackages = [ strongswan ];
64 services.strongswan-swanctl = {
69 local_addrs = [ moonIp ];
79 updown = "${strongswan}/libexec/ipsec/_updown iptables";
80 inherit esp_proposals;
97 carol = { config, ...} :
98 let strongswan = config.services.strongswan-swanctl.package;
100 virtualisation.vlans = [ 1 ];
102 dhcpcd.enable = false;
103 firewall.extraCommands = allowESP;
105 environment.systemPackages = [ strongswan ];
106 services.strongswan-swanctl = {
111 local_addrs = [ carolIp ];
112 remote_addrs = [ moonIp ];
123 remote_ts = [ vlan0 ];
124 start_action = "trap";
125 updown = "${strongswan}/libexec/ipsec/_updown iptables";
126 inherit esp_proposals;
146 carol.wait_until_succeeds("ping -c 1 alice")