Skip to content

Commit c57801c

Browse files
kyessenovlizan
authored andcommitted
update cel-cpp (envoyproxy#8746)
Description: update CEL runtime to tighten the complexity bounds: - remove comprehension operators (forall, exists) - remove list and string concat to avoid memory allocation - limit RE2 regex max program size - remove string conversion to avoid string allocation Risk Level: low Testing: unit tests Docs Changes: remove upstream.mtls attribute due to ongoing envoyproxy#8464 Release Notes: Signed-off-by: Kuat Yessenov <[email protected]>
1 parent 911c9ae commit c57801c

File tree

5 files changed

+13
-21
lines changed

5 files changed

+13
-21
lines changed

bazel/repository_locations.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,10 @@ REPOSITORY_LOCATIONS = dict(
269269
urls = ["https://storage.googleapis.com/quiche-envoy-integration/4abb566fbbc63df8fe7c1ac30b21632b9eb18d0c.tar.gz"],
270270
),
271271
com_google_cel_cpp = dict(
272-
sha256 = "f027c551d57d38fb9f0b5e4f21a2b0b8663987119e23b1fd8dfcc7588e9a2350",
273-
strip_prefix = "cel-cpp-d9d02b20ab85da2444dbdd03410bac6822141364",
274-
# 2019-08-15
275-
urls = ["https://github.com/google/cel-cpp/archive/d9d02b20ab85da2444dbdd03410bac6822141364.tar.gz"],
272+
sha256 = "e21d11be5eca677fe79839d310ceffb2f950d9d03f7682af8c0d311e573a1302",
273+
strip_prefix = "cel-cpp-d85f82972c2def6db9c90f3d9a23f56a0ac3caff",
274+
# 2019-10-23
275+
urls = ["https://github.com/google/cel-cpp/archive/d85f82972c2def6db9c90f3d9a23f56a0ac3caff.tar.gz"],
276276
),
277277
com_googlesource_code_re2 = dict(
278278
sha256 = "b0382aa7369f373a0148218f2df5a6afd6bfa884ce4da2dfb576b979989e615e",

docs/root/intro/arch_overview/security/rbac_filter.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ The following attributes are exposed to the language runtime:
9191
connection.tls_version, string, TLS version of the downstream TLS connection
9292
upstream.address, string, Upstream connection remote address
9393
upstream.port, int, Upstream connection remote port
94-
upstream.mtls, bool, Indicates whether TLS is applied to the upstream connection and the peer ceritificate is presented
9594

9695

9796
Most attributes are optional and provide the default value based on the type of the attribute.

source/extensions/filters/common/expr/context.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,6 @@ absl::optional<CelValue> UpstreamWrapper::operator[](CelValue key) const {
142142
upstream_host->address()->ip() != nullptr) {
143143
return CelValue::CreateInt64(upstream_host->address()->ip()->port());
144144
}
145-
} else if (value == MTLS) {
146-
return CelValue::CreateBool(info_.upstreamSslConnection() != nullptr &&
147-
info_.upstreamSslConnection()->peerCertificatePresented());
148145
}
149146

150147
return {};

source/extensions/filters/common/expr/evaluator.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,23 @@ namespace Expr {
1414
BuilderPtr createBuilder(Protobuf::Arena* arena) {
1515
google::api::expr::runtime::InterpreterOptions options;
1616

17-
// Conformance with spec/go runtimes requires this setting
18-
options.partial_string_match = true;
17+
// Security-oriented defaults
18+
options.enable_comprehension = false;
19+
options.enable_regex = true;
20+
options.regex_max_program_size = 100;
21+
options.enable_string_conversion = false;
22+
options.enable_string_concat = false;
23+
options.enable_list_concat = false;
1924

25+
// Enable constant folding (performance optimization)
2026
if (arena != nullptr) {
2127
options.constant_folding = true;
2228
options.constant_arena = arena;
2329
}
2430

2531
auto builder = google::api::expr::runtime::CreateCelExpressionBuilder(options);
2632
auto register_status =
27-
google::api::expr::runtime::RegisterBuiltinFunctions(builder->GetRegistry());
33+
google::api::expr::runtime::RegisterBuiltinFunctions(builder->GetRegistry(), options);
2834
if (!register_status.ok()) {
2935
throw EnvoyException(
3036
absl::StrCat("failed to register built-in functions: ", register_status.message()));

test/extensions/filters/common/expr/context_test.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ TEST(Context, ConnectionAttributes) {
257257
std::shared_ptr<NiceMock<Envoy::Upstream::MockHostDescription>> upstream_host(
258258
new NiceMock<Envoy::Upstream::MockHostDescription>());
259259
auto downstream_ssl_info = std::make_shared<NiceMock<Ssl::MockConnectionInfo>>();
260-
auto upstream_ssl_info = std::make_shared<NiceMock<Ssl::MockConnectionInfo>>();
261260
ConnectionWrapper connection(info);
262261
UpstreamWrapper upstream(info);
263262
PeerWrapper source(info, false);
@@ -273,11 +272,9 @@ TEST(Context, ConnectionAttributes) {
273272
EXPECT_CALL(info, downstreamLocalAddress()).WillRepeatedly(ReturnRef(local));
274273
EXPECT_CALL(info, downstreamRemoteAddress()).WillRepeatedly(ReturnRef(remote));
275274
EXPECT_CALL(info, downstreamSslConnection()).WillRepeatedly(Return(downstream_ssl_info));
276-
EXPECT_CALL(info, upstreamSslConnection()).WillRepeatedly(Return(upstream_ssl_info));
277275
EXPECT_CALL(info, upstreamHost()).WillRepeatedly(Return(upstream_host));
278276
EXPECT_CALL(info, requestedServerName()).WillRepeatedly(ReturnRef(sni_name));
279277
EXPECT_CALL(*downstream_ssl_info, peerCertificatePresented()).WillRepeatedly(Return(true));
280-
EXPECT_CALL(*upstream_ssl_info, peerCertificatePresented()).WillRepeatedly(Return(true));
281278
const std::string tls_version = "TLSv1";
282279
EXPECT_CALL(*downstream_ssl_info, tlsVersion()).WillRepeatedly(ReturnRef(tls_version));
283280
EXPECT_CALL(*upstream_host, address()).WillRepeatedly(Return(upstream_address));
@@ -344,13 +341,6 @@ TEST(Context, ConnectionAttributes) {
344341
EXPECT_EQ(679, value.value().Int64OrDie());
345342
}
346343

347-
{
348-
auto value = upstream[CelValue::CreateString(MTLS)];
349-
EXPECT_TRUE(value.has_value());
350-
ASSERT_TRUE(value.value().IsBool());
351-
EXPECT_TRUE(value.value().BoolOrDie());
352-
}
353-
354344
{
355345
auto value = connection[CelValue::CreateString(MTLS)];
356346
EXPECT_TRUE(value.has_value());

0 commit comments

Comments
 (0)