Repository navigation
Commit dc4b20e
authored
### What changes were proposed in this pull request?
Adds the `ACCESS_CONTROL` built-in policy type (wire name
`system_access_control`) and its
content class `AccessControlContent`, constructed through
`PolicyContents.accessControl(...)`.
The content carries two fields:
- `privileges` — the privileges the rule confers on an object the tag is
applied to.
- `applicableRoles` — the roles that satisfy the rule's condition. These
are a *condition* on
the caller's roles, not the principals the privilege is granted to.
A rule is authored as an ordinary policy and bound to a tag:
```java
PolicyContent content =
PolicyContents.accessControl(
ImmutableList.of(Privilege.Name.SELECT_TABLE, Privilege.Name.MODIFY_TABLE),
ImmutableList.of("analyst", "data_engineer"));
```
which carries the content
```json
{
"privileges": ["SELECT_TABLE", "MODIFY_TABLE"],
"applicableRoles": ["analyst", "data_engineer"]
}
```
and, once bound to the tag `certified`, reads: *a caller whose active
roles include either
`analyst` or `data_engineer` may select from and modify any object
carrying the tag `certified`.*
Any listed role satisfies the condition; every listed privilege is then
conferred.
Two invariants are enforced in the class:
- `PERMITTED_PRIVILEGES` is an explicit allowlist rather than a
denylist, so the boundary fails
closed: a privilege added to `Privilege.Name` later confers nothing
through a tag until it is
listed here deliberately. `USE_CATALOG` and `USE_SCHEMA` are excluded on
purpose — traversal
stays RBAC, so a tag can only widen access inside territory a role can
already reach.
- `supportedObjectTypes()` is the union of `canBindTo` over
`PERMITTED_PRIVILEGES`, minus
`METALAKE`.
This is the API surface only. Nothing reads it yet: no authorizer
change, no enforcement, no
REST path.
**This is part 1 of M1** in the milestone table of the design doc. The
rest of M1 — the content
DTO, the `DTOConverters` branches, and the derived policy-to-role record
written on create and
update — follows in separate PRs. Until the DTO lands,
`system_access_control` is accepted by
`fromPolicyType` but is not creatable over REST.
### Why are the changes needed?
Tag-based access control needs a policy content type before a rule can
be authored, stored or
evaluated. Every later milestone rests on this shape.
Fix: #13510
### Does this PR introduce _any_ user-facing change?
New public API in the `api` module:
- `Policy.BuiltInType.ACCESS_CONTROL`, wire name `system_access_control`
- `AccessControlContent`, with `privileges()` and `applicableRoles()`
- `PolicyContents.accessControl(List<Privilege.Name>, List<String>)`
No property keys are added and no existing behaviour changes. The type
is not reachable over
REST yet.
### How was this patch tested?
Unit tests in `TestPolicyContents` and `TestPolicyBuiltInType`,
covering:
- every privilege in `PERMITTED_PRIVILEGES` is accepted, and privileges
outside it — including
`USE_CATALOG` and `USE_SCHEMA` — are rejected
- `privileges` and `applicableRoles` reject null, empty, blank and
empty-string entries
- `supportedObjectTypes()` is recomputed from `PERMITTED_PRIVILEGES` in
the test rather than
asserted against a hardcoded set, so the two cannot drift apart silently
- equality and the built-in type name mapping in both directions
```
./gradlew :api:test --tests '*TestPolicyContents*' --tests '*TestPolicyBuiltInType*'
```
1 parent 19d88d7 commit dc4b20e
5 files changed
Lines changed: 383 additions & 0 deletions
File tree
- api/src
- main/java/org/apache/gravitino/policy
- test/java/org/apache/gravitino/policy
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
65 | 68 | | |
66 | 69 | | |
67 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
218 | 220 | | |
219 | 221 | | |
220 | 222 | | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
221 | 236 | | |
222 | 237 | | |
223 | 238 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
87 | 98 | | |
0 commit comments