Codebase list glance / 0f50bfc
Avoid printing URIs which can contain credentials Fix for bug 1233275. Change-Id: I24d8b57418eb678767b33840973a632eb2132c6a Stuart McLaren authored 10 years ago Mark J. Washenberger committed 10 years ago
6 changed file(s) with 22 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
6868 req.environ['api.version'] = version
6969 req.path_info = ''.join(('/v', str(version), req.path_info))
7070 LOG.debug(_("Matched version: v%d"), version)
71 LOG.debug('new uri %s' % req.path_info)
71 LOG.debug('new path %s' % req.path_info)
7272 return None
7373
7474 def _match_version_string(self, subject):
5252 'swift')).execute())
5353
5454 for image in images:
55 fixed_uri = legacy_parse_uri(image['location'], to_quoted)
55 fixed_uri = legacy_parse_uri(image['location'], to_quoted,
56 image['id'])
5657 images_table.update()\
5758 .where(images_table.c.id == image['id'])\
5859 .values(location=fixed_uri).execute()
5960
6061
61 def legacy_parse_uri(uri, to_quote):
62 def legacy_parse_uri(uri, to_quote, image_id):
6263 """
6364 Parse URLs. This method fixes an issue where credentials specified
6465 in the URL are interpreted differently in Python 2.6.1+ than prior
8687 "like so: "
8788 "swift+http://user:pass@authurl.com/v1/container/obj")
8889
89 LOG.error(_("Invalid store uri %(uri)s: %(reason)s") % locals())
90 LOG.error(_("Invalid store uri for image %s: %s") % (image_id, reason))
9091 raise exception.BadStoreUri(message=reason)
9192
9293 pieces = urlparse.urlparse(uri)
7979
8080 for image in images:
8181 try:
82 fixed_uri = fix_uri_credentials(image['location'], to_quoted)
82 fixed_uri = fix_uri_credentials(image['location'], to_quoted,
83 image['id'])
8384 images_table.update()\
8485 .where(images_table.c.id == image['id'])\
8586 .values(location=fixed_uri).execute()
9697 return crypt.urlsafe_encrypt(CONF.metadata_encryption_key, uri, 64)
9798
9899
99 def fix_uri_credentials(uri, to_quoted):
100 def fix_uri_credentials(uri, to_quoted, image_id):
100101 """
101102 Fix the given uri's embedded credentials by round-tripping with
102103 StoreLocation.
118119 except (TypeError, ValueError) as e:
119120 raise exception.Invalid(str(e))
120121
121 return legacy_parse_uri(decrypted_uri, to_quoted)
122
123
124 def legacy_parse_uri(uri, to_quote):
122 return legacy_parse_uri(decrypted_uri, to_quoted, image_id)
123
124
125 def legacy_parse_uri(uri, to_quote, image_id):
125126 """
126127 Parse URLs. This method fixes an issue where credentials specified
127128 in the URL are interpreted differently in Python 2.6.1+ than prior
149150 "like so: "
150151 "swift+http://user:pass@authurl.com/v1/container/obj")
151152
152 LOG.error(_("Invalid store uri %(uri)s: %(reason)s") % locals())
153 LOG.error(_("Invalid store uri for image %s: %s") % (image_id, reason))
153154 raise exception.BadStoreUri(message=reason)
154155
155156 pieces = urlparse.urlparse(uri)
271271 try:
272272 return delete_from_backend(context, uri, **kwargs)
273273 except exception.NotFound:
274 msg = _('Failed to delete image in store at URI: %s')
275 LOG.warn(msg % uri)
274 msg = _('Failed to delete image %s in store from URI')
275 LOG.warn(msg % image_id)
276276 except exception.StoreDeleteNotSupported as e:
277277 LOG.warn(str(e))
278278 except UnsupportedBackend:
279279 exc_type = sys.exc_info()[0].__name__
280 msg = (_('Failed to delete image at %s from store (%s)') %
281 (uri, exc_type))
280 msg = (_('Failed to delete image %s from store (%s)') %
281 (image_id, exc_type))
282282 LOG.error(msg)
283283
284284
121121 "s3+https:// scheme, like so: "
122122 "s3+https://accesskey:secretkey@"
123123 "s3.amazonaws.com/bucket/key-id")
124 LOG.debug(_("Invalid store uri %(uri)s: %(reason)s") % locals())
124 LOG.debug(_("Invalid store uri: %s") % reason)
125125 raise exception.BadStoreUri(message=reason)
126126
127127 pieces = urlparse.urlparse(uri)
441441 uri = crypt.urlsafe_decrypt(CONF.metadata_encryption_key, uri)
442442
443443 try:
444 LOG.debug(_("Deleting %(uri)s from image %(image_id)s.") %
445 {'image_id': image_id, 'uri': uri})
444 LOG.debug(_("Deleting URI from image %(image_id)s.") %
445 {'image_id': image_id})
446446
447447 # Here we create a request context with credentials to support
448448 # delayed delete when using multi-tenant backend storage
454454
455455 self.store_api.delete_from_backend(admin_context, uri)
456456 except Exception:
457 msg = _("Failed to delete image %(image_id)s from %(uri)s.")
458 LOG.error(msg % {'image_id': image_id, 'uri': uri})
457 msg = _("Failed to delete URI from image %(image_id)s")
458 LOG.error(msg % {'image_id': image_id})
459459
460460 def _read_cleanup_file(self, file_path):
461461 """Reading cleanup to get latest cleanup timestamp.