Show HN: CEL by Example
This "Show HN" presents an interactive guide to Common Expression Language (CEL), a powerful tool for evaluating expressions against data in critical systems like Kubernetes and Google Cloud. Its popularity on HN stems from its practical utility for developers needing fine-grained control and policy enforcement, clearly demonstrated through a series of accessible, runnable examples. The resource demystifies CEL's syntax and capabilities, making a complex topic approachable for a wide technical audience.
The Lowdown
CEL by Example is an interactive educational resource designed to introduce developers to the Common Expression Language (CEL), a declarative expression language used across various Google products and open-source projects for policy enforcement, data validation, and configuration. The website provides clear, runnable code examples demonstrating CEL's syntax and functionality, making it an excellent resource for learning this powerful, yet sometimes complex, language.
- What is CEL: Common Expression Language (CEL) is a language for evaluating expressions against structured data (e.g., Protobuf messages, JSON objects), known for its speed, portability, and safety.
- Real-world Applications: CEL is widely adopted in critical infrastructure like Kubernetes admission control, Google Cloud IAM conditions, Firebase security rules, Envoy Proxy routing, and Protovalidate's constraint rules, highlighting its importance in modern distributed systems.
- Core Concepts Demonstrated: The guide illustrates CEL's capabilities through practical examples covering:
- Basic Data Types: Handling strings, numbers, and boolean comparisons.
- Collection Operations: Using
infor membership,exists()for conditional checks, andfilter()to narrow down lists. - Time Handling: Native support for timestamps and durations, enabling comparisons like
user.email_verified - user.created < duration("24h"). - Logical Operations: Combining conditions with
&&and using the conditional operator? :for branching logic. - Data Transformation: Building new data structures (maps) and transforming collections using
map()to enrich or modify data.
- Interactive Learning: The "by Example" format allows users to see CEL expressions in action and understand their results immediately, fostering a hands-on learning experience. Overall, "CEL by Example" serves as an invaluable, practical guide for engineers looking to understand and implement CEL in their applications, offering a clear path from basic syntax to advanced data manipulation and policy enforcement.