Documentation ¶
Overview ¶
Package dynamictls implements dynamic TLS configuration.
Index ¶
- func NewListener(inner net.Listener, config *Config) net.Listener
- type Config
- type Observer
- type Option
- func WithBase(config *tls.Config) Option
- func WithCertificate(certFile, keyFile string) Option
- func WithClientCAs(file string) Option
- func WithHTTP() Option
- func WithHTTP1() Option
- func WithHTTP2() Option
- func WithLogger(log logr.Logger) Option
- func WithObserver(observer Observer) Option
- func WithRootCAs(file string) Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
A Config is used to configure a TLS client or server.
func NewConfig ¶
NewConfig returns a new Config with the given options. It's an error if no dynamic file options are specified.
func (*Config) Config ¶
Config returns the latest TLS config. It is shared and must not be modified.
func (*Config) Dial ¶
Dial connects to the given network address and initiates a TLS handshake, returning the resulting TLS connection.
Example ¶
observer, err := tlsprom.NewObserver( tlsprom.WithHTTP(), tlsprom.WithClient(), ) check(err) prometheus.MustRegister(observer) cfg, err := dynamictls.NewConfig( dynamictls.WithObserver(observer), dynamictls.WithBase(&tls.Config{ MinVersion: tls.VersionTLS12, }), dynamictls.WithCertificate(certFile, keyFile), dynamictls.WithRootCAs(caFile), dynamictls.WithHTTP(), // NB: adds HTTP/2 and HTTP/1.1 protocols ) check(err) defer cfg.Close() client := &http.Client{ Transport: &http.Transport{ DialTLSContext: cfg.Dial, // NB: DialTLSContext added in go 1.14 ForceAttemptHTTP2: true, // NB: required if using a custom dialer with HTTP/2 }, } defer client.CloseIdleConnections()
Output:
func (*Config) Listen ¶
Listen creates a TLS listener accepting connections on the given network address.
Example ¶
observer, err := tlsprom.NewObserver( tlsprom.WithHTTP(), tlsprom.WithServer(), ) check(err) prometheus.MustRegister(observer) cfg, err := dynamictls.NewConfig( dynamictls.WithObserver(observer), dynamictls.WithCertificate(primaryCertFile, primaryKeyFile), dynamictls.WithCertificate(secondaryCertFile, secondaryKeyFile), dynamictls.WithRootCAs(caFile), dynamictls.WithHTTP(), // NB: adds HTTP/2 and HTTP/1.1 protocols ) check(err) defer cfg.Close() lis, err := cfg.Listen(context.Background(), "tcp", addr) check(err) check(http.Serve(lis, http.DefaultServeMux))
Output:
type Observer ¶ added in v0.4.0
An Observer observes when new config data is loaded or an error occurs loading new config data.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
An Option applies optional configuration.
func WithCertificate ¶
WithCertificate returns an Option that adds the public/private key pair in the PEM encoded files to the config's certificates.
func WithClientCAs ¶
WithClientCAs returns an Option that adds the certificates in the file to the config's client certificate pool.
func WithHTTP ¶
func WithHTTP() Option
WithHTTP returns an Option that adds HTTP/2 and HTTP/1.1 protocol negotiation to the config.
func WithHTTP1 ¶
func WithHTTP1() Option
WithHTTP1 returns an Option that adds HTTP/1.1 protocol negotiation to the config.
func WithHTTP2 ¶
func WithHTTP2() Option
WithHTTP2 returns an Option that adds HTTP/2 protocol negotiation to the config.
func WithLogger ¶ added in v0.3.0
WithLogger returns an Option that sets the logger for errors.
func WithObserver ¶ added in v0.4.0
WithObserver returns an Option that registers the Observer.
func WithRootCAs ¶
WithRootCAs returns an Option that adds the certificates in the file to the config's root certificate pool.
Directories ¶
Path | Synopsis |
---|---|
Package grpctls implements dynamic TLS credential support for gRPC.
|
Package grpctls implements dynamic TLS credential support for gRPC. |
internal
|
|
tlstest
Package tlstest provides utilities for testing with TLS certificates.
|
Package tlstest provides utilities for testing with TLS certificates. |
Package tlsprom provides Prometheus instrumentation for TLS configuration.
|
Package tlsprom provides Prometheus instrumentation for TLS configuration. |