databroker: add encryption for records (#1168)

This commit is contained in:
Caleb Doxsey 2020-07-30 14:04:31 -06:00 committed by GitHub
parent 8cae3f27bb
commit 29fb96a955
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 332 additions and 7 deletions

13
cache/databroker.go vendored
View file

@ -1,10 +1,14 @@
package cache
import (
"encoding/base64"
"fmt"
"google.golang.org/grpc"
"github.com/pomerium/pomerium/config"
internal_databroker "github.com/pomerium/pomerium/internal/databroker"
"github.com/pomerium/pomerium/pkg/cryptutil"
"github.com/pomerium/pomerium/pkg/grpc/databroker"
)
@ -14,12 +18,17 @@ type DataBrokerServer struct {
}
// NewDataBrokerServer creates a new databroker service server.
func NewDataBrokerServer(grpcServer *grpc.Server, opts config.Options) *DataBrokerServer {
func NewDataBrokerServer(grpcServer *grpc.Server, opts config.Options) (*DataBrokerServer, error) {
key, err := base64.StdEncoding.DecodeString(opts.SharedKey)
if err != nil || len(key) != cryptutil.DefaultKeySize {
return nil, fmt.Errorf("shared key is required and must be %d bytes long", cryptutil.DefaultKeySize)
}
internalSrv := internal_databroker.New(
internal_databroker.WithSecret(key),
internal_databroker.WithStorageType(opts.DataBrokerStorageType),
internal_databroker.WithStorageConnectionString(opts.DataBrokerStorageConnectionString),
)
srv := &DataBrokerServer{DataBrokerServiceServer: internalSrv}
databroker.RegisterDataBrokerServiceServer(grpcServer, srv)
return srv
return srv, nil
}