Skip to content

proto validation: Cluster message should require "connect_timeout" field be set #16583

Closed

Description

@tonya11en

Cluster message should require "connect_timeout" instead of only checking the duration is greater-than 0.

Description

I'm not sure if this belongs here or in https://github.com/envoyproxy/protoc-gen-validate. Feel free to redirect me there if it's more appropriate

The Cluster message in cluster.proto does not require the connect_timeout field as part of the proto validation. It only requires it to be greater than the default duration (which I assume is 0):
https://github.com/envoyproxy/envoy/blob/main/api/envoy/config/cluster/v3/cluster.proto#L712

When dealing with Go-compiled Cluster messages that don't have the connect_timeout field set, we can call Validate() on them without error. This is because the generated code only cares so validate if the field has been set. It doesn't consider the default value since the duration is nil:

	if d := m.GetConnectTimeout(); d != nil {
		dur, err := ptypes.Duration(d)
		if err != nil {
			return ClusterValidationError{
				field:  "ConnectTimeout",
				reason: "value is not a valid duration",
				cause:  err,
			}
		}

		gt := time.Duration(0*time.Second + 0*time.Nanosecond)

		if dur <= gt {
			return ClusterValidationError{
				field:  "ConnectTimeout",
				reason: "value must be greater than 0s",
			}
		}

	}

This would be trivial to fix and I'm more than happy to just fire off the PR. I'm just not clear on the API implications and whether it would break anything.

Repro steps

I'm running a fairly recent main build:
./envoy_static version: 2026543d30272e816bd1b46d1e99d50b2212d80f/1.19.0-dev/Modified/DEBUG/BoringSSL

I can successfully validate the following static configuration with that binary:

static_resources:
  listeners:
  - name: listener_0
    address:
      socket_address:
        address: 0.0.0.0
        port_value: 10000
    filter_chains:
    - filters:

  clusters:
  - name: testing123
    type: LOGICAL_DNS
    connect_timeout: 1s
    load_assignment:
      cluster_name: service_envoyproxy_io
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: www.envoyproxy.io
                port_value: 443

With the following output:

[2021-05-19 21:13:03.586][124567][info][main] [source/server/server.cc:667] runtime: layers:
  - name: base
    static_layer:
      {}
  - name: admin
    admin_layer:
      {}
[2021-05-19 21:13:03.586][124567][info][config] [source/server/configuration_impl.cc:128] loading tracing configuration
[2021-05-19 21:13:03.586][124567][info][config] [source/server/configuration_impl.cc:88] loading 0 static secret(s)
[2021-05-19 21:13:03.586][124567][info][config] [source/server/configuration_impl.cc:94] loading 1 cluster(s)
[2021-05-19 21:13:03.592][124567][info][config] [source/server/configuration_impl.cc:98] loading 1 listener(s)
[2021-05-19 21:13:03.594][124567][info][config] [source/server/configuration_impl.cc:110] loading stats configuration
configuration 'good.yaml' OK

However, removing the connect_timeout field results in a failure to validate.

[txallen@dev-dsk-txallen-2a-95bb9472 ~]$ diff -u3 good.yaml bad.yaml
--- good.yaml	2021-05-19 21:13:00.416024933 +0000
+++ bad.yaml	2021-05-19 21:13:19.331503991 +0000
@@ -11,7 +11,6 @@
   clusters:
   - name: testing123
     type: LOGICAL_DNS
-    connect_timeout: 1s
     load_assignment:
       cluster_name: service_envoyproxy_io
       endpoints:
[txallen@dev-dsk-txallen-2a-95bb9472 ~]$ ./envoy_static --mode validate -c bad.yaml 
[2021-05-19 21:21:03.242][128680][info][main] [source/server/server.cc:667] runtime: layers:
  - name: base
    static_layer:
      {}
  - name: admin
    admin_layer:
      {}
[2021-05-19 21:21:03.243][128680][info][config] [source/server/configuration_impl.cc:128] loading tracing configuration
[2021-05-19 21:21:03.243][128680][info][config] [source/server/configuration_impl.cc:88] loading 0 static secret(s)
[2021-05-19 21:21:03.243][128680][info][config] [source/server/configuration_impl.cc:94] loading 1 cluster(s)
[2021-05-19 21:21:03.246][128680][critical][main] [source/server/config_validation/server.cc:62] error initializing configuration 'bad.yaml': Field 'connect_timeout' is missing in: name: "testing123"
type: LOGICAL_DNS
load_assignment {
  cluster_name: "service_envoyproxy_io"
  endpoints {
    lb_endpoints {
      endpoint {
        address {
          socket_address {
            address: "www.envoyproxy.io"
            port_value: 443
          }
        }
      }
    }
  }
}
183412668: "envoy.api.v2.Cluster"

Activity

  1. added
    triage
    on May 19, 2021
  2. phlax commented on May 19, 2021

    @phlax
    Member

    related #16453

  3. antoniovicente commented on May 20, 2021

    @antoniovicente
    Contributor

    The proposed fix is to add a default value. Previously reported in #16439

  4. removed
    triage
    on May 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions