Exemplo n.º 1
0
 def _format_image_from_db(self, db_image, db_tags):
     visibility = 'public' if db_image['is_public'] else 'private'
     properties = {}
     for prop in db_image.pop('properties'):
         # NOTE(markwash) db api requires us to filter deleted
         if not prop['deleted']:
             properties[prop['name']] = prop['value']
     locations = [loc for loc in db_image['locations']
                  if loc['status'] == 'active']
     if CONF.metadata_encryption_key:
         key = CONF.metadata_encryption_key
         for l in locations:
             l['url'] = crypt.urlsafe_decrypt(key, l['url'])
     return xmonitor.domain.Image(
         image_id=db_image['id'],
         name=db_image['name'],
         status=db_image['status'],
         created_at=db_image['created_at'],
         updated_at=db_image['updated_at'],
         visibility=visibility,
         min_disk=db_image['min_disk'],
         min_ram=db_image['min_ram'],
         protected=db_image['protected'],
         locations=location_strategy.get_ordered_locations(locations),
         checksum=db_image['checksum'],
         owner=db_image['owner'],
         disk_format=db_image['disk_format'],
         container_format=db_image['container_format'],
         size=db_image['size'],
         virtual_size=db_image['virtual_size'],
         extra_properties=properties,
         tags=db_tags
     )
Exemplo n.º 2
0
 def _format_image_from_db(self, db_image, db_tags):
     visibility = 'public' if db_image['is_public'] else 'private'
     properties = {}
     for prop in db_image.pop('properties'):
         # NOTE(markwash) db api requires us to filter deleted
         if not prop['deleted']:
             properties[prop['name']] = prop['value']
     locations = [
         loc for loc in db_image['locations'] if loc['status'] == 'active'
     ]
     if CONF.metadata_encryption_key:
         key = CONF.metadata_encryption_key
         for l in locations:
             l['url'] = crypt.urlsafe_decrypt(key, l['url'])
     return xmonitor.domain.Image(
         image_id=db_image['id'],
         name=db_image['name'],
         status=db_image['status'],
         created_at=db_image['created_at'],
         updated_at=db_image['updated_at'],
         visibility=visibility,
         min_disk=db_image['min_disk'],
         min_ram=db_image['min_ram'],
         protected=db_image['protected'],
         locations=location_strategy.get_ordered_locations(locations),
         checksum=db_image['checksum'],
         owner=db_image['owner'],
         disk_format=db_image['disk_format'],
         container_format=db_image['container_format'],
         size=db_image['size'],
         virtual_size=db_image['virtual_size'],
         extra_properties=properties,
         tags=db_tags)
Exemplo n.º 3
0
 def decrypt_metadata(self, image_metadata):
     if self.metadata_encryption_key:
         if image_metadata.get('location'):
             location = crypt.urlsafe_decrypt(self.metadata_encryption_key,
                                              image_metadata['location'])
             image_metadata['location'] = location
         if image_metadata.get('location_data'):
             ld = []
             for loc in image_metadata['location_data']:
                 url = crypt.urlsafe_decrypt(self.metadata_encryption_key,
                                             loc['url'])
                 ld.append({'id': loc['id'], 'url': url,
                            'metadata': loc['metadata'],
                            'status': loc['status']})
             image_metadata['location_data'] = ld
     return image_metadata
Exemplo n.º 4
0
 def test_encrypt_locations_on_add(self):
     image = self.image_factory.new_image(UUID1)
     image.locations = self.foo_bar_location
     self.image_repo.add(image)
     db_data = self.db.image_get(self.context, UUID1)
     self.assertNotEqual(db_data['locations'], ['foo', 'bar'])
     decrypted_locations = [crypt.urlsafe_decrypt(self.crypt_key, l['url'])
                            for l in db_data['locations']]
     self.assertEqual([l['url'] for l in self.foo_bar_location],
                      decrypted_locations)
Exemplo n.º 5
0
 def test_encrypt_locations_on_add(self):
     image = self.image_factory.new_image(UUID1)
     image.locations = self.foo_bar_location
     self.image_repo.add(image)
     db_data = self.db.image_get(self.context, UUID1)
     self.assertNotEqual(db_data['locations'], ['foo', 'bar'])
     decrypted_locations = [
         crypt.urlsafe_decrypt(self.crypt_key, l['url'])
         for l in db_data['locations']
     ]
     self.assertEqual([l['url'] for l in self.foo_bar_location],
                      decrypted_locations)
Exemplo n.º 6
0
    def test_encryption(self):
        # Check that original plaintext and unencrypted ciphertext match
        # Check keys of the three allowed lengths
        key_list = ["1234567890abcdef",
                    "12345678901234567890abcd",
                    "1234567890abcdef1234567890ABCDEF"]
        plaintext_list = ['']
        blocksize = 64
        for i in range(3 * blocksize):
            text = os.urandom(i)
            if six.PY3:
                text = text.decode('latin1')
            plaintext_list.append(text)

        for key in key_list:
            for plaintext in plaintext_list:
                ciphertext = crypt.urlsafe_encrypt(key, plaintext, blocksize)
                self.assertIsInstance(ciphertext, str)
                self.assertNotEqual(ciphertext, plaintext)
                text = crypt.urlsafe_decrypt(key, ciphertext)
                self.assertIsInstance(text, str)
                self.assertEqual(plaintext, text)
Exemplo n.º 7
0
    def _delete_image_location_from_backend(self, image_id, loc_id, uri):
        if CONF.metadata_encryption_key:
            uri = crypt.urlsafe_decrypt(CONF.metadata_encryption_key, uri)
        try:
            LOG.debug("Scrubbing image %s from a location.", image_id)
            try:
                self.store_api.delete_from_backend(uri, self.admin_context)
            except store_exceptions.NotFound:
                LOG.info(_LI("Image location for image '%s' not found in "
                             "backend; Marking image location deleted in "
                             "db."), image_id)

            if loc_id != '-':
                db_api.get_api().image_location_delete(self.admin_context,
                                                       image_id,
                                                       int(loc_id),
                                                       'deleted')
            LOG.info(_LI("Image %s is scrubbed from a location."), image_id)
        except Exception as e:
            LOG.error(_LE("Unable to scrub image %(id)s from a location. "
                          "Reason: %(exc)s ") %
                      {'id': image_id,
                       'exc': encodeutils.exception_to_unicode(e)})
            raise
Exemplo n.º 8
0
def decrypt_location(uri):
    return crypt.urlsafe_decrypt(CONF.metadata_encryption_key, uri)