Implement policy in code (1)
This commit will prepare for implementing policies in code [1]. Like oslo.config, with oslo.policy, we can define all of default rules in code base and only change some rules via policy file. Another thing that we should use yaml format instead of json format. [1] https://governance.openstack.org/tc/goals/queens/policy-in-code.html Change-Id: I8cd6e148d9b6bb1dc61e2cb1728acafc325bca65 Co-authored-By: Hieu LE <hieulq@vn.fujitsu.com>
This commit is contained in:
parent
a6176569cf
commit
1eb39637ac
|
@ -26,3 +26,4 @@ tags
|
|||
.tox
|
||||
.venv
|
||||
.DS_Store
|
||||
.stestr
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
{
|
||||
"context_is_admin": "role:admin",
|
||||
"deny_everybody": "!",
|
||||
|
||||
"build_info:build_info": "",
|
||||
"profile_types:index": "",
|
||||
"profile_types:get": "",
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# Borrowed from Zun
|
||||
|
||||
|
||||
import itertools
|
||||
|
||||
from senlin.common.policies import base
|
||||
|
||||
|
||||
def list_rules():
|
||||
return itertools.chain(
|
||||
base.list_rules()
|
||||
)
|
|
@ -0,0 +1,35 @@
|
|||
# All Rights Reserved.
|
||||
#
|
||||
# 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_policy import policy
|
||||
|
||||
|
||||
ROLE_ADMIN = 'role:admin'
|
||||
DENY_EVERYBODY = '!'
|
||||
|
||||
rules = [
|
||||
policy.RuleDefault(
|
||||
name="context_is_admin",
|
||||
check_str=ROLE_ADMIN
|
||||
),
|
||||
policy.RuleDefault(
|
||||
name="deny_everybody",
|
||||
check_str=DENY_EVERYBODY
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
def list_rules():
|
||||
return rules
|
|
@ -19,6 +19,7 @@ from oslo_config import cfg
|
|||
from oslo_policy import policy
|
||||
|
||||
from senlin.common import exception
|
||||
from senlin.common import policies
|
||||
|
||||
POLICY_ENFORCER = None
|
||||
CONF = cfg.CONF
|
||||
|
@ -34,6 +35,7 @@ def _get_enforcer(policy_file=None, rules=None, default_rule=None):
|
|||
policy_file=policy_file,
|
||||
rules=rules,
|
||||
default_rule=default_rule)
|
||||
POLICY_ENFORCER.register_defaults(policies.list_rules())
|
||||
return POLICY_ENFORCER
|
||||
|
||||
|
||||
|
|
|
@ -37,6 +37,9 @@ oslo.config.opts =
|
|||
oslo.config.opts.defaults =
|
||||
senlin.config = senlin.common.config:set_config_defaults
|
||||
|
||||
oslo.policy.policies =
|
||||
senlin = senlin.common.policies:list_rules
|
||||
|
||||
senlin.drivers =
|
||||
openstack = senlin.drivers.openstack
|
||||
openstack_test = senlin.tests.drivers.openstack
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
oslopolicy-sample-generator --config-file tools/policy-generator.conf
|
|
@ -0,0 +1,3 @@
|
|||
[DEFAULT]
|
||||
output_file = etc/senlin/policy.yaml.sample
|
||||
namespace = senlin
|
Loading…
Reference in New Issue