summaryrefslogtreecommitdiff
path: root/keystone/common/policies/trust.py
blob: 82acb0a93fd48821f048c091fd811377a5778342 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# 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_log import versionutils
from oslo_policy import policy

from keystone.common.policies import base

RULE_TRUSTOR = 'user_id:%(target.trust.trustor_user_id)s'
RULE_TRUSTEE = 'user_id:%(target.trust.trustee_user_id)s'
SYSTEM_READER_OR_TRUSTOR_OR_TRUSTEE = (
    base.SYSTEM_READER + ' or ' + RULE_TRUSTOR + ' or ' + RULE_TRUSTEE
)
SYSTEM_READER_OR_TRUSTOR = base.SYSTEM_READER + ' or ' + RULE_TRUSTOR
SYSTEM_READER_OR_TRUSTEE = base.SYSTEM_READER + ' or ' + RULE_TRUSTEE
SYSTEM_ADMIN_OR_TRUSTOR = base.SYSTEM_ADMIN + ' or ' + RULE_TRUSTOR

deprecated_list_trusts = policy.DeprecatedRule(
    name=base.IDENTITY % 'list_trusts',
    check_str=base.RULE_ADMIN_REQUIRED
)
deprecated_list_roles_for_trust = policy.DeprecatedRule(
    name=base.IDENTITY % 'list_roles_for_trust',
    check_str=RULE_TRUSTOR + ' or ' + RULE_TRUSTEE
)
deprecated_get_role_for_trust = policy.DeprecatedRule(
    name=base.IDENTITY % 'get_role_for_trust',
    check_str=RULE_TRUSTOR + ' or ' + RULE_TRUSTEE
)
deprecated_delete_trust = policy.DeprecatedRule(
    name=base.IDENTITY % 'delete_trust',
    check_str=RULE_TRUSTOR
)
deprecated_get_trust = policy.DeprecatedRule(
    name=base.IDENTITY % 'get_trust',
    check_str=RULE_TRUSTOR + ' or ' + RULE_TRUSTEE
)

DEPRECATED_REASON = (
    "The trust API is now aware of system scope and default roles."
)

trust_policies = [
    policy.DocumentedRuleDefault(
        name=base.IDENTITY % 'create_trust',
        check_str=base.RULE_TRUST_OWNER,
        # FIXME(lbragstad): Trusts have the ability to optionally include a
        # project, but until trusts deal with system scope it's not really
        # useful. For now, this should be a project only operation.
        scope_types=['project'],
        description='Create trust.',
        operations=[{'path': '/v3/OS-TRUST/trusts',
                     'method': 'POST'}]),
    policy.DocumentedRuleDefault(
        name=base.IDENTITY % 'list_trusts',
        check_str=base.SYSTEM_READER,
        scope_types=['system'],
        description='List trusts.',
        operations=[{'path': '/v3/OS-TRUST/trusts',
                     'method': 'GET'},
                    {'path': '/v3/OS-TRUST/trusts',
                     'method': 'HEAD'}],
        deprecated_rule=deprecated_list_trusts,
        deprecated_reason=DEPRECATED_REASON,
        deprecated_since=versionutils.deprecated.TRAIN),
    policy.DocumentedRuleDefault(
        name=base.IDENTITY % 'list_trusts_for_trustor',
        check_str=SYSTEM_READER_OR_TRUSTOR,
        scope_types=['system', 'project'],
        description='List trusts for trustor.',
        operations=[{'path': '/v3/OS-TRUST/trusts?'
                             'trustor_user_id={trustor_user_id}',
                     'method': 'GET'},
                    {'path': '/v3/OS-TRUST/trusts?'
                             'trustor_user_id={trustor_user_id}',
                     'method': 'HEAD'}]),
    policy.DocumentedRuleDefault(
        name=base.IDENTITY % 'list_trusts_for_trustee',
        check_str=SYSTEM_READER_OR_TRUSTEE,
        scope_types=['system', 'project'],
        description='List trusts for trustee.',
        operations=[{'path': '/v3/OS-TRUST/trusts?'
                             'trustee_user_id={trustee_user_id}',
                     'method': 'GET'},
                    {'path': '/v3/OS-TRUST/trusts?'
                             'trustee_user_id={trustee_user_id}',
                     'method': 'HEAD'}]),
    policy.DocumentedRuleDefault(
        name=base.IDENTITY % 'list_roles_for_trust',
        check_str=SYSTEM_READER_OR_TRUSTOR_OR_TRUSTEE,
        scope_types=['system', 'project'],
        description='List roles delegated by a trust.',
        operations=[{'path': '/v3/OS-TRUST/trusts/{trust_id}/roles',
                     'method': 'GET'},
                    {'path': '/v3/OS-TRUST/trusts/{trust_id}/roles',
                     'method': 'HEAD'}],
        deprecated_rule=deprecated_list_roles_for_trust,
        deprecated_reason=DEPRECATED_REASON,
        deprecated_since=versionutils.deprecated.TRAIN),
    policy.DocumentedRuleDefault(
        name=base.IDENTITY % 'get_role_for_trust',
        check_str=SYSTEM_READER_OR_TRUSTOR_OR_TRUSTEE,
        scope_types=['system', 'project'],
        description='Check if trust delegates a particular role.',
        operations=[{'path': '/v3/OS-TRUST/trusts/{trust_id}/roles/{role_id}',
                     'method': 'GET'},
                    {'path': '/v3/OS-TRUST/trusts/{trust_id}/roles/{role_id}',
                     'method': 'HEAD'}],
        deprecated_rule=deprecated_get_role_for_trust,
        deprecated_reason=DEPRECATED_REASON,
        deprecated_since=versionutils.deprecated.TRAIN),
    policy.DocumentedRuleDefault(
        name=base.IDENTITY % 'delete_trust',
        check_str=SYSTEM_ADMIN_OR_TRUSTOR,
        scope_types=['system', 'project'],
        description='Revoke trust.',
        operations=[{'path': '/v3/OS-TRUST/trusts/{trust_id}',
                     'method': 'DELETE'}],
        deprecated_rule=deprecated_delete_trust,
        deprecated_reason=DEPRECATED_REASON,
        deprecated_since=versionutils.deprecated.TRAIN),
    policy.DocumentedRuleDefault(
        name=base.IDENTITY % 'get_trust',
        check_str=SYSTEM_READER_OR_TRUSTOR_OR_TRUSTEE,
        scope_types=['system', 'project'],
        description='Get trust.',
        operations=[{'path': '/v3/OS-TRUST/trusts/{trust_id}',
                     'method': 'GET'},
                    {'path': '/v3/OS-TRUST/trusts/{trust_id}',
                     'method': 'HEAD'}],
        deprecated_rule=deprecated_get_trust,
        deprecated_reason=DEPRECATED_REASON,
        deprecated_since=versionutils.deprecated.TRAIN)
]


def list_rules():
    return trust_policies