3个版本 (破坏性更新)

0.4.0 2022年2月1日
0.2.0 2022年1月11日
0.1.0 2022年1月10日

#envoy中排名6

Apache-2.0

6.5MB
121K SLoC

Bazel 86K SLoC // 0.1% comments Go 26K SLoC // 0.1% comments Python 4K SLoC // 0.2% comments Rust 2K SLoC // 0.0% comments Java 1.5K SLoC // 0.2% comments Ruby 537 SLoC // 0.1% comments C++ 372 SLoC // 0.1% comments Shell 303 SLoC // 0.3% comments Batch 61 SLoC Forge Config 33 SLoC // 0.2% comments PowerShell 4 SLoC // 0.3% comments

包含 (JAR文件, 55KB) gradle-wrapper.jar

envoy-control-plane for Rust

此包通过prost公开了Envoy xDS协议和gRPC服务。它还允许将JSON和YAML引导文件读取到prost生成的结构体中,例如,如果您有一个包含以下内容的bootstrap.yaml

---
admin:
  address:
    socketAddress:
      address: "127.0.0.1"
      portValue: 9901
node:
  id: envoy-test-1
  cluster: envoy-test-cluster-1
staticResources:
  listeners:
    - name: server-1
      address:
        socketAddress:
          address: 127.0.0.1
          portValue: 9000
      filterChains:
        - filters:
          - name: envoy.filters.network.http_connection_manager
            typedConfig:
              "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
              statPrefix: ingress_http
              httpFilters:
                - name: envoy.filters.http.router
              routeConfig:
                name: local_route
                virtualHosts:
                  - name: local_service
                    domains: ["*"]
                    routes:
                      - match:
                          prefix: "/"
                        route:
                          cluster: local-srv
          transportSocket:
            name: envoy.transport_sockets.tls
            typedConfig:
              '@type': type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext
              requireClientCertificate:
                value: true
              commonTlsContext:
                tlsParams:
                  tlsMinimumProtocolVersion: TLSv1_3
                  tlsMaximumProtocolVersion: TLSv1_3
                validationContext:
                  trustedCa:
                    filename: ./certs/ca.crt
                  matchTypedSubjectAltNames:
                    - sanType: DNS
                      matcher:
                        exact: client.test
                tlsCertificates:
                  - certificateChain:
                      filename: ./certs/server.test.ecdsa-p256.crt
                    privateKey:
                      filename: ./certs/server.test.ecdsa-p256.key
  clusters:
    - name: local-srv
      type: STATIC
      lbPolicy: ROUND_ROBIN
      loadAssignment:
        clusterName: local-srv
        endpoints:
          - lbEndpoints:
            - endpoint:
                address:
                  socketAddress:
                    address: "127.0.0.1"
                    portValue: 9110

您可以使用以下方式读取该引导配置:

use envoy_control_plane::envoy::config::bootstrap::v3::Bootstrap;

let config_contents = read_all(&args.config_path).await?;
let config_ext = args.config_path.extension().unwrap_or_default();
let bootstrap: Bootstrap = if config_ext == "yaml" || config_ext == "yml" {
    eprintln!("WARNING: YAML support is incomplete (e.g. durations don't work)");
    serde_yaml::from_str(&config_contents)?
} else {
    serde_json::from_str(&config_contents)?
};

Envoy使用大量的protobuf Any值来实现多态性。如您所见,我们已从磁盘正确读取它们,但为了实际访问类型化的实例,还需要跳过一个额外的障碍

let downstream_tls_context_type_url = DownstreamTlsContext::default().type_url();

// this works for the bootstrap config above, but real code wouldn't hardcode pulling
// the value out in such a fragile way.
let bootstrap_tls_config = bootstrap
    .static_resources
    .as_ref()
    .unwrap()
    .listeners[0]
    .filter_chains[0]
    .transport_socket
    .as_ref()
    .unwrap()
    .config_type
    .as_ref()
    .unwrap();
// there are not other `ConfigType` enum variants, so this let works fine.
let ConfigType::TypedConfig(tls_any) = bootstrap_tls_config;
// because the `TypedConfig` is `Any`, we need to check the type_url
if &tls_any.type_url == downstream_tls_context_type_url {
    let ctx = DownstreamTlsContext::decode(&*tls_any.value).unwrap();
    // store or do something with the `DownstreamTlsContext` instance
} else {
    panic!("unsupported typed config: {}", &tls_any.type_url);
}

注意事项

  • Envoy对JSON/YAML的支持允许字段名称同时使用camelCase和snake_case,但我们只支持snake_case(例如lbPolicy而不是lb_policy)。
  • 我们使用pbjson的修改版本来正确读取JSON/YAML中的Any值。

许可证

此包中的代码可在Apache 2.0许可证下使用,如LICENSE文件中所述。Envoy本身(及其API协议)也受Apache 2.0许可证的约束。

依赖项

~3–14MB
~167K SLoC