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): enable tls for grpc connection #3922

Closed
wants to merge 9 commits into from

Conversation

vgonkivs
Copy link
Member

@vgonkivs vgonkivs commented Nov 6, 2024

This PR includes all changes from #3917.
The PR introduces 2 additional fields in the core config and 2 cli flags that allow to configure these fields.

@codecov-commenter
Copy link

codecov-commenter commented Nov 6, 2024

Codecov Report

Attention: Patch coverage is 30.37037% with 94 lines in your changes missing coverage. Please review.

Project coverage is 45.28%. Comparing base (2469e7a) to head (06bab7b).
Report is 391 commits behind head on main.

Files with missing lines Patch % Lines
nodebuilder/core/tls.go 0.00% 35 Missing ⚠️
state/core_access.go 36.73% 27 Missing and 4 partials ⚠️
nodebuilder/state/core.go 0.00% 16 Missing ⚠️
nodebuilder/core/flags.go 65.71% 10 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3922      +/-   ##
==========================================
+ Coverage   44.83%   45.28%   +0.44%     
==========================================
  Files         265      309      +44     
  Lines       14620    22026    +7406     
==========================================
+ Hits         6555     9974    +3419     
- Misses       7313    10974    +3661     
- Partials      752     1078     +326     

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


🚨 Try these New Features:

@vgonkivs vgonkivs changed the title improvements to pr-3917 feat!(core): enable tls for grpc connection Nov 6, 2024
@vgonkivs vgonkivs self-assigned this Nov 6, 2024
@vgonkivs vgonkivs added kind:break! Attached to breaking PRs kind:feat Attached to feature PRs labels Nov 6, 2024
@vgonkivs vgonkivs marked this pull request as ready for review November 6, 2024 13:32
// It should not include file names('cert.pem' and 'key.pem').
// If left empty, the client will be configured for an insecure (non-TLS) connection.
TLSPath string
// XTokenPath specifies the file path to the JSON file containing the X-Token for gRPC authentication.

Choose a reason for hiding this comment

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

comments say this is path to the JSON file, but due to the use of the xtoken const, needs to be the path to the directory containing a file named xtoken.json

Comment on lines +37 to +39
if !exist {
return nil, os.ErrNotExist
}
Copy link
Member

Choose a reason for hiding this comment

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

Should just return empty tls config? Seems os.ErrNotExist is not needed

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. I added this behavior initially but then realized that we may have more usecases in the future so the caller will decide what to do with this error.

Comment on lines +47 to +51
xtoken, err := core.XToken(corecfg.XTokenPath)
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

Choose a reason for hiding this comment

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

If token is not present, perhaps we should not invoke state.WithXToken options

Copy link
Member Author

Choose a reason for hiding this comment

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

in this case xToken is "" so, I don't think it will break any logic but from the other - less code fewer problems 🙂 . I can add a comment explaining the usage of state.WithXToken

Comment on lines +619 to +628
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

Choose a reason for hiding this comment

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

nit, but would be easier to read if interceptor is extracted

Copy link
Member Author

@vgonkivs vgonkivs Nov 20, 2024

Choose a reason for hiding this comment

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

Yeah, I was planning to move it out. Thanks 🙏

@vgonkivs
Copy link
Member Author

closed in favor of #3954

All comments from @walldiss have been linked in #3954

@vgonkivs vgonkivs closed this Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:break! Attached to breaking PRs kind:feat Attached to feature PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants