-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
initial POC for grpc tls #3917
base: main
Are you sure you want to change the base?
initial POC for grpc tls #3917
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,18 @@ | |
|
||
import ( | ||
"context" | ||
"crypto/tls" | ||
"errors" | ||
"fmt" | ||
"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" | ||
|
@@ -20,15 +27,9 @@ | |
"github.com/tendermint/tendermint/proto/tendermint/crypto" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/connectivity" | ||
"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" | ||
) | ||
|
||
|
@@ -67,10 +68,11 @@ | |
|
||
prt *merkle.ProofRuntime | ||
|
||
coreConn *grpc.ClientConn | ||
coreIP string | ||
grpcPort string | ||
network string | ||
coreConn *grpc.ClientConn | ||
coreIP string | ||
grpcPort string | ||
enableTLS bool | ||
network string | ||
|
||
// these fields are mutatable and thus need to be protected by a mutex | ||
lock sync.Mutex | ||
|
@@ -86,15 +88,7 @@ | |
// NewCoreAccessor dials the given celestia-core endpoint and | ||
// constructs and returns a new CoreAccessor (state service) with the active | ||
// connection. | ||
func NewCoreAccessor( | ||
keyring keyring.Keyring, | ||
keyname string, | ||
getter libhead.Head[*header.ExtendedHeader], | ||
coreIP, | ||
grpcPort string, | ||
network string, | ||
options ...Option, | ||
) (*CoreAccessor, error) { | ||
func NewCoreAccessor(keyring keyring.Keyring, keyname string, getter libhead.Head[*header.ExtendedHeader], coreIP, grpcPort string, enableTLS bool, network string, options ...Option) (*CoreAccessor, error) { | ||
// create verifier | ||
prt := merkle.DefaultProofRuntime() | ||
prt.RegisterOpDecoder(storetypes.ProofOpIAVLCommitment, storetypes.CommitmentOpDecoder) | ||
|
@@ -106,6 +100,7 @@ | |
getter: getter, | ||
coreIP: coreIP, | ||
grpcPort: grpcPort, | ||
enableTLS: enableTLS, | ||
prt: prt, | ||
network: network, | ||
} | ||
|
@@ -124,9 +119,15 @@ | |
|
||
// dial given celestia-core endpoint | ||
endpoint := fmt.Sprintf("%s:%s", ca.coreIP, ca.grpcPort) | ||
grpcOpts := make([]grpc.DialOption, 0) | ||
if ca.enableTLS { | ||
grpcOpts = append(grpcOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{}))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without specifying valid certificates in the tls.Config object will not secure gRPC connection. By default, an empty tls.Config{} means that no certificate or private key is provided, which leads to an insecure setup. Node already has TLS certificates handling logic here for web socket, so you can reuse the certificate for the grpc connection. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a proof of concept to get the Light node working against a Quicknode celestia endpoint. QN doesn't support client certs. gRPC auth for a QN endpoint occurs over the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One more point here is the solution is not generic. You may not support the certificates but if someone does, the connection won't be established. Also, it is recommended to manually specify the MinTLSVersion(linter confirmed it) |
||
} else { | ||
grpcOpts = append(grpcOpts, grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
} | ||
client, err := grpc.NewClient( | ||
endpoint, | ||
grpc.WithTransportCredentials(insecure.NewCredentials()), | ||
grpcOpts..., | ||
) | ||
if err != nil { | ||
return err | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's avoid growing the node's config. We have an env variable that signals that TLS should be enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just wanted to create a POC. My recommended approach would be to have a RPC url and gRPC url.