KCS CEL tests
English
A collection of example CEL (Common Expression Language) rules used to test custom admission-control checks in Kaspersky Container Security (KCS). The rules cover Kubernetes resources: Pod, Service, Ingress, IngressClass, NetworkPolicy, Role, ClusterRole, RoleBinding, ClusterRoleBinding, ServiceAccount and CertificateSigningRequests.
Each rule has its own Markdown file, <Kind>/<rule_id>.md, with a short brief (English and Russian), the resource kind, the operations it applies to, the test payload parameters, the expected verdict and the CEL snippet. The original, unmodified source is examples.py.
Reading the rules:
{obj}and{name}are placeholders substituted by the test harness.- Verdict
truemeans the check failed, i.e. the object is non-compliant. Verdictallowmeans the rule must not trigger and the request is admitted. - The rules also exercise CEL language features: macros (
exists,all,exists_one,has), string functions,in, ternary, type conversions (bytes,double,duration,timestamp) andrequest.oldObjectcomparisons on UPDATE.
Credits: all scripts were written by Igor Rogozhin (QA engineer). This repository only documents them.
Русский
Коллекция примеров правил на CEL (Common Expression Language) для тестирования пользовательских admission-проверок в Kaspersky Container Security (KCS). Правила охватывают ресурсы Kubernetes: Pod, Service, Ingress, IngressClass, NetworkPolicy, Role, ClusterRole, RoleBinding, ClusterRoleBinding, ServiceAccount и CertificateSigningRequests.
Для каждого правила есть отдельный Markdown-файл <Kind>/<rule_id>.md: краткое описание (на английском и русском), тип ресурса, операции, параметры тестовой нагрузки, ожидаемый вердикт и CEL-код. Исходный файл без изменений — examples.py.
Как читать правила:
{obj}и{name}— плейсхолдеры, которые подставляет тестовый харнесс.- Вердикт
trueозначает, что проверка провалена, то есть объект non-compliant. Вердиктallowозначает, что правило не должно сработать и запрос пропускается. - Правила также проверяют возможности языка CEL: макросы (
exists,all,exists_one,has), строковые функции,in, тернарный оператор, преобразования типов (bytes,double,duration,timestamp) и сравнение сrequest.oldObjectпри UPDATE.
Авторство: все скрипты написаны Игорем Рогожиным (QA-инженер). Этот репозиторий лишь документирует их.
Index / Оглавление
Pod
name_eq— Matches the object whosemetadata.nameequals the test object’s nameimage_startswith— True if any container image starts withtest/(startsWithstring function insideexists)privileged_eq— Flags pods where at least one container runs privilegedhostnet_has_eq— Flags pods using the host network (hostNetwork: true), checking the optional field withhas()firstsize_gt— True if the pod has more than one container (size()on a list,>comparison)label_in_map— True if the label keydac-testexists (inoperator on a map tests keys)name_neq— Inequality operator: name differs from a constant that no real pod uses, so it is true for ordinary podsannotations_not_set— True if the pod has no annotations at all (negatedhas())priv_or_hostnet— Combines two risky settings with||: host network or any privileged containerimage_matches— Regex match (matches, RE2) of the first container image againsttest/.*image_contains— True if the first container image contains the substringtest(contains)image_endswith— True if the first container image ends with:latest, i.elabel_index_eq— Index access on the labels map:labels['env'] == 'prod', guarded byhas()size_ge_2— True if the pod has two or more containers (>=comparison)all_privileged— Macroall: every container must be privilegedexists_one_priv— Macroexists_one: exactly one container is privileged, not zero and not severalternary_default— Ternary operator as a default value: usehostNetworkif set, otherwisefalse, then compare totruebytes_image_size— Type conversionbytes(): the byte length of the first image string is greater than 5double_count— Type conversiondouble(): the container count converted to a double is greater than0.0duration_grace—duration()built fromterminationGracePeriodSecondsplus anssuffix and compared with0stimestamp_literal— Pure literal check oftimestamp()orderingimage_changed_diff— UPDATE only: the first container image differs betweenrequest.objectandrequest.oldObjectnaive_object_on_delete— Naive use ofrequest.objecton DELETE
Service
name_eq— Matches the object whosemetadata.nameequals the test object’s nametype_eq— True if the Service type isLoadBalancerport_exists_eq— True if any port equals 22 (existsoverspec.ports)port_index_gt— First port is above 30000, i.etype_neq— Type is set and is notClusterIP, so the Service is exposed outside the clusterport_index_lt— First port is below 1024, a privileged port (<)double_port—double()conversion of the first port, compared with0.0port_changed_diff— UPDATE only: the first port differs between new and old objectnaive_object_on_delete— Naive use ofrequest.objecton DELETE
Ingress
name_eq— Matches the object whosemetadata.nameequals the test object’s namehost_exists— True if any rule host equalstest.example.comhost_or_ends— First rule host equalstest.comor ends with.test(||plusendsWith)naive_object_on_delete— Naive use ofrequest.objecton DELETE
IngressClass
name_eq— Matches the object whosemetadata.nameequals the test object’s namecontroller_eq— Controller is exactlytest.io/ingresscontroller_neq— Controller is anything other thank8s.io/ingress-nginxnaive_object_on_delete— Naive use ofrequest.objecton DELETE
NetworkPolicy
name_eq— Matches the object whosemetadata.nameequals the test object’s nameingress_size_eq_0— Policy has an empty ingress list (size(...) == 0)not_size_gt_0— Same intent asingress_size_eq_0, written as negation!(size > 0); checks that!works over a comparisonptype_index_eq— First policy type isIngress(list index access)naive_object_on_delete— Naive use ofrequest.objecton DELETE
Role
name_eq— Matches the object whosemetadata.nameequals the test object’s namewildcard_verb_in— Any rule grants the wildcard verb*(inon a list)secrets_get— Any single rule allowsgetonsecrets(twointests in oneexists)wildcard_resource— Any rule covers all resources via*all_rules_have_get— Every rule includes thegetverb (macroall)naive_object_on_delete— Naive use ofrequest.objecton DELETE
ClusterRole
name_eq— Matches the object whosemetadata.nameequals the test object’s namewildcard_verb— Any rule grants the wildcard verb*exists_one_wild— Exactly one rule grants*(macroexists_one)naive_object_on_delete— Naive use ofrequest.objecton DELETE
RoleBinding
name_eq— Matches the object whosemetadata.nameequals the test object’s namesubject_eq— Any subject issystem:anonymous, i.eroleref_neq— The bound role is notdefault-rolenaive_object_on_delete— Naive use ofrequest.objecton DELETE
ClusterRoleBinding
name_eq— Matches the object whosemetadata.nameequals the test object’s namecluster_admin_eq— Binding references thecluster-adminrolesubject_index_eq— First subject issystem:anonymous(index access)naive_object_on_delete— Naive use ofrequest.objecton DELETE
ServiceAccount
name_eq— Matches the object whosemetadata.nameequals the test object’s nameautomount_eq_true— Token automount is explicitly set totrue, guarded byhas()automount_or_unset— Automount is unset ortrue, i.enaive_object_on_delete— Naive use ofrequest.objecton DELETE
CertificateSigningRequests
name_eq— Matches the object whosemetadata.nameequals the test object’s namesigner_eq— Signer is exactlykubernetes.io/kubelet-servingsigner_matches— Signer matches the regex^kubernetes\.io/.*(anchoredmatches)bytes_request—bytes()conversion of the CSR payload and a non-empty checknaive_object_on_delete— Naive use ofrequest.objecton DELETE