Skip to content

Commit 9834136

Browse files
committed
Apply feedback
1 parent 6361495 commit 9834136

File tree

1 file changed

+60
-68
lines changed
  • keps/sig-api-machinery/3488-cel-admission-control

1 file changed

+60
-68
lines changed

keps/sig-api-machinery/3488-cel-admission-control/README.md

Lines changed: 60 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ spec:
362362
# ...other rule related fields here...
363363
```
364364

365-
The `spec.validations[*].expression` fields contain CEL expressions. If a
365+
The `spec.validations[*].expression` fields contain CEL expressions. If an
366366
expression evaluates to false, the validation check has failed.
367367

368368
The `spec.config` field of the `ValidatingAdmissionPolicy` specifies the
@@ -417,6 +417,13 @@ spec:
417417
maxReplicas: 100
418418
```
419419
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+
420427
This design separates admission policy _definition_ from _configuration_. This
421428
has a couple advantages:
422429
@@ -600,27 +607,47 @@ The idea of this alternative is to use duck typing: If a CRD author includes a
600607
below) and then for the apiserver access the data and treats it as match
601608
criteria.
602609

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`.
605631

606632
A partial `spec.match` schema (subset of the full schema) is okay so long as
607633
only optional fields are omitted. But any unrecognized field in the `spec.match`
608634
would not be allowed.
609635

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+
610642
Pros:
611643

612644
- A single resource is used to configure both the match criteria and
613645
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.
618646

619647
Cons:
620648

621649
- API server must check for a wide range of error conditions and define how
622650
exactly it handles each of them.
623-
- The way CRDs expose Match criteria is entirely implicit.
624651
- If the `spec.match` schema is incorrectly defined, CRD author might not
625652
realize it since they need to check the status of the corresponding
626653
`ValidatingAdmissionPolicy` for any errors.
@@ -760,7 +787,7 @@ Matching is performed in quite a few systems across Kubernetes:
760787
| namespace | Audit, P&F | phase 1 |
761788
| namespace label selectors | WH | phase 1 |
762789
| 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 |
764791
| apiVersion | WH | phase 1 |
765792
| resource name | Audit/RBAC | phase 1 |
766793
| scope (cluster\|namespace) | WH/P&F | phase 1 |
@@ -770,6 +797,7 @@ Matching is performed in quite a few systems across Kubernetes:
770797
| NonResourceURLs | Audit/RBAC/P&F | No |
771798
| default / fallthrough matching | | phase 2 see "Default matching" section |
772799
| user/userGroup | Audit | phase 2 see "Secondary Authz" section |
800+
| user.Extra | (in WH AdmissionReview) | phase 2 see "Secondary Authz" section |
773801
| permissions (RBAC verb) | RBAC | phase 2 see "Secondary Authz" section |
774802

775803
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
780808
Audit. Match criteria will also use ordered list of rules similar to these other
781809
systems.
782810

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-
792811
Proposed matching mechanism:
793812

794813
- Ordered list of matches. First match that is true determine if the request is
795814
validated by the policy-- if exclude is false, it is validated, otherwise it
796815
is not.
797816
- Supported criteria for each match:
798-
- GVR (resource apiGroup + resource)
817+
- GVR (apiGroup + resource)
799818
- scope (cluster|namespace)
800819
- operation (HTTP verb)
801820
- exclude (if criteria matches, match result is "no match")
802-
- namespace selectors
803-
- object selectors
821+
- namespace label selectors
822+
- label selectors
804823
- resource name
805824
- user/userGroup
806825
- permissions (RBAC verb)
@@ -818,53 +837,6 @@ Wildcards support? Or defer this type of check for CEL expression evaluation?
818837
Offer both GVR and GVK matching? Need to add GVK matching to below, if so.
819838
<<[/UNRESOLVED]>>
820839

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-
868840
`MatchPolicy` will work the same as for admission webhooks. It will default to
869841
`Equivalent` but may be set to `Exact`. See "Use Case: Multiple policy
870842
definitions for different versions of CRD" for an explanation of why we need
@@ -1253,6 +1225,26 @@ Use cases:
12531225
- security.openshift.io/SecurityContextConstraint
12541226
- security.openshift.io/SCCExecRestrictions
12551227

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+
12561248
#### Default configurations
12571249

12581250
<<[UNRESOLVED jpbetz, maxsmythe ]>>

0 commit comments

Comments
 (0)