Skip to content

Commit

Permalink
Pass in signers rather than keys into witness
Browse files Browse the repository at this point in the history
This allows implementations to be used that don't have the key material locally, for example in a KMS. Fixes #303.
  • Loading branch information
mhutchinson committed Dec 10, 2024
1 parent 4ed8a89 commit 8879b00
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
14 changes: 13 additions & 1 deletion cmd/omniwitness/monolith.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ import (
"time"

"github.com/prometheus/client_golang/prometheus/promhttp"
f_note "github.com/transparency-dev/formats/note"
"github.com/transparency-dev/witness/internal/persistence"
"github.com/transparency-dev/witness/internal/persistence/inmemory"
psql "github.com/transparency-dev/witness/internal/persistence/sql"
"github.com/transparency-dev/witness/monitoring"
"github.com/transparency-dev/witness/monitoring/prometheus"
"github.com/transparency-dev/witness/omniwitness"
"golang.org/x/mod/sumdb/note"
"k8s.io/klog/v2"

_ "github.com/mattn/go-sqlite3" // Load drivers for sqlite3
Expand Down Expand Up @@ -103,8 +105,18 @@ func main() {
}
}

signerLegacy, err := note.NewSigner(*signingKey)
if err != nil {
klog.Exitf("Failed to init signer v0: %v", err)
}
signerCosigV1, err := f_note.NewSignerForCosignatureV1(*signingKey)
if err != nil {
klog.Exitf("Failed to init signer v1: %v", err)
}

opConfig := omniwitness.OperatorConfig{
WitnessKey: *signingKey,
WitnessKeys: []note.Signer{signerLegacy, signerCosigV1},
WitnessVerifier: signerCosigV1.Verifier(),
RestDistributorBaseURL: *restDistributorBaseURL,
BastionAddr: *bastionAddr,
BastionKey: bastionKey,
Expand Down
19 changes: 5 additions & 14 deletions omniwitness/omniwitness.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
"gopkg.in/yaml.v3"
"k8s.io/klog/v2"

f_note "github.com/transparency-dev/formats/note"
"github.com/transparency-dev/witness/internal/distribute/rest"
"github.com/transparency-dev/witness/internal/feeder"
"github.com/transparency-dev/witness/internal/feeder/bastion"
Expand Down Expand Up @@ -70,7 +69,8 @@ const (
// OperatorConfig allows the bare minimum operator-specific configuration.
// This should only contain configuration details that are custom per-operator.
type OperatorConfig struct {
WitnessKey string
WitnessKeys []note.Signer
WitnessVerifier note.Verifier // This should verify at least one of the sigs from the above signers

// BastionAddr is the host:port of the bastion host to connect to, if any.
BastionAddr string
Expand Down Expand Up @@ -119,22 +119,13 @@ func Main(ctx context.Context, operatorConfig OperatorConfig, p LogStatePersiste
klog.Infof("Added log %q: %s", lc.Origin, lc.ID)
}

signerLegacy, err := note.NewSigner(operatorConfig.WitnessKey)
if err != nil {
return fmt.Errorf("failed to init signer v0: %v", err)
}
signerCosigV1, err := f_note.NewSignerForCosignatureV1(operatorConfig.WitnessKey)
if err != nil {
return fmt.Errorf("failed to init signer v1: %v", err)
}

knownLogs, err := logCfg.AsLogMap()
if err != nil {
return fmt.Errorf("failed to convert witness config to map: %v", err)
}
witness, err := witness.New(witness.Opts{
Persistence: p,
Signers: []note.Signer{signerLegacy, signerCosigV1},
Signers: operatorConfig.WitnessKeys,
KnownLogs: knownLogs,
})
if err != nil {
Expand Down Expand Up @@ -166,7 +157,7 @@ func Main(ctx context.Context, operatorConfig OperatorConfig, p LogStatePersiste
Addr: operatorConfig.BastionAddr,
Logs: logs,
BastionKey: operatorConfig.BastionKey,
WitnessVerifier: signerCosigV1.Verifier(),
WitnessVerifier: operatorConfig.WitnessVerifier,
Limits: bastion.RequestLimits{
TotalPerSecond: rate.Limit(operatorConfig.BastionRateLimit),
}}
Expand All @@ -179,7 +170,7 @@ func Main(ctx context.Context, operatorConfig OperatorConfig, p LogStatePersiste

if operatorConfig.RestDistributorBaseURL != "" {
klog.Infof("Starting RESTful distributor for %q", operatorConfig.RestDistributorBaseURL)
runRestDistributors(ctx, g, httpClient, operatorConfig.DistributeInterval, logs, operatorConfig.RestDistributorBaseURL, bw, signerCosigV1.Verifier())
runRestDistributors(ctx, g, httpClient, operatorConfig.DistributeInterval, logs, operatorConfig.RestDistributorBaseURL, bw, operatorConfig.WitnessVerifier)
}

r := mux.NewRouter()
Expand Down

0 comments on commit 8879b00

Please sign in to comment.