@@ -362,7 +362,7 @@ spec:
362
362
# ...other rule related fields here...
363
363
```
364
364
365
- The ` spec.validations[*].expression ` fields contain CEL expressions. If a
365
+ The ` spec.validations[*].expression ` fields contain CEL expressions. If an
366
366
expression evaluates to false, the validation check has failed.
367
367
368
368
The ` spec.config ` field of the ` ValidatingAdmissionPolicy ` specifies the
@@ -417,6 +417,13 @@ spec:
417
417
maxReplicas : 100
418
418
` ` `
419
419
420
+ Configurations can have overlapping match criteria. The policy is evaluated for
421
+ each matching configuration. For example, if you have a blocklist policy and
422
+ have two policy configurations (each containing their own set of blocklist
423
+ entries) that overlap, the policy is evaluated twice, once with each blocklist.
424
+ (We won't attempt to merge the blocklists, we'll just run the policy as-is with
425
+ each blocklist).
426
+
420
427
This design separates admission policy _definition_ from _configuration_. This
421
428
has a couple advantages:
422
429
@@ -600,27 +607,47 @@ The idea of this alternative is to use duck typing: If a CRD author includes a
600
607
below) and then for the apiserver access the data and treats it as match
601
608
criteria.
602
609
603
- If the schema for `spec.match` it is malformed, errors are reported in the
604
- status of the `ValidatingAdmissionPolicy`.
610
+ To detect and handle any mismatches between how CRDs declare the `spec.match`
611
+ schema and what the apiserver expects :
612
+ - When consuming configuration CRDs OR policy configuration resources used for
613
+ policy configuration :
614
+ - If any unrecognized fields, missing required fields, or incorrectly typed
615
+ fields are found under `spec.match` :
616
+ - For configuration CRDs :
617
+ - Set the `ValidatingAdmissionPolicy` state to "misconfigured" in the
618
+ status (via a Condition, I believe).
619
+ - Trigger the `FailurePolicy` on all admission validations.
620
+ - Add a detailed error in the status of the `ValidatingAdmissionPolicy`.
621
+ - For policy configuration resources :
622
+ - Track in the status of `ValidatingAdmissionPolicy` that some policy
623
+ configurations are misconfigured. (also via a Condition?).
624
+ - Add a detailed error in the status of the `ValidatingAdmissionPolicy`.
625
+ - Trigger the `FailurePolicy` on admission for resources that match the
626
+ policy configuration.
627
+ - If the CRD is deleted :
628
+ - Set state to "misconfigured
629
+ - Trigger `FailurePolicy` on all admission validations
630
+ - Add a detailed error in the status of the `ValidatingAdmissionPolicy`.
605
631
606
632
A partial `spec.match` schema (subset of the full schema) is okay so long as
607
633
only optional fields are omitted. But any unrecognized field in the `spec.match`
608
634
would not be allowed.
609
635
636
+ Allow an annotation on a CRD manifest that means "inject the correct .spec.match
637
+ during admission and keep it up to date with a controller". (Suggested by
638
+ deads2k). This minimizes version skew if new match criteria is added to
639
+ ` spec.match` and also minimizes development effort by removing the need
640
+ to manually declare the fields in CRDs.
641
+
610
642
Pros :
611
643
612
644
- A single resource is used to configure both the match criteria and
613
645
configuration params of a policy.
614
- - Policy authors can choose to only provide the subset of `spec.match` schema
615
- that apply to the configuration of the policy they have defined. E.g. a policy
616
- that is already constrained to pods by the policy definition does not
617
- need to expose the match criteria for GVR matching.
618
646
619
647
Cons :
620
648
621
649
- API server must check for a wide range of error conditions and define how
622
650
exactly it handles each of them.
623
- - The way CRDs expose Match criteria is entirely implicit.
624
651
- If the `spec.match` schema is incorrectly defined, CRD author might not
625
652
realize it since they need to check the status of the corresponding
626
653
` ValidatingAdmissionPolicy` for any errors.
@@ -760,7 +787,7 @@ Matching is performed in quite a few systems across Kubernetes:
760
787
| namespace | Audit, P&F | phase 1 |
761
788
| namespace label selectors | WH | phase 1 |
762
789
| label selectors | WH | phase 1 |
763
- | resource apiGroup + resource | WH/Audit/P&F/RBAC | phase 1 |
790
+ | apiGroup + resource | WH/Audit/P&F/RBAC | phase 1 |
764
791
| apiVersion | WH | phase 1 |
765
792
| resource name | Audit/RBAC | phase 1 |
766
793
| scope (cluster\|namespace) | WH/P&F | phase 1 |
@@ -770,6 +797,7 @@ Matching is performed in quite a few systems across Kubernetes:
770
797
| NonResourceURLs | Audit/RBAC/P&F | No |
771
798
| default / fallthrough matching | | phase 2 see "Default matching" section |
772
799
| user/userGroup | Audit | phase 2 see "Secondary Authz" section |
800
+ | user.Extra | (in WH AdmissionReview) | phase 2 see "Secondary Authz" section |
773
801
| permissions (RBAC verb) | RBAC | phase 2 see "Secondary Authz" section |
774
802
775
803
WH = Admission webhooks, P&F = Priority and Fairness
@@ -780,27 +808,18 @@ declared with API types in a format similar to admission webhooks, P&F, RBAC and
780
808
Audit. Match criteria will also use ordered list of rules similar to these other
781
809
systems.
782
810
783
- In order for policy configuration resources to declare match criteria, the
784
- corresponding configuration CRD schema must have a `spec.match` property. This
785
- property must conform to the below "matching schema template". This ensures that
786
- the match criteria is in the format that API server expects (the API server will
787
- be using duck typing here since there is no established way to do polymorphism
788
- across CRDs). The schemas of these fields in the configuration CRD may omit any
789
- optional properties; policy definition authors should only include the parts of
790
- the "match schema template" that are useful for configuring a particular policy.
791
-
792
811
Proposed matching mechanism :
793
812
794
813
- Ordered list of matches. First match that is true determine if the request is
795
814
validated by the policy-- if exclude is false, it is validated, otherwise it
796
815
is not.
797
816
- Supported criteria for each match :
798
- - GVR (resource apiGroup + resource)
817
+ - GVR (apiGroup + resource)
799
818
- scope (cluster|namespace)
800
819
- operation (HTTP verb)
801
820
- exclude (if criteria matches, match result is "no match")
802
- - namespace selectors
803
- - object selectors
821
+ - namespace label selectors
822
+ - label selectors
804
823
- resource name
805
824
- user/userGroup
806
825
- permissions (RBAC verb)
@@ -818,53 +837,6 @@ Wildcards support? Or defer this type of check for CEL expression evaluation?
818
837
Offer both GVR and GVK matching? Need to add GVK matching to below, if so.
819
838
<<[/UNRESOLVED]>>
820
839
821
- TBD :
822
-
823
- ` ` ` go
824
- // TODO: Add this as a struct into the Kubernetes codebase so it can easily be
825
- // imported?
826
- type MatchCriteria struct {
827
- admissionregisterationv1.RuleWithOperations ` json:,inline`
828
-
829
- Namespaces ... `json:...`
830
- NamespaceLabelSelector *metav1.LabelSelector `json:...`
831
- LabelSelector *metav1.LabelSelector `json:...`
832
- ResourceNames ... `json:...`
833
- Users ... `json:...` // See "Secondary Authz" section below
834
- UserGroups ... `json:...` // See "Secondary Authz" section below
835
- Permissions ... `json:...` // See "Secondary Authz" section below
836
- Effect MatchEffect ... `json:...` // See "Exclude matching" section below
837
- }
838
- ```
839
-
840
- (Also, by allowing the "matching schema template" in configuration CRDs to be a
841
- omit optional properties, this API is future proofed against the addition of
842
- other match related properties in the future).
843
-
844
- "matching schema template":
845
-
846
- ``` go
847
- type PolicyConfiguration struct {
848
- Match []MatchCriteria ` json:...`
849
- MatchPolicy MatchPolicy ` json:...`
850
- Enforcement EnforcementAction ` json:...` // See "Reporting violations" section below
851
- FailurePolicy FailurePolicy ` json:...` // See "Failure Policy" section below
852
- }
853
- ```
854
-
855
- Example usage:
856
-
857
- ``` go
858
- // +genclient
859
- // +genclient:nonNamespaced
860
- // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
861
- type ReplicaLimit struct {
862
- PolicyConfiguration ` json:",inline"
863
-
864
- MaxReplicas int32 ` json:" maxReplicas" protobuf:" varint,2,name=maxReplicas" `
865
- }
866
- ` ` `
867
-
868
840
` MatchPolicy` will work the same as for admission webhooks. It will default to
869
841
`Equivalent` but may be set to `Exact`. See "Use Case : Multiple policy
870
842
definitions for different versions of CRD" for an explanation of why we need
@@ -1253,6 +1225,26 @@ Use cases:
1253
1225
- security.openshift.io/SecurityContextConstraint
1254
1226
- security.openshift.io/SCCExecRestrictions
1255
1227
1228
+ From deads2k :
1229
+
1230
+ > Note that user.Extra in AdmissionReview has pod claims, which are valuable.
1231
+
1232
+ > sig-auth has previous talked about trying to find a way to restrict access
1233
+ > from a daemonset pod to a customresource/foo that has Foo.spec.NodeName set to
1234
+ > the Node.metadata.name of the pod bound to the particular SA token. This is
1235
+ > tantalizingly close because user.Extra contains
1236
+ > authentication.kubernetes.io/pod-uid to locate a pod, determine a
1237
+ > Pod.spec.NodeName.
1238
+
1239
+ > A built-in that does that may be well received and unlock many use-cases.
1240
+ > Exploring the idea may be useful. If most also require controlled read
1241
+ > permission, then its probably better to create something specifically for the
1242
+ > purpose.
1243
+
1244
+ Looking up the pod (or any other additional resources) is not something we are
1245
+ currently planning to support in this KEP, but the use case is interesting and
1246
+ we should investigate with sig-auth.
1247
+
1256
1248
# ### Default configurations
1257
1249
1258
1250
<<[UNRESOLVED jpbetz, maxsmythe ]>>
0 commit comments