Skip to content

protobuf: allow relaxed opaque message with no properties#17122

Merged
htuch merged 3 commits intoenvoyproxy:mainfrom
Shikugawa:fix-config-dump
Jul 9, 2021
Merged

protobuf: allow relaxed opaque message with no properties#17122
htuch merged 3 commits intoenvoyproxy:mainfrom
Shikugawa:fix-config-dump

Conversation

@Shikugawa
Copy link
Copy Markdown
Member

Signed-off-by: Shikugawa rei@tetrate.io

Commit Message: I faced a crash while opening config_dump.

[2021-06-24 14:48:48.771][934895][critical][assert] [source/common/protobuf/utility.cc:778] assert failure: type_url_field_descriptor != nullptr && value_field_descriptor != nullptr && reflection->HasField(*message, type_url_field_descriptor).

It is because we passed opaque message without any properties as follows.

- name: envoy.filters.http.router
  typed_config: {}

We can avoid this crash with providing as follows

- name: envoy.filters.http.router
  typed_config:
    "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

But, initial way should be accepted even if config_dump because Envoy accepts it while bootstrap.
This PR fixes to accept relaxed opaque type and avoid crash with it.

Additional Description:
Risk Level: Low
Testing: Unit
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Deprecated:]
[Optional API Considerations:]

Signed-off-by: Shikugawa <rei@tetrate.io>
@Shikugawa Shikugawa requested a review from htuch June 24, 2021 07:13
@Shikugawa Shikugawa changed the title protobuf: fix insignificant assertion on message redact protobuf: allow relaxed opaque message with no properties Jun 24, 2021
TEST_F(ProtobufUtilityTest, RedactEmptyTypeUrlTypedStruct) {
udpa::type::v1::TypedStruct actual;
MessageUtil::redact(actual);
udpa::type::v1::TypedStruct expected = actual;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and the test below: expected gets a copy of actual after it's been (potentially) modified by the call to MessageUtil::redact. The equality comparison on the next line will always return true in this case. You probably want to reverse the order of lines 1006 and 1007? I think the return value of MessageUtil::redact should be verified too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah sorry. I overlooked.

@htuch
Copy link
Copy Markdown
Member

htuch commented Jun 25, 2021

Did you consider having Envoy just reject these invalid configs? CC @phlax who I know was looking at this recently (maybe same conversation?)

@phlax
Copy link
Copy Markdown
Member

phlax commented Jun 25, 2021

passing

- name: envoy.filters.http.router
  typed_config: {}

should work as i understand - so if its not working somewhere - like other than bootstrap - then probs a good idea to fix

in lots of config around the repo that previously had this, it has been replaced with just:

- name: envoy.filters.http.router

or similar i think for other fields - which i understood to work the same

@phlax
Copy link
Copy Markdown
Member

phlax commented Jun 25, 2021

Did you consider having Envoy just reject these invalid configs?

i think if we do that we need to deprecate as a ~large chunk of the demo/example/docs configs have had this for quite some time so its likely to have been used in production configs etc

@phlax
Copy link
Copy Markdown
Member

phlax commented Jun 25, 2021

related pr is here #17065

@Shikugawa
Copy link
Copy Markdown
Member Author

Did you consider having Envoy just reject these invalid configs?

i think if we do that we need to deprecate as a ~large chunk of the demo/example/docs configs have had this for quite some time so its likely to have been used in production configs etc

+1. But I think that we can reject empty value on next major API version during bootstrap.

@htuch
Copy link
Copy Markdown
Member

htuch commented Jun 27, 2021

passing

- name: envoy.filters.http.router
  typed_config: {}

So, there are two things:

  1. This is allowed as a legacy mechanism. We are pushing to avoid people relying on special names for filters to convey types and to use type URLs instead. This allows, for example, multiple filters of the same type in a single filter chain.
  2. In the interest of not breaking the world, I think we can continue to allow these. I don't see the harm, but would prefer we encourage the new style where possible, and in particular, never add special purpose hacks for advanced use cases around these names (e.g. multiple filters per chain, overrides, etc.)

Signed-off-by: Shikugawa <rei@tetrate.io>
}
if (!reflection->HasField(*message, type_url_field_descriptor) ||
!reflection->HasField(*message, value_field_descriptor)) {
return false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this case covered in test?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added value exists but type_url not exists on typed_struct

Signed-off-by: Shikugawa <rei@tetrate.io>
@Shikugawa
Copy link
Copy Markdown
Member Author

@htuch friendly ping

Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@htuch htuch merged commit 29ef851 into envoyproxy:main Jul 9, 2021
@Shikugawa Shikugawa deleted the fix-config-dump branch July 9, 2021 01:35
leyao-daily pushed a commit to leyao-daily/envoy that referenced this pull request Sep 30, 2021
…#17122)

I faced a crash while opening config_dump.

[2021-06-24 14:48:48.771][934895][critical][assert] [source/common/protobuf/utility.cc:778] assert failure: type_url_field_descriptor != nullptr && value_field_descriptor != nullptr && reflection->HasField(*message, type_url_field_descriptor).
It is because we passed opaque message without any properties as follows.

- name: envoy.filters.http.router
  typed_config: {}
We can avoid this crash with providing as follows

- name: envoy.filters.http.router
  typed_config:
    "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
But, initial way should be accepted even if config_dump because Envoy accepts it while bootstrap.
This PR fixes to accept relaxed opaque type and avoid crash with it.

Additional Description:
Risk Level: Low
Testing: Unit

Signed-off-by: Shikugawa <rei@tetrate.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants