summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2020-04-21 01:50:39 +0000
committerGerrit Code Review <review@openstack.org>2020-04-21 01:50:39 +0000
commit0421968f4a2ef2df43f21c739206c38fa047115b (patch)
treedbb03713b646c78dc80d488b87fa4040ffb0846a
parentbed20cf04b7290f6b0762c6037a21d00ff2fafe9 (diff)
parent240d0309023fcaf20df44f819e9b3e14af97f526 (diff)
downloadnova-0421968f4a2ef2df43f21c739206c38fa047115b.tar.gz
Merge "Reject boot request for unsupported images" into stable/train20.2.0
-rw-r--r--nova/api/openstack/compute/servers.py1
-rw-r--r--nova/compute/api.py26
-rw-r--r--nova/tests/unit/api/openstack/compute/test_serversV21.py16
-rw-r--r--releasenotes/notes/cinder-detect-nonbootable-image-6fad7f865b45f879.yaml9
4 files changed, 52 insertions, 0 deletions
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py
index 300b2b4485..42308af931 100644
--- a/nova/api/openstack/compute/servers.py
+++ b/nova/api/openstack/compute/servers.py
@@ -736,6 +736,7 @@ class ServersController(wsgi.Controller):
except (exception.ImageNotActive,
exception.ImageBadRequest,
exception.ImageNotAuthorized,
+ exception.ImageUnacceptable,
exception.FixedIpNotFoundForAddress,
exception.FlavorNotFound,
exception.FlavorDiskTooSmall,
diff --git a/nova/compute/api.py b/nova/compute/api.py
index ff64ea5a8b..37457c4f34 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -577,6 +577,31 @@ class API(base.Base):
root_bdm, validate_numa)
@staticmethod
+ def _detect_nonbootable_image_from_properties(image_id, image):
+ """Check image for a property indicating it's nonbootable.
+
+ This is called from the API service to ensure that there are
+ no known image properties indicating that this image is of a
+ type that we do not support booting from.
+
+ Currently the only such property is 'cinder_encryption_key_id'.
+
+ :param image_id: UUID of the image
+ :param image: a dict representation of the image including properties
+ :raises: ImageUnacceptable if the image properties indicate
+ that booting this image is not supported
+ """
+ if not image:
+ return
+
+ image_properties = image.get('properties', {})
+ if image_properties.get('cinder_encryption_key_id'):
+ reason = _('Direct booting of an image uploaded from an '
+ 'encrypted volume is unsupported.')
+ raise exception.ImageUnacceptable(image_id=image_id,
+ reason=reason)
+
+ @staticmethod
def _validate_flavor_image_nostatus(context, image, instance_type,
root_bdm, validate_numa=True,
validate_pci=False):
@@ -876,6 +901,7 @@ class API(base.Base):
validate_numa=True):
self._check_metadata_properties_quota(context, metadata)
self._check_injected_file_quota(context, files_to_inject)
+ self._detect_nonbootable_image_from_properties(image_id, image)
self._validate_flavor_image(context, image_id, image,
instance_type, root_bdm,
validate_numa=validate_numa)
diff --git a/nova/tests/unit/api/openstack/compute/test_serversV21.py b/nova/tests/unit/api/openstack/compute/test_serversV21.py
index 6980676b58..80af96ebb6 100644
--- a/nova/tests/unit/api/openstack/compute/test_serversV21.py
+++ b/nova/tests/unit/api/openstack/compute/test_serversV21.py
@@ -4317,6 +4317,22 @@ class ServersControllerCreateTest(test.TestCase):
"Flavor's disk is too small for requested image."):
self.controller.create(self.req, body=self.body)
+ @mock.patch.object(fake._FakeImageService, 'show',
+ return_value=dict(
+ id='76fa36fc-c930-4bf3-8c8a-ea2a2420deb6',
+ status='active',
+ properties=dict(
+ cinder_encryption_key_id=fakes.FAKE_UUID)))
+ def test_create_server_image_nonbootable(self, mock_show):
+ self.req.body = jsonutils.dump_as_bytes(self.body)
+
+ expected_msg = ("Image {} is unacceptable: Direct booting of an image "
+ "uploaded from an encrypted volume is unsupported.")
+ with testtools.ExpectedException(
+ webob.exc.HTTPBadRequest,
+ expected_msg.format(self.image_uuid)):
+ self.controller.create(self.req, body=self.body)
+
def test_create_instance_with_image_non_uuid(self):
self.body['server']['imageRef'] = 'not-uuid'
self.assertRaises(exception.ValidationError,
diff --git a/releasenotes/notes/cinder-detect-nonbootable-image-6fad7f865b45f879.yaml b/releasenotes/notes/cinder-detect-nonbootable-image-6fad7f865b45f879.yaml
new file mode 100644
index 0000000000..0746df58f2
--- /dev/null
+++ b/releasenotes/notes/cinder-detect-nonbootable-image-6fad7f865b45f879.yaml
@@ -0,0 +1,9 @@
+---
+fixes:
+ - |
+ The Compute service has never supported direct booting of an instance from
+ an image that was created by the Block Storage service from an encrypted
+ volume. Previously, this operation would result in an ACTIVE instance that
+ was unusable. Beginning with this release, an attempt to boot from such an
+ image will result in the Compute API returning a 400 (Bad Request)
+ response.