05827810ca
Currently, when creating an encrypted volume from an image, Cinder writes raw data to the encrypted volume. When Cinder uploads an encrypted volume to an image, it writes encrypted data to the image. As a result, Nova cannot use these images or volumes. To fix above problem, cinder needs to add encryptor attach/detach layers. As both Nova and Cinder needs to use the module, the fix is to move it to os-brick. It copies encryptors from Nova to os-brick, and keep all interfaces unchanged except initialization. Change-Id: I8044183ad02110c8b2468e20327d822c0437c772 Implements: blueprint improve-encrypted-volume Related-bug: #1482464 Related-bug: #1465656
66 lines
2.2 KiB
Python
66 lines
2.2 KiB
Python
# Copyright (c) 2013 The Johns Hopkins University/Applied Physics Laboratory
|
|
# 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 abc
|
|
|
|
from os_brick import executor
|
|
from oslo_log import log as logging
|
|
import six
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
@six.add_metaclass(abc.ABCMeta)
|
|
class VolumeEncryptor(executor.Executor):
|
|
"""Base class to support encrypted volumes.
|
|
|
|
A VolumeEncryptor provides hooks for attaching and detaching volumes, which
|
|
are called immediately prior to attaching the volume to an instance and
|
|
immediately following detaching the volume from an instance. This class
|
|
performs no actions for either hook.
|
|
"""
|
|
|
|
def __init__(self, root_helper,
|
|
connection_info,
|
|
keymgr,
|
|
execute=None,
|
|
*args, **kwargs):
|
|
super(VolumeEncryptor, self).__init__(root_helper,
|
|
execute=execute,
|
|
*args, **kwargs)
|
|
self._key_manager = keymgr
|
|
|
|
self.encryption_key_id = kwargs.get('encryption_key_id')
|
|
|
|
def _get_key(self, context):
|
|
"""Retrieves the encryption key for the specified volume.
|
|
|
|
:param: the connection information used to attach the volume
|
|
"""
|
|
return self._key_manager.get(context, self.encryption_key_id)
|
|
|
|
@abc.abstractmethod
|
|
def attach_volume(self, context, **kwargs):
|
|
"""Hook called immediately prior to attaching a volume to an instance.
|
|
"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def detach_volume(self, **kwargs):
|
|
"""Hook called immediately after detaching a volume from an instance.
|
|
"""
|
|
pass
|