Skip to content

Commit

Permalink
extend config with tls path field
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Nov 6, 2024
1 parent e0f0fd3 commit d7a682e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion nodebuilder/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ type Config struct {
RPCPort string
GRPCPort string
EnableTLS bool
TLSPath string
}

// DefaultConfig returns default configuration for managing the
// node's connection to a Celestia-Core endpoint.
func DefaultConfig() Config {
return Config{
IP: "",
RPCPort: DefaultRPCPort,
GRPCPort: DefaultGRPCPort,
}
Expand Down
11 changes: 11 additions & 0 deletions nodebuilder/core/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var (
coreRPCFlag = "core.rpc.port"
coreGRPCFlag = "core.grpc.port"
coreEnableTLSFlag = "core.grpc.tls"
coreTLSPAthFlag = "core.grpc.tls.path"
)

// Flags gives a set of hardcoded Core flags.
Expand Down Expand Up @@ -40,6 +41,11 @@ func Flags() *flag.FlagSet {
false,
"Enables grpc TLS. The --core.ip flag must also be provided.",
)
flags.String(
coreTLSPAthFlag,
"",
fmt.Sprintf("Set a path to the TLS certificates. The --%s must be set to true ", coreEnableTLSFlag),
)
return flags
}

Expand Down Expand Up @@ -71,6 +77,11 @@ func ParseFlags(
cfg.EnableTLS = enabled
}

if cmd.Flag(coreTLSPAthFlag).Changed {
path := cmd.Flag(coreTLSPAthFlag).Value.String()
cfg.TLSPath = path
}

cfg.IP = coreIP
return cfg.Validate()
}
23 changes: 11 additions & 12 deletions nodebuilder/core/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package core

import (
"crypto/tls"
"fmt"
"github.com/celestiaorg/celestia-node/libs/utils"
"os"
"path/filepath"
)

Expand All @@ -12,22 +12,21 @@ const (
key = "key.pem"
)

var tlsPath = "CELESTIA_GRPC_TLS_PATH"

// TLS tries to read `CELESTIA_GRPC_TLS_PATH` to get the tls path and configure the config
// with build certificate. In returns an empty config in case the path hasn't specified.
func TLS() (*tls.Config, error) {
// TLS parses the tls path and tries to configure the config with tls certificates.
// In returns an empty config in case the path was not specified.
func TLS(tlsPath string) (*tls.Config, error) {
cfg := &tls.Config{MinVersion: tls.VersionTLS12}
path := os.Getenv(tlsPath)
if path == "" {
if tlsPath == "" {
return cfg, nil
}

certPath := filepath.Join(path, cert)
keyPath := filepath.Join(path, key)
certPath := filepath.Join(tlsPath, cert)
keyPath := filepath.Join(tlsPath, key)
exist := utils.Exists(certPath) && utils.Exists(keyPath)
if !exist {
return cfg, nil
return nil, fmt.Errorf("can't find %s or %s under %s"+
"Please specify another path or disable tls in the config",
cert, key, tlsPath,
)
}

cert, err := tls.LoadX509KeyPair(certPath, keyPath)
Expand Down
2 changes: 1 addition & 1 deletion nodebuilder/state/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func coreAccessor(
error,
) {
if corecfg.EnableTLS {
tls, err := core.TLS()
tls, err := core.TLS(corecfg.TLSPath)
if err != nil {
return nil, nil, nil, err
}
Expand Down
13 changes: 7 additions & 6 deletions state/core_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ import (
"sync"
"time"

"github.com/celestiaorg/celestia-app/v3/app"
"github.com/celestiaorg/celestia-app/v3/app/encoding"
apperrors "github.com/celestiaorg/celestia-app/v3/app/errors"
"github.com/celestiaorg/celestia-app/v3/pkg/user"
libhead "github.com/celestiaorg/go-header"
libshare "github.com/celestiaorg/go-square/v2/share"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
Expand All @@ -30,6 +24,13 @@ import (
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"

"github.com/celestiaorg/celestia-app/v3/app"
"github.com/celestiaorg/celestia-app/v3/app/encoding"
apperrors "github.com/celestiaorg/celestia-app/v3/app/errors"
"github.com/celestiaorg/celestia-app/v3/pkg/user"
libhead "github.com/celestiaorg/go-header"
libshare "github.com/celestiaorg/go-square/v2/share"

"github.com/celestiaorg/celestia-node/header"
)

Expand Down

0 comments on commit d7a682e

Please sign in to comment.