Skip to content

Commit 3dcb842

Browse files
julianvmodestoTim Bannister
andauthored
Document dry-run authorization requirements (#18235)
* Document dry-run write access requirement. - Add section on dry-run authorization - Refer to dry-run authorization for diff - Consistently hyphenate dry-run * Update content/en/docs/reference/using-api/api-concepts.md Co-Authored-By: Tim Bannister <[email protected]> Co-authored-by: Tim Bannister <[email protected]>
1 parent 995e242 commit 3dcb842

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,16 +334,16 @@ are not vulnerable to ordering changes in the list.
334334
Once the last finalizer is removed, the resource is actually removed from etcd.
335335

336336

337-
## Dry run
337+
## Dry-run
338338

339-
{{< feature-state for_k8s_version="v1.13" state="beta" >}} In version 1.13, the dry run beta feature is enabled by default. The modifying verbs (`POST`, `PUT`, `PATCH`, and `DELETE`) can accept requests in a dry run mode. Dry run mode helps to evaluate a request through the typical request stages (admission chain, validation, merge conflicts) up until persisting objects to storage. The response body for the request is as close as possible to a non dry run response. The system guarantees that dry run requests will not be persisted in storage or have any other side effects.
339+
{{< feature-state for_k8s_version="v1.13" state="beta" >}} In version 1.13, the dry-run beta feature is enabled by default. The modifying verbs (`POST`, `PUT`, `PATCH`, and `DELETE`) can accept requests in a dry-run mode. DryRun mode helps to evaluate a request through the typical request stages (admission chain, validation, merge conflicts) up until persisting objects to storage. The response body for the request is as close as possible to a non-dry-run response. The system guarantees that dry-run requests will not be persisted in storage or have any other side effects.
340340

341341

342-
### Make a dry run request
342+
### Make a dry-run request
343343

344-
Dry run is triggered by setting the `dryRun` query parameter. This parameter is a string, working as an enum, and in 1.13 the only accepted values are:
344+
Dry-run is triggered by setting the `dryRun` query parameter. This parameter is a string, working as an enum, and in 1.13 the only accepted values are:
345345

346-
* `All`: Every stage runs as normal, except for the final storage stage. Admission controllers are run to check that the request is valid, mutating controllers mutate the request, merge is performed on `PATCH`, fields are defaulted, and schema validation occurs. The changes are not persisted to the underlying storage, but the final object which would have been persisted is still returned to the user, along with the normal status code. If the request would trigger an admission controller which would have side effects, the request will be failed rather than risk an unwanted side effect. All built in admission control plugins support dry run. Additionally, admission webhooks can declare in their [configuration object](/docs/reference/generated/kubernetes-api/v1.13/#webhook-v1beta1-admissionregistration-k8s-io) that they do not have side effects by setting the sideEffects field to "None". If a webhook actually does have side effects, then the sideEffects field should be set to "NoneOnDryRun", and the webhook should also be modified to understand the `DryRun` field in AdmissionReview, and prevent side effects on dry run requests.
346+
* `All`: Every stage runs as normal, except for the final storage stage. Admission controllers are run to check that the request is valid, mutating controllers mutate the request, merge is performed on `PATCH`, fields are defaulted, and schema validation occurs. The changes are not persisted to the underlying storage, but the final object which would have been persisted is still returned to the user, along with the normal status code. If the request would trigger an admission controller which would have side effects, the request will be failed rather than risk an unwanted side effect. All built in admission control plugins support dry-run. Additionally, admission webhooks can declare in their [configuration object](/docs/reference/generated/kubernetes-api/v1.13/#webhook-v1beta1-admissionregistration-k8s-io) that they do not have side effects by setting the sideEffects field to "None". If a webhook actually does have side effects, then the sideEffects field should be set to "NoneOnDryRun", and the webhook should also be modified to understand the `DryRun` field in AdmissionReview, and prevent side effects on dry-run requests.
347347
* Leave the value empty, which is also the default: Keep the default modifying behavior.
348348

349349
For example:
@@ -352,12 +352,28 @@ For example:
352352
Content-Type: application/json
353353
Accept: application/json
354354

355-
The response would look the same as for non dry run request, but the values of some generated fields may differ.
355+
The response would look the same as for non-dry-run request, but the values of some generated fields may differ.
356356

357+
### Dry-run authorization
358+
359+
Authorization for dry-run and non-dry-run requests is identical. Thus, to make
360+
a dry-run request, the user must be authorized to make the non-dry-run request.
361+
362+
For example, to run a dry-run `PATCH` for Deployments, you must have the
363+
`PATCH` permission for Deployments, as in the example of the RBAC rule below.
364+
365+
```yaml
366+
rules:
367+
- apiGroups: ["extensions", "apps"]
368+
resources: ["deployments"]
369+
verbs: ["patch"]
370+
```
371+
372+
See [Authorization Overview](/docs/reference/access-authn-authz/authorization/).
357373
358374
### Generated values
359375
360-
Some values of an object are typically generated before the object is persisted. It is important not to rely upon the values of these fields set by a dry run request, since these values will likely be different in dry run mode from when the real request is made. Some of these fields are:
376+
Some values of an object are typically generated before the object is persisted. It is important not to rely upon the values of these fields set by a dry-run request, since these values will likely be different in dry-run mode from when the real request is made. Some of these fields are:
361377
362378
* `name`: if `generateName` is set, `name` will have a unique random name
363379
* `creationTimestamp`/`deletionTimestamp`: records the time of creation/deletion

content/en/docs/tasks/manage-kubernetes-objects/declarative-config.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,14 @@ kubectl diff -f https://k8s.io/examples/application/simple_deployment.yaml
8383
```
8484

8585
{{< note >}}
86-
`diff` uses [server-side dry-run](/docs/reference/using-api/api-concepts/#dry-run), which needs to be enabled on `kube-apiserver`.
86+
`diff` uses [server-side dry-run](/docs/reference/using-api/api-concepts/#dry-run),
87+
which needs to be enabled on `kube-apiserver`.
88+
89+
Since `diff` performs a server-side apply request in dry-run mode,
90+
it requires granting `PATCH`, `CREATE`, and `UPDATE` permissions.
91+
See [Dry-Run Authorization](/docs/reference/using-api/api-concepts#dry-run-authorization)
92+
for details.
93+
8794
{{< /note >}}
8895

8996
Create the object using `kubectl apply`:

0 commit comments

Comments
 (0)