Code Monkey home page Code Monkey logo

grpc-tls's Introduction

gRPC TLS testing

Basic service to retrive user names based on their ID. This is just for TLS testing purposes.

Run

  • Server

    make run-server
  • Client

You need to provide an ID which is the id of the user we want to retrieve from the Server, for example export ID=1.

  1. Connect using the cert the Server provides during the TLS Handshake without verifying it.

    make run-client
  2. Connect using the cert the Server provides during the TLS Handshake and verify it.

    make run-client-noca
  3. Connect using the cert the Server provides during the TLS Handshake and verify it with a CA cert file provided.

    make run-client-ca
  4. Connect using a cert provided at runtime.

    make run-client-file
  • Help

    make

Generating TSL Certificates

You need these before running the examples. To create them run make cert. The certificates are valid for a year (-days 365). Below the step by step, for your reference.

  • CA Signed certificates
  1. Create Root signing Key

    openssl genrsa -out ca.key 4096
  2. Generate self-signed Root certificate

    openssl req -new -x509 -key ca.key -sha256 -subj "/C=US/ST=NJ/O=CA, Inc." -days 365 -out ca.cert
  3. Create a Key certificate for your service

    openssl genrsa -out service.key 4096
  4. Create signing CSR

    For local testing you can use '/CN=localhost'. For Online testing CN needs to be replaced with your gRPC Server, for example: '/CN=grpc.nleiva.com'. Include this in a config file (certificate.conf).

    openssl req -new -key service.key -out service.csr -config certificate.conf
  5. Generate a certificate for the service

    openssl x509 -req -in service.csr -CA ca.cert -CAkey ca.key -CAcreateserial -out service.pem -days 365 -sha256 -extfile certificate.conf -extensions req_ext
  6. Verify

    openssl x509 -in service.pem -text -noout

Vault and Certify

See vault-cert.md for setup details.

  • Server

    make run-server-vault
  • Client

    export CAFILE="ca-vault.cert"
    make run-client-ca

You need to provide an ID which is the id of the user we want to retrieve from the Server, for example export ID=1. Also, the name of the Vault's CA certificate file as CAFILE.

Running in Docker Containers

Build Docker images with make docker-build. You need to provide HOST and PORT as enviromental variables.

export HOST=grpc.nleiva.com
export PORT=443
  • Run the Docker Client image. Provide any ID.

    export ID=1
    make run-docker-client
  • Run the Docker Server image

    make run-docker-server

Compiling protocol buffers

Run make proto.

grpc-tls's People

Contributors

nleiva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

grpc-tls's Issues

client fails to run inside docker

The main README.md has instructions for how to run the server and client inside docker. When I follow these instructions, I can start the server fine:

$ export HOST=grpc.nleiva.com
$ export PORT=443
$ make docker-build
...
$ make run-docker-server
docker run -t --rm \
        --name my-server \
        --publish=443:443 \
        server
level=info time=2020-09-17T17:52:10.762406133Z caller=main.go:206 msg="Server listening" port=443
level=info time=2020-09-17T17:52:10.76250748Z caller=main.go:209 msg="Starting gRPC services"
level=info time=2020-09-17T17:52:10.762551842Z caller=main.go:212 msg="Listening for incoming connections"

But in another shell, when I run the client in docker, it fails

$ export HOST=grpc.nleiva.com
$ export PORT=443
$ export ID=1
$ make run-docker-client
docker run -t --rm --name my-client -e 1 client
2020/09/17 17:53:57 HOST environment variable not set.
panic: HOST environment variable not set.

goroutine 1 [running]:
log.Panicf(0x8dff0b, 0x20, 0xc0000a3f10, 0x1, 0x1)
        /usr/local/go/src/log/log.go:340 +0xc0
main.getenv(0x8d0f0e, 0x4, 0x10, 0xc0000e8100)
        /go/src/github.com/nleiva/grpc-tls/client/main.go:32 +0xd1
main.init.ializers()
        /go/src/github.com/nleiva/grpc-tls/client/main.go:24 +0x3a
Makefile:39: recipe for target 'run-docker-client' failed
make: *** [run-docker-client] Error 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.