HeadlinesBriefing favicon HeadlinesBriefing.com

CEL by Example: Common Expression Language Tutorial

Hacker News •
×

CEL (Common Expression Language) is a fast, portable, and safe expression language used in Kubernetes admission control, Google Cloud IAM conditions, and Firebase security rules. The Show HN post provides a hands-on tutorial using a sample user object with fields like name, roles, age, and email to demonstrate CEL's capabilities.

Starting with basic comparisons, the tutorial shows how to check if a user is over 18 or verify email domains using string functions. It then explores collections with membership tests and the `exists()` function for pattern matching. The `filter()` function demonstrates how to narrow lists to specific elements, such as extracting elevated roles from a user's role list.

Advanced features include timestamp arithmetic for calculating durations between events, logical operators for combining conditions, and the conditional operator for branching logic. The tutorial concludes with data transformation using `map()` to build new structures, annotate roles with elevation status, and filter while transforming in a single operation. This practical approach makes CEL accessible for developers implementing policy checks and data validation in production systems.