Skip to content

Commit eac2213

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Modify remaining APIs as per RBAC new guidelines"
2 parents fa8f481 + ab084d4 commit eac2213

36 files changed

+659
-828
lines changed

nova/api/openstack/compute/assisted_volume_snapshots.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ def __init__(self):
3939
def create(self, req, body):
4040
"""Creates a new snapshot."""
4141
context = req.environ['nova.context']
42+
# NOTE(gmann) We pass empty target to policy enforcement. This API
43+
# is called by cinder which does not have correct project_id.
44+
# By passing the empty target, we make sure that we do not check
45+
# the requester project_id and allow users with
46+
# allowed role to create snapshot.
4247
context.can(avs_policies.POLICY_ROOT % 'create', target={})
4348

4449
snapshot = body['snapshot']
@@ -69,6 +74,11 @@ def create(self, req, body):
6974
def delete(self, req, id):
7075
"""Delete a snapshot."""
7176
context = req.environ['nova.context']
77+
# NOTE(gmann) We pass empty target to policy enforcement. This API
78+
# is called by cinder which does not have correct project_id.
79+
# By passing the empty target, we make sure that we do not check
80+
# the requester project_id and allow users with allowed role to
81+
# delete snapshot.
7282
context.can(avs_policies.POLICY_ROOT % 'delete', target={})
7383

7484
delete_metadata = {}

nova/api/openstack/compute/console_auth_tokens.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ConsoleAuthTokensController(wsgi.Controller):
3030
def _show(self, req, id, rdp_only):
3131
"""Checks a console auth token and returns the related connect info."""
3232
context = req.environ['nova.context']
33-
context.can(cat_policies.BASE_POLICY_NAME, target={})
33+
context.can(cat_policies.BASE_POLICY_NAME)
3434

3535
token = id
3636
if not token:

nova/api/openstack/compute/limits.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ def _index(self, req, filtered_limits=None, max_image_meta=True):
7878
project_id = context.project_id
7979
if 'tenant_id' in req.GET:
8080
project_id = req.GET.get('tenant_id')
81-
context.can(limits_policies.OTHER_PROJECT_LIMIT_POLICY_NAME,
82-
target={'project_id': project_id})
81+
context.can(limits_policies.OTHER_PROJECT_LIMIT_POLICY_NAME)
8382

8483
quotas = QUOTAS.get_project_quotas(context, project_id,
8584
usages=True)

nova/api/openstack/compute/migrations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def _index(self, req, add_link=False, next_link=False, add_uuid=False,
8989
sort_dirs=None, sort_keys=None, limit=None, marker=None,
9090
allow_changes_since=False, allow_changes_before=False):
9191
context = req.environ['nova.context']
92-
context.can(migrations_policies.POLICY_ROOT % 'index', target={})
92+
context.can(migrations_policies.POLICY_ROOT % 'index')
9393
search_opts = {}
9494
search_opts.update(req.GET)
9595
if 'changes-since' in search_opts:

nova/api/openstack/compute/server_external_events.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ def _get_instances_all_cells(self, context, instance_uuids,
7373
def create(self, req, body):
7474
"""Creates a new instance event."""
7575
context = req.environ['nova.context']
76+
# NOTE(gmann) We pass empty target to policy enforcement. This API
77+
# is called by neutron which does not have correct project_id where
78+
# server belongs to. By passing the empty target, we make sure that
79+
# we do not check the requester project_id and allow users with
80+
# allowed role to create external event.
7681
context.can(see_policies.POLICY_ROOT % 'create', target={})
7782

7883
response_events = []

nova/policies/assisted_volume_snapshots.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,40 @@
2424
assisted_volume_snapshots_policies = [
2525
policy.DocumentedRuleDefault(
2626
name=POLICY_ROOT % 'create',
27-
check_str=base.SYSTEM_ADMIN,
27+
# TODO(gmann): This is internal API policy and called by
28+
# cinder. Add 'service' role in this policy so that cinder
29+
# can call it with user having 'service' role (not having
30+
# correct project_id). That is for phase-2 of RBAC goal and until
31+
# then, we keep it open for all admin in any project. We cannot
32+
# default it to PROJECT_ADMIN which has the project_id in
33+
# check_str and will fail if cinder call it with other project_id.
34+
check_str=base.ADMIN,
2835
description="Create an assisted volume snapshot",
2936
operations=[
3037
{
3138
'path': '/os-assisted-volume-snapshots',
3239
'method': 'POST'
3340
}
3441
],
35-
scope_types=['system']),
42+
scope_types=['project']),
3643
policy.DocumentedRuleDefault(
3744
name=POLICY_ROOT % 'delete',
38-
check_str=base.SYSTEM_ADMIN,
45+
# TODO(gmann): This is internal API policy and called by
46+
# cinder. Add 'service' role in this policy so that cinder
47+
# can call it with user having 'service' role (not having
48+
# correct project_id). That is for phase-2 of RBAC goal and until
49+
# then, we keep it open for all admin in any project. We cannot
50+
# default it to PROJECT_ADMIN which has the project_id in
51+
# check_str and will fail if cinder call it with other project_id.
52+
check_str=base.ADMIN,
3953
description="Delete an assisted volume snapshot",
4054
operations=[
4155
{
4256
'path': '/os-assisted-volume-snapshots/{snapshot_id}',
4357
'method': 'DELETE'
4458
}
4559
],
46-
scope_types=['system']),
60+
scope_types=['project']),
4761
]
4862

4963

nova/policies/console_auth_tokens.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
console_auth_tokens_policies = [
2525
policy.DocumentedRuleDefault(
2626
name=BASE_POLICY_NAME,
27-
check_str=base.SYSTEM_READER,
27+
check_str=base.PROJECT_ADMIN,
2828
description="Show console connection information for a given console "
2929
"authentication token",
3030
operations=[
@@ -33,7 +33,7 @@
3333
'path': '/os-console-auth-tokens/{console_token}'
3434
}
3535
],
36-
scope_types=['system'])
36+
scope_types=['project'])
3737
]
3838

3939

nova/policies/console_output.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
console_output_policies = [
2525
policy.DocumentedRuleDefault(
2626
name=BASE_POLICY_NAME,
27-
check_str=base.PROJECT_MEMBER_OR_SYSTEM_ADMIN,
27+
check_str=base.PROJECT_MEMBER,
2828
description='Show console output for a server',
2929
operations=[
3030
{
3131
'method': 'POST',
3232
'path': '/servers/{server_id}/action (os-getConsoleOutput)'
3333
}
3434
],
35-
scope_types=['system', 'project'])
35+
scope_types=['project'])
3636
]
3737

3838

nova/policies/create_backup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
create_backup_policies = [
2525
policy.DocumentedRuleDefault(
2626
name=BASE_POLICY_NAME,
27-
check_str=base.PROJECT_MEMBER_OR_SYSTEM_ADMIN,
27+
check_str=base.PROJECT_MEMBER,
2828
description='Create a back up of a server',
2929
operations=[
3030
{
3131
'method': 'POST',
3232
'path': '/servers/{server_id}/action (createBackup)'
3333
}
3434
],
35-
scope_types=['system', 'project'])
35+
scope_types=['project'])
3636
]
3737

3838

nova/policies/deferred_delete.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,27 @@
3636
deferred_delete_policies = [
3737
policy.DocumentedRuleDefault(
3838
name=BASE_POLICY_NAME % 'restore',
39-
check_str=base.PROJECT_MEMBER_OR_SYSTEM_ADMIN,
39+
check_str=base.PROJECT_MEMBER,
4040
description="Restore a soft deleted server",
4141
operations=[
4242
{
4343
'method': 'POST',
4444
'path': '/servers/{server_id}/action (restore)'
4545
},
4646
],
47-
scope_types=['system', 'project'],
47+
scope_types=['project'],
4848
deprecated_rule=DEPRECATED_POLICY),
4949
policy.DocumentedRuleDefault(
5050
name=BASE_POLICY_NAME % 'force',
51-
check_str=base.PROJECT_MEMBER_OR_SYSTEM_ADMIN,
51+
check_str=base.PROJECT_MEMBER,
5252
description="Force delete a server before deferred cleanup",
5353
operations=[
5454
{
5555
'method': 'POST',
5656
'path': '/servers/{server_id}/action (forceDelete)'
5757
}
5858
],
59-
scope_types=['system', 'project'],
59+
scope_types=['project'],
6060
deprecated_rule=DEPRECATED_POLICY)
6161
]
6262

0 commit comments

Comments
 (0)