Skip to content
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

feat(core): added support of the TLS certificates along with x-token authorisation token for the gRPC connection #3954

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

vgonkivs
Copy link
Member

@vgonkivs vgonkivs commented Nov 20, 2024

The PR introduces breaking changes to the Core config. It extends the config with 3 additional fields that allow for configuring a secure grpc connection:

  • TLSEnabled;
  • XTokenPath;

Three additional flags have been added to configure these fields.

@vgonkivs vgonkivs self-assigned this Nov 20, 2024
@vgonkivs vgonkivs added kind:break! Attached to breaking PRs area:config CLI and config area:core_and_app Relationship with Core node and Celestia-App labels Nov 20, 2024
@codecov-commenter
Copy link

codecov-commenter commented Nov 20, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 72 lines in your changes missing coverage. Please review.

Project coverage is 45.36%. Comparing base (2469e7a) to head (3ce38b2).
Report is 392 commits behind head on main.

Files with missing lines Patch % Lines
state/core_access.go 40.00% 29 Missing and 4 partials ⚠️
nodebuilder/core/tls.go 0.00% 21 Missing ⚠️
nodebuilder/state/core.go 0.00% 10 Missing ⚠️
nodebuilder/core/flags.go 63.63% 6 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3954      +/-   ##
==========================================
+ Coverage   44.83%   45.36%   +0.52%     
==========================================
  Files         265      309      +44     
  Lines       14620    21999    +7379     
==========================================
+ Hits         6555     9980    +3425     
- Misses       7313    10944    +3631     
- Partials      752     1075     +323     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

certPath := filepath.Join(tlsPath, cert)
keyPath := filepath.Join(tlsPath, key)
exist := utils.Exists(certPath) && utils.Exists(keyPath)
if !exist {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if err != nil && !errors.Is(err, os.ErrNotExist) {
return nil, nil, nil, err
}
opts = append(opts, state.WithTLSConfig(tlsCfg), state.WithXToken(xtoken))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 619 to 627
authInterceptor := func(ctx context.Context,
method string,
req, reply interface{},
cc *grpc.ClientConn,
invoker grpc.UnaryInvoker,
opts ...grpc.CallOption,
) error {
ctx = metadata.AppendToOutgoingContext(ctx, "x-token", ca.xtoken)
return invoker(ctx, method, req, reply, cc, opts...)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@renaynay renaynay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vgonkivs this isn't a breaking change bc those fields are purely additive - nothing about validation logic for config has changed so no worries to base it on api-breaks. You can re-base it on main actually.

@@ -19,13 +19,23 @@ type Config struct {
IP string
RPCPort string
GRPCPort string
// TLSEnabled specifies whether the connection is secure or not.
// PLEASE NOTE: it should be set to true in order to handle TLSPath and/or XTokenPath.
TLSEnabled bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this if we just provide a TLSPath?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need it for a use case when we have to provide an empty config.

coreRPCFlag = "core.rpc.port"
coreGRPCFlag = "core.grpc.port"
coreFlag = "core.ip"
coreRPCFlag = "core.rpc.port"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you rebase, you won't need this anymore and also won't need to specify grpc in the name of the flag

so core.grpc.tls.path --> core.tls.path and same for xtoken

@vgonkivs
Copy link
Member Author

vgonkivs commented Nov 21, 2024

@vgonkivs this isn't a breaking change bc those fields are purely additive - nothing about validation logic for config has changed so no worries to base it on api-breaks. You can re-base it on main actually.

I'd propose merging it inside api breaks as we have one more PR related to the grpc connection. So, imo it's better to keep everything in one place. + I'm going to open one more PR based on the @rach-id changes to unify grpc clients. Merging current PR to main will block clients unification

@vgonkivs vgonkivs changed the title feat!(core): added support of the TLS certificates along with x-token authorisation token for the gRPC connection feat(core): added support of the TLS certificates along with x-token authorisation token for the gRPC connection Nov 21, 2024
@walldiss
Copy link
Member

I was reviewing the PR and noticed that we're configuring client certificates, which seems to be for setting up mutual TLS (mTLS). My understanding is that we only need to verify the server's certificate since we'll be sending an x-token authorization header for client authentication. Do we really need client certificates on the client side in this case?

Also, I didn't see any setup for root CA certificates, which are necessary when dealing with self-signed or custom certificates—a pretty common use case. Without specifying the root CA, the client won't be able to validate the server's certificate.

Could we adjust the implementation to focus on server-side certificates and include support for custom root CAs? What are your thoughts?

@vgonkivs
Copy link
Member Author

We agreed with @walldiss in DM that we don't want to keep any certificates for now(as they were out of the scope of the initial request)

@vgonkivs vgonkivs changed the base branch from feature/api-breaks to main November 25, 2024 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:config CLI and config area:core_and_app Relationship with Core node and Celestia-App kind:break! Attached to breaking PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants