kubewarden / cel-policy

A policy that can run CEL expressions
Apache License 2.0
3 stars 5 forks source link

Feature Request: Use NativeType instead of DynType when binding request and namespaceObject #7

Open fabriziosestito opened 8 months ago

fabriziosestito commented 8 months ago

Is your feature request related to a problem?

ATM we are binding request and namespaceObject as DynType. This is a workaround since recursively add sub-types to NativeTypes is not possible yet. Instead, we need to bind our k8s-objects to the cel environment. This allows the CEL compiler to type-check the expressions.

This WIP PR introduces the recursive NativeType: https://github.com/google/cel-go/pull/892

Once the PR above is merged, we need to create a custom type provider based on the CEL NativeType. This type will have the same behaviour of the vanilla NativeType, but it will convert downcase fields to uppercase. This is needed to be as close as possible to Kubernetes ValidatingAdmissionPolicy (which binds proto-generated objects instead).

Example:

namespaceObject.metadata -> namespaceObject.Metadata

Acceptance criteria

Alternatives you've considered

Using proto-generated objects. This alternative has been discarded because it's simpler to bind a NativeType based on kw k8s-objects.