← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1135541] Re: v1 api returns location as header for cached images

 

** Changed in: glance/folsom
       Status: Fix Committed => Fix Released

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to Glance.
https://bugs.launchpad.net/bugs/1135541

Title:
  v1 api returns location as header for cached images

Status in OpenStack Image Registry and Delivery Service (Glance):
  Fix Released
Status in Glance essex series:
  Fix Committed
Status in Glance folsom series:
  Fix Released
Status in Glance grizzly series:
  Fix Released

Bug description:

  When an image which is not in cache is downloaded:

  rm /opt/stack/data/glance/cache/2e877e45-5c13-42e8-995a-ffb28f888df4 ;
  glance  --os-image-api-version 1 --os-username glance --os-password
  XXX --os-tenant-name service  --os-auth-url http://localhost:5000/v2.0
  image-download  2e877e45-5c13-42e8-995a-ffb28f888df4

  The headers don't contain the backend 'location' field:

   T 10.6.51.191:9292 -> 10.6.51.191:52150 [AP]
   HTTP/1.1 200 OK.
   Content-Type: application/octet-stream.
   X-Image-Meta-Id: 2e877e45-5c13-42e8-995a-ffb28f888df4.
   X-Image-Meta-Deleted: False.
   X-Image-Meta-Container_format: bare.
   X-Image-Meta-Checksum: ccad32d005750c1005a80079b6fe8a9f.
   X-Image-Meta-Protected: False.
   X-Image-Meta-Min_disk: 0.
   X-Image-Meta-Created_at: 2013-02-27T10:37:24.
   X-Image-Meta-Size: 332.
   X-Image-Meta-Status: active.
   X-Image-Meta-Is_public: False.
   X-Image-Meta-Min_ram: 0.
   X-Image-Meta-Owner: 1bc9a6b4c0064336bc877f813244ffa1.
   X-Image-Meta-Updated_at: 2013-02-27T10:37:25.
   X-Image-Meta-Disk_format: qcow2.
   X-Image-Meta-Name: Image1.
   Location: http://10.6.51.191:9292/v1/images/2e877e45-5c13-42e8-995a-ffb28f888df4.
   Etag: ccad32d005750c1005a80079b6fe8a9f. 
   X-Openstack-Request-Id: req-60ab20e6-4c3b-43a6-8203-c20d113fd7a4.
   Date: Thu, 28 Feb 2013 10:23:06 GMT.
   Transfer-Encoding: chunked.
   .
   14c.

  
  But if the image is cached:

  glance  --os-image-api-version 1 --os-username glance --os-password
  XXX --os-tenant-name service  --os-auth-url http://localhost:5000/v2.0
  image-download  2e877e45-5c13-42e8-995a-ffb28f888df4

  the backend location field (with credentials) is returned as a header:

   T 10.6.51.191:9292 -> 10.6.51.191:51954 [AP]
   HTTP/1.1 200 OK.
   Content-Length: 332.
   Content-Type: application/octet-stream.
   X-Image-Meta-Id: 2e877e45-5c13-42e8-995a-ffb28f888df4.
   X-Image-Meta-Deleted: False.
   X-Image-Meta-Container_format: bare.
   X-Image-Meta-Location: swift+http://service%3Aglance:<redacted>@10.6.51.191:5000/v2.0/glance/2e877e45-5c13-42e8-995a-f fb28f888df4.
   X-Image-Meta-Protected: False.
   X-Image-Meta-Min_disk: 0.
   X-Image-Meta-Created_at: 2013-02-27T10:37:24.
   X-Image-Meta-Size: 332.
   X-Image-Meta-Status: active.
   X-Image-Meta-Is_public: False.
   X-Image-Meta-Min_ram: 0.
   X-Image-Meta-Owner: 1bc9a6b4c0064336bc877f813244ffa1.
   X-Image-Meta-Updated_at: 2013-02-27T10:37:25.
   X-Image-Meta-Checksum: ccad32d005750c1005a80079b6fe8a9f.
   X-Image-Meta-Disk_format: qcow2.
   X-Image-Meta-Name: Image1.
   Location: http://10.6.51.191:9292/v1/images/2e877e45-5c13-42e8-995a-ffb28f888df4.
   Etag: ccad32d005750c1005a80079b6fe8a9f. 
   X-Openstack-Request-Id: req-a854a036-5abb-477e-a6da-69012befe2ad.
   Date: Thu, 28 Feb 2013 10:22:15 GMT.
   .

  
  A possible fix for this:

   $ git diff glance/api/v1/images.py
   diff --git a/glance/api/v1/images.py b/glance/api/v1/images.py
   index 4b62946..fadc888 100644
   --- a/glance/api/v1/images.py
   +++ b/glance/api/v1/images.py
   @@ -933,6 +933,9 @@ class ImageSerializer(wsgi.JSONResponseSerializer):
            self.notifier = notifier.Notifier()
   
        def _inject_location_header(self, response, image_meta):
   +        # Remove original location for security reasons 
   +        if 'location' in image_meta:
   +            del image_meta['location']
            location = self._get_image_location(image_meta)
            response.headers['Location'] = location.encode('utf-8')

To manage notifications about this bug go to:
https://bugs.launchpad.net/glance/+bug/1135541/+subscriptions