• Stars
    star
    462
  • Rank 92,666 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Automatic client and server certificate distribution and maintenance

Certify

CircleCI GoDoc Go Report Card Code Coverage Releases License Join the chat at https://gitter.im/go-certify/community

Certify

Certify allows easy automatic certificate distribution and maintenance. Certificates are requested as TLS connections are made, courtesy of the GetCertificate and GetClientCertificate tls.Config hooks. Certificates are optionally cached. Simultaneous requests are deduplicated to minimize pressure on issuers.

Vault walkthrough

My presentation from GolangPiter 2019 contains a walkthrough of how to configure your Vault instance to securely issue certificates for your Go clients and servers.

Certify presentation

Users

Are you using Certify and want to be visible here? Open an issue!

Issuers

Certify exposes an Issuer interface which is used to allow switching between issuer backends.

Currently implemented issuers:

Usage

Create an issuer:

issuer := &vault.Issuer{
    URL: &url.URL{
        Scheme: "https",
        Host: "my-local-vault-instance.com",
    },
    Token:     "myVaultToken",
    Role:      "myVaultRole",
}

Create a Certify:

c := &certify.Certify{
    // Used when request client-side certificates and
    // added to SANs or IPSANs depending on format.
    CommonName: "MyServer.com",
    Issuer: issuer,
    // It is recommended to use a cache.
    Cache: certify.NewMemCache(),
    // It is recommended to set RenewBefore.
    // Refresh cached certificates when < 24H left before expiry.
    RenewBefore: 24*time.Hour,
}

Use in your TLS Config:

tlsConfig := &tls.Config{
    GetCertificate: c.GetCertificate,
}

That's it! Both server-side and client-side certificates can be generated:

tlsConfig := &tls.Config{
    GetClientCertificate: c.GetClientCertificate,
}

For an end-to-end example using gRPC with mutual TLS authentication, see the Vault tests.

Vault PKI Key Types

When setting up a Vault PKI backend and creating a role for Certify to use when it requests certificates, you'll be asked to specify the key type for the role to use. By default, Certify uses ecdsa keys with a 256-bit key length when it generates CSRs for Vault to sign.

If your Vault PKI role is created with a key type other than ec or any, API calls to Vault will fail with errors like

Error making API request.

URL: PUT https://localhost:8200/v1/pki/sign/example.com
Code: 400. Errors:

* role requires keys of type rsa

To use Certify with rsa or ed25519 keys, you'll need to pass a custom KeyGenerator to Certify which satisfies the certify.KeyGenerator interface. For example, for an rsa key:

type rsaKeyGenerator struct {
    key crypto.PrivateKey
    err error
    o   sync.Once
}

// This satisfies the `certify.KeyGenerator` interface.
func (s *rsaKeyGenerator) Generate() (crypto.PrivateKey, error) {
    s.o.Do(func() {
        // Use a different random data provider and key length if required.
        s.key, s.err = rsa.GenerateKey(rand.Reader, 2048)
    })
    return s.key, s.err
}

// Configure Certify's CSR generator to use our custom KeyGenerator
cfg := &certify.CertConfig{
    KeyGenerator: &rsaKeyGenerator{},
}

certify := &certify.Certify{
    CommonName:  "service1.example.com",
    Cache:       certify.DirCache("certificates"),
    Issuer:      issuer,
    RenewBefore: 10 * time.Minute,
    // Pass our custom configuration to Certify
    CertConfig:  cfg,
}

Docker image (sidecar model)

If you really want to use Certify but you are not able to use Go, there is now a Docker image available!

Simply configure this image as the access point for your Kubernetes pod and let it proxy traffic to your server.

How does it work?

How it works

Certify hooks into the GetCertificate and GetClientCertificate methods of the Go TLS stack Config struct. These get called when the server/client respectively is required to present its certificate. If possible, this is fetched from the cache, based on the requested server name. If not, a new certificate is issued with the requested server name present. For client requests, the configured CommonName is used.

More Repositories

1

grpc-gateway-boilerplate

All the boilerplate you need to get started with writing grpc-gateway powered REST services in Go
Go
464
star
2

grpc-postgres

An example repo of how I like to use postgres with gRPC
Go
285
star
3

grpc-auth-example

Examples of client authentication with gRPC
Go
97
star
4

grpcweb-example

An example implementation of a GopherJS client and a Go server using the Improbable gRPC-Web implementation
Go
94
star
5

protobuf

GopherJS Bindings for ProtobufJS and gRPC-Web
Go
81
star
6

wasm-experiments

Go
63
star
7

grpc-web-compatibility-test

Test various implementations of gRPC-Web Clients with various implementations of gRPC-Web proxies
JavaScript
62
star
8

grpc-wasm

gRPC-Web implementation in Go, built using the WASM architecture target
Go
50
star
9

grpc-json-example

Example of using gRPC-Go with JSON as the transport encoding
Go
49
star
10

grpcweb-wasm-example

Small example server using gRPC-Web via the gRPC-Go WASM fork
JavaScript
47
star
11

grpcweb-boilerplate

A minimal repo containing all the boilerplate for getting started with GopherJS using gRPC-Web
Go
44
star
12

chunker

Small demo of a server splitting binary blobs into streamed chunks
Go
39
star
13

connect-gateway-example

Example of using the gRPC-Gateway with Connect
Go
26
star
14

gopherjs-grpc-websocket

An example implementation of bridging gRPC with a GopherJS frontend over Websockets
Go
25
star
15

grpc-web-go-react-example

Example of using Go and React/TypeScript with gRPC-Web
TypeScript
24
star
16

rust-grpc-web-wasm-test

Go
15
star
17

sortslice

Warn if user provides a non-slice to sort.Slice
Go
12
star
18

bazel-mono

Playing around with using Bazel for CI
Starlark
11
star
19

gogoproto-experiments

Testing various Go protobuf and gRPC packages with GoGoProtobuf
Go
9
star
20

redeploy

Simple application for redeploying containers when Docker hub webhooks are sent
Go
8
star
21

protoc-gen-gopherjs

This repo has moved
8
star
22

presentations

My presentations
Go
7
star
23

go-protobuf-plugin-versioning-example

An example of easy consistent versioning of Go based Protobuf plugins
Go
6
star
24

simple-grpc

Minimal gRPC example
Go
6
star
25

collapse-gitlab-files

A small userscript for collapsing all files on a GitLab merge request diffs page
JavaScript
5
star
26

concurrency

Concurrency example
Go
5
star
27

grpc-web-generators

Dockerfile for generating grpc-web protofiles.
Dockerfile
5
star
28

fetch

The Go http.Transport interface implemented over the WHATWG Fetch API
Go
5
star
29

gopherjs-grpc-web-example

Example implementation of a GopherJS gRPC-web client talking to a Go gRPC server
Go
4
star
30

blog

My blog
HTML
4
star
31

gopherjs-json

Convenience functions for interacting with JSON in GopherJS
Go
3
star
32

papers

Collection of talk proposals
3
star
33

cat-collection

JavaScript
3
star
34

hashipet

HashiPet API
Go
3
star
35

bomberman

A bomberman clone me and some friends from uni made as part of a C++ project
C++
2
star
36

chronic-pain-tracker

Tracks pain through the day
Go
2
star
37

rust-experiments

2
star
38

delete-gitlab-registry-tags

Simple userscript that adds a button to the GitLab registry page for mass tag deletion
JavaScript
2
star
39

aoc2019

Advent of Code 2019
Rust
2
star
40

grpcweb-presentation

Files for my presentation about my gRPC-Web bindings
Protocol Buffer
2
star
41

gopherjs-grpc-web

A GopherJS binding and generator for gRPC-web
JavaScript
2
star
42

rag-experiment

Go
2
star
43

templ-exp

1
star
44

websocket

Implementing Go interfaces in WASM using the Websockets API
1
star
45

buf-example

Using buf to develop APIs with protocol buffers
1
star
46

docker-go-protobuf

For building a simple Docker container with Go and Protobuf installed
1
star
47

moq-vendor-bug

Go
1
star
48

go-wazero-experimenting

Go
1
star
49

grpc-web

gRPC-Web implementation in Rust, targeting WebAssembly
1
star