Set up a VPN connection with IPsec
In the current implementation of CGW, we use strongSwan as the software used for VPN termination using the IPsec protocol.
In the following, we will go through an example of setting up an IPSEC connection for the CGW Helm Chart. The focus is to get an understanding of the IPSEC part of the CGW, therefore, we will assume for this tutorial, that the IP addresses and interfaces are already set up.
Prerequisites
To complete this tutorial, you need a configured inet0 interface which is connected to the Internet and has a public IP address.
The configuration is the following: inet0: 2001:db8:0:1::1/64.
All the following configurations will be part of the value.yaml file you create for configuring the CGW chart.
You can combine multiple parts of the configuration, therefore we will not repeat parts set in previous steps.
Enable strongSwan
To enable strongSwan to terminate IPsec traffic, set the following:
Configure interface
If you have more than one interface in the pod, it does make sense to specify on which interface strongSwan should listen, as it narrows down the area of attacks.
To set the interfaces strongSwan shall bind on, set ipsec.interfaces with a comma separated list of interfaces, for example:
Manual configuration of strongSwan
The recommended way for this version of CGW is to use a manual strongSwan configuration. The framework strongSwan configurations is the following:
The ipsecConfig section
Under ipsecConfig you can add multiple configurations, where each key is the corresponding filename. For debugging, it does make sense to give it a reasonable name.
The content of this key is a block string which is a strongSwan configuration file. For all details of possible parameters, read the strongSwan documentationOpens in a new tab.
This is a simple configuration for route-based VPN:
The sts-base section
Starting in line 7 the connection sts-base is configured. Everything which is indented further is part of this configuration (till line 20).
The first part is the default configuration, which will be inherited by the following configurations.
dpdaction defines, what will happen, if the other side does not send liveliness messages and so a dead peer is detected. For site to site VPNs it is preferred to set it to restart as the CGW will try to create a new connection immediately.
closeaction is closely related and defines the action, when the other peer ends the connection with a closing message. Also here restart should be used for site to site connections.
auto defines how strongSwan behaves, when it is started. The options are ignore, add, route and start.
ignoreactually ignores the whole connection and will not respond even to connection requests from the other side.addwill add the connection and respond to requests from the other side, but not start a connection itself. This is useful in the road warrior scenario.routewill install a trap into the network stack and not do anything immediately. If the first packet, which matches the parameter of the connection though, it will try to create a connection.- With
startit will immediately try to open up a connection. This setting is preferred in site to site scenarios.
ike and esp are setting the cryptographic algorithms, which are preferred or even enforced (when ending with !) by strongSwan. Often these parameters are given to you by the other side, you try to connect to. If this is not the case, and you do not control the other side, you have to negotiate, what their router will support. In the case you are controlling the both ends of the tunnel, you can have a look at Cryptographic AlgorithmsBroken link or just stick with the setting above.
The ike parameter is setting the algorithms for the IKE phase (first phase), which is used for the control traffic and key exchange, whereas the esp parameter is setting the algorithms for the ESP part, which encapsulate the actual data traffic.
keyingretries defines how often it tries to choose now keys between the peers, when the negotiation fails.
This value can be set to all positive integers or to %forever.
lifetime and ikelifetime defines the duration of the connections, when they are not disconnected my other means.
After this period the ESP or IKE connection will be rekeyed respectively.
keyexchange selects, which protocol will be used for key exchange. If it is your choice, you should use ikev2. If the other party is not able to support it, you can choose ikev1.
mobike enables or disables the usage of the MOBIKEOpens in a new tab protocol.
This is not in general advised for site to site links.
leftauth and rightauth are defining, which method is used to authenticate.
The second-site section
The second part of the configuration stating at line 22 is the actual connection we are creating.
also defines, from which connection we inherit all parameters. These will then be extended or overwritten in this configuration.
leftsubnet and rightsubnet set the subnets, for which traffic will be transferred of the connection or what packets will be allowed. In this case, all packets with an IP address from leftsubnet, as sender on the left side and as receiver on the right side, will be send thorough the tunnel.
The mode used here is called policy-based routing. When the source and destination of a packets are matched by the rules, the packets will be transferred over the VPN.
For further information about differences between Route-based and Policy-based VPN, please have a look at the concepts or the tutorial for route-based vpnBroken link.
left and right set the IP, which is used on the corresponding nodes. Besides setting a specific IP, it is also possible to set the value to %any to allow connections from any IP address. This is common in the road warrior scenario but uncommon in site to site VPNs.
left and right prefix
strongSwan uses left and right as prefixes for a lot of parameters to separate between both sides. There is no clear separation which one is the current configured CGW, so you can use the same configuration on both sides.
It is very common to use the left side for the CGW you are configuring, and the right side for the "other side".
The ipsecSecrets section
The ipsecSecrets part contains the actual secrets for the VPN connection. This can either be a pre-shared key or parameters for the used private key.
The following code snippet shows the case for using a pre-shared key:
The first part of the line 6 is the ID of the other peer, which is by default the IP address, but can also be a FQDN, an email address, %any or %any6.
%any and %any6 match all IPv4 and IPv6 addresses respectively.
Further follows the mode for the authentication and finally the parameters for it. In this case PSK for pre-shared key and CorrectHorstBatteryStaple for the PSK itself.
You can also refer to an existing secret by name. This allows to not expose credentials in a plain value files, but instead use some common secret management tools to deploy the secret. The secret must contain the base64 encoded strongswan credentials like stated above, e.g.:
Instead of defining ipsec.strongswan.ipsecSecrets, refer to the secret like:
Further reading
If you want to set up VPN with certificates, go to the Certificate-based VPN tutorial.