Skip to content

Commit

Permalink
Improve access check on images
Browse files Browse the repository at this point in the history
Makes sure that users can delete only their own images, snapshots.
Enable listing of all images, both private which are owned and the public
ones. Only list the private images/snapshots for the owner and admin users.
Fixes bug 863305

(cherry picked from commit cb37d89)

Change-Id: Idc15125371950e0c07b1dac48e8b844887fefc9d
  • Loading branch information
Loganathan Parthipan authored and markmc committed Oct 27, 2011
1 parent c206f73 commit c116592
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions Authors
Expand Up @@ -74,6 +74,7 @@ Kevin Bringard <kbringard@attinteractive.com>
Kevin L. Mitchell <kevin.mitchell@rackspace.com>
Kirill Shileev <kshileev@gmail.com>
Koji Iida <iida.koji@lab.ntt.co.jp>
Loganathan Parthipan <parthipan@hp.com>
Lorin Hochstein <lorin@isi.edu>
Lvov Maxim <usrleon@gmail.com>
Mandell Degerness <mdegerne@gmail.com>
Expand Down
20 changes: 19 additions & 1 deletion nova/image/glance.py
Expand Up @@ -295,10 +295,28 @@ def delete(self, context, image_id):
"""Delete the given image.
:raises: ImageNotFound if the image does not exist.
:raises: NotAuthorized if the user is not an owner.
"""
# NOTE(vish): show is to check if image is available
self.show(context, image_id)
image_meta = self.show(context, image_id)

if FLAGS.use_deprecated_auth:
# NOTE(parthi): only allow image deletions if the user
# is a member of the project owning the image, in case of
# setup without keystone
# TODO Currently this access control breaks if
# 1. Image is not owned by a project
# 2. Deleting user is not bound a project
properties = image_meta['properties']
if (context.project_id and ('project_id' in properties)
and (context.project_id != properties['project_id'])):
raise exception.NotAuthorized(_("Not the image owner"))

if (context.project_id and ('owner_id' in properties)
and (context.project_id != properties['owner_id'])):
raise exception.NotAuthorized(_("Not the image owner"))

try:
result = self._get_client(context).delete_image(image_id)
except glance_exception.NotFound:
Expand Down
3 changes: 3 additions & 0 deletions nova/image/service.py
Expand Up @@ -151,6 +151,9 @@ def _is_image_available(context, image_meta):

properties = image_meta['properties']

if context.project_id and ('owner_id' in properties):
return str(properties['owner_id']) == str(context.project_id)

if context.project_id and ('project_id' in properties):
return str(properties['project_id']) == str(context.project_id)

Expand Down

0 comments on commit c116592

Please sign in to comment.