Skip to content

Commit 307f270

Browse files
committed
Add authz library details to CEL documentation
1 parent cac1228 commit 307f270

File tree

1 file changed

+39
-1
lines changed
  • content/en/docs/reference/using-api

1 file changed

+39
-1
lines changed

content/en/docs/reference/using-api/cel.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,44 @@ Examples:
144144
See the [Kubernetes URL library](https://pkg.go.dev/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/library#URLs)
145145
godoc for more information.
146146

147+
### Kubernetes authorizer library
148+
149+
For CEL expressions in the API where a variable of type `Authorizer` is available,
150+
the authorizer may be used to perform authorization checks for the principal
151+
(authenticated user) of the request.
152+
153+
API resource checks are performed as follows:
154+
155+
1. Specify the group and resource to check: `Authorizer.group(string).resource(string) ResourceCheck`
156+
2. Optionally call any combination of the following to further narrow the authorization check:
157+
- `ResourceCheck.subresource(string) ResourceCheck`
158+
- `ResourceCheck.namespace(string) ResourceCheck`
159+
- `ResourceCheck.name(string) ResourceCheck`
160+
3. Call `ResourceCheck.check(verb string) Decision` to perform the authorization check.
161+
4. Call `allowed() bool` or `reason() string` to inspect the result of the authorization check.
162+
163+
Non-resource authorization performed are used as follows:
164+
165+
1. specify only a path: `Authorizer.path(string) PathCheck`
166+
2. Call `PathCheck.check(httpVerb string) Decision` to perform the authorization check.
167+
3. Call `allowed() bool` or `reason() string` to inspect the result of the authorization check.
168+
169+
To perform an authorization check for a service account:
170+
171+
- `Authorizer.serviceAccount(namespace string, name string) Authorizer`
172+
173+
{{< table caption="Examples of CEL expressions using URL library functions" >}}
174+
| CEL Expression | Purpose |
175+
|--------------------------------------------------------------------------------------------------------------|------------------------------------------------|
176+
| `authorizer.group('').resource('pods').namespace('default').check('create').allowed()` | Returns true if the principal (user or service account) is allowed create pods in the 'default' namespace. |
177+
| `authorizer.path('/healthz').check('get').allowed()` | Checks if the principal (user or service account) is authorized to make HTTP GET requests to the /healthz API path. |
178+
| `authorizer.serviceAccount('default', 'myserviceaccount').resource('deployments').check('delete').allowed()` | Checks if the service account is authorized to delete deployments. |
179+
{{< /table >}}
180+
181+
See the [Kubernetes Authz library](https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz)
182+
godoc for more information.
183+
184+
147185
## Type checking
148186

149187
CEL is a [gradually typed language](https://github.com/google/cel-spec/blob/master/doc/langdef.md#gradual-type-checking).
@@ -297,4 +335,4 @@ execute. If so, the API server prevent the CEL expression from being written to
297335
API resources by rejecting create or update operations containing the CEL
298336
expression to the API resources. This feature offers a stronger assurance that
299337
CEL expressions written to the API resource will be evaluate at runtime without
300-
exceeding the runtime cost budget.
338+
exceeding the runtime cost budget.

0 commit comments

Comments
 (0)