envoy icon indicating copy to clipboard operation
envoy copied to clipboard

envoy google_grpc TLS seems not work

Open quanjielin opened this issue 8 years ago • 10 comments

Description: envoy google_grpc TLS seems not work

Repro steps: server is built on gRPC/go client is envoy built on gRPC/c++

Our scenario is envoy(client based on gRPC/C++) needs to send Google credentials(some GKE token) to server(based on gRPC/go) through UDS(unix domain socket).

Below is from envoy(client) side config

                grpc_services:
                - google_grpc:
                    stat_prefix: test
                    target_uri: unix:/var/run/sds/uds_path
                    channel_credentials:
                      ssl_credentials:
                        root_certs:
                          filename: /etc/istio/nodeagent-root-cert.pem

server side error

ransport: http2Server.HandleStreams failed to receive the preface from client: EOF"
2018-07-21T01:30:37.250966Z	info	grpc: Server.Serve failed to create ServerTransport: connection error: desc = "transport: http2Server.HandleStreams failed to receive the preface from client: EOF"
2018-07-21T01:31:42.641122Z	info	grpc: Server.Serve failed to create ServerTransport: connection error: desc = "transport: http2Server.HandleStreams failed to receive the preface from client: EOF

server side error is thrown from https://github.com/grpc/grpc-go/blob/11b582728a13ef54e14e4fa930d693de2e32420f/internal/transport/http2_server.go#L264

Notes -

  1. attached envoy log - envoy_grpc.log

  2. if I write a simple grpc client using go to setup channel cred(TLS), server side didn't see this error; looks like gRPC/go client takes care of clientPreface https://github.com/grpc/grpc-go/blob/11b582728a13ef54e14e4fa930d693de2e32420f/internal/transport/http2_client.go#L274

quanjielin avatar Jul 24 '18 00:07 quanjielin

/cc @qiwzhang @lizan @menghanl @PiotrSikora @htuch @wattli @yihuazhang

quanjielin avatar Jul 24 '18 00:07 quanjielin

@quanjielin can you attach your simple client 2.?

lizan avatar Jul 24 '18 00:07 lizan

I built it locally; client : https://github.com/istio/istio/blob/collab-gcp-identity/security/tools/sds/sds_cli.go with code bring back from security/tools/sds/sds_cli.go in https://github.com/istio/istio/pull/6990/files

quanjielin avatar Jul 24 '18 00:07 quanjielin

@quanjielin can you run with these env vars set and get a trace GRPC_TRACE=ssl,http GRPC_VERBOSITY=debug? I think this will tell us what happens at the wire level.

htuch avatar Jul 24 '18 01:07 htuch

@htuch I shared with you and @lizan my test env so that you could debug; I will pull the logs tomorrow after finishing something else.

quanjielin avatar Jul 24 '18 01:07 quanjielin

@quanjielin FWIW, we have an integration test in Envoy for ADS + Google gRPC + TLS, see https://github.com/envoyproxy/envoy/blob/master/test/integration/ads_integration_test.cc#L258. So, we know that at least the basics of this work. What we're trying to do here is understand why it's not working in this particular setup.

htuch avatar Jul 24 '18 02:07 htuch

@htuch thanks for the info, there maybe some env/setup issue, also gRPC/c++ -> gRPC/go may introduce some complexity.

  1. from the server error, seems ClientPreface is missing from the connection; does envoy/grpc c++ set this value ?
    // ClientPreface is the string that must be sent by new
    // connections from clients.
    ClientPreface = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"

btw I tried config like below(set alpn_protocols) still hit same error

     tls_context:
        common_tls_context:
          tls_certificate_sds_secret_configs:
          - name: "spiffe://cluster.local/ns/default/sa/default"
            sds_config:
              api_config_source:
                api_type: GRPC
                grpc_services:
                - google_grpc:
                    stat_prefix: test
                    target_uri: unix:/var/run/sds/uds_path
                    channel_credentials:
                      ssl_credentials:
                        root_certs:
                          filename: /etc/istio/nodeagent-root-cert.pem
                refresh_delay: 60s
          alpn_protocols:
          - h2
            http/1.1
  1. I've set env variables in envoy container and attached logs; let me know if it's good enough
root@envoy-65675f8f54-bwknn:/# echo $GRPC_TRACE
ssl,http
root@envoy-65675f8f54-bwknn:/# export GRPC_VERBOSITY=debug
root@envoy-65675f8f54-bwknn:/# echo $GRPC_VERBOSITY
debug

envoy_grpc_1.log

quanjielin avatar Jul 24 '18 02:07 quanjielin

Not seeing the gRPC trace in the logs; I wonder if they are somewhere else, like stderr. BTW, I don't think we've ever validated Google gRPC with Unix Domain Sockets, so there could be some fun surprises there.

htuch avatar Jul 24 '18 02:07 htuch

repro in my local env, from logs looks like it's related to the cert; will dig into more

https://github.com/grpc/grpc/blob/master/src/core/lib/security/security_connector/security_connector.cc#L873

[2018-07-24 10:01:47.032][92863][trace][upstream] external/envoy/source/common/config/grpc_mux_impl.cc:84] Sending DiscoveryRequest for type.googleapis.com/envoy.api.v2.auth.Secret: node {
  id: "front-proxy"
  cluster: "front-proxy"
  build_version: "0/1.8.0-dev//DEBUG"
}
resource_names: "spiffe://cluster.local/ns/default/sa/default"
type_url: "type.googleapis.com/envoy.api.v2.auth.Secret"

[2018-07-24 10:01:47.033][92863][trace][grpc] external/envoy/source/common/grpc/google_async_client_impl.cc:190] Queued message to write (140 bytes)
I0724 10:01:47.421525370   92865 subchannel.cc:425]          Failed to connect to channel, retrying
E0724 10:01:47.432218859   92866 ssl_transport_security.cc:269] Could not get common name of subject from certificate.
D0724 10:01:47.432440359   92866 security_handshaker.cc:129] Security handshake failed: {"created":"@1532451707.432419515","description":"Peer name localhost is not in peer certificate","file":"external/com_github_grpc_grpc/src/core/lib/security/security_connector/security_connector.cc","file_line":868}
I0724 10:01:47.432578668   92866 subchannel.cc:646]          Connect failed: {"created":"@1532451707.432419515","description":"Peer name localhost is not in peer certificate","file":"external/com_github_grpc_grpc/src/core/lib/security/security_connector/security_connector.cc","file_line":868}
I0724 10:01:47.432610918   92866 subchannel.cc:470]          Subchannel 0x46ef680: Retry in 1275 milliseconds
[2018-07-24 10:01:47.432][92866][trace][grpc] external/envoy/source/common/grpc/google_async_client_impl.cc:46] completionThread CQ event 0 false
[2018-07-24 10:01:47.432][92863][trace][grpc] external/envoy/source/common/grpc/google_async_client_impl.cc:239] handleOpCompletion op=0 ok=false inflight=1
[2018-07-24 10:01:47.432][92863][debug][grpc] external/envoy/source/common/grpc/google_async_client_impl.cc:180] notifyRemoteClose 13 

quanjielin avatar Jul 24 '18 17:07 quanjielin

Server side could receive request through TLS after regenerating certs below, close this issue.

One remaining questions is how to generate cert in server in GKE env (dynamically DNS, IP, etc); Anyway TLS is workaround, eventually we will get rid of certs after local_credentials is ready to use( @yihuazhang and @qiwzhang are working on) /cc @wenchenglu

        X509v3 extensions:
            X509v3 Key Usage: critical
                Digital Signature, Key Encipherment
            X509v3 Basic Constraints: critical
                CA:FALSE
            X509v3 Subject Alternative Name: 
                DNS:/tmp/uds_path, DNS:localhost

quanjielin avatar Jul 24 '18 17:07 quanjielin