README.md

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 true means the check failed, i.e. the object is non-compliant. Verdict allow means 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) and request.oldObject comparisons 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 whose metadata.name equals the test object’s name
  • image_startswith — True if any container image starts with test/ (startsWith string function inside exists)
  • privileged_eq — Flags pods where at least one container runs privileged
  • hostnet_has_eq — Flags pods using the host network (hostNetwork: true), checking the optional field with has() first
  • size_gt — True if the pod has more than one container (size() on a list, > comparison)
  • label_in_map — True if the label key dac-test exists (in operator 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 pods
  • annotations_not_set — True if the pod has no annotations at all (negated has())
  • priv_or_hostnet — Combines two risky settings with ||: host network or any privileged container
  • image_matches — Regex match (matches, RE2) of the first container image against test/.*
  • image_contains — True if the first container image contains the substring test (contains)
  • image_endswith — True if the first container image ends with :latest, i.e
  • label_index_eq — Index access on the labels map: labels['env'] == 'prod', guarded by has()
  • size_ge_2 — True if the pod has two or more containers (>= comparison)
  • all_privileged — Macro all: every container must be privileged
  • exists_one_priv — Macro exists_one: exactly one container is privileged, not zero and not several
  • ternary_default — Ternary operator as a default value: use hostNetwork if set, otherwise false, then compare to true
  • bytes_image_size — Type conversion bytes(): the byte length of the first image string is greater than 5
  • double_count — Type conversion double(): the container count converted to a double is greater than 0.0
  • duration_grace — duration() built from terminationGracePeriodSeconds plus an s suffix and compared with 0s
  • timestamp_literal — Pure literal check of timestamp() ordering
  • image_changed_diff — UPDATE only: the first container image differs between request.object and request.oldObject
  • naive_object_on_delete — Naive use of request.object on DELETE

Service

  • name_eq — Matches the object whose metadata.name equals the test object’s name
  • type_eq — True if the Service type is LoadBalancer
  • port_exists_eq — True if any port equals 22 (exists over spec.ports)
  • port_index_gt — First port is above 30000, i.e
  • type_neq — Type is set and is not ClusterIP, so the Service is exposed outside the cluster
  • port_index_lt — First port is below 1024, a privileged port (<)
  • double_port — double() conversion of the first port, compared with 0.0
  • port_changed_diff — UPDATE only: the first port differs between new and old object
  • naive_object_on_delete — Naive use of request.object on DELETE

Ingress

  • name_eq — Matches the object whose metadata.name equals the test object’s name
  • host_exists — True if any rule host equals test.example.com
  • host_or_ends — First rule host equals test.com or ends with .test (|| plus endsWith)
  • naive_object_on_delete — Naive use of request.object on DELETE

IngressClass

NetworkPolicy

  • name_eq — Matches the object whose metadata.name equals the test object’s name
  • ingress_size_eq_0 — Policy has an empty ingress list (size(...) == 0)
  • not_size_gt_0 — Same intent as ingress_size_eq_0, written as negation !(size > 0); checks that ! works over a comparison
  • ptype_index_eq — First policy type is Ingress (list index access)
  • naive_object_on_delete — Naive use of request.object on DELETE

Role

ClusterRole

RoleBinding

  • name_eq — Matches the object whose metadata.name equals the test object’s name
  • subject_eq — Any subject is system:anonymous, i.e
  • roleref_neq — The bound role is not default-role
  • naive_object_on_delete — Naive use of request.object on DELETE

ClusterRoleBinding

ServiceAccount

CertificateSigningRequests

  • name_eq — Matches the object whose metadata.name equals the test object’s name
  • signer_eq — Signer is exactly kubernetes.io/kubelet-serving
  • signer_matches — Signer matches the regex ^kubernetes\.io/.* (anchored matches)
  • bytes_request — bytes() conversion of the CSR payload and a non-empty check
  • naive_object_on_delete — Naive use of request.object on DELETE
Описание
Конвейеры
0 успешных
0 с ошибкой
Разработчики