Skip to content

Commit

Permalink
Wire up CSA Auth for Beholder
Browse files Browse the repository at this point in the history
  • Loading branch information
4of9 committed Nov 1, 2024
1 parent 1169073 commit e75052b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
33 changes: 27 additions & 6 deletions core/cmd/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"bytes"
"context"
"crypto/ed25519"
"crypto/tls"
"database/sql"
"encoding/json"
Expand Down Expand Up @@ -66,7 +67,7 @@ var (
grpcOpts loop.GRPCOpts
)

func initGlobals(cfgProm config.Prometheus, cfgTracing config.Tracing, cfgTelemetry config.Telemetry, lggr logger.Logger) error {
func initGlobals(cfgProm config.Prometheus, cfgTracing config.Tracing, cfgTelemetry config.Telemetry, lggr logger.Logger, csaPubKey []byte, csaSigner func([]byte) []byte) error {
// Avoid double initializations, but does not prevent relay methods from being called multiple times.
var err error
initGlobalsOnce.Do(func() {
Expand Down Expand Up @@ -97,12 +98,15 @@ func initGlobals(cfgProm config.Prometheus, cfgTracing config.Tracing, cfgTeleme
for k, v := range cfgTelemetry.ResourceAttributes() {
attributes = append(attributes, attribute.String(k, v))
}

clientCfg := beholder.Config{
InsecureConnection: cfgTelemetry.InsecureConnection(),
CACertFile: cfgTelemetry.CACertFile(),
OtelExporterGRPCEndpoint: cfgTelemetry.OtelExporterGRPCEndpoint(),
ResourceAttributes: attributes,
TraceSampleRatio: cfgTelemetry.TraceSampleRatio(),
AuthenticatorPublicKey: csaPubKey,
AuthenticatorSigner: csaSigner,
}
if tracingCfg.Enabled {
clientCfg.TraceSpanExporter, err = tracingCfg.NewSpanExporter()
Expand Down Expand Up @@ -180,11 +184,7 @@ type AppFactory interface {
type ChainlinkAppFactory struct{}

// NewApplication returns a new instance of the node with the given config.
func (n ChainlinkAppFactory) NewApplication(ctx context.Context, cfg chainlink.GeneralConfig, appLggr logger.Logger, db *sqlx.DB) (app chainlink.Application, err error) {
err = initGlobals(cfg.Prometheus(), cfg.Tracing(), cfg.Telemetry(), appLggr)
if err != nil {
appLggr.Errorf("Failed to initialize globals: %v", err)
}
func (n ChainlinkAppFactory) NewApplication(ctx context.Context, cfg chainlink.GeneralConfig, appLggr logger.Logger, db *sqlx.DB, keyStoreAuthenticator TerminalKeyStoreAuthenticator) (app chainlink.Application, err error) {

err = migrate.SetMigrationENVVars(cfg)
if err != nil {
Expand All @@ -204,6 +204,27 @@ func (n ChainlinkAppFactory) NewApplication(ctx context.Context, cfg chainlink.G
return nil, errors.Wrap(err, "error authenticating keystore")
}

err = keyStore.CSA().EnsureKey(ctx)
if err != nil {
return nil, errors.Wrap(err, "failed to ensure CSA key")
}

csaKeys, err := keyStore.CSA().GetAll()
if err != nil {
return nil, err
}
csaKey := csaKeys[0]
csaPubKey := csaKey.PublicKey
csaPrivKey := csaKey.Raw().Bytes()
csaSigner := func(data []byte) []byte {
return ed25519.Sign(csaPrivKey, data)
}

err = initGlobals(cfg.Prometheus(), cfg.Tracing(), cfg.Telemetry(), appLggr, csaPubKey, csaSigner)
if err != nil {
appLggr.Errorf("Failed to initialize globals: %v", err)
}

mailMon := mailbox.NewMonitor(cfg.AppID().String(), appLggr.Named("Mailbox"))

loopRegistry := plugins.NewLoopRegistry(appLggr, cfg.Tracing(), cfg.Telemetry())
Expand Down
5 changes: 0 additions & 5 deletions core/cmd/shell_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,6 @@ func (s *Shell) runNode(c *cli.Context) error {
}
}

err2 := app.GetKeyStore().CSA().EnsureKey(rootCtx)
if err2 != nil {
return errors.Wrap(err2, "failed to ensure CSA key")
}

if e := checkFilePermissions(lggr, s.Config.RootDir()); e != nil {
lggr.Warn(e)
}
Expand Down

0 comments on commit e75052b

Please sign in to comment.