forked from openstack/nova
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement granular policy rules for placement
This adds a granular policy checking framework for placement based on nova.policy but with a lot of the legacy cruft removed, like the is_admin and context_is_admin rules. A new PlacementPolicyFixture is added along with a new configuration option, [placement]/policy_file, which is needed because the default policy file that gets used in config is from [oslo_policy]/policy_file which is being used as the nova policy file. As far as I can tell, oslo.policy doesn't allow for multiple policy files with different names unless I'm misunderstanding how the policy_dirs option works. With these changes, we can have something like: /etc/nova/policy.json - for nova policy rules /etc/nova/placement-policy.yaml - for placement rules The docs are also updated to include the placement policy sample along with a tox builder for the sample. This starts by adding granular rules for CRUD operations on the /resource_providers and /resource_providers/{uuid} routes which use the same descriptions from the placement API reference. Subsequent patches will add new granular rules for the other routes. Part of blueprint granular-placement-policy Change-Id: I17573f5210314341c332fdcb1ce462a989c21940
- Loading branch information
Showing
33 changed files
with
711 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
================== | ||
Placement Policies | ||
================== | ||
|
||
The following is an overview of all available policies in Placement. | ||
For a sample configuration file, refer to | ||
:doc:`/configuration/sample-placement-policy`. | ||
|
||
.. show-policy:: | ||
:config-file: etc/nova/placement-policy-generator.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
============================ | ||
Sample Placement Policy File | ||
============================ | ||
|
||
The following is a sample placement policy file for adaptation and use. | ||
|
||
The sample policy can also be viewed in :download:`file form | ||
</_static/placement.policy.yaml.sample>`. | ||
|
||
.. important:: | ||
|
||
The sample policy file is auto-generated from placement when this | ||
documentation is built. You must ensure your version of placement matches | ||
the version of this documentation. | ||
|
||
.. literalinclude:: /_static/placement.policy.yaml.sample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,24 @@ | ||
To generate the sample policy.yaml file, run the following command from the top | ||
level of the nova directory: | ||
Nova | ||
==== | ||
|
||
To generate the sample nova policy.yaml file, run the following command from | ||
the top level of the nova directory: | ||
|
||
tox -egenpolicy | ||
|
||
For a pre-generated example of the latest policy.yaml, see: | ||
For a pre-generated example of the latest nova policy.yaml, see: | ||
|
||
https://docs.openstack.org/nova/latest/configuration/sample-policy.html | ||
|
||
|
||
Placement | ||
========= | ||
|
||
To generate the sample placement policy.yaml file, run the following command | ||
from the top level of the nova directory: | ||
|
||
tox -e genplacementpolicy | ||
|
||
For a pre-generated example of the latest placement policy.yaml, see: | ||
|
||
https://docs.openstack.org/nova/latest/configuration/sample-placement-policy.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[DEFAULT] | ||
# TODO: When placement is split out of the nova repo, this can change to | ||
# etc/placement/policy.yaml.sample. | ||
output_file = etc/nova/placement-policy.yaml.sample | ||
namespace = placement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from oslo_context import context | ||
from oslo_db.sqlalchemy import enginefacade | ||
|
||
from nova.api.openstack.placement import exception | ||
from nova.api.openstack.placement import policy | ||
|
||
|
||
@enginefacade.transaction_context_provider | ||
class RequestContext(context.RequestContext): | ||
|
||
def can(self, action, target=None, fatal=True): | ||
"""Verifies that the given action is valid on the target in this | ||
context. | ||
:param action: string representing the action to be checked. | ||
:param target: As much information about the object being operated on | ||
as possible. The target argument should be a dict instance or an | ||
instance of a class that fully supports the Mapping abstract base | ||
class and deep copying. For object creation this should be a | ||
dictionary representing the location of the object e.g. | ||
``{'project_id': context.project_id}``. If None, then this default | ||
target will be considered:: | ||
{'project_id': self.project_id, 'user_id': self.user_id} | ||
:param fatal: if False, will return False when an | ||
exception.PolicyNotAuthorized occurs. | ||
:raises nova.exception.PolicyNotAuthorized: if verification fails and | ||
fatal is True. | ||
:return: returns a non-False value (not necessarily "True") if | ||
authorized and False if not authorized and fatal is False. | ||
""" | ||
if target is None: | ||
target = {'project_id': self.project_id, | ||
'user_id': self.user_id} | ||
try: | ||
return policy.authorize(self, action, target) | ||
except exception.PolicyNotAuthorized: | ||
if fatal: | ||
raise | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.