#GRPC server requires TLS connection? Why?

14 messages · Page 1 of 1 (latest)

orchid thistle
#

Go code

package main

import (
    "context"
    "fmt"
    grpc_server_grpc "github.com/exapsy/grpc_server/proto"
    "google.golang.org/grpc"
    "net"
)

type HelloWorldService struct {
    grpc_server_grpc.UnimplementedHelloWorldServer
}

func (HelloWorldService) SayHello(_ context.Context, in *grpc_server_grpc.HelloWorldReq) (*grpc_server_grpc.HelloWorldRes, error) {
    return &grpc_server_grpc.HelloWorldRes{
        Name: "Hello " + in.Name,
    }, nil
}

func main() {
    var server *grpc.Server
    var serverOptions []grpc.ServerOption

    server = grpc.NewServer(serverOptions...)
    server.RegisterService(&grpc_server_grpc.HelloWorld_ServiceDesc, HelloWorldService{})

    addr := "localhost:8008"
    lis, err := net.Listen("tcp", addr)
    if err != nil {
        panic(fmt.Errorf("failed to listen: %v", err))
    }

    fmt.Printf("serving grpc server at %s\n", addr)
    err = server.Serve(lis)
    if err != nil {
        panic(fmt.Sprintf("failed to serve: %v", err))
    }
}

Command

$ grpcurl -insecure 127.0.0.1:8080 HelloWorld/SayHello

Failed to dial target host "127.0.0.1:8080": tls: first record does not look like a TLS handshake
orchid thistle
#

I just read the documentation of grpc.Server.ServeHTTP
and it says

ServeHTTP implements the Go standard library's http.Handler interface by responding to the gRPC request r, by looking up the requested gRPC method in the gRPC server s.
The provided HTTP request must have arrived on an HTTP/2 connection. When using the Go standard library's server, practically this means that the Request must also have arrived over TLS.
So probably it means it's a limitation of the Golang standard library? Even though I'm not using ServeHTTP I think a tcp connection over Golang's Standard Lib probably has the same limitation.

urban juniper
#

I think you want -plaintext

#

That serveHTTP function is certainly interesting. although you are not using it

orchid thistle
orchid thistle
orchid thistle
urban juniper
#

yes

orchid thistle
#

its also interesting that when I write insecure and plaintext it says that those two are mutually exclusive. how so huh

urban juniper
#

yes, insecure is TLS with no cert verification and plaintext is just no TLS

orchid thistle
#

aha I see, so it's still TLS, but without certs.
it seems to me that plaintext does require a ServeHTTP? Or is it supposed to work with a clean tcp listener?

#

with the code above I got

$ grpcurl -plaintext 127.0.0.1:8080 HelloWorld/SayHello                         
                                           
Failed to dial target host "127.0.0.1:8080": context deadline exceeded
#

can't see why exactly, if I recall that is supposed to work.

#

in any case @urban juniper thanx folk! that actually made sense and at least I have a lead now. I had no idea -plaintext was used for this so didnt read much into it.