-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add resource constraints for CEL #3144
Changes from 12 commits
ae09cbb
16283e1
11be065
eea4fd8
ff38644
efda13f
fa0b979
bf2b434
76e4605
e4b49ba
8bd777a
e541ae3
6a550cb
ac9e0e7
4e440b0
3e36b22
8736077
49fe807
5f96b1c
5f44379
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
- [Type Checking](#type-checking) | ||
- [Type System Integration](#type-system-integration) | ||
- [Why not represent associative lists as maps in CEL?](#why-not-represent-associative-lists-as-maps-in-cel) | ||
- [Resource constraints](#resource-constraints) | ||
- [Test Plan](#test-plan) | ||
- [Graduation Criteria](#graduation-criteria) | ||
- [Alpha](#alpha) | ||
|
@@ -589,6 +590,29 @@ associativeList.all(e, e.key1 == 'a' && e.key2 == 'b' && e.val == 100) | |
associativeList.all(e, e.val == 100) | ||
``` | ||
|
||
### Resource constraints | ||
|
||
For Beta, per-request execution time will be constrained via a context-passed timeout. For Beta, we are looking at a range between 100 milliseconds and 1 second for the timeout. We want to see how | ||
CEL performs in benchmarks once our Beta optimizations are in place before deciding what specific | ||
duration to set the timeout to. If the timeout is exceeded, the error message will include how | ||
long each expression took to evaluate. | ||
|
||
We will provide time and space benchmarks to show what can be expected in typical and worst-case | ||
scenarios for CEL expressions, and that for most use cases, the timeout alone will be sufficient. | ||
The alternatives listed below would be more aimed at malformed/malicious expressions. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. guarding against malformed/malicious expressions is definitely in scope |
||
|
||
If the context timeout proves to be insufficient, we have other alternatives to explore, such as | ||
limiting nested list comprehensions to a depth of 2. According to the performance section of | ||
[the CEL spec](https://github.com/google/cel-spec/blob/master/doc/langdef.md#performance), the | ||
time complexity of these operations are all O(n), so by limiting nesting to 2 deep, we limit | ||
expression complexity to O(n<sup>2</sup>). We can limit regular expression complexity | ||
as well. | ||
|
||
CEL also provides a [cost subsystem](https://github.com/google/cel-go/blob/dfef54b359b05532fb9695bc88937aa8530ab055/cel/program.go#L309) that could be used in the future, | ||
but the cost subsystem would need to know the length of any relevant lists in order to be useful. | ||
That information can be supplied using `maxLength`, but this is an optional field, and if not | ||
passed, CEL would not be able to provide a useful figure. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if it's useful, but we could set a max length of a list based on the 3MB request limit and the size of the most compact encoding possible:
I'm not sure if passing such big list sizes to CEL would make the cost subsystem go nuts or not, but we could check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'll give passing lists of that size through CEL a shot and see what happens. I think that list might work well to provide |
||
|
||
### Test Plan | ||
|
||
We will extend both the unit test suite and the integration test suite to cover the CRD validation rule described in this KEP. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has the downside of permitting costly CEL expressions that time out to be persisted in the CRD, and fail at CR request time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely - only having a timeout doesn't provide nearly as strong guarantees as estimating expression cost. I think if we can guarantee good cost estimation, we should go with it. I'm a little concerned about accuracy, since I feel there could be cases where an incorrect estimate is given, and an expression that should be allowed isn't permitted (or vice versa).