Skip to content

Commit

Permalink
Add support for TLS to HTTP servers
Browse files Browse the repository at this point in the history
We support TLS for gRPC clients, gRPC servers, and HTTP clients. HTTP
servers are the only ones for which TLS is not supported. This is
typically not an issue, because people generally put ingress controllers
in front of HTTP servers. However, if people want to run Buildbarn in
bare metal environments it may be useful to support this.
  • Loading branch information
EdSchouten committed Jun 12, 2024
1 parent a9d0937 commit 118cb9c
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 103 deletions.
19 changes: 16 additions & 3 deletions pkg/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,30 @@ func NewServersFromConfigurationAndServe(configurations []*configuration.ServerC
return err
}
authenticatedHandler := NewAuthenticatingHandler(handler, authenticator)

tlsConfig, err := util.NewTLSConfigFromServerConfiguration(configuration.Tls)
if err != nil {
return err
}

for _, listenAddress := range configuration.ListenAddresses {
server := http.Server{
Addr: listenAddress,
Handler: authenticatedHandler,
Addr: listenAddress,
Handler: authenticatedHandler,
TLSConfig: tlsConfig,
}
group.Go(func(ctx context.Context, siblingsGroup, dependenciesGroup program.Group) error {
<-ctx.Done()
return server.Close()
})
group.Go(func(ctx context.Context, siblingsGroup, dependenciesGroup program.Group) error {
if err := server.ListenAndServe(); err != http.ErrServerClosed {
var err error
if tlsConfig == nil {
err = server.ListenAndServe()
} else {
err = server.ListenAndServeTLS("", "")
}
if err != http.ErrServerClosed {
return util.StatusWrapf(err, "Failed to launch HTTP server %#v", server.Addr)
}
return nil
Expand Down
Loading

0 comments on commit 118cb9c

Please sign in to comment.