NSX|P: Fix certificate secret to use the correct password
DbCertificateStorageDriver should use the pk_password from the nsx_p config section and not from the nsx_v3 one Change-Id: Ibe843e9e994bb679bdae68b0683aa36e2c78d891
This commit is contained in:
parent
b662977ca2
commit
d553f307ed
@ -41,13 +41,16 @@ PORT_SG_SCOPE = 'os-security-group'
|
|||||||
NSX_NEUTRON_PLUGIN = 'NSX Neutron plugin'
|
NSX_NEUTRON_PLUGIN = 'NSX Neutron plugin'
|
||||||
|
|
||||||
|
|
||||||
|
def get_DbCertProvider(conf_path):
|
||||||
class DbCertProvider(client_cert.ClientCertProvider):
|
class DbCertProvider(client_cert.ClientCertProvider):
|
||||||
"""Write cert data from DB to file and delete after use
|
"""Write cert data from DB to file and delete after use
|
||||||
|
|
||||||
New provider object with random filename is created for each request.
|
New provider object with random filename is created for each
|
||||||
This is not most efficient, but the safest way to avoid race conditions,
|
request.
|
||||||
since backend connections can occur both before and after neutron
|
This is not most efficient, but the safest way to avoid race
|
||||||
fork, and several concurrent requests can occupy the same thread.
|
conditions, since backend connections can occur both before and
|
||||||
|
after neutron fork, and several concurrent requests can occupy the
|
||||||
|
same thread.
|
||||||
Note that new cert filename for each request does not result in new
|
Note that new cert filename for each request does not result in new
|
||||||
connection for each request (at least for now..)
|
connection for each request (at least for now..)
|
||||||
"""
|
"""
|
||||||
@ -57,6 +60,7 @@ class DbCertProvider(client_cert.ClientCertProvider):
|
|||||||
super(DbCertProvider, self).__init__(None)
|
super(DbCertProvider, self).__init__(None)
|
||||||
random.seed()
|
random.seed()
|
||||||
self._filename = '/tmp/.' + str(random.randint(1, 10000000))
|
self._filename = '/tmp/.' + str(random.randint(1, 10000000))
|
||||||
|
self.conf_path = conf_path
|
||||||
|
|
||||||
def _check_expiration(self, expires_in_days):
|
def _check_expiration(self, expires_in_days):
|
||||||
if expires_in_days > self.EXPIRATION_ALERT_DAYS:
|
if expires_in_days > self.EXPIRATION_ALERT_DAYS:
|
||||||
@ -74,7 +78,7 @@ class DbCertProvider(client_cert.ClientCertProvider):
|
|||||||
try:
|
try:
|
||||||
context = q_context.get_admin_context()
|
context = q_context.get_admin_context()
|
||||||
db_storage_driver = cert_utils.DbCertificateStorageDriver(
|
db_storage_driver = cert_utils.DbCertificateStorageDriver(
|
||||||
context)
|
context, self.conf_path.nsx_client_cert_pk_password)
|
||||||
with client_cert.ClientCertificateManager(
|
with client_cert.ClientCertificateManager(
|
||||||
cert_utils.NSX_OPENSTACK_IDENTITY,
|
cert_utils.NSX_OPENSTACK_IDENTITY,
|
||||||
None,
|
None,
|
||||||
@ -109,6 +113,8 @@ class DbCertProvider(client_cert.ClientCertProvider):
|
|||||||
def filename(self):
|
def filename(self):
|
||||||
return self._filename
|
return self._filename
|
||||||
|
|
||||||
|
return DbCertProvider
|
||||||
|
|
||||||
|
|
||||||
def get_client_cert_provider(conf_path=cfg.CONF.nsx_v3):
|
def get_client_cert_provider(conf_path=cfg.CONF.nsx_v3):
|
||||||
if not conf_path.nsx_use_client_auth:
|
if not conf_path.nsx_use_client_auth:
|
||||||
@ -123,18 +129,19 @@ def get_client_cert_provider(conf_path=cfg.CONF.nsx_v3):
|
|||||||
if conf_path.nsx_client_cert_storage.lower() == 'nsx-db':
|
if conf_path.nsx_client_cert_storage.lower() == 'nsx-db':
|
||||||
# Cert data is stored in DB, and written to file system only
|
# Cert data is stored in DB, and written to file system only
|
||||||
# when new connection is opened, and deleted immediately after.
|
# when new connection is opened, and deleted immediately after.
|
||||||
return DbCertProvider
|
return get_DbCertProvider(conf_path)
|
||||||
|
|
||||||
|
|
||||||
def get_nsxlib_wrapper(nsx_username=None, nsx_password=None, basic_auth=False,
|
def get_nsxlib_wrapper(nsx_username=None, nsx_password=None, basic_auth=False,
|
||||||
plugin_conf=None, allow_overwrite_header=False):
|
plugin_conf=None, allow_overwrite_header=False):
|
||||||
|
if not plugin_conf:
|
||||||
|
plugin_conf = cfg.CONF.nsx_v3
|
||||||
|
|
||||||
client_cert_provider = None
|
client_cert_provider = None
|
||||||
if not basic_auth:
|
if not basic_auth:
|
||||||
# if basic auth requested, dont use cert file even if provided
|
# if basic auth requested, dont use cert file even if provided
|
||||||
client_cert_provider = get_client_cert_provider()
|
client_cert_provider = get_client_cert_provider(conf_path=plugin_conf)
|
||||||
|
|
||||||
if not plugin_conf:
|
|
||||||
plugin_conf = cfg.CONF.nsx_v3
|
|
||||||
nsxlib_config = config.NsxLibConfig(
|
nsxlib_config = config.NsxLibConfig(
|
||||||
username=nsx_username or plugin_conf.nsx_api_user,
|
username=nsx_username or plugin_conf.nsx_api_user,
|
||||||
password=nsx_password or plugin_conf.nsx_api_password,
|
password=nsx_password or plugin_conf.nsx_api_password,
|
||||||
|
@ -17,7 +17,6 @@ import base64
|
|||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
from cryptography import fernet
|
from cryptography import fernet
|
||||||
from oslo_config import cfg
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
from vmware_nsx.db import db as nsx_db
|
from vmware_nsx.db import db as nsx_db
|
||||||
@ -55,12 +54,11 @@ def symmetric_decrypt(secret, ciphertext):
|
|||||||
|
|
||||||
class DbCertificateStorageDriver(object):
|
class DbCertificateStorageDriver(object):
|
||||||
"""Storage for certificate and private key in neutron DB"""
|
"""Storage for certificate and private key in neutron DB"""
|
||||||
def __init__(self, context):
|
def __init__(self, context, cert_pk_password=None):
|
||||||
global _SECRET
|
global _SECRET
|
||||||
self._context = context
|
self._context = context
|
||||||
if cfg.CONF.nsx_v3.nsx_client_cert_pk_password and not _SECRET:
|
if cert_pk_password and not _SECRET:
|
||||||
_SECRET = generate_secret_from_password(
|
_SECRET = generate_secret_from_password(cert_pk_password)
|
||||||
cfg.CONF.nsx_v3.nsx_client_cert_pk_password)
|
|
||||||
|
|
||||||
def store_cert(self, purpose, certificate, private_key):
|
def store_cert(self, purpose, certificate, private_key):
|
||||||
# encrypt private key
|
# encrypt private key
|
||||||
|
@ -56,7 +56,8 @@ def get_certificate_manager(plugin_conf, **kwargs):
|
|||||||
LOG.info("Certificate storage is %s", storage_driver_type)
|
LOG.info("Certificate storage is %s", storage_driver_type)
|
||||||
if storage_driver_type == 'nsx-db':
|
if storage_driver_type == 'nsx-db':
|
||||||
storage_driver = cert_utils.DbCertificateStorageDriver(
|
storage_driver = cert_utils.DbCertificateStorageDriver(
|
||||||
context.get_admin_context())
|
context.get_admin_context(),
|
||||||
|
plugin_conf.nsx_client_cert_pk_password)
|
||||||
elif storage_driver_type == 'none':
|
elif storage_driver_type == 'none':
|
||||||
storage_driver = cert_utils.DummyCertificateStorageDriver()
|
storage_driver = cert_utils.DummyCertificateStorageDriver()
|
||||||
# TODO(annak) - add support for barbican storage driver
|
# TODO(annak) - add support for barbican storage driver
|
||||||
|
Loading…
x
Reference in New Issue
Block a user