Skip to content

Commit

Permalink
[S-RBAC] Allow admin user to do all API requests by default
Browse files Browse the repository at this point in the history
By default ADMIN user in the new Secure RBAC policies should behave in
the same way as in the legacy rules so basically every API operation for
any project should be allowed for ADMIN user.
In the new rules there are roles like PROJECT_MEMBER and PROJECT_READER
and those personas don't inherits directly from ADMIN which means that
if something is possible to e.g. PROJECT_MEMBER it isn't automatically
also allowed to ADMIN and we need to explicitly allow ADMIN user to do
such requests. It was done like that for many of API calls already but
not for all of them (probably by mistake).

This patch introduces new composite check ADMIN_OR_PROJECT_MEMBER and
uses it in the check strings where ADMIN or PROJECT_MEMBER user is
allowed to use the API.
It also changes some of the check strings which used "policy_or" to
combine ADMIN and PROJECT_MEMBER or PROJECT_READER so that those
composite checks ADMIN_OR_PROJECT_MEMBER and ADMIN_OR_PROJECT_READER are
used everywhere.

Closes-Bug: #1997089

Change-Id: Iab5cd6c7aa07ca8527c5fa8396c9ed0da65b4fa7
  • Loading branch information
slawqo committed Nov 24, 2022
1 parent a76b20d commit 6d8ada0
Show file tree
Hide file tree
Showing 31 changed files with 435 additions and 273 deletions.
2 changes: 1 addition & 1 deletion neutron/conf/policies/address_group.py
Expand Up @@ -32,7 +32,7 @@
policy.DocumentedRuleDefault(
name='get_address_group',
check_str=base.policy_or(
base.PROJECT_READER,
base.ADMIN_OR_PROJECT_READER,
'rule:shared_address_groups'),
description='Get an address group',
operations=[
Expand Down
12 changes: 3 additions & 9 deletions neutron/conf/policies/address_scope.py
Expand Up @@ -31,9 +31,7 @@
),
policy.DocumentedRuleDefault(
name='create_address_scope',
check_str=base.policy_or(
base.ADMIN,
base.PROJECT_MEMBER),
check_str=base.ADMIN_OR_PROJECT_MEMBER,
description='Create an address scope',
operations=[
{
Expand Down Expand Up @@ -92,9 +90,7 @@
),
policy.DocumentedRuleDefault(
name='update_address_scope',
check_str=base.policy_or(
base.ADMIN,
base.PROJECT_MEMBER),
check_str=base.ADMIN_OR_PROJECT_MEMBER,
description='Update an address scope',
operations=[
{
Expand Down Expand Up @@ -128,9 +124,7 @@
),
policy.DocumentedRuleDefault(
name='delete_address_scope',
check_str=base.policy_or(
base.ADMIN,
base.PROJECT_MEMBER),
check_str=base.ADMIN_OR_PROJECT_MEMBER,
description='Delete an address scope',
operations=[
{
Expand Down
4 changes: 2 additions & 2 deletions neutron/conf/policies/auto_allocated_topology.py
Expand Up @@ -25,7 +25,7 @@
rules = [
policy.DocumentedRuleDefault(
name='get_auto_allocated_topology',
check_str=base.PROJECT_READER,
check_str=base.ADMIN_OR_PROJECT_READER,
description="Get a project's auto-allocated topology",
operations=[
{
Expand All @@ -42,7 +42,7 @@
),
policy.DocumentedRuleDefault(
name='delete_auto_allocated_topology',
check_str=base.PROJECT_MEMBER,
check_str=base.ADMIN_OR_PROJECT_MEMBER,
description="Delete a project's auto-allocated topology",
operations=[
{
Expand Down
6 changes: 4 additions & 2 deletions neutron/conf/policies/base.py
Expand Up @@ -49,9 +49,11 @@ def policy_or(*args):
PROJECT_READER = 'role:reader and project_id:%(project_id)s'

# The following are common composite check strings that are useful for
# protecting APIs designed to operate with multiple scopes (e.g., a system
# administrator should be able to delete any router in the deployment, a
# protecting APIs designed to operate with multiple scopes (e.g.,
# an administrator should be able to delete any router in the deployment, a
# project member should only be able to delete routers in their project).
ADMIN_OR_PROJECT_MEMBER = (
'(' + ADMIN + ') or (' + PROJECT_MEMBER + ')')
ADMIN_OR_PROJECT_READER = (
'(' + ADMIN + ') or (' + PROJECT_READER + ')')

Expand Down
16 changes: 4 additions & 12 deletions neutron/conf/policies/floatingip.py
Expand Up @@ -25,9 +25,7 @@
rules = [
policy.DocumentedRuleDefault(
name='create_floatingip',
check_str=base.policy_or(
base.ADMIN,
base.PROJECT_MEMBER),
check_str=base.ADMIN_OR_PROJECT_MEMBER,
description='Create a floating IP',
operations=[
{
Expand Down Expand Up @@ -61,9 +59,7 @@
),
policy.DocumentedRuleDefault(
name='get_floatingip',
check_str=base.policy_or(
base.ADMIN,
base.PROJECT_READER),
check_str=base.ADMIN_OR_PROJECT_READER,
description='Get a floating IP',
operations=[
{
Expand All @@ -84,9 +80,7 @@
),
policy.DocumentedRuleDefault(
name='update_floatingip',
check_str=base.policy_or(
base.ADMIN,
base.PROJECT_MEMBER),
check_str=base.ADMIN_OR_PROJECT_MEMBER,
description='Update a floating IP',
operations=[
{
Expand All @@ -103,9 +97,7 @@
),
policy.DocumentedRuleDefault(
name='delete_floatingip',
check_str=base.policy_or(
base.ADMIN,
base.PROJECT_MEMBER),
check_str=base.ADMIN_OR_PROJECT_MEMBER,
description='Delete a floating IP',
operations=[
{
Expand Down
2 changes: 1 addition & 1 deletion neutron/conf/policies/floatingip_pools.py
Expand Up @@ -21,7 +21,7 @@
rules = [
policy.DocumentedRuleDefault(
name='get_floatingip_pool',
check_str=base.PROJECT_READER,
check_str=base.ADMIN_OR_PROJECT_READER,
description='Get floating IP pools',
operations=[
{
Expand Down
8 changes: 4 additions & 4 deletions neutron/conf/policies/floatingip_port_forwarding.py
Expand Up @@ -30,7 +30,7 @@
policy.DocumentedRuleDefault(
name='create_floatingip_port_forwarding',
check_str=base.policy_or(
base.PROJECT_MEMBER,
base.ADMIN_OR_PROJECT_MEMBER,
base.RULE_PARENT_OWNER),
scope_types=['project'],
description='Create a floating IP port forwarding',
Expand All @@ -49,7 +49,7 @@
policy.DocumentedRuleDefault(
name='get_floatingip_port_forwarding',
check_str=base.policy_or(
base.PROJECT_READER,
base.ADMIN_OR_PROJECT_READER,
base.RULE_PARENT_OWNER),
scope_types=['project'],
description='Get a floating IP port forwarding',
Expand All @@ -72,7 +72,7 @@
policy.DocumentedRuleDefault(
name='update_floatingip_port_forwarding',
check_str=base.policy_or(
base.PROJECT_MEMBER,
base.ADMIN_OR_PROJECT_MEMBER,
base.RULE_PARENT_OWNER),
scope_types=['project'],
description='Update a floating IP port forwarding',
Expand All @@ -91,7 +91,7 @@
policy.DocumentedRuleDefault(
name='delete_floatingip_port_forwarding',
check_str=base.policy_or(
base.PROJECT_MEMBER,
base.ADMIN_OR_PROJECT_MEMBER,
base.RULE_PARENT_OWNER),
scope_types=['project'],
description='Delete a floating IP port forwarding',
Expand Down
8 changes: 4 additions & 4 deletions neutron/conf/policies/l3_conntrack_helper.py
Expand Up @@ -30,7 +30,7 @@
policy.DocumentedRuleDefault(
name='create_router_conntrack_helper',
check_str=base.policy_or(
base.PROJECT_MEMBER,
base.ADMIN_OR_PROJECT_MEMBER,
base.RULE_PARENT_OWNER),
scope_types=['project'],
description='Create a router conntrack helper',
Expand All @@ -49,7 +49,7 @@
policy.DocumentedRuleDefault(
name='get_router_conntrack_helper',
check_str=base.policy_or(
base.PROJECT_READER,
base.ADMIN_OR_PROJECT_READER,
base.RULE_PARENT_OWNER),
scope_types=['project'],
description='Get a router conntrack helper',
Expand All @@ -72,7 +72,7 @@
policy.DocumentedRuleDefault(
name='update_router_conntrack_helper',
check_str=base.policy_or(
base.PROJECT_MEMBER,
base.ADMIN_OR_PROJECT_MEMBER,
base.RULE_PARENT_OWNER),
scope_types=['project'],
description='Update a router conntrack helper',
Expand All @@ -91,7 +91,7 @@
policy.DocumentedRuleDefault(
name='delete_router_conntrack_helper',
check_str=base.policy_or(
base.PROJECT_MEMBER,
base.ADMIN_OR_PROJECT_MEMBER,
base.RULE_PARENT_OWNER),
scope_types=['project'],
description='Delete a router conntrack helper',
Expand Down
8 changes: 4 additions & 4 deletions neutron/conf/policies/local_ip.py
Expand Up @@ -25,7 +25,7 @@
rules = [
policy.DocumentedRuleDefault(
name='create_local_ip',
check_str=base.PROJECT_MEMBER,
check_str=base.ADMIN_OR_PROJECT_MEMBER,
description='Create a Local IP',
operations=[
{
Expand All @@ -42,7 +42,7 @@
),
policy.DocumentedRuleDefault(
name='get_local_ip',
check_str=base.PROJECT_READER,
check_str=base.ADMIN_OR_PROJECT_READER,
description='Get a Local IP',
operations=[
{
Expand All @@ -63,7 +63,7 @@
),
policy.DocumentedRuleDefault(
name='update_local_ip',
check_str=base.PROJECT_MEMBER,
check_str=base.ADMIN_OR_PROJECT_MEMBER,
description='Update a Local IP',
operations=[
{
Expand All @@ -80,7 +80,7 @@
),
policy.DocumentedRuleDefault(
name='delete_local_ip',
check_str=base.PROJECT_MEMBER,
check_str=base.ADMIN_OR_PROJECT_MEMBER,
description='Delete a Local IP',
operations=[
{
Expand Down
6 changes: 3 additions & 3 deletions neutron/conf/policies/local_ip_association.py
Expand Up @@ -27,7 +27,7 @@
policy.DocumentedRuleDefault(
name='create_local_ip_port_association',
check_str=base.policy_or(
base.PROJECT_MEMBER,
base.ADMIN_OR_PROJECT_MEMBER,
base.RULE_PARENT_OWNER),
scope_types=['project'],
description='Create a Local IP port association',
Expand All @@ -46,7 +46,7 @@
policy.DocumentedRuleDefault(
name='get_local_ip_port_association',
check_str=base.policy_or(
base.PROJECT_READER,
base.ADMIN_OR_PROJECT_READER,
base.RULE_PARENT_OWNER),
scope_types=['project'],
description='Get a Local IP port association',
Expand All @@ -69,7 +69,7 @@
policy.DocumentedRuleDefault(
name='delete_local_ip_port_association',
check_str=base.policy_or(
base.PROJECT_MEMBER,
base.ADMIN_OR_PROJECT_MEMBER,
base.RULE_PARENT_OWNER),
scope_types=['project'],
description='Delete a Local IP port association',
Expand Down
8 changes: 2 additions & 6 deletions neutron/conf/policies/metering.py
Expand Up @@ -46,9 +46,7 @@
),
policy.DocumentedRuleDefault(
name='get_metering_label',
check_str=base.policy_or(
base.ADMIN,
base.PROJECT_READER),
check_str=base.ADMIN_OR_PROJECT_READER,
scope_types=['project'],
description='Get a metering label',
operations=[
Expand Down Expand Up @@ -103,9 +101,7 @@
),
policy.DocumentedRuleDefault(
name='get_metering_label_rule',
check_str=base.policy_or(
base.ADMIN,
base.PROJECT_READER),
check_str=base.ADMIN_OR_PROJECT_READER,
scope_types=['project'],
description='Get a metering label rule',
operations=[
Expand Down
8 changes: 4 additions & 4 deletions neutron/conf/policies/ndp_proxy.py
Expand Up @@ -25,7 +25,7 @@
rules = [
policy.DocumentedRuleDefault(
name='create_ndp_proxy',
check_str=base.PROJECT_MEMBER,
check_str=base.ADMIN_OR_PROJECT_MEMBER,
description='Create a ndp proxy',
operations=[
{
Expand All @@ -42,7 +42,7 @@
),
policy.DocumentedRuleDefault(
name='get_ndp_proxy',
check_str=base.PROJECT_READER,
check_str=base.ADMIN_OR_PROJECT_READER,
description='Get a ndp proxy',
operations=[
{
Expand All @@ -63,7 +63,7 @@
),
policy.DocumentedRuleDefault(
name='update_ndp_proxy',
check_str=base.PROJECT_MEMBER,
check_str=base.ADMIN_OR_PROJECT_MEMBER,
description='Update a ndp proxy',
operations=[
{
Expand All @@ -80,7 +80,7 @@
),
policy.DocumentedRuleDefault(
name='delete_ndp_proxy',
check_str=base.PROJECT_MEMBER,
check_str=base.ADMIN_OR_PROJECT_MEMBER,
description='Delete a ndp proxy',
operations=[
{
Expand Down
23 changes: 6 additions & 17 deletions neutron/conf/policies/network.py
Expand Up @@ -45,9 +45,7 @@

policy.DocumentedRuleDefault(
name='create_network',
check_str=base.policy_or(
base.ADMIN,
base.PROJECT_MEMBER),
check_str=base.ADMIN_OR_PROJECT_MEMBER,
scope_types=['project'],
description='Create a network',
operations=ACTION_POST,
Expand Down Expand Up @@ -95,9 +93,7 @@
),
policy.DocumentedRuleDefault(
name='create_network:port_security_enabled',
check_str=base.policy_or(
base.ADMIN,
base.PROJECT_MEMBER),
check_str=base.ADMIN_OR_PROJECT_MEMBER,
scope_types=['project'],
description=(
'Specify ``port_security_enabled`` '
Expand Down Expand Up @@ -170,8 +166,7 @@
policy.DocumentedRuleDefault(
name='get_network',
check_str=base.policy_or(
base.ADMIN,
base.PROJECT_READER,
base.ADMIN_OR_PROJECT_READER,
'rule:shared',
'rule:external',
base.RULE_ADVSVC
Expand Down Expand Up @@ -240,9 +235,7 @@

policy.DocumentedRuleDefault(
name='update_network',
check_str=base.policy_or(
base.ADMIN,
base.PROJECT_MEMBER),
check_str=base.ADMIN_OR_PROJECT_MEMBER,
scope_types=['project'],
description='Update a network',
operations=ACTION_PUT,
Expand Down Expand Up @@ -344,9 +337,7 @@
),
policy.DocumentedRuleDefault(
name='update_network:port_security_enabled',
check_str=base.policy_or(
base.ADMIN,
base.PROJECT_MEMBER),
check_str=base.ADMIN_OR_PROJECT_MEMBER,
scope_types=['project'],
description='Update ``port_security_enabled`` attribute of a network',
operations=ACTION_PUT,
Expand All @@ -359,9 +350,7 @@

policy.DocumentedRuleDefault(
name='delete_network',
check_str=base.policy_or(
base.ADMIN,
base.PROJECT_MEMBER),
check_str=base.ADMIN_OR_PROJECT_MEMBER,
scope_types=['project'],
description='Delete a network',
operations=ACTION_DELETE,
Expand Down

0 comments on commit 6d8ada0

Please sign in to comment.