Giter VIP home page Giter VIP logo

grpc-ziti-starter's Introduction

OpenZiti gRPC Project Template

Use this project to quickly start your next gRPC project that uses open-source, secure, zero-trust OpenZiti Network.

This project shows how to use your own net.Conn and net.Listener implementations to override networking layer in golang gRPC communications.

Start

Create your project's repo using this one as a template.

Try it

  • Get yourself an OpenZiti network:
  • Create a Ziti service to use for gRPC.
  • Create, and enroll you server and client identities
  • Run it! See below:
    • 'grpc-service' - name of the service
    • 'client.json' - name of client identity file
    • 'server.json' - name of server identity file

Run server:

$ go run ./server -identity server.json -service grpc-service
2022/09/14 14:27:17 server listening at grpc-service
...

Note: the server is powered by OpenZiti network and does not have any inbound ports open

Run client:

$ go run ./client -identity client.json -service grpc-service -what-is foo
2022/09/14 14:29:32 Answer: I don't know what foo is :(

$ go run ./client -identity client.json -service grpc-service -what-is ziti
2022/09/14 14:29:56 Answer: ziti is a type of pasta

Next Steps

  • design and implement your gRPC API
    • modify protocol/starter.proto to fit your needs
    • generate Golang code for the protocol: $ protoc --go_out=plugins=grpc:. ./protocol/starter.proto
    • make changes in server/ package to implement your API
    • make changes in client/ package to use your new API
  • deploy your server on your production OpenZiti network
  • profit!!

How it's done

In this project we use google.golang.com/grpc.

Server

We start gRPC server with Ziti listener.

This is all is needed to zitify gRPC server (error handling is stripped for brevity):

// bootstrap Ziti
ztx := ziti.NewContextWithConfig(cfg)
_ = ztx.Authenticate()
lis, _ := ztx.Listen(*service)

// standard gRCP init
s := grpc.NewServer()
protocol.RegisterAnswerServiceServer(s, &server{})

// serve using Ziti server connection
_ = s.Serve(lis)

Client

We create gRPC client with Ziti connection, like this

// bootstrap Ziti
ztx := ziti.NewContextWithConfig(cfg)
_ = ztx.Authenticate()

// Provide Ziti Dialer to connect to ziti service
conn, err := grpc.Dial(*service,
     grpc.WithTransportCredentials(insecure.NewCredentials()),
     grpc.WithContextDialer(func(ctx context.Context, s string) (net.Conn, error) {
              return ztx.Dial(s)
     }),
)

// create client
c := protocol.NewAnswerServiceClient(conn)

Have questions?

grpc-ziti-starter's People

Contributors

dovholuknf avatar ekoby avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

qrkourier

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.