Skip to content

Floating-point numbers in filter configuration does not get read correctly for dynamic modules and Go filters #45678

@HusseinKabbout

Description

@HusseinKabbout

Title: Floating-point numbers in filter configuration does not get read correctly for dynamic modules and Go filters

Description:
Dynamic modules (or Go Filters) must use type.googleapis.com/google.protobuf.Struct when configuring a filter. Example:

          http_filters:
          - name: myfilter
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.dynamic_modules.v3.DynamicModuleFilter
              dynamic_module_config:
                name: composer
                do_not_close: true
              filter_config:
                "@type": "type.googleapis.com/google.protobuf.Struct"
                value:
                  body:
                    maxSize: 5000
              filter_name: myfilter

The above config works only if maxSize is a integer type. However, the issue that I am observing here is that if maxSize is a floating-point number then Envoy will always read it as a string, see here.

Repro steps:

Assuming that we have the following config structure for a dynamic module:

type Config struct {
	Body           BodyConfig     `json:"body"`
}

type BodyConfig struct {
	MaxSize           *uint64 `json:"maxSize"`
}

and our filter factory looks like this:

func (p *filterConfigFactory) Create(handle shared.HttpFilterConfigHandle, unparsedConfig []byte) (shared.HttpFilterFactory, error) {
    config := &Config{}
	if err := json.Unmarshal(unparsedConfig, config); err != nil {
		return nil, err
	}
	return &filterFactory{config: config}, nil
}

Then the following config cannot be parsed because Envoy sees maxSize as a string:

          http_filters:
          - name: myfilter
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.dynamic_modules.v3.DynamicModuleFilter
              dynamic_module_config:
                name: composer
                do_not_close: true
              filter_config:
                "@type": "type.googleapis.com/google.protobuf.Struct"
                value:
                  body:
                    maxSize: 5000.0
              filter_name: myfilter

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtriageIssue requires triage

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions