from Hacker News

Common Expression Language

by siliconmountain on 12/10/20, 7:41 PM with 106 comments

  • by habosa on 12/11/20, 10:02 AM

    Googler here: for those of you who have ever used Firebase this is the language that powers Cloud Firestore / Cloud Storage security rules.

    Specifically in our rules everything after the "if" is Common Expression Language.

    See: https://firebase.google.com/docs/firestore/security/rules-co...

    The efficiency and safety of CEL enables us to put security rules in the critical path of every database request.

  • by iso8859-1 on 12/11/20, 7:36 AM

    Looks like it has similar goals to the Dhall config language: https://dhall-lang.org . But Dhall has functions, so probably more powerful.
  • by jmeister on 12/11/20, 4:12 AM

    Every major investment bank has an in-house variation of this, commonly called “payoff language” or “cashflow language”.
  • by frou_dh on 12/10/20, 9:37 PM

    I remember seeing this used inside config files for the Caddy webserver.

    Google seem to like these executable config languages because they've got another open source one ("Starlark") a few notches up in expressivity.

  • by scythe on 12/11/20, 2:06 AM

    This non-Turing-complete language space seems like it should be useful for UI themes and other user scripting in particular:

    - hard to write exploits, can be shared/installed without warnings

    - easy(-er) to predict behavior of themes so they won't break in new versions

  • by jt2190 on 12/11/20, 1:27 PM

    The creator of Apache Ant, James Duncan Davidson, wrote about choosing XML as the “language”:

    > Now, I never intended for the file format to become a scripting language—after all, my original view of Ant was that there was a declaration of some properties that described the project and that the tasks written in Java performed all the logic. The current maintainers of Ant generally share the same feelings. But when I fused XML and task reflection in Ant, I put together something that is 70-80% of a scripting environment. I just didn't recognize it at the time. To deny that people will use it as a scripting language is equivalent to asking them to pretend that sugar isn't sweet.

    https://web.archive.org/web/20041217023752///x180.net/Journa...

  • by stevekemp on 12/11/20, 6:19 AM

    I've never used this particular library, but I did put together my own simple evaluation engine and have found it very useful for a range of purposes.

    Initially it was designed to process incoming slack messages, and sometimes trigger a notification to an on-call engineer, but over time I've found uses for it processing email, scripting simple actions on my desktop, and more.

    https://github.com/skx/evalfilter/

    These kind of things are pretty simple to write, but sometimes I almost think it is a shame there isn't something more standard. (Lua was kinda winning for that embedded-logic role for a long time, but nowadays we still have the mixture of YAML, HCL, and other niche-specific language/filtering and I imagine the time has passed to pick one standard.)

  • by dathinab on 12/11/20, 2:43 AM

    > Expr = ConditionalOr ["?" ConditionalOr ":" Expr] ;

    I believe this was a mistake. "?" based conditionals aren't really a good idea IMHO.

  • by hardwaresofton on 12/10/20, 10:03 PM

    This looks really similar to Open Policy Agent[0], wonder how they compare.

    [0]: https://www.openpolicyagent.org/

  • by tlarkworthy on 12/10/20, 9:25 PM

    Genuine trinary logic so exceptions are mapped to unknown but can still short circuit the overall expression.

    https://github.com/google/cel-spec/blob/master/doc/langdef.m...

  • by hadrien01 on 12/10/20, 9:15 PM

    At the end of the README: Disclaimer: This is not an official Google product.
  • by sandstrom on 12/10/20, 9:58 PM

    I’m curious how this differs from Sentinel, hashicorps language for similar things.

    Too bad it isn’t open sourced.

    https://www.hashicorp.com/sentinel

  • by taeric on 12/11/20, 1:35 AM

    I can't escape the feeling that emacs got this right. Nobody wants their config to be lisp, but it fits the bill for what you needed. Especially combined with the custom sections. So nice.
  • by nojvek on 12/11/20, 4:02 PM

    If you’re constantly fighting yaml, consider jsonnet. It’s another project by google and similarly not Turing complete. Works wonderful at generating templates.
  • by brundolf on 12/10/20, 11:43 PM

    Very cool idea. I'd be curious to find out more about what it is being/might be used for
  • by partialstate on 12/11/20, 8:00 PM

    The goal of CEL is fast, scalable, and portable expression evaluation.

    Fast - CEL runs without the need for sandboxing, making it much faster than sandboxed solutions like WebAssembly, Lua, and embedded JavaScript.

    Scalable - Features like variables and functions would make CEL more expressive, but also less scalable as it's easy to write a few lines of code with functions that consume exponential amounts of memory and compute. CEL is simply the expression and nothing more.

    Portable - CEL is implemented in Go[0], C++[1], and Python[2] with Java open sourcing in development. There is a public codelab[3] available for Go if anyone is interested. There is also a conformance suite in CEL-Spec to ensure consistent behavior between runtimes and environments. Our objective is to make it possible to bring CEL to K8s, J2EE apps, and C++ proxies. Evaluate at line-rate everywhere. Personally, I hope someone tries to make CEL work on IoT devices some day too.

    Where? - CEL is usually embedded into larger projects rather than being the one stop shop for solving a particular kind of problem. For example, CEL Policy Templates[4] has an opinionated way of using CEL to validate/evaluate YAML configs. Most of the time CEL is part of a service API.

    In addition to being used in Firebase's Cloud Firestore / Cloud Storage security rules, it is also used in several other Google Cloud services: - Cloud Armor[5] - IAM Conditions[6] - Cloud Healthcare Consents[7] - Cloud Build Notifiers[8] - Security Token Service[9] - Access Levels[10], and more.

    CEL is also used in some prominent open source projects like Envoy RBAC[11], Caddyserver[12], Krakend.io[13], and Cloud Custodian[14].

    [0]: https://github.com/google/cel-go [1]: https://github.com/google/cel-cpp [2]: https://github.com/cloud-custodian/cel-python [3]: https://codelabs.developers.google.com/codelabs/cel-go [4]: https://github.com/google/cel-policy-templates-go [5]: https://cloud.google.com/armor/docs/rules-language-reference [6]: https://cloud.google.com/iam/docs/conditions-overview [7]: https://cloud.google.com/healthcare/docs/concepts/consent-mo... [8]: https://cloud.google.com/cloud-build/docs/filter-build-notif... [9]: https://cloud.google.com/iam/docs/workload-identity-federati... [10]: https://cloud.google.com/access-context-manager/docs/custom-... [11]: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overv... [12]: https://caddyserver.com/docs/caddyfile/matchers#expression [13]: https://www.krakend.io/docs/endpoints/common-expression-lang... [14]: https://github.com/cloud-custodian/cel-python

  • by ilaksh on 12/11/20, 7:25 PM

    What programming languages can you currently use this with?
  • by contravariant on 12/10/20, 10:25 PM

    I'd be a bit suspicious about the claim that it is not Turing complete. To be fair I can't yet find a way to allow arbitrary computation (though it seems easy to add one with fairly innocuous features). Although you can get it to solve 3-SAT, though only for some predefined number of variables (which it assures can be at least 32). Combinatorics stuff like printing all possible sudokus also seems like it should be feasible.

    Don't expect your config files to terminate when they use macros, that's all I'm saying.