@@ -359,8 +359,8 @@ This API separates policy _definition_ from policy _configuration_ by splitting
359
359
responsibilities across resources. The resources involved are:
360
360
361
361
- Policy definitions (ValidatingAdmissionPolicy)
362
- - Policy bindings (PolicyBinding )
363
- - Policy param resources (custom resources)
362
+ - Policy bindings (ValidatingAdmissionPolicyBinding )
363
+ - Policy param resources (custom resources or config maps )
364
364
365
365
![ Relatinships between policy resources] ( erd.png )
366
366
@@ -394,7 +394,7 @@ kind: ValidatingAdmissionPolicy
394
394
metadata :
395
395
name : " replicalimit-policy.example.com"
396
396
spec :
397
- paramSource :
397
+ paramKind :
398
398
group : rules.example.com
399
399
kind : ReplicaLimit
400
400
version : v1
@@ -412,7 +412,7 @@ spec:
412
412
# ...other rule related fields here...
413
413
```
414
414
415
- The ` spec.paramSource ` field of the ` ValidatingAdmissionPolicy ` specifies the
415
+ The ` spec.paramKind ` field of the ` ValidatingAdmissionPolicy ` specifies the
416
416
kind of resources used to parameterize this policy. For this example, it is
417
417
configured by ` ReplicaLimit ` custom resources. Note in this example how the CEL
418
418
expression references to the parameters via the CEL ` params ` variable, e.g.
@@ -434,13 +434,15 @@ resource are created. For example:
434
434
435
435
``` yaml
436
436
# Policy binding
437
- apiVersion : admissionregistration.k8s.io/v1
438
- kind : PolicyBinding
437
+ apiVersion : admissionregistration.k8s.io/v1alpha1
438
+ kind : ValidatingAdmissionPolicyBinding
439
439
metadata :
440
440
name : " replicalimit-binding-test.example.com"
441
441
spec :
442
- policy : " replicalimit-policy.example.com"
443
- params : " replica-limit-test.example.com"
442
+ policyName : " replicalimit-policy.example.com"
443
+ paramRef :
444
+ name : " replica-limit-test.example.com"
445
+ namespace : " default"
444
446
matchResources :
445
447
namespaceSelectors :
446
448
- key : environment,
@@ -464,13 +466,15 @@ An admission policy may have multiple bindings. To bind all other environments
464
466
environment to have a maxReplicas limit of 100, create another ` PolicyBinding`:
465
467
466
468
` ` ` yaml
467
- apiVersion: admissionregistration .k8s.io/v1
468
- kind: PolicyBinding
469
+ apiVersion: aadmissionregistration .k8s.io/v1alpha1
470
+ kind: ValidatingAdmissionPolicyBinding
469
471
metadata:
470
472
name: "replicalimit-binding-nontest"
471
473
spec:
472
- policy: "replicalimit-policy.example.com"
473
- params: "replica-limit-clusterwide.example.com"
474
+ policyName: "replicalimit-policy.example.com"
475
+ paramRef:
476
+ name: "replica-limit-test.example.com"
477
+ namespace: "default"
474
478
matchResources:
475
479
namespaceSelectors:
476
480
- key: environment,
@@ -491,13 +495,14 @@ matching binding. In the above example, the "nontest" policy binding could
491
495
instead have been defined as a global policy :
492
496
493
497
` ` ` yaml
494
- apiVersion: admissionregistration .k8s.io/v1
495
- kind: PolicyBinding
498
+ apiVersion: aadmissionregistration .k8s.io/v1alpha1
499
+ kind: ValidatingAdmissionPolicyBinding
496
500
metadata:
497
501
name: "replicalimit-binding-global"
498
502
spec:
499
- policy: "replicalimit-policy.example.com"
500
- params: "replica-limit-clusterwide.example.com"
503
+ policyName: "replicalimit-policy.example.com"
504
+ paramRef:
505
+ name: replica-limit-clusterwide.example.com"
501
506
matchResources:
502
507
namespaceSelectors:
503
508
- key: environment,
@@ -534,7 +539,7 @@ organized into CEL variables as well as some other useful variables:
534
539
535
540
- ' object'
536
541
- ' oldObject'
537
- - ' review '
542
+ - ' request '
538
543
- ' requestResource' (GVR)
539
544
- ' resource' (GVR)
540
545
- ' name'
@@ -543,35 +548,35 @@ organized into CEL variables as well as some other useful variables:
543
548
- ' userInfo'
544
549
- ' dryRun'
545
550
- ' options'
546
- - ' config ' - configuration data of the policy configuration being validated
551
+ - ' params ' - referred params object, maybe null if no object is referred
547
552
548
553
See below "Decisions and Enforcement" for more detail about how the
549
554
` spec.validations` field works and how violations are reported.
550
555
551
556
# #### Policy Configuration
552
557
553
- ` PolicyBinding ` resources and parameter CRDs together define how cluster
558
+ ` ValidatingAdmissionPolicyBinding ` resources and parameter CRDs together define how cluster
554
559
administrators configure policies for clusters.
555
560
556
- Each `PolicyBinding ` contains :
561
+ Each `ValidatingAdmissionPolicyBinding ` contains :
557
562
558
- - ` spec.policy ` - A reference to the policy being configured
563
+ - ` spec.policyName ` - A reference to the policy being configured
559
564
- ` spec.matchResources` - Match criteria for which resources the policy should
560
565
validate
561
- - ` spec.params ` - Reference to the custom resource containing the params to use
566
+ - ` spec.paramKind ` - Reference to the custom resource containing the params to use
562
567
when validating resources
563
- - ` spec.mode` - See "Decisions and Enforcement" for details.
564
568
565
569
Example :
566
570
567
571
` ` ` yaml
568
- apiVersion: admissionregistration .k8s.io/v1
569
- kind: PolicyBinding
572
+ apiVersion: aadmissionregistration .k8s.io/v1alpha1
573
+ kind: ValidatingAdmissionPolicyBinding
570
574
metadata:
571
575
name: "xyzlimit-scale.example.com"
572
576
spec:
573
- policy: xyzlimit-scale.example.com
574
- params: xyzlimit-scale-settings.example.com
577
+ policyName: xyzlimit-scale.example.com
578
+ paramRef:
579
+ name: xyzlimit-scale-settings.example.com
575
580
matchResources:
576
581
namespaceSelectors:
577
582
- key: environment,
@@ -962,8 +967,8 @@ higher level. This could be added later.
962
967
963
968
# ### Singleton Policies
964
969
965
- For simple policies that apply cluster wide , a policy can be authored using a
966
- single `ValidatingAdmissionPolicy` resource.
970
+ For simple policies that does not refer to a param , a policy can be authored using a
971
+ single `ValidatingAdmissionPolicy` resource without a `paramKind` field .
967
972
968
973
This is only available for cases where there is no need to have multiple
969
974
bindings, and where all params can be inlined in CEL.
@@ -975,17 +980,16 @@ apiVersion: admissionregistration.k8s.io/v1
975
980
kind: ValidatingAdmissionPolicy
976
981
...
977
982
spec:
983
+ # no paramKind
978
984
matchConstraints: ...
979
985
validations:
980
986
- expression: "object.spec.replicas < 100"
981
- singletonBinding:
982
- matchResources: ...
983
987
` ` `
984
988
985
989
Note that :
986
990
987
- - ` spec.paramSource ` must be absent and validations may not reference `params`
988
- - If `spec.singletonBinding` is present policy binding support is disabled.
991
+ - ` spec.paramKind ` must be absent
992
+ - validation expressions may not refer `params`
989
993
990
994
Safety features :
991
995
@@ -1536,7 +1540,7 @@ Steps:
1536
1540
1537
1541
1. Webhook is configured and in-use.
1538
1542
2. `ValidatingAdmissionPolicy` created with `FailPolicy : Ignore`
1539
- 3. `ValidatingAdmissionPolicy` is monitored to ensure it behaves the same as te webhook (logs or audit annotations can be used)
1543
+ 3. `ValidatingAdmissionPolicy` is monitored to ensure it behaves the same as the webhook (logs or audit annotations can be used)
1540
1544
4. `ValidatingAdmissionPolicy` is updated to `FailPolicy : Fail`
1541
1545
5. Verify the webhook never denies any requests. If the admission policy is
1542
1546
equivalent, then policy will be run first and deny the request before
@@ -1716,7 +1720,7 @@ metadata:
1716
1720
generation: 2
1717
1721
...
1718
1722
status:
1719
- paramSource :
1723
+ paramKind :
1720
1724
apiVersion: "example.com/v1"
1721
1725
kind: "fooLimits"
1722
1726
generation: 5
@@ -2475,7 +2479,7 @@ kind: ValidatingAdmissionPolicy
2475
2479
metadata:
2476
2480
name: "validate-xyz.example.com"
2477
2481
spec:
2478
- paramSource :
2482
+ paramKind :
2479
2483
group: rules.example.com
2480
2484
kind: ReplicaLimit
2481
2485
version: v1
0 commit comments