Commit Graph

21 Commits

Author SHA1 Message Date
Rodolfo Alonso Hernandez 8813b0ed2d Replace "target_tenant" with "target_project" in RBAC OVOs and models
This is part of the remaining technical debt of the specs
https://specs.openstack.org/openstack/neutron-specs/specs/newton/moving-to-keystone-v3.html

Blueprint: https://blueprints.launchpad.net/neutron/+spec/keystone-v3

Change-Id: I2d2fd4d1802c9dfe0778ac8fdddc7b9a8afe7d25
2021-12-03 10:48:57 +00:00
Rodolfo Alonso Hernandez f8c879ddbf Add new indexes to RBAC DB models
Added two new indexes to all RBAC DB models: "target_tenant" and
"action".

The DB models affected are "networkrbacs", "qospolicyrbacs",
"securitygrouprbacs", "addressscoperbacs", "subnetpoolrbacs" and
"addressgrouprbacs".

The goal of this patch is to speed up the model query if RBAC apply to
this object. If the object query scope is a project, [1] will be added
to the DB query. If "action" and "target_tenant" are indexed, the exact
match filtering will be faster.

[1]890d62a3df/neutron_lib/db/model_query.py (L123-L131)

Change-Id: I0a70a1a500fad52ca55006d6e2ebc1044aef0fc8
Closes-Bug: #1918145
2021-09-30 12:55:02 +00:00
Miguel Lavalle 8094b524f6 Allow sharing of address groups via RBAC mechanism
Client: https://review.opendev.org/c/openstack/python-openstackclient/+/775045
Tempest tests: https://review.opendev.org/c/openstack/neutron-tempest-plugin/+/773274

Allow sharing of address groups via RBAC mechanism

Change-Id: I9d9e2bd4add5bb6fa4105352bfda739340932571
2021-03-01 18:28:31 -06:00
Rodolfo Alonso Hernandez 790fff1d24 Remove "abc.abstractproperty"
"@abc.abstractproperty" is deprecated since 3.3. Now it's possible
to use "@property" on top of "@abstractmethod".

Change-Id: I0cca37b626a94a05fb983a8528c22a660e89e673
2020-11-20 16:02:07 +00:00
Igor Malinovskiy 56b971bb42 Allow sharing of subnet pools via RBAC mechanism
Neutron-lib api ref: https://review.opendev.org/705998/
Client: https://review.opendev.org/#/c/712705/
Tempest tests: https://review.opendev.org/#/c/711656/

Change-Id: I1d6125513cd8cb088b84c92497866f78955019a9
Partial-Bug: #1862032
Depends-On: https://review.opendev.org/709122
2020-04-09 19:02:47 +03:00
Igor Malinovskiy eb6104c0ac Allow sharing of address scopes via RBAC mechanism
Neutron-lib api ref: https://review.opendev.org/#/c/707407/
Client: https://review.opendev.org/#/c/709124/
Tempest tests: https://review.opendev.org/#/c/711610/

Change-Id: I74bedae4de4eb25e5427ecb129543885a020a0a8
Depends-On: https://review.opendev.org/712633
Partial-Bug: #1862968
Closes-Bug: #1697925
2020-03-19 16:51:39 +02:00
Doug Wiegley 5e0fc3d2da Allow sharing of security groups via RBAC mechanism
Neutron-lib api ref: https://review.openstack.org/#/c/635313/
Tempest tests: https://review.openstack.org/#/c/635312/
Client: https://review.openstack.org/#/c/635428/

Partial-Bug: #1817119
Depends-On: https://review.openstack.org/635313
Change-Id: I974b0a603b6ca75cf080fb7b0751c7fb87df8443
2019-03-09 17:30:14 -06:00
Rodolfo Alonso Hernandez 8eee74f626 Use RBACBaseObject OVO in neutron/db/rbac_db_mixin.py
Implemented RBACBaseObject metaclass, inherited from NetworkRBAC
and QosPolicyRBAC.

Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db

Change-Id: I07d1e0bb27e19bd19911255c069fa27a42451264
2018-11-08 13:41:36 +00:00
Kevin Benton 32814bb39e Bump network rev on RBAC change
Increment the revision number when RBAC policies are
changed since it impacts the calculation of the 'shared'
field.

Closes-Bug: #1708079
Change-Id: I4c7eeff8745eff3761d54ef6d3665cf3dc6e6222
2017-08-02 16:44:01 +00:00
Henry Gessau 1c5bf09a03 Use DB field sizes instead of _MAX_LEN constants
Remove The following _MAX_LEN constants from
neutron/api/v2/attributes.py and use the corresponding DB field size
constants from neutron_lib.db.constants instead.

 NAME_MAX_LEN              -->  NAME_FIELD_SIZE
 TENANT_ID_MAX_LEN         -->  PROJECT_ID_FIELD_SIZE
 DESCRIPTION_MAX_LEN       -->  DESCRIPTION_FIELD_SIZE
 LONG_DESCRIPTION_MAX_LEN  -->  LONG_DESCRIPTION_FIELD_SIZE
 DEVICE_ID_MAX_LEN         -->  DEVICE_ID_FIELD_SIZE
 DEVICE_OWNER_MAX_LEN      -->  DEVICE_NAME_FIELD_SIZE

In alembic migration scripts, the raw numerical value is used.

For more information, see:
http://lists.openstack.org/pipermail/openstack-dev/2016-October/105789.html

NeutronLibImpact

Change-Id: I734890372584fe27e5d6ec38c0cad2de882ff11c
2016-12-23 13:48:57 +00:00
Armando Migliaccio 17563a802e Adopt neutron-lib plugin directory
Neutron Manager is loaded at the very startup of the neutron
server process and with it plugins are loaded and stored for
lookup purposes as their references are widely used across the
entire neutron codebase.

Rather than holding these references directly in NeutronManager
this patch refactors the code so that these references are held
by a plugin directory.

This allows subprojects and other parts of the Neutron codebase
to use the directory in lieu of the manager. The result is a
leaner, cleaner, and more decoupled code.

Usage pattern [1,2] can be translated to [3,4] respectively.

[1] manager.NeutronManager.get_service_plugins()[FOO]
[2] manager.NeutronManager.get_plugin()
[3] directory.get_plugin(FOO)
[4] directory.get_plugin()

The more entangled part is in the neutron unit tests, where the
use of the manager can be simplified as mocking is typically
replaced by a call to the directory add_plugin() method. This is
safe as each test case gets its own copy of the plugin directory.
That said, unit tests that look more like API tests and that rely on
the entire plugin machinery, need some tweaking to avoid stumbling
into plugin loading failures.

Due to the massive use of the manager, deprecation warnings are
considered impractical as they cause logs to bloat out of proportion.

Follow-up patches that show how to adopt the directory in neutron
subprojects are tagged with topic:plugin-directory.

NeutronLibImpact

Partially-implements: blueprint neutron-lib

Change-Id: I7331e914234c5f0b7abe836604fdd7e4067551cf
2016-11-23 04:45:33 -07:00
Henry Gessau 61cc14fd67 Switch to neutron-lib for model_base
Change-Id: If5b2b4cc0346515ddef3da1255ab49327c8e5732
2016-08-31 11:12:18 -04:00
Dariusz Smigiel df9411dc11 Rename DB columns: tenant -> project
All occurences of ``tenant_id`` across the database are renamed
to ``project_id``. Both options are equally valid, but ``project_id``
is preferred.
To inform external users about the change, HasTenant class was
deprecated.

UpgradeImpact
Partially-Implements: blueprint keystone-v3

Change-Id: I87a8ef342ccea004731ba0192b23a8e79bc382dc
2016-08-03 14:34:37 +00:00
Henry Gessau ae5bad49cc Use exceptions from neutron-lib
Related-Blueprint: neutron-lib

Change-Id: Ia014468bd621c4ee6aea95bf19328c61070174c4
2016-04-21 21:29:44 -04:00
Kevin Benton 49b4dd3478 Use network RBAC feature for external access
This allows access to external networks to be controlled via the
RBAC framework added during Liberty with a new 'access_as_external'
action.

A migration adds all current external networks to the RBAC policies
table with a wildcard indicating that all tenants can access the network
as RBAC.

Unlike the conversion of shared networks to RBAC, the external table
is left in the DB to avoid invasive changes throughout the codebase
to calculate the flag relative to the caller. So the current 'external'
flag is used throughout the code base as it previously was for wiring
up floating IPs, router gateway ports, etc. Then the RBAC entries are
only referenced when determining what networks to show the tenants.

API Behavior:
 * Marking a network as 'external' will automatically create a wildcard
   entry that allows that network to be accessed by all tenants.
 * An external network may have all of its RBAC entries deleted and then
   only an admin will be able to attach to it.
 * An RBAC 'access_as_external' entry cannot be deleted if it is required
   for a tenant that currently has a router attached to that network.
 * Creating an 'access_as_external' RBAC entry will automatically convert
   the network into an external network. (This is to enable a workflow
   where a private external network is never visible to everyone.)
 * The default policy.json will prevent a non-admin from creating wildcard
   'access_as_external' RBAC entries to align with the current default policy
   we have on setting the 'external' field on the network to prevent poluting
   everyone else's network lists.
 * The default policy.json will allow a tenant to create an
   'access_as_external' RBAC entry to allow specific tenants
   (including itself) the ability to use its network as an external network.

Closes-Bug: #1547985
DocImpact: External networks can now have access restricted to small subsets
           of tenants
APIImpact: 'access_as_external' will be allowed as an action in the RBAC
           API for networks
Change-Id: I4d8ee78a9763c58884e4fd3d7b40133da659cd61
2016-02-29 19:05:26 -08:00
Kevin Benton 35e234db90 Make __table_args__ declarative in RBACColumns
The UniqueConstraint being constructed at class load time for
RBACColumns meant that all tables inheriting from it ended up
sharing the same UniqueConstraint object. This led to a bunch
of warnings about columns being replaced from one table to
another. This didn't appear to affect any functionality but it
may have broken queries across both tables.

This patch just converts it into a declared attr so a separate
constraint object gets created for each table that inherits the
class.

Closes-Bug: #1550618
Change-Id: I02b8e911125c06691bf02b6e7ac02cf25c4c4142
2016-02-24 15:18:56 -08:00
Haim Daniel aeaf77a529 Qos policy RBAC DB setup and migration
This patch implements a new database model required for the
qos-policy RBAC support. In addition it migrates the current qos-policy
'shared' attribute to leverage the new 'qospolicyrbacs' table.

'shared' is no longer a property of the QosPolicy DB model. Its status
is based on the tenant ID of the API caller. From an API perspective the
logic remains the same - tenants will see qos-policies as 'shared=True'
in case the qos-policy is shared with them). However, internal callers
(e.g. plugins, drivers, services) must not check for the 'shared'
attribute on qos-policy db objects any more.

DocImpact
APIImpact

Blueprint: rbac-qos
Related-bug: #1512587

Change-Id: I1c59073daa181005a3e878bc2fe033a0709fbf31
2016-02-26 17:03:59 +00:00
Akihiro Motoki 2d8632e412 Use _ from neutron._i18n
Partial-Bug: #1520094
Change-Id: I874a4aa1d71d1f7034a1ff0b7450b419ef5c6864
2015-12-06 19:39:04 +09:00
Manjeet Singh Bhatia ae40bf1fd9 Reuse constants defined in attributes
This change reuses constants defined in attributes module in db
modules.

Change-Id: Idbb5f21a485a41a814b6b8c5744348d25443239e
2015-12-04 05:14:55 +00:00
Kevin Benton 2ef027ed39 Make models_v2 explicitly import rbac_db_models
The Network model was implicitly relying on a core plugin to import
the db_base_plugin_v2 module which would import the rbac model module
so "NetworkRBAC" would be defined by the time something would query
the DB. However, this isn't the case for scripts or agents that are
importing models_v2 and trying to query the DB directly so they will
now break with an sqlaclhemy error about a missing model.

This patch makes models_v2 import the rbac_db_models module directly
so the model will always be defined.

This would have resulted in a circular import because the
rbac_db_models module required the HasId and HasTenant classes
in models_v2. So this patch also moves these helper classes
into model_base.

Change-Id: I338ce1c0ba55647e6410a63f937737f75a63057d
Closes-Bug: #1488032
2015-08-24 03:13:14 -07:00
Kevin Benton 3e0328b992 Network RBAC DB setup and legacy migration
This patch implements the database model required for the network
RBAC work. In addition it migrates the current network and subnet
'shared' attributes to leverage the new table.

'shared' is no longer a property of the DB model because its status
is based on the tenant ID of the API caller. From an API perspective
this is the same (tenants will see networks as 'shared=True' if the
network is shared with them). However, internal callers (e.g. plugins,
drivers, services) will not be able to check for the 'shared' attribute
on network and subnet db objects any more.

This patch just achieves parity with the current shared behavior so it
doesn't add the ability to manipulate the RBAC entries directly. The
RBAC API is in the following patch.

Partially-Implements: blueprint rbac-networks
Change-Id: I3426b13eede8bfa29729cf3efea3419fb91175c4
2015-07-16 05:48:10 -07:00