REDHAT-BUG-2547840: Openstack Manila vulnerability
Description: Chen YuXiang from the Institute of Computing Technology, Chinese Academy of Sciences reported a vulnerability in Manila's public share authorization handling. The "ispublic" flag grants a share API visibility to all projects without transferring management authority, and the controller authorizes write operations against the caller's own project rather than the target share's project. By performing management operations on a public share owned by another project, a project member may add, update, or revoke access rules, modify export-location metadata, create backups or replicas, and soft-delete or restore the share, resulting in unauthorized cross-project data access and the potential to deny the owner access to their own share. Only deployments in which at least one share is marked public are affected.
Proposed patch: See attached patches. Unless a flaw is discovered in them, these patches will be merged to their corresponding branches on the public disclosure date. One patch targets manila-tempest-plugin: it updates two negative tests to expect 404 instead of 403 for unauthorized access to another project's share, matching the corrected authorization behavior; it will follow the core fixes once they merge.
CVE: CVE-2026-71195
Proposed public disclosure date/time: 2026-10-20, 1500UTC Please do not make the issue public (or release public patches) before this coordinated embargo date.
Original private report: https://launchpad.net/bugs/2161412 For access to read and comment on this report, please reply to me with your Launchpad username and I will subscribe you.
-- Goutham Pacha Ravi OpenStack Vulnerability Management Team https://security.openstack.org/vmt.html
Patch From 9c862f231be81c9b0dfa2645cbcd0dab7e0d6a40 Mon Sep 17 00:00:00 2001 From: Carlos da Silva <ces.eduardo98> Date: Fri, 7 Aug 2026 20:55:09 -0300 Subject: [PATCH] Fix policy control for public shares
A public share is visible to all tenants, but users other than the owner should not be able to modify it. Several operations skipped the ownership policy check for public shares. Also, the export location metadata endpoints resolved the export location globally, instead of within the share in the request URL.
This commit enforces the ownership checks when manipulating access rules, creating backups or replicas, and soft deleting or restoring public shares. Export location metadata operations are now scoped to the share in the request URL; export locations that do not belong to that share now return 404.
Change-Id: Ie283dce157f9c90f5d2ab38c1e74daa7df3ac118 Signed-off-by: Carlos da Silva <ces.eduardo98> Closes-Bug: #2161412 Closes-Bug: #2168962
#+beginsrc diff --- manila/api/v2/metadata.py | 5 +- manila/api/v2/shareaccesses.py | 3 +- manila/api/v2/sharebackups.py | 3 +- manila/api/v2/shareexportlocations.py | 35 ++++--- manila/api/v2/sharereplicas.py | 3 +- manila/api/v2/shares.py | 8 +- manila/share/api.py | 8 +- manila/tests/api/v2/testmetadata.py | 41 ++++++++ manila/tests/api/v2/testshareaccesses.py | 55 +++++++++-- manila/tests/api/v2/testsharebackups.py | 25 ++++- .../api/v2/testshareexportlocations.py | 35 ++++++- manila/tests/api/v2/testsharereplicas.py | 47 ++++++++- manila/tests/api/v2/testshares.py | 96 +++++++++++++++++-- manila/tests/share/testapi.py | 58 +++++++++++ ...cks-on-public-shares-6cb60f669bb20f6c.yaml | 11 +++ 15 files changed, 380 insertions(+), 53 deletions(-) create mode 100644 releasenotes/notes/bug-2161412-enforce-policy-checks-on-public-shares-6cb60f669bb20f6c.yaml
diff --git a/manila/api/v2/metadata.py b/manila/api/v2/metadata.py index 174be16..ad07ec4 100644 --- a/manila/api/v2/metadata.py +++ b/manila/api/v2/metadata.py @@ -99,7 +99,10 @@ class MetadataController(object): getresmethod = getattr( db, self.resourceget[self.resourcename]) if parentid is not None: - kwargs["parentid"] = parentid + if self.resourcename == 'shareexportlocation': + kwargs["shareid"] = parentid + else: + kwargs["parentid"] = parentid if self.resourcename == 'sharereplica': kwargs['withsharedata'] = True res = getresmethod(context, resourceid, kwargs) diff --git a/manila/api/v2/shareaccesses.py b/manila/api/v2/shareaccesses.py index 78148a5..ece6e63 100644 --- a/manila/api/v2/shareaccesses.py +++ b/manila/api/v2/shareaccesses.py @@ -168,7 +168,8 @@ class ShareAccessesController(wsgi.Controller, wsgi.AdminActionsMixin): if accesslevel == shareaccess.accesslevel: return self.viewbuilder.view(req, shareaccess) - share = self.shareapi.get(context, shareaccess.shareid) + share = self.shareapi.get( + context, shareaccess.shareid, formodification=True) values = { 'accesslevel': accesslevel, } diff --git a/manila/api/v2/sharebackups.py b/manila/api/v2/sharebackups.py index afae556..4f82c06 100644 --- a/manila/api/v2/sharebackups.py +++ b/manila/api/v2/sharebackups.py @@ -158,7 +158,8 @@ class ShareBackupController(wsgi.Controller, wsgi.AdminActionsMixin): raise exc.HTTPBadRequest(explanation=msg) try: - share = self.shareapi.get(context, shareid) + share = self.shareapi.get( + context, shareid, formodification=True) except exception.NotFound: msg = ("No share exists with ID %s.") raise exc.HTTPBadRequest(explanation=msg % shareid) diff --git a/manila/api/v2/shareexportlocations.py b/manila/api/v2/shareexportlocations.py index 3106d3d..48157e7 100644 --- a/manila/api/v2/shareexportlocations.py +++ b/manila/api/v2/shareexportlocations.py @@ -26,6 +26,7 @@ from manila.db import api as dbapi from manila import exception from manila.i18n import from manila import policy +from manila.share import api as shareapi LOG = log.getLogger(name) CONF = cfg.CONF @@ -43,12 +44,13 @@ class ShareExportLocationController(wsgi.Controller, self.confadminonlymetadatakeys = getattr( CONF, 'adminonlyelmetadata', [] ) + self.shareapi = shareapi.API() - def verifyshare(self, context, shareid): + def verifyshare(self, context, shareid, formodification=False): try: - share = dbapi.shareget(context, shareid) - if not share['ispublic']: - policy.checkpolicy(context, 'share', 'get', share) + self.shareapi.get( + context, shareid, formodification=formodification + ) except exception.NotFound: msg = ("Share '%s' not found.") % shareid raise exc.HTTPNotFound(explanation=msg) @@ -165,7 +167,7 @@ class ShareExportLocationController(wsgi.Controller, """Returns the list of metadata for a given share export location.""" context = req.environ['manila.context'] self.verifyshare(context, shareid) - return self.indexmetadata(req, resourceid) + return self.indexmetadata(req, resourceid, parentid=shareid) @wsgi.Controller.apiversion("2.87") @wsgi.Controller.authorize("updatemetadata") @@ -178,8 +180,9 @@ class ShareExportLocationController(wsgi.Controller, delete=False) body['metadata'] = metadata context = req.environ['manila.context'] - self.verifyshare(context, shareid) - return self.createmetadata(req, resourceid, body) + self.verifyshare(context, shareid, formodification=True) + return self.createmetadata( + req, resourceid, body, parentid=shareid) @wsgi.Controller.apiversion("2.87") @wsgi.Controller.authorize("updatemetadata") @@ -191,8 +194,9 @@ class ShareExportLocationController(wsgi.Controller, body['metadata']) body['metadata'] = metadata context = req.environ['manila.context'] - self.verifyshare(context, shareid) - return self.updateallmetadata(req, resourceid, body) + self.verifyshare(context, shareid, formodification=True) + return self.updateallmetadata( + req, resourceid, body, parentid=shareid) @wsgi.Controller.apiversion("2.87") @wsgi.Controller.authorize("updatemetadata") @@ -205,8 +209,9 @@ class ShareExportLocationController(wsgi.Controller, delete=False) body['metadata'] = metadata context = req.environ['manila.context'] - self.verifyshare(context, shareid) - return self.updatemetadataitem(req, resourceid, body, key) + self.verifyshare(context, shareid, formodification=True) + return self.updatemetadataitem( + req, resourceid, body, key, parentid=shareid) @wsgi.Controller.apiversion("2.87") @wsgi.Controller.authorize("getmetadata") @@ -216,7 +221,8 @@ class ShareExportLocationController(wsgi.Controller, """Show metadata for a given share export location.""" context = req.environ['manila.context'] self.verifyshare(context, shareid) - return self.showmetadata(req, resourceid, key) + return self.showmetadata( + req, resourceid, key, parentid=shareid) @wsgi.Controller.apiversion("2.87") @wsgi.Controller.authorize("deletemetadata") @@ -224,8 +230,9 @@ class ShareExportLocationController(wsgi.Controller, def deletemetadata(self, req, shareid, resourceid, key): """Delete metadata for a given share export location.""" context = req.environ['manila.context'] - self.verifyshare(context, shareid) - return self.deletemetadata(req, resourceid, key) + self.verifyshare(context, shareid, formodification=True) + return self.deletemetadata( + req, resourceid, key, parentid=shareid) def createresource(): diff --git a/manila/api/v2/sharereplicas.py b/manila/api/v2/sharereplicas.py index c7cce66..d29983d 100644 --- a/manila/api/v2/sharereplicas.py +++ b/manila/api/v2/sharereplicas.py @@ -206,7 +206,8 @@ class ShareReplicationController(wsgi.Controller, metadata.MetadataController, raise exc.HTTPBadRequest(explanation=msg) try: - shareref = db.shareget(context, shareid) + shareref = self.shareapi.get( + context, shareid, formodification=True) except exception.NotFound: msg = ("No share exists with ID %s.") raise exc.HTTPNotFound(explanation=msg % shareid) diff --git a/manila/api/v2/shares.py b/manila/api/v2/shares.py index c3c0708..0baac35 100644 --- a/manila/api/v2/shares.py +++ b/manila/api/v2/shares.py @@ -432,7 +432,7 @@ class ShareController( LOG.debug("Soft delete share with id: %s", id, context=context) try: - share = self.shareapi.get(context, id) + share = self.shareapi.get(context, id, formodification=True) self.shareapi.softdelete(context, share) except exception.NotFound: raise exc.HTTPNotFound() @@ -457,7 +457,7 @@ class ShareController( LOG.debug("Restore share with id: %s", id, context=context) try: - share = self.shareapi.get(context, id) + share = self.shareapi.get(context, id, formodification=True) except exception.NotFound: msg = ("No share exists with ID %s.") raise exc.HTTPNotFound(explanation=msg % id) @@ -792,7 +792,7 @@ class ShareController( accessdata = body.get('allowaccess', body.get('os-allowaccess')) if not enablemetadata: accessdata.pop('metadata', None) - share = self.shareapi.get(context, id) + share = self.shareapi.get(context, id, formodification=True) if share.get('issoftdeleted'): msg = ("Cannot allow access for share '%s' " @@ -937,7 +937,7 @@ class ShareController( self.checkforaccessrulelocks(context, accessdata, accessid, id) - share = self.shareapi.get(context, id) + share = self.shareapi.get(context, id, formodification=True) if share.get('issoftdeleted'): msg = ("Cannot deny access for share '%s' " diff --git a/manila/share/api.py b/manila/share/api.py index 96b657a..f3ee109 100644 --- a/manila/share/api.py +++ b/manila/share/api.py @@ -2427,11 +2427,13 @@ class API(base.Base): def snapshotupdate(self, context, snapshot, fields): return self.db.sharesnapshotupdate(context, snapshot['id'], fields) - def get(self, context, shareid): + def get(self, context, shareid, formodification=False): share = self.db.shareget(context, shareid) - if not share['ispublic']: + shareispublic = share['ispublic'] + if not shareispublic or formodification: authorized = policy.checkpolicy( - context, 'share', 'get', share, doraise=False) + context, 'share', 'get', share, + doraise=shareispublic and formodification) if not authorized: raise exception.NotFound() if share['status'] in ( diff --git a/manila/tests/api/v2/testmetadata.py b/manila/tests/api/v2/testmetadata.py index d443f0c..b031afa 100644 --- a/manila/tests/api/v2/testmetadata.py +++ b/manila/tests/api/v2/testmetadata.py @@ -17,6 +17,7 @@ import webob from manila.api.v2 import metadata from manila import context +from manila import db from manila import exception from manila import policy from manila import test @@ -81,6 +82,46 @@ class MetadataAPITest(test.TestCase): policyresourceobj = mockpolicycheck.callargs[0][3] self.assertEqual(shareobj['id'], policyresourceobj['id']) + def testgetresourceexportlocationscopedtoshare(self): + # Export location lookups must be scoped to the share in the + # request URL, so that the metadata of an export location + # belonging to a different share cannot be retrieved. + self.controller.resourcename = 'shareexportlocation' + fakecontext = context.RequestContext('fake', 'fake') + exportlocation = {'id': 'fake-el-uuid'} + mockgetbyuuid = self.mockobject( + db, 'exportlocationgetbyuuid', + mock.Mock(returnvalue=exportlocation)) + + res = self.controller.getresource( + fakecontext, 'fake-el-uuid', formodification=True, + parentid='fake-share-id') + + self.assertEqual(exportlocation, res) + mockgetbyuuid.assertcalledoncewith( + fakecontext, 'fake-el-uuid', shareid='fake-share-id') + self.mockpolicycheck.assertnotcalled() + + def testgetresourceexportlocationnotinsharenotfound(self): + # An export location that does not belong to the share in the + # request URL must not be accessible, regardless of the type + # of the share it belongs to. + self.controller.resourcename = 'shareexportlocation' + fakecontext = context.RequestContext('fake', 'fake') + self.mockobject( + db, 'exportlocationgetbyuuid', + mock.Mock(sideeffect=exception.ExportLocationNotFound( + uuid='fake-el-uuid'))) + + self.assertRaises( + webob.exc.HTTPNotFound, + self.controller.getresource, + fakecontext, + 'fake-el-uuid', + formodification=True, + parentid='fake-share-id', + ) + def testcreateindexmetadata(self): url = self.getrequest() body = {'metadata': {'testkey1': 'testv1', 'testkey2': 'testv2'}} diff --git a/manila/tests/api/v2/testshareaccesses.py b/manila/tests/api/v2/testshareaccesses.py index bb84d23..0b8319f 100644 --- a/manila/tests/api/v2/testshareaccesses.py +++ b/manila/tests/api/v2/testshareaccesses.py @@ -15,7 +15,6 @@ from unittest import mock -import copy import ddt from webob import exc @@ -247,17 +246,55 @@ class ShareAccessesAPITest(test.TestCase): return req def testupdateaccesslevel(self): - updateshareaccess = copy.deepcopy(self.access) - updateshareaccess.update({'accesslevel': 'ro'}) - self.mockobject( + fakeaccess = mock.Mock( + accesslevel='rw', shareid=self.share['id']) + updatedaccess = mock.Mock( + accesslevel='ro', shareid=self.share['id']) + mockgetaccess = self.mockobject( + self.controller, 'getshareaccess', + mock.Mock(returnvalue=fakeaccess)) + mockget = self.mockobject( + self.controller.shareapi, 'get', + mock.Mock(returnvalue=self.share)) + mockupdate = self.mockobject( self.controller.shareapi, 'updateaccess', - mock.Mock(returnvalue=updateshareaccess)) + mock.Mock(returnvalue=updatedaccess)) + mockview = self.mockobject( + self.controller.viewbuilder, 'view', + mock.Mock(returnvalue={'access': {'accesslevel': 'ro'}})) body = {'updateaccess': {'accesslevel': 'ro'}} - url = self.getupdaterequest() - ret = self.controller.update(url, self.access['id'], body=body) - self.assertEqual(updateshareaccess['accesslevel'], - ret['access']['accesslevel']) + req = self.getupdaterequest() + context = req.environ['manila.context'] + ret = self.controller.update(req, self.access['id'], body=body) + + self.assertEqual('ro', ret['access']['accesslevel']) + mockgetaccess.assertcalledoncewith( + context, self.access['id']) + mockget.assertcalledoncewith( + context, self.share['id'], formodification=True) + mockupdate.assertcalledoncewith( + context, self.share, fakeaccess, {'accesslevel': 'ro'}) + mockview.assertcalledoncewith(req, updatedaccess) + + def testupdatepolicynotauthorized(self): + fakeaccess = mock.Mock( + accesslevel='rw', shareid=self.share['id']) + self.mockobject( + self.controller, 'getshareaccess', + mock.Mock(returnvalue=fakeaccess)) + self.mockobject( + self.controller.shareapi, 'get', + mock.Mock(sideeffect=exception.PolicyNotAuthorized( + action='share:get'))) + + body = {'updateaccess': {'accesslevel': 'ro'}} + req = self.getupdaterequest() + + self.assertRaises( + exception.PolicyNotAuthorized, + self.controller.update, + req, self.access['id'], body=body) def testupdateaccesslevelinvalidaccesslevel(self): body = {'access': {'accesslevel': 'fakeaccess'}} diff --git a/manila/tests/api/v2/testsharebackups.py b/manila/tests/api/v2/testsharebackups.py index 7e1e820..015d0ae 100644 --- a/manila/tests/api/v2/testsharebackups.py +++ b/manila/tests/api/v2/testsharebackups.py @@ -362,19 +362,38 @@ class ShareBackupsApiTest(test.TestCase): def testcreate(self): fakebackup, expectedbackup = self.getfakebackup() + shareid = 'FAKESHAREID' body = { 'sharebackup': { - 'shareid': 'FAKESHAREID', + 'shareid': shareid, } } - self.mockobject(share.API, 'get', - mock.Mock(returnvalue={'id': 'FAKESHAREID'})) + mockget = self.mockobject( + share.API, 'get', mock.Mock(returnvalue={'id': shareid})) self.mockobject(share.API, 'createsharebackup', mock.Mock(returnvalue=fakebackup)) req = self.backupsreq resdict = self.controller.create(req, body) self.assertEqual(expectedbackup, resdict['sharebackup']) + mockget.assertcalledoncewith( + self.backupsreq.environ['manila.context'], shareid, + formodification=True) + + def testcreatepolicynotauthorized(self): + body = { + 'sharebackup': { + 'shareid': 'FAKESHAREID', + } + } + self.mockobject( + share.API, 'get', + mock.Mock(sideeffect=exception.PolicyNotAuthorized( + action='share:get'))) + + self.assertRaises(exception.PolicyNotAuthorized, + self.controller.create, + self.backupsreq, body) def testdeleteinvalidbackup(self): fakeexception = exception.ShareBackupNotFound( diff --git a/manila/tests/api/v2/testshareexportlocations.py b/manila/tests/api/v2/testshareexportlocations.py index 65d4e22..f96829f 100644 --- a/manila/tests/api/v2/testshareexportlocations.py +++ b/manila/tests/api/v2/testshareexportlocations.py @@ -339,7 +339,8 @@ class ShareExportLocationsAPITest(test.TestCase): self.assertEqual(body, res) mockvalidate.assertcalledoncewith(req, elid, body['metadata'], delete=False) - mockcreate.assertcalledoncewith(req, elid, body) + mockcreate.assertcalledoncewith( + req, elid, body, parentid=self.share['id']) def testupdateallmetadata(self): indexresult = self.controller.index(self.req, self.share['id']) @@ -361,7 +362,34 @@ class ShareExportLocationsAPITest(test.TestCase): body=body) self.assertEqual(body, res) mockvalidate.assertcalledoncewith(req, elid, body['metadata']) - mockupdate.assertcalledoncewith(req, elid, body) + mockupdate.assertcalledoncewith( + req, elid, body, parentid=self.share['id']) + + def testverifysharepublicshareskipspolicyforread(self): + publicshare = dbutils.createshare(ispublic=True) + + self.controller.verifyshare( + self.ctxt['user'], publicshare['id']) + + self.mockpolicycheck.assertnotcalled() + + def testverifysharepublicshareenforcespolicyformodification(self): + publicshare = dbutils.createshare(ispublic=True) + + self.controller.verifyshare( + self.ctxt['user'], publicshare['id'], formodification=True) + + self.mockpolicycheck.assertcalledoncewith( + self.ctxt['user'], 'share', 'get', mock.ANY, doraise=True) + + def testverifyshareprivatesharealwaysenforcespolicy(self): + privateshare = dbutils.createshare(ispublic=False) + + self.controller.verifyshare( + self.ctxt['user'], privateshare['id']) + + self.mockpolicycheck.assertcalledoncewith( + self.ctxt['user'], 'share', 'get', mock.ANY, doraise=False) def testdeletemetadata(self): indexresult = self.controller.index(self.req, self.share['id']) @@ -375,4 +403,5 @@ class ShareExportLocationsAPITest(test.TestCase): version="2.87", useadmincontext=True) self.controller.deletemetadata(req, self.share['id'], elid, 'fakekey') - mockdelete.assertcalledoncewith(req, elid, 'fakekey') + mockdelete.assertcalledoncewith( + req, elid, 'fakekey', parentid=self.share['id']) diff --git a/manila/tests/api/v2/testsharereplicas.py b/manila/tests/api/v2/testsharereplicas.py index 4936a99..4ca7f21 100644 --- a/manila/tests/api/v2/testsharereplicas.py +++ b/manila/tests/api/v2/testsharereplicas.py @@ -384,6 +384,43 @@ class ShareReplicasApiTest(test.TestCase): self.mockpolicycheck.assertcalledoncewith( self.membercontext, self.resourcename, 'create') + def testcreatesharefromotherprojectnotfound(self): + # A share that belongs to another project is not visible to the + # caller, so the ownership lookup must fail with 404. + body = { + 'sharereplica': { + 'shareid': 'FAKESHAREID', + 'availabilityzone': 'FAKEAZ' + } + } + self.mockobject(share.API, 'get', + mock.Mock(sideeffect=exception.NotFound)) + + self.assertRaises(exc.HTTPNotFound, + self.controller.create, + self.replicasreq, body) + self.mockpolicycheck.assertcalledoncewith( + self.membercontext, self.resourcename, 'create') + + def testcreatesharefromotherprojectnotauthorized(self): + # A public share that belongs to another project: the ownership + # policy check inside the share lookup must raise + # PolicyNotAuthorized, which the WSGI layer converts to 403. + body = { + 'sharereplica': { + 'shareid': 'FAKESHAREID', + 'availabilityzone': 'FAKEAZ' + } + } + self.mockobject(share.API, 'get', mock.Mock( + sideeffect=exception.PolicyNotAuthorized(action='share:get'))) + + self.assertRaises(exception.PolicyNotAuthorized, + self.controller.create, + self.replicasreq, body) + self.mockpolicycheck.assertcalledoncewith( + self.membercontext, self.resourcename, 'create') + def testcreatehasbeensoftdeleted(self): shareref = fakeshare.fakeshare(issoftdeleted=True) body = { @@ -395,7 +432,7 @@ class ShareReplicasApiTest(test.TestCase): mockviewbuildercall = self.mockobject( sharereplicas.replicationview.ReplicationViewBuilder, 'detaillist') - self.mockobject(sharereplicas.db, 'shareget', + self.mockobject(share.API, 'get', mock.Mock(returnvalue=shareref)) self.assertRaises(exc.HTTPForbidden, @@ -416,7 +453,7 @@ class ShareReplicasApiTest(test.TestCase): mockviewbuildercall = self.mockobject( sharereplicas.replicationview.ReplicationViewBuilder, 'detaillist') - self.mockobject(sharereplicas.db, 'shareget', + self.mockobject(share.API, 'get', mock.Mock(returnvalue=shareref)) self.assertRaises(exc.HTTPForbidden, @@ -442,7 +479,7 @@ class ShareReplicasApiTest(test.TestCase): mockviewbuildercall = self.mockobject( sharereplicas.replicationview.ReplicationViewBuilder, 'detaillist') - self.mockobject(sharereplicas.db, 'shareget', + self.mockobject(share.API, 'get', mock.Mock(returnvalue=fakereplica)) self.mockobject(sharereplicas.db, 'sharenetworkget', mock.Mock(sideeffect=exception.ShareNetworkNotFound( @@ -471,7 +508,7 @@ class ShareReplicasApiTest(test.TestCase): } } excargs = {'id': 'xyz', 'reason': 'abc'} - self.mockobject(sharereplicas.db, 'shareget', + self.mockobject(share.API, 'get', mock.Mock(returnvalue=fakereplica)) self.mockobject(share.API, 'createsharereplica', mock.Mock(sideeffect=exceptiontype(excargs))) @@ -513,7 +550,7 @@ class ShareReplicasApiTest(test.TestCase): if self.ismicroversionge(microversion, '2.95'): body["sharereplica"].update({"metadata": {"foo": "bar"}}) - self.mockobject(sharereplicas.db, 'shareget', + self.mockobject(share.API, 'get', mock.Mock(returnvalue=fakereplica)) self.mockobject(share.API, 'createsharereplica', mock.Mock(returnvalue=fakereplica)) diff --git a/manila/tests/api/v2/testshares.py b/manila/tests/api/v2/testshares.py index 170f825..531db4c 100644 --- a/manila/tests/api/v2/testshares.py +++ b/manila/tests/api/v2/testshares.py @@ -1995,8 +1995,14 @@ class ShareAPITest(test.TestCase): req = fakes.HTTPRequest.blank('/v2/fake/shares/1/action', version='2.69') body = {"softdelete": None} + mockget = self.mockobject( + shareapi.API, 'get', mock.Mock(returnvalue=self.share)) + resp = self.controller.sharesoftdelete(req, 1, body=body) + self.assertEqual(202, resp.statusint) + mockget.assertcalledoncewith( + req.environ['manila.context'], 1, formodification=True) def testsharesoftdeletehasbeensoftdeletedalready(self): req = fakes.HTTPRequest.blank('/v2/fake/shares/1/action', @@ -2029,10 +2035,15 @@ class ShareAPITest(test.TestCase): req = fakes.HTTPRequest.blank('/v2/fake/shares/1/action', version='2.69') body = {"restore": None} - self.mockobject(shareapi.API, 'get', - mock.Mock(returnvalue=self.shareinrecyclebin)) + mockget = self.mockobject( + shareapi.API, 'get', + mock.Mock(returnvalue=self.shareinrecyclebin)) + resp = self.controller.sharerestore(req, 1, body=body) + self.assertEqual(202, resp.statusint) + mockget.assertcalledoncewith( + req.environ['manila.context'], 1, formodification=True) def testsharerestorewithdeletingstatus(self): req = fakes.HTTPRequest.blank('/v2/fake/shares/1/action', @@ -2045,6 +2056,34 @@ class ShareAPITest(test.TestCase): webob.exc.HTTPForbidden, self.controller.sharerestore, req, 1, body=body) + def testsharesoftdeletepolicynotauthorized(self): + req = fakes.HTTPRequest.blank('/v2/fake/shares/1/action', + version='2.69') + body = {"softdelete": None} + self.mockobject( + shareapi.API, 'get', + mock.Mock(sideeffect=exception.PolicyNotAuthorized( + action='share:get'))) + + self.assertRaises( + exception.PolicyNotAuthorized, + self.controller.sharesoftdelete, + req, 1, body=body) + + def testsharerestorepolicynotauthorized(self): + req = fakes.HTTPRequest.blank('/v2/fake/shares/1/action', + version='2.69') + body = {"restore": None} + self.mockobject( + shareapi.API, 'get', + mock.Mock(sideeffect=exception.PolicyNotAuthorized( + action='share:get'))) + + self.assertRaises( + exception.PolicyNotAuthorized, + self.controller.sharerestore, + req, 1, body=body) + def testsharedelete(self): req = fakes.HTTPRequest.blank('/v2/fake/shares/1') resp = self.controller.delete(req, 1) @@ -2975,7 +3014,8 @@ class ShareActionsTest(test.TestCase): mock.Mock(returnvalue={'fake': 'fake'})) self.mockobject(self.controller.accessviewbuilder, 'view', mock.Mock(returnvalue={'access': {'fake': 'fake'}})) - self.mockobject(shareapi.API, 'get', mock.Mock(returnvalue=share)) + mockget = self.mockobject( + shareapi.API, 'get', mock.Mock(returnvalue=share)) id = 'fakeshareid' body = {'os-allowaccess': access} @@ -2985,6 +3025,8 @@ class ShareActionsTest(test.TestCase): res = self.controller.allowaccess(req, id, body) self.assertEqual(expected, res) + mockget.assertcalledoncewith( + req.environ['manila.context'], id, formodification=True) self.mockpolicycheck.assertcalledoncewith( req.environ['manila.context'], 'share', 'allowaccess') @@ -3249,7 +3291,8 @@ class ShareActionsTest(test.TestCase): self.mockobject(shareapi.API, "accessget", fakeaccessget) sharenetwork = dbutils.createsharenetwork() share = dbutils.createshare(sharenetworkid=sharenetwork['id']) - self.mockobject(shareapi.API, 'get', mock.Mock(returnvalue=share)) + mockget = self.mockobject( + shareapi.API, 'get', mock.Mock(returnvalue=share)) self.mockobject(self.controller, 'checkforaccessrulelocks') id = 'fakeshareid' @@ -3260,12 +3303,15 @@ class ShareActionsTest(test.TestCase): res = self.controller.denyaccess(req, id, body) self.assertEqual(202, res.statusint) + context = req.environ['manila.context'] + mockget.asserthascalls([ + mock.call(context, id, formodification=True), + mock.call(context, id), + ]) self.controller.checkforaccessrulelocks.assertcalledoncewith( - req.environ['manila.context'], accessdata, - accessdata['accessid'], id - ) + context, accessdata, accessdata['accessid'], id) self.mockpolicycheck.assertcalledoncewith( - req.environ['manila.context'], 'share', 'denyaccess') + context, 'share', 'denyaccess') def testdenyaccessnotfound(self): def stubdenyaccess(args, kwargs): @@ -3307,6 +3353,40 @@ class ShareActionsTest(test.TestCase): context, body['denyaccess'], bodydata['accessid'], id ) + def testallowaccesspolicynotauthorizedformodification(self): + mockget = self.mockobject( + shareapi.API, 'get', + mock.Mock(sideeffect=exception.PolicyNotAuthorized( + action='share:get'))) + id = 'fakeshareid' + body = {'os-allowaccess': { + 'accesstype': 'ip', 'accessto': '127.0.0.1'}} + req = fakes.HTTPRequest.blank( + '/v2/tenant1/shares/%s/action' % id) + + self.assertRaises( + exception.PolicyNotAuthorized, + self.controller.allowaccess, req, id, body) + mockget.assertcalledoncewith( + req.environ['manila.context'], id, formodification=True) + + def testdenyaccesspolicynotauthorizedformodification(self): + mockget = self.mockobject( + shareapi.API, 'get', + mock.Mock(sideeffect=exception.PolicyNotAuthorized( + action='share:get'))) + self.mockobject(self.controller, 'checkforaccessrulelocks') + id = 'fakeshareid' + body = {"os-denyaccess": {"accessid": 'fakeaccesid'}} + req = fakes.HTTPRequest.blank( + '/v2/tenant1/shares/%s/action' % id) + + self.assertRaises( + exception.PolicyNotAuthorized, + self.controller.denyaccess, req, id, body) + mockget.assertcalledoncewith( + req.environ['manila.context'], id, formodification=True) + def testcheckforaccessrulelocksnolocks(self): self.mockobject( resourcelocks.API, "getall", mock.Mock(returnvalue=([], 0))) diff --git a/manila/tests/share/testapi.py b/manila/tests/share/testapi.py index cbf2050..2183a05 100644 --- a/manila/tests/share/testapi.py +++ b/manila/tests/share/testapi.py @@ -3414,6 +3414,64 @@ class ShareAPITestCase(test.TestCase): ctx, 'share', 'get', share, doraise=False) dbapi.shareget.assertcalledoncewith(ctx, share['id']) + def testgetpublicshareskipspolicycheck(self): + fakeshare = dbutils.createshare(ispublic=True) + self.mockobject(dbapi, 'shareget', + mock.Mock(returnvalue=fakeshare)) + + result = self.api.get(self.context, 'fakeid') + + self.assertEqual(fakeshare, result) + shareapi.policy.checkpolicy.assertnotcalled() + + def testgetpublicshareformodificationcheckspolicy(self): + fakeshare = dbutils.createshare(ispublic=True) + shareapi.policy.checkpolicy.returnvalue = True + self.mockobject(dbapi, 'shareget', + mock.Mock(returnvalue=fakeshare)) + + result = self.api.get( + self.context, 'fakeid', formodification=True) + + self.assertEqual(fakeshare, result) + shareapi.policy.checkpolicy.assertcalledoncewith( + self.context, 'share', 'get', fakeshare, doraise=True) + + def testgetpublicshareformodificationnotauthorized(self): + fakeshare = dbutils.createshare( + ispublic=True, + projectid='df6d65cc1f8946ba86be06b8140ec4b3') + self.mockobject( + shareapi.policy, 'checkpolicy', + mock.Mock(sideeffect=exception.PolicyNotAuthorized( + action='share:get'))) + self.mockobject(dbapi, 'shareget', + mock.Mock(returnvalue=fakeshare)) + ctx = context.RequestContext('fakeuid', 'fakepid', isadmin=False) + + self.assertRaises(exception.PolicyNotAuthorized, + self.api.get, + ctx, + fakeshare['id'], + formodification=True) + + def testgetprivateshareformodificationnotauthorized(self): + fakeshare = dbutils.createshare( + ispublic=False, + projectid='df6d65cc1f8946ba86be06b8140ec4b3') + shareapi.policy.checkpolicy.returnvalue = False + self.mockobject(dbapi, 'shareget', + mock.Mock(returnvalue=fakeshare)) + ctx = context.RequestContext('fakeuid', 'fakepid', isadmin=False) + + self.assertRaises(exception.NotFound, + self.api.get, + ctx, + fakeshare['id'], + formodification=True) + shareapi.policy.checkpolicy.assertcalledoncewith( + ctx, 'share', 'get', fakeshare, doraise=False) + @mock.patch.object(dbapi, 'sharesnapshotgetallbyproject', mock.Mock()) def testgetallsnapshotsadminnotalltenants(self): diff --git a/releasenotes/notes/bug-2161412-enforce-policy-checks-on-public-shares-6cb60f669bb20f6c.yaml b/releasenotes/notes/bug-2161412-enforce-policy-checks-on-public-shares-6cb60f669bb20f6c.yaml new file mode 100644 index 0000000..8709e6e --- /dev/null +++ b/releasenotes/notes/bug-2161412-enforce-policy-checks-on-public-shares-6cb60f669bb20f6c.yaml @@ -0,0 +1,11 @@ +--- +security: + - | + Any user was able to manipulate the access rules, create backups or + replicas, soft delete or restore public shares they did not own, + and read or manipulate the export location metadata of shares they + did not own. These operations now enforce ownership, and export + location metadata is scoped to the share in the request URL. For + details, see Launchpad bug #2161412 + <https://bugs.launchpad.net/manila/+bug/2161412> and Launchpad + bug #2168962 <https://bugs.launchpad.net/manila/+bug/2168962>. -- 2.54.0 (Apple Git-157) #+endsrc
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
OpenStack Manilato a version that resolves this vulnerability.Patch CVE-2026-71195