Provide Fedora support for StrongSwan

The initial release of StrongSwan VPNaaS driver only support Ubuntu.
This patch will provide the Fedora support. The different usage of
StrongSwan between Fedora and Ubuntu are:
- Uses 'strongswan' CLI command instead of 'ipsec'
- Configuration files location is different
- Strongswan.d directory in template directory does not include
  'charon' directory

Change-Id: I27d8518d1d8110453d4674a0c6fb3cb6072a32f0
Closes-bug: 1444776
Closes-bug: 1441788
This commit is contained in:
Wei Hu 2015-04-16 13:15:00 +08:00
parent 0bf029ed53
commit f8a62b09b6
4 changed files with 127 additions and 0 deletions

View File

@ -11,5 +11,6 @@
ip: IpFilter, ip, root
ip_exec: IpNetnsExecFilter, ip, root
ipsec: CommandFilter, ipsec, root
strongswan: CommandFilter, strongswan, root
neutron_netns_wrapper: CommandFilter, neutron-vpn-netns-wrapper, root
neutron_netns_wrapper_local: CommandFilter, /usr/local/bin/neutron-vpn-netns-wrapper, root

View File

@ -12,6 +12,7 @@
# vpn_device_driver=neutron_vpnaas.services.vpn.device_drivers.cisco_ipsec.CiscoCsrIPsecDriver
# vpn_device_driver=neutron_vpnaas.services.vpn.device_drivers.vyatta_ipsec.VyattaIPSecDriver
# vpn_device_driver=neutron_vpnaas.services.vpn.device_drivers.strongswan_ipsec.StrongSwanDriver
# vpn_device_driver=neutron_vpnaas.services.vpn.device_drivers.fedora_strongswan_ipsec.FedoraStrongSwanDriver
# vpn_device_driver=another_driver
[ipsec]

View File

@ -0,0 +1,107 @@
# Copyright (c) 2015 IBM, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
from oslo_config import cfg
from oslo_log import log as logging
from neutron_vpnaas.services.vpn.device_drivers import ipsec
from neutron_vpnaas.services.vpn.device_drivers import strongswan_ipsec
LOG = logging.getLogger(__name__)
TEMPLATE_PATH = os.path.dirname(os.path.abspath(__file__))
cfg.CONF.set_default(name='default_config_area',
default=os.path.join(
TEMPLATE_PATH,
'/usr/share/strongswan/templates/'
'config/strongswan.d'),
group='strongswan')
class FedoraStrongSwanProcess(strongswan_ipsec.StrongSwanProcess):
binary = 'strongswan'
CONFIG_DIRS = [
'var/run',
'log',
'etc',
'etc/strongswan/ipsec.d/aacerts',
'etc/strongswan/ipsec.d/acerts',
'etc/strongswan/ipsec.d/cacerts',
'etc/strongswan/ipsec.d/certs',
'etc/strongswan/ipsec.d/crls',
'etc/strongswan/ipsec.d/ocspcerts',
'etc/strongswan/ipsec.d/policies',
'etc/strongswan/ipsec.d/private',
'etc/strongswan/ipsec.d/reqs',
'etc/pki/nssdb/'
]
STATUS_NOT_RUNNING_RE = ('Command:.*[ipsec|strongswan].*status.*'
'Exit code: [1|3] ')
def __init__(self, conf, process_id, vpnservice, namespace):
super(FedoraStrongSwanProcess, self).__init__(conf, process_id,
vpnservice, namespace)
def ensure_configs(self):
"""Generate config files which are needed for StrongSwan.
If there is no directory, this function will create
dirs.
"""
self.ensure_config_dir(self.vpnservice)
self.ensure_config_file(
'ipsec.conf',
cfg.CONF.strongswan.ipsec_config_template,
self.vpnservice)
self.ensure_config_file(
'strongswan.conf',
cfg.CONF.strongswan.strongswan_config_template,
self.vpnservice)
self.ensure_config_file(
'ipsec.secrets',
cfg.CONF.strongswan.ipsec_secret_template,
self.vpnservice)
self.copy_and_overwrite(cfg.CONF.strongswan.default_config_area,
self._get_config_filename('strongswan.d'))
# Fedora uses /usr/share/strongswan/templates/config/ as strongswan
# template directory. But /usr/share/strongswan/templates/config/
# strongswan.d does not include charon. Those configuration files
# are in /usr/share/strongswan/templates/config/plugins directory.
charon_dir = os.path.join(
cfg.CONF.strongswan.default_config_area,
'charon')
if not os.path.exists(charon_dir):
plugins_dir = os.path.join(
cfg.CONF.strongswan.default_config_area, '../plugins')
self.copy_and_overwrite(
plugins_dir,
self._get_config_filename('strongswan.d/charon'))
def _get_config_filename(self, kind):
config_dir = '%s/strongswan' % self.etc_dir
return os.path.join(config_dir, kind)
class FedoraStrongSwanDriver(ipsec.IPsecDriver):
def create_process(self, process_id, vpnservice, namespace):
return FedoraStrongSwanProcess(
self.conf,
process_id,
vpnservice,
namespace)

View File

@ -25,6 +25,7 @@ from neutron.plugins.common import constants
from oslo_config import cfg
from neutron_vpnaas.extensions import vpnaas
from neutron_vpnaas.services.vpn.device_drivers import fedora_strongswan_ipsec
from neutron_vpnaas.services.vpn.device_drivers import ipsec as openswan_ipsec
from neutron_vpnaas.services.vpn.device_drivers import strongswan_ipsec
from neutron_vpnaas.tests import base
@ -727,3 +728,20 @@ class IPsecStrongswanDeviceDriverDVR(IPSecDeviceDVR):
ipsec_process=strongswan_ipsec.StrongSwanProcess):
super(IPsecStrongswanDeviceDriverDVR, self).setUp(driver,
ipsec_process)
class IPsecFedoraStrongswanDeviceDriverLegacy(
IPsecStrongswanDeviceDriverLegacy):
def setUp(self, driver=fedora_strongswan_ipsec.FedoraStrongSwanDriver,
ipsec_process=fedora_strongswan_ipsec.FedoraStrongSwanProcess):
super(IPsecFedoraStrongswanDeviceDriverLegacy,
self).setUp(driver, ipsec_process)
class IPsecFedoraStrongswanDeviceDriverDVR(IPSecDeviceDVR):
def setUp(self, driver=fedora_strongswan_ipsec.FedoraStrongSwanDriver,
ipsec_process=fedora_strongswan_ipsec.FedoraStrongSwanProcess):
super(IPsecFedoraStrongswanDeviceDriverDVR, self).setUp(driver,
ipsec_process)