envoyproxy / envoy

Cloud-native high-performance edge/middle/service proxy
https://www.envoyproxy.io
Apache License 2.0
24.72k stars 4.75k forks source link

Issue: Boolean Values Interpreted as 1/0 in RTDS Configuration #35762

Open gordon-wang-lyft opened 4 weeks ago

gordon-wang-lyft commented 4 weeks ago

If you are reporting any crash or any potential security issue, do not open an issue in this repo. Please report the issue via emailing envoy-security@googlegroups.com where the issue will be triaged appropriately.

Title: Issue: Boolean Values Interpreted as 1/0 in RTDS Configuration

Description:

While working with the Envoy Runtime Discovery Service (RTDS), I encountered an issue where boolean values (bool_value:true/false) in the RTDS configuration are being interpreted as 1/0 instead of true/false when processed by Envoy.

Repro steps:

  1. Configure RTDS with a boolean value, e.g., (fields:{key:"envoy.features.http2_use_oghttp2" value:{bool_value:true}}).
  2. Observe the processed configuration in Envoy, where the boolean is represented as 1 instead of true. See the following section for detailed output

Admin and Stats Output:

There is not specific admin output. While when query the 9901/runtime we do obtain the mis-interpreted value:

curl -s 0:9901/runtime | grep -A10 oghttp2
"envoy.features.http2_use_oghttp2": {
"final_value": 1,
"layer_values": [
"false",
1,
""
]
},

Config:

Envoy Version: this bug still exists after we upgraded Envoy to 1.30

Expected Behavior:

The boolean values in the RTDS configuration should be preserved as true/false when processed by Envoy.

Actual Behavior: The boolean values are being converted to 1/0 in the final layer configuration seen by the Envoy sidecar.

Additional Context:

  1. This issue could lead to unexpected behavior in features relying on boolean flags.
  2. The problem seems to stem from how RTDS handles the protobuf message type for booleans, converting them to integers in the final config.
milton0825 commented 4 weeks ago

@alyssawilk

alyssawilk commented 1 week ago

any chance you can dump an actual RTDS update? My guess is you're sending the value "true" in quotes at which point it'd be parsed as a string not a boolean

milton0825 commented 1 week ago

@gordon-wang-lyft was able to reproduce this issue in a unit test and is working on a patch.

gordon-wang-lyft commented 1 week ago

Thanks, @alyssawilk! We are sending boolean true or false instead of string "true" and "false".

We performed a dump of an actual RTDS update with a boolean value and observed the same result. We identified the root cause:

Regarding the suggestion to use "true" and "false" strings, our preference is to avoid this. Envoy's direction, as per issue #27434, is to pass correct data types directly instead of using strings for booleans and numbers. We’ve already adapted our implementation to pass in booleans directly, aligning with this approach.

Since true and false are initially loaded correctly as strings, onConfigUpdate should maintain that format rather than convert them to "0" and "1". I will create a PR to address this behavior and update the ticket accordingly.

gordon-wang-lyft commented 1 week ago

https://github.com/envoyproxy/envoy/pull/36044