Skip to content

Commit bcf6220

Browse files
author
kcp-ci-bot
committed
update authorizer documentation
On-behalf-of: @SAP [email protected]
1 parent 70b5401 commit bcf6220

File tree

3 files changed

+162
-76
lines changed

3 files changed

+162
-76
lines changed

docs/content/concepts/authorization/authorizers.md

Lines changed: 151 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,89 @@ description: >
55

66
# Authorizers
77

8-
The following authorizers are configured in kcp:
8+
In kcp, a request has four different ways of being admitted:
99

10-
| Authorizer | Description |
11-
|----------------------------------------|-----------------------------------------------------------------------------------|
12-
| Top-Level organization authorizer | checks that the user is allowed to access the organization |
13-
| Workspace content authorizer | determines additional groups a user gets inside of a workspace |
14-
| Maximal permission policy authorizer | validates the maximal permission policy RBAC policy in the API exporter workspace |
15-
| Local Policy authorizer | validates the RBAC policy in the workspace that is accessed |
16-
| Kubernetes Bootstrap Policy authorizer | validates the RBAC Kubernetes standard policy |
10+
* It can be made to one of the preconfigured paths that do not require authorization, like `/healthz`.
11+
* It can be performed by a user in one of the configured always-allow groups, by default `system:masters`.
12+
* It can pass through the RBAC chain and match configured Roles and ClusterRoles.
13+
* It can be permitted by an external HTTPS webhook backend.
1714

1815
They are related in the following way:
1916

20-
1. top-level organization authorizer must allow
21-
2. workspace content authorizer must allow, and adds additional (virtual per-request) groups to the request user influencing the follow authorizers.
22-
3. maximal permission policy authorizer must allow
23-
4. one of the local authorizer or bootstrap policy authorizer must allow.
24-
25-
```
26-
┌──────────────┐
27-
│ │
28-
┌────►│ Local Policy ├──┐
29-
┌──────────────┐ ┌──────────────┐ ┌───────────────────┐ │ │ authorizer │ │
30-
request │ Workspace │ │ Required │ │ Max. Permission │ │ │ │ │
31-
─────────►│ Content ├────►│ Groups ├────┤ Policy authorizer ├───┤ └──────────────┘ │
32-
│ Authorizer │ │ Authorizer │ │ │ │ ▼
33-
└──────────────┘ └──────────────┘ └───────────────────┘ │ OR───►
34-
│ ┌──────────────┐ ▲
35-
│ │ Bootstrap │ │
36-
└────►│ Policy ├──┘
37-
│ authorizer │
38-
│ │
39-
└──────────────┘
17+
``` mermaid
18+
graph TD
19+
start(Request):::state --> main_alt[/one of\]:::or
20+
main_alt --> aapa[Always Allow Paths Auth]
21+
main_alt --> aaga[Always Allow Groups Auth]
22+
main_alt --> wa[Webhook Auth]
23+
main_alt --> rga[Required Groups Auth]
24+
25+
aapa --> decision(Decision):::state
26+
aaga --> decision
27+
wa --> decision
28+
29+
subgraph "RBAC"
30+
rga --> wca[Workspace Content Auth]
31+
wca --> scrda[System CRD Authorizer]
32+
scrda --> mppa[Max. Permission Policy Auth]
33+
34+
mppa --- mppa_alt[/one of\]:::or
35+
mppa_alt --> lpa[Local Policy Auth]
36+
mppa_alt --> gpa[Global Policy Auth]
37+
mppa_alt --> bpa[Bootstrap Policy Auth]
38+
end
39+
40+
lpa --> decision
41+
gpa --> decision
42+
bpa --> decision
43+
44+
classDef state color:#F77
45+
classDef or fill:none,stroke:none
4046
```
4147

42-
[ASCIIFlow document](https://asciiflow.com/#/share/eJyrVspLzE1VslLydg5QcCwtycgvyqxKLVLSUcpJrATSVkrVMUoVMUpWhgYGBjoxSpVAppGlGZBVklpRAuTEKClQGzya0vNoSgPRaEJMTB4N3NCEIUBde9B9OW0XyE6f%2FOTEHIWA%2FJzM5EqgkjnYPfloyh6SENmaSNWDaQQsIEF0Ijx9wSSgoVqUWliaWlwCtk9BITy%2FKLu4IDE5VQEqAKODgMoyi1JTFBASIMo3sUJPISC1KDezuDgzPw8uiWw1ZuRCrMbnflCMAM1xzs8rSc0rwRqGUCXuRfmlBcW44gYWnUjeB0vAI38JVOMUUpL9DMw0CXaLI1Igo4QeFgmYPJbgwQw1hPy0PUM9NWIC%2FyDkrEjtrA5LiKQVbKCg3kQrpwBpp%2Fz8kuKSosQCBZQ8QVXrUNM0pJCDZQioEnghN4NmJXkiStqnsieR7EEToI09pBUTMUq1SrUA%2FWv8Mg%3D%3D)
48+
[View graph on Kroki](https://kroki.io/mermaid/svg/eNqFkkFLw0AQhe_-iqVeKlg9FnIQ2gZ7UShV8BCLTDbTZOk2s-5uiPXXO9lEadoUcxrmfTu8eZPcginEa3wl-HMerB-v8bNC52-iKOKGRzGZPIg9qPIDtE_uqURB2_cNy2TDs18tgAAGkpmu4eDETGuqxQp8wXXli80Qnp_gS0uVucjXkLxhWhDtLhGWBzYrKItZf1hgG3-By1Aqp6gcx13xt3DH5X0udOuTXhtbleYhxtF6PluMQs92r2vJhsnunAGJYkGlx9IfWWc9cE7aDJKXg_O4F4t1HBCy6httCwagPYXhhJ_h606s0O6Va4yIFWklD8eLNhjzk1BcPF2nhcGa5z6RBN2fdsblzC01pf-CKYNzIu88x3POYpm1VrUZiDofaqZm6ABSg3MxbkX7v0rSZKPrx-m0r5IVW6V1VHIOt-yJdhjqH2Oz8iY=)
49+
50+
### Always Allow Paths Authorizer
51+
52+
Like in vanilla Kubernetes, this authorizer always grants access to the configured URL paths. This is
53+
used for the health and liveness checks of kcp.
54+
55+
### Always Allow Groups Authorizer
56+
57+
This authorizer always permits access if the user is in one of the configured groups. By default this
58+
only includes the `system:masters` group.
59+
60+
### RBAC Chain
61+
62+
The primary authorization flow is handled by a sequence of RBAC-based authorizers that a request must
63+
satisfy all in order to be granted access.
64+
65+
The following authorizers work together to implement RBAC in kcp:
4366

67+
| Authorizer | Description |
68+
|----------------------------------------|--------------------------------------------------------------------------------------------|
69+
| Workspace content authorizer | validates that the user has `access` permission to the workspace |
70+
| Required groups authorizer | validates that the user is in the annotation-based list of groups required for a workspace |
71+
| System CRD authorizer | prevents undesired updates to certain core resources, like the status subresource on APIBindings |
72+
| Maximal permission policy authorizer | validates the maximal permission policy RBAC policy in the API exporter workspace |
73+
| Local Policy authorizer | validates the RBAC policy in the workspace that is accessed |
74+
| Global Policy authorizer | validates the RBAC policy in the workspace that is accessed across shards |
75+
| Kubernetes Bootstrap Policy authorizer | validates the RBAC Kubernetes standard policy |
4476

45-
### Workspace Content Authorizer
77+
#### Required Groups Authorizer
4678

47-
The workspace content authorizer checks whether the user is granted access to the workspace.
79+
A `authorization.kcp.io/required-groups` annotation can be added to a LogicalCluster
80+
to specify additional groups that are required to access a workspace for a user to be member of.
81+
The syntax is a disjunction (separator `,`) of conjunctions (separator `;`).
82+
83+
For example, `<group1>;<group2>,<group3>` means that a user must be member of `<group1>` AND `<group2>`, OR of `<group3>`.
84+
85+
The annotation is copied onto sub-workspaces during workspace creation, but is then not updated
86+
automatically if it's changed.
87+
88+
#### Workspace Content Authorizer
89+
90+
The workspace content authorizer checks whether the user is granted access to the workspace.
4891
Access is granted access through `verb=access` non-resource permission to `/` inside of the workspace.
4992

5093
The ClusterRole `system:kcp:workspace:access` is pre-defined which makes it easy
@@ -86,39 +129,30 @@ A service-account defined in a workspace implicitly is granted access to it.
86129

87130
A service-account defined in a different workspace is NOT given access to it.
88131

89-
### Required Groups Authorizer
90-
91-
A `authorization.kcp.io/required-groups` annotation can be added to a LogicalCluster
92-
to specify additional groups that are required to access a workspace for a user to be member of.
93-
The syntax is a disjunction (separator `,`) of conjunctions (separator `;`).
94-
95-
For example, `<group1>;<group2>,<group3>` means that a user must be member of `<group1>` AND `<group2>`, OR of `<group3>`.
96-
97-
The annotation is copied onto sub-workspaces during scheduling.
132+
!!! note
133+
By default, workspaces are only accessible to a user if they are in `Ready` phase. Workspaces that are initializing
134+
can be accessed only by users that are granted `admin` verb on the `workspaces/content` resource in the
135+
parent workspace.
98136

99-
#### Initializing Workspaces
137+
Service accounts declared within a workspace don't have access to initializing workspaces.
100138

101-
By default, workspaces are only accessible to a user if they are in `Ready` phase. Workspaces that are initializing
102-
can be access only by users that are granted `admin` verb on the `workspaces/content` resource in the
103-
parent workspace.
139+
#### System CRD Authorizer
104140

105-
Service accounts declared within a workspace don't have access to initializing workspaces.
141+
This small authorizer simply prevents updates to the `status` subresource on APIExports or APIBindings. Note that this authorizer does not validate changes to the CustomResourceDefitions themselves, but to objects from those CRDs instead.
106142

107-
### Maximal Permission Policy Authorizer
143+
#### Maximal Permission Policy Authorizer
108144

109145
If the requested resource type is part of an API binding, then this authorizer verifies that
110146
the request is not exceeding the maximum permission policy of the related API export.
111147
Currently, the "local policy" maximum permission policy type is supported.
112148

113-
#### Local Policy
149+
##### Local Policy
114150

115151
The local maximum permission policy delegates the decision to the RBAC of the related API export.
116152
To distinguish between local RBAC role bindings in that workspace and those for this these maximum permission policy,
117153
every name and group is prefixed with `apis.kcp.io:binding:`.
118154

119-
Example:
120-
121-
Given an API binding for type `foo` declared in workspace `consumer` that refers to an API export declared in workspace `provider`
155+
**Example:** Given an APIBinding for type `foo` declared in workspace `consumer` that refers to an APIExport declared in workspace `provider`
122156
and a user `user-1` having the group `group-1` requesting a `create` of `foo` in the `default` namespace in the `consumer` workspace,
123157
this authorizer verifies that `user-1` is allowed to execute this request by delegating to `provider`'s RBAC using prefixed attributes.
124158

@@ -128,13 +162,13 @@ Using prefixed attributes prevents RBAC collisions i.e. if `user-1` is granted t
128162
For the given example RBAC request looks as follows:
129163

130164
- Username: `apis.kcp.io:binding:user-1`
131-
- Group: `apis.kcp.io:binding:group-1`
165+
- Groups: [`apis.kcp.io:binding:group-1`]
132166
- Resource: `foo`
133167
- Namespace: `default`
134168
- Workspace: `provider`
135169
- Verb: `create`
136170

137-
The following role and role binding declared within the `provider` workspace will grant access to the request:
171+
The following Role and RoleBinding declared within the `provider` workspace will grant access to the request:
138172

139173
```yaml
140174
apiVersion: rbac.authorization.k8s.io/v1
@@ -166,32 +200,81 @@ roleRef:
166200
```
167201

168202
!!! note
169-
The same authorization scheme is enforced when executing the request of a claimed resource via the virtual API Export API server,
203+
The same authorization scheme is enforced when executing the request of a claimed resource via the virtual APIExport API server,
170204
i.e. a claimed resource is bound to the same maximal permission policy. Only the actual owner of that resources can go beyond that policy.
171205

172206
TBD: Example
173207

174-
### Kubernetes Bootstrap Policy Authorizer
208+
#### Local Policy Authorizer
175209

176-
The bootstrap policy authorizer works just like the local authorizer but references RBAC rules
177-
defined in the `system:admin` system workspace.
210+
This authorizer ensures that RBAC rules contained within a workspace are being applied
211+
and work just like in a regular Kubernetes cluster.
178212

179-
### Local Policy Authorizer
213+
It is possible to bind to Roles and ClusterRoles in the bootstrap policy from a local policy's
214+
`RoleBinding` or `ClusterRoleBinding`, for example the `system:kcp:workspace:access` ClusterRole exists in the
215+
`system:admin` logical cluster, but can still be bound from without any other logical cluster.
180216

181-
Once the top-level organization authorizer and the workspace content authorizer granted access to a
182-
workspace, RBAC rules contained in the workspace derived from the request context are evaluated.
217+
#### Global Policy Authorizer
183218

184-
This authorizer ensures that RBAC rules contained within a workspace are being applied
185-
and work just like in a regular Kubernetes cluster.
219+
This authorizer works identically to the Local Policy Authorizer, just with the difference
220+
that it uses a global (i.e. across shards) getter for Roles and RoleBindings.
186221

187-
!!! note
188-
Groups added by the workspace content authorizer can be used for role bindings in that workspace.
222+
#### Bootstrap Policy Authorizer
223+
224+
The bootstrap policy authorizer works just like the local authorizer but references RBAC rules
225+
defined in the `system:admin` system workspace. This workspace is where the classic Kubernetes
226+
RBAC like the `cluster-admin` ClusterRole is being defined and the policy defined in this workspace
227+
applies to every workspace in a kcp shard.
189228

190-
It is possible to bind to roles and cluster roles in the bootstrap policy from a local policy `RoleBinding` or `ClusterRoleBinding`.
229+
### Webhook Authorizer
191230

192-
### Service Accounts
231+
This authorizer can be enabled by providing the `--authorization-webhook-config-file` flag to the kcp process
232+
and works identically to [how it works in vanilla Kubernetes](https://kubernetes.io/docs/reference/access-authn-authz/webhook/).
193233

194-
Kubernetes service accounts are granted access to the workspaces they are defined in and that are ready.
234+
The given configuration file must be of the kubeconfg format and point to an HTTPS server, potentially including certificate information as needed:
195235

196-
E.g. a service account "default" in `root:org:ws:ws` is granted access to `root:org:ws:ws`, and through the
197-
workspace content authorizer it gains the `system:kcp:clusterworkspace:access` group membership.
236+
```yaml
237+
apiVersion: v1
238+
kind: Config
239+
clusters:
240+
- name: webhook
241+
cluster:
242+
server: https://localhost:8080/
243+
current-context: webhook
244+
contexts:
245+
- name: webhook
246+
context:
247+
cluster: webhook
248+
```
249+
250+
The webhook will receive every authorization request made in kcp, including internal ones. This means if the webhook
251+
is badly configured, it can even prevent kcp from starting up successfully, but on the other hand this allows
252+
a lot of influence over the authorization in kcp.
253+
254+
The webhook will receive JSON-marshalled `SubjectAccessReview` objects, that (compared to vanilla Kubernetes) include the name of target logical cluster as an `extra` field, like so:
255+
256+
```json
257+
{
258+
"apiVersion": "authorization.k8s.io/v1beta1",
259+
"kind": "SubjectAccessReview",
260+
"spec": {
261+
"resourceAttributes": {
262+
"namespace": "kittensandponies",
263+
"verb": "get",
264+
"group": "unicorn.example.org",
265+
"resource": "pods"
266+
},
267+
"user": "jane",
268+
"group": [
269+
"group1",
270+
"group2"
271+
],
272+
"extra": {
273+
"authorization.kubernetes.io/cluster-name": ["root"]
274+
}
275+
}
276+
}
277+
```
278+
279+
!!! note
280+
The extra field will contain the logical cluster _name_ (e.g. o43u2gh528rtfg721rg92), not the human-readable path. Webhooks need to resolve the name to a path themselves if necessary.

docs/content/concepts/authorization/index.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ Generally, the same (cluster) role and (cluster) role binding principles apply e
1111

1212
In addition, additional RBAC semantics is implemented cross-workspaces, namely the following:
1313

14-
- **Top-Level Organization** access: the user must have this as pre-requisite to access any other workspace, or is
15-
even member and by that can create workspaces inside the organization workspace.
16-
- **Workspace Content** access: the user needs access to a workspace or is even admin.
17-
- for some resources, additional permission checks are performed, not represented by local or Kubernetes standard RBAC rules. E.g.
18-
- workspace creation checks for organization membership (see above).
19-
- workspace creation checks for `use` verb on the `WorkspaceType`.
20-
- API binding via APIBinding objects requires verb `bind` access to the corresponding `APIExport`.
14+
- **Workspace Content** access: the user needs `access` permissions to a workspace or be even admin.
15+
- for some resources, additional permission checks are performed, not represented by local or Kubernetes standard RBAC rules; for example
16+
- workspace creation checks for organization membership (see above).
17+
- workspace creation checks for `use` verb on the `WorkspaceType`.
18+
- API binding via APIBinding objects requires verb `bind` access to the corresponding `APIExport`.
2119
- **System Workspaces** access: system workspaces are prefixed with `system:` and are not accessible by users.
2220

2321
The details of the authorizer chain are documented in [Authorizers](./authorizers.md).

docs/mkdocs.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ theme:
3737

3838
# Palette toggle for light mode
3939
- media: "(prefers-color-scheme: light)"
40-
scheme: default
40+
scheme: default
4141
primary: white
4242
toggle:
4343
icon: material/brightness-7
@@ -92,6 +92,11 @@ markdown_extensions:
9292
- pymdownx.highlight:
9393
# Allows linking directly to specific lines in code blocks
9494
anchor_linenums: true
95+
- pymdownx.superfences:
96+
custom_fences:
97+
- name: mermaid
98+
class: mermaid
99+
format: !!python/name:pymdownx.superfences.fence_code_format
95100
# Inline code block highlighting
96101
- pymdownx.inlinehilite
97102
# Lets you embed content from another file

0 commit comments

Comments
 (0)