{"id":16541943,"url":"https://github.com/itzg/grpc-authenticated-greeter","last_synced_at":"2025-07-27T18:15:05.190Z","repository":{"id":145317830,"uuid":"209389508","full_name":"itzg/grpc-authenticated-greeter","owner":"itzg","description":"Trying out authenticated gRPC communication with Go","archived":false,"fork":false,"pushed_at":"2019-09-19T18:50:43.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-01T21:50:03.792Z","etag":null,"topics":["golang","grpc","grpc-go","x509-auth"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itzg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-18T19:37:11.000Z","updated_at":"2024-06-19T07:59:01.692Z","dependencies_parsed_at":null,"dependency_job_id":"f576c69f-440b-463e-b174-1264b60e3c0d","html_url":"https://github.com/itzg/grpc-authenticated-greeter","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzg%2Fgrpc-authenticated-greeter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzg%2Fgrpc-authenticated-greeter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzg%2Fgrpc-authenticated-greeter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzg%2Fgrpc-authenticated-greeter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itzg","download_url":"https://codeload.github.com/itzg/grpc-authenticated-greeter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241794136,"owners_count":20021192,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","grpc","grpc-go","x509-auth"],"created_at":"2024-10-11T18:56:17.501Z","updated_at":"2025-03-04T06:09:52.855Z","avatar_url":"https://github.com/itzg.png","language":"Go","readme":"## Building\n\n```shell script\ngo build\n```\n\n## Example usage\n\nGenerate CA, server, and client certs\n```shell script\n./grpc-authenticated-greeter gencerts\n```\n\nStart the server on port 7676:\n```shell script\n./grpc-authenticated-greeter server \\\n  --ca ca_cert.pem --cert server_cert.pem --key server_key.pem \\\n  --binding :7676\n```\n\nIn another terminal, run a client:\n```shell script\n./grpc-authenticated-greeter client \\\n  --ca ca_cert.pem --cert client1_cert.pem --key client1_key.pem \\\n  --serveraddress 127.0.0.1:7676 --servername server \\\n  --message \"Read me\"\n```\n\nThe client should log the response from the server, such as:\n```\nINFO[0000] got response   response=\"Hello, client1. You said 'Read me'\"\n```\n\n## Re-generating protobuf/gRPC code\n\n[Follow these instructions](https://grpc.io/docs/quickstart/go/#install-protocol-buffers-v3) to install protoc and the grpc plugin.\n\nRun the following to regenerate the `*.pb.go` file, [protocol/HelloService.pb.go](protocol/HelloService.pb.go)\n\n```shell script\ngo generate ./...\n```\n\n## What I learned\n\n- [go-arg](https://github.com/alexflint/go-arg) is very cool! Just feed it a struct and it'll parse command line arguments. It's very flexible and intuitive. Even embedding common arguments into a \"command struct\" did what I expected\n```go\ntype ClientServerArgs struct {\n\tCa   string `arg:\"required\" help:\"PEM file containing the CA cert shared by server and clients\"`\n\tKey  string `arg:\"required\" help:\"PEM file containing private key\"`\n\tCert string `arg:\"required\" help:\"PEM file containing public certificate\"`\n}\n\ntype ServerCmd struct {\n\tClientServerArgs\n\tBinding string `arg:\"required\" help:\"host:port of server binding where host is optional\"`\n}\n```\n- Generating a self-signed CA cert and then signing client and server certs is quite doable in Go. Check out [certs/generate.go](certs/generate.go) to see how that's done\n- The authenticating client info is a little bit buried when implementing a server handler, but [peer.FromContext](https://godoc.org/google.golang.org/grpc/peer#FromContext) was the key to cracking that open. [server/server.go](server/server.go) is where that is used.\n- To do full [mTLS authentication](https://grpc.io/docs/guides/auth/), be sure to configure the server's TLS to require and verify the client cert:\n```go\n\ttransportCreds := credentials.NewTLS(\u0026tls.Config{\n\t\tCertificates: []tls.Certificate{cert},\n\t\tClientAuth:   tls.RequireAndVerifyClientCert,\n\t\tClientCAs:    clientCertPool,\n\t})\n```\n- The [Go package can be configured](https://github.com/golang/protobuf#packages-and-input-paths) for the code generated from the protobuf declarations. The following in [protocol/HelloService.proto](protocol/HelloService.proto) avoids the awkwardness of a package named for the proto file:\n```proto\noption go_package = \"protocol\";\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitzg%2Fgrpc-authenticated-greeter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitzg%2Fgrpc-authenticated-greeter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitzg%2Fgrpc-authenticated-greeter/lists"}