Skip to content
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

Remove RapidJSON from Envoy #4705

Closed
htuch opened this issue Oct 12, 2018 · 38 comments · Fixed by #14467
Closed

Remove RapidJSON from Envoy #4705

htuch opened this issue Oct 12, 2018 · 38 comments · Fixed by #14467

Comments

@htuch
Copy link
Member

htuch commented Oct 12, 2018

Now that v1 has been officially deprecated and is on track for removal in the near future, we shouldn't need RapidJSON anymore. All JSON parsing and printing should be possible via the protobuf library. This will simplify dependencies and reduce the trusted compute base.

@htuch htuch self-assigned this Oct 12, 2018
@htuch
Copy link
Member Author

htuch commented Oct 12, 2018

@mattklein123 WDYT?

@htuch
Copy link
Member Author

htuch commented Oct 12, 2018

(CC @jmarantz who reminded me we can do this now ;) )

@mattklein123
Copy link
Member

Sure, though I'm not sure we want to start ripping anything out until we wait a bit and see if anyone complains about v1 being gone? (Note also that RapidJSON is used for v1 schema)

@lizan
Copy link
Member

lizan commented Oct 12, 2018

FWIW, JWT auth filter still use it.

@htuch
Copy link
Member Author

htuch commented Oct 12, 2018

@lizan I think any users can be converted fairly mechanically to using protobuf, since they can just switch to using Struct and then doing (de)serialization.

@htuch
Copy link
Member Author

htuch commented Oct 12, 2018

Also CC @aa-stripe in the context of #4693

@qiwzhang
Copy link
Contributor

In that case, I need to switch this repo: https://github.com/google/jwt_verify_lib
to use protobuf first before you can give ride of RapidJson

@htuch
Copy link
Member Author

htuch commented Oct 12, 2018

@qiwzhang ack. I think if we can at least try and avoid any new users of RapidJSON we can make this easier. @qiwzhang do you think it's reasonable to rewrite to using Struct + Protobuf<->JSON?

If this turns out to be too much of a pain, or there are other advantages of RapidJSON (better formatting, better error messages), we can stick with status quo.

@qiwzhang
Copy link
Contributor

I can try, it should not be that difficult.

@ramaraochavali
Copy link
Contributor

admin interface that displays stats in json format still uses it

@htuch
Copy link
Member Author

htuch commented Oct 15, 2018

@ramaraochavali yeah, but that should be possible to convert. I think everything internal to Envoy should not be a huge problem, it's more sticky with external deps though.

@stale
Copy link

stale bot commented Nov 14, 2018

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.

@stale stale bot added the stale stalebot believes this issue/PR has not been touched recently label Nov 14, 2018
@zuercher zuercher added the no stalebot Disables stalebot from closing an issue label Nov 14, 2018
@stale stale bot removed the stale stalebot believes this issue/PR has not been touched recently label Nov 14, 2018
@qiwzhang
Copy link
Contributor

qiwzhang commented Dec 2, 2018

#5181

This PR will remove rapidjson from jwt_verify_lib.

@derekargueta
Copy link
Member

Looks like the Zipkin tracer has become a user of RapidJSON as well
https://github.com/envoyproxy/envoy/blob/master/source/extensions/tracers/zipkin/zipkin_core_types.cc#L29

@htuch
Copy link
Member Author

htuch commented Sep 2, 2019

@yanavlasov any chance you can take a look at this? It's in the bucket of "reducing our external dependencies".

@mattklein123
Copy link
Member

FYI this will be much easier when all of the v1 code/schemas are deleted, which I think can finally happen once 1.12.0 is cut.

@yanavlasov
Copy link
Contributor

yanavlasov commented Sep 3, 2019 via email

@htuch
Copy link
Member Author

htuch commented Sep 3, 2019

@yanavlasov EOQ

@htuch
Copy link
Member Author

htuch commented Oct 25, 2019

An update on this. json_fuzz_test has discovered that RapidJSON can be easily caused to stack overflow as used today. Generally this isn't a concern, as we expect that control plane handling untrusted input should be sanitizing for this or be using gRPC/proto3. RapidJSON is used on the data path in places, specifically Dynamo and MongoDB extensions, the Envoy OSS security team has audited these and made the assessment that the only uses are in extensions where we expect the other parties to be effectively trusted, so we do not need to treat this as actionable. Nonetheless, we should move ahead with this to reduce any potential future security exploit potential here (e.g. someone parsing out a header value with RapidJSON in HCM).

It's not sufficient to switch RapidJSON to iterative parsing FWIW, since the Json Objects that we build can still overflow in some situations, e.g. destructors. We should definitely switch to protobuf, which has inbuilt (and configurable) recursion depth limits when parsing.

There should be no new uses of RapidJSON, or Json::Object, please keep this in mind during reviews @envoyproxy/maintainers @envoyproxy/security-team.

Once we cut 1.12.0 and v1 is gone, we can move forward with this.

@htuch
Copy link
Member Author

htuch commented Nov 4, 2019

Now that 1.12.0 has been cut, we can move ahead with this. @derekargueta are you planning to remove the remainder of the v1 JSON sites? That's probably the first step.

@derekargueta
Copy link
Member

@htuch done :)

@asraa
Copy link
Contributor

asraa commented Oct 22, 2020

But there seems to be a problem with the performance of protobuf, especially when doing some write operations or converting JSON.

Did rapidjson perform better than the current protobuf json parser for access logging? I would love to get rid of rapidjson as well. I think maybe improving json formatted access logging could be done orthogonally, it seems like protocol buffer json parsing is a little nitty with what is fast (e.g. ListValue's are slow).

Another high performance alternatives is the gRPC JSON parser, but I don't see any benchmarks for it online.

@lizan
Copy link
Member

lizan commented Oct 22, 2020

Another option would be https://github.com/nlohmann/json ? I remember @htuch said it has been tested internally?

@asraa
Copy link
Contributor

asraa commented Oct 22, 2020

Actually that would be the most ideal from our perspective!!
It has 100% test coverage, fuzzed in OSS-Fuzz, uses sanitizers for test, and is fast

@mattklein123
Copy link
Member

Given that we no longer use JSON schema, any of our JSON needs should be very simple, so I think any supported/fast library is fine!

@aa-stripe
Copy link
Contributor

I skimmed the nlohmann::json docs and that looks like it would work great. iirc the main reason we switched to using protobuf was a) to align with the rest of json handling in envoy code and b) because as long as we could fit the data into a valid proto struct, we were guaranteed to have valid data, good serialization etc.

But if we get these guarantees through another library as well, I'm all for it.

On a side note, it's lame that the qps drops so much when using json logging :(

@kyessenov
Copy link
Contributor

kyessenov commented Oct 22, 2020

Yes, nlohmann::json is approved for use within Google for parsing JSON. We chose it to parse config in Wasm (protobuf is too big for that purpose, and kind of slow).

@mattklein123
Copy link
Member

Sounds like a plan! I'm guessing it will be very straightforward to swap.

@htuch
Copy link
Member Author

htuch commented Oct 22, 2020

I'm in general agreement, but could someone walk through the formalities of answering the questions in https://github.com/envoyproxy/envoy/blob/master/DEPENDENCY_POLICY.md#new-external-dependencies? Since this is an new dependency, we'd like to make sure we walk through this checklist.

@htuch
Copy link
Member Author

htuch commented Oct 22, 2020

CC @moderation

@asraa
Copy link
Contributor

asraa commented Oct 23, 2020

Sure! I'll give it a shot.

Where this was lacking:

  • Generally only one maintainer and one recipient of the security vulnerabilities. Pros: seem very friendly, can probably clarify and ask.
  • No (?) contributor 2FA.

@htuch
Copy link
Member Author

htuch commented Oct 23, 2020

Thanks @asraa, that's really thorough. I think this scores relatively high on our criteria, @envoyproxy/dependency-shepherds WDYT?

@mattklein123
Copy link
Member

SGTM!

@moderation
Copy link
Contributor

SGTM too

@mattklein123 mattklein123 removed the no stalebot Disables stalebot from closing an issue label Jan 15, 2021
alyssawilk added a commit that referenced this issue Nov 8, 2021
We added the code to switch json libraries over in #14467
The removal is tracked by #4705 and smoke tested (#18451)

Risk Level: Medium for folks using json
Testing: n/a
Docs Changes: n/a
Release Notes: inline
Fixes #18451
Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
keith added a commit to keith/envoy that referenced this issue Feb 4, 2022
This has been replaced by nlohmann/json

envoyproxy#4705

Unfortunately this library cannot be removed entirely because it is used
by opencensus-cpp. We continue to load it here because upstream they do
not pin the dependency to a specific version, which could lead to random
failures as that library is updated upstream.

Signed-off-by: Keith Smiley <keithbsmiley@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.