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
68 | 68 | req.environ['api.version'] = version |
69 | 69 | req.path_info = ''.join(('/v', str(version), req.path_info)) |
70 | 70 | 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) | |
72 | 72 | return None |
73 | 73 | |
74 | 74 | def _match_version_string(self, subject): |
52 | 52 | 'swift')).execute()) |
53 | 53 | |
54 | 54 | 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']) | |
56 | 57 | images_table.update()\ |
57 | 58 | .where(images_table.c.id == image['id'])\ |
58 | 59 | .values(location=fixed_uri).execute() |
59 | 60 | |
60 | 61 | |
61 | def legacy_parse_uri(uri, to_quote): | |
62 | def legacy_parse_uri(uri, to_quote, image_id): | |
62 | 63 | """ |
63 | 64 | Parse URLs. This method fixes an issue where credentials specified |
64 | 65 | in the URL are interpreted differently in Python 2.6.1+ than prior |
86 | 87 | "like so: " |
87 | 88 | "swift+http://user:pass@authurl.com/v1/container/obj") |
88 | 89 | |
89 | LOG.error(_("Invalid store uri %(uri)s: %(reason)s") % locals()) | |
90 | LOG.error(_("Invalid store uri for image %s: %s") % (image_id, reason)) | |
90 | 91 | raise exception.BadStoreUri(message=reason) |
91 | 92 | |
92 | 93 | pieces = urlparse.urlparse(uri) |
79 | 79 | |
80 | 80 | for image in images: |
81 | 81 | try: |
82 | fixed_uri = fix_uri_credentials(image['location'], to_quoted) | |
82 | fixed_uri = fix_uri_credentials(image['location'], to_quoted, | |
83 | image['id']) | |
83 | 84 | images_table.update()\ |
84 | 85 | .where(images_table.c.id == image['id'])\ |
85 | 86 | .values(location=fixed_uri).execute() |
96 | 97 | return crypt.urlsafe_encrypt(CONF.metadata_encryption_key, uri, 64) |
97 | 98 | |
98 | 99 | |
99 | def fix_uri_credentials(uri, to_quoted): | |
100 | def fix_uri_credentials(uri, to_quoted, image_id): | |
100 | 101 | """ |
101 | 102 | Fix the given uri's embedded credentials by round-tripping with |
102 | 103 | StoreLocation. |
118 | 119 | except (TypeError, ValueError) as e: |
119 | 120 | raise exception.Invalid(str(e)) |
120 | 121 | |
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): | |
125 | 126 | """ |
126 | 127 | Parse URLs. This method fixes an issue where credentials specified |
127 | 128 | in the URL are interpreted differently in Python 2.6.1+ than prior |
149 | 150 | "like so: " |
150 | 151 | "swift+http://user:pass@authurl.com/v1/container/obj") |
151 | 152 | |
152 | LOG.error(_("Invalid store uri %(uri)s: %(reason)s") % locals()) | |
153 | LOG.error(_("Invalid store uri for image %s: %s") % (image_id, reason)) | |
153 | 154 | raise exception.BadStoreUri(message=reason) |
154 | 155 | |
155 | 156 | pieces = urlparse.urlparse(uri) |
271 | 271 | try: |
272 | 272 | return delete_from_backend(context, uri, **kwargs) |
273 | 273 | 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) | |
276 | 276 | except exception.StoreDeleteNotSupported as e: |
277 | 277 | LOG.warn(str(e)) |
278 | 278 | except UnsupportedBackend: |
279 | 279 | 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)) | |
282 | 282 | LOG.error(msg) |
283 | 283 | |
284 | 284 |
121 | 121 | "s3+https:// scheme, like so: " |
122 | 122 | "s3+https://accesskey:secretkey@" |
123 | 123 | "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) | |
125 | 125 | raise exception.BadStoreUri(message=reason) |
126 | 126 | |
127 | 127 | pieces = urlparse.urlparse(uri) |
441 | 441 | uri = crypt.urlsafe_decrypt(CONF.metadata_encryption_key, uri) |
442 | 442 | |
443 | 443 | 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}) | |
446 | 446 | |
447 | 447 | # Here we create a request context with credentials to support |
448 | 448 | # delayed delete when using multi-tenant backend storage |
454 | 454 | |
455 | 455 | self.store_api.delete_from_backend(admin_context, uri) |
456 | 456 | 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}) | |
459 | 459 | |
460 | 460 | def _read_cleanup_file(self, file_path): |
461 | 461 | """Reading cleanup to get latest cleanup timestamp. |