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

Use GRPC interceptors for bearer token #6063

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

Conversation

chahatsagarmain
Copy link
Contributor

Which problem is this PR solving?

Resolves #6035

Description of the changes

How was this change tested?

Checklist

Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
@chahatsagarmain chahatsagarmain requested a review from a team as a code owner October 6, 2024 19:21
@chahatsagarmain chahatsagarmain marked this pull request as draft October 6, 2024 19:21
@yurishkuro
Copy link
Member

I don't see any interceptors in this PR

@chahatsagarmain
Copy link
Contributor Author

I have started working on it , will add in next commits .

Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
@chahatsagarmain chahatsagarmain marked this pull request as ready for review October 8, 2024 06:03
Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

where all these functions are going to be used? This should be part of the PR.

@chahatsagarmain
Copy link
Contributor Author

where all these functions are going to be used? This should be part of the PR.

Do i need to write it in the comments of the code or mention it in the PR description ?

@yurishkuro
Copy link
Member

the new functions need to be called from the real code. What's the point of having them otherwise?

@chahatsagarmain
Copy link
Contributor Author

Got it 👍🏼

Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
pkg/bearertoken/grpc.go Outdated Show resolved Hide resolved
plugin/storage/grpc/factory.go Outdated Show resolved Hide resolved
pkg/bearertoken/grpc.go Outdated Show resolved Hide resolved
pkg/bearertoken/grpc.go Outdated Show resolved Hide resolved
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
pkg/bearertoken/grpc.go Outdated Show resolved Hide resolved
pkg/bearertoken/grpc.go Outdated Show resolved Hide resolved
pkg/bearertoken/grpc.go Outdated Show resolved Hide resolved
cmd/query/app/server.go Outdated Show resolved Hide resolved
pkg/bearertoken/grpc.go Outdated Show resolved Hide resolved
pkg/bearertoken/grpc.go Outdated Show resolved Hide resolved
pkg/bearertoken/grpc.go Outdated Show resolved Hide resolved
pkg/bearertoken/grpc.go Outdated Show resolved Hide resolved
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
cmd/query/app/server.go Outdated Show resolved Hide resolved
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
Copy link

codecov bot commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 98.24561% with 2 lines in your changes missing coverage. Please review.

Project coverage is 96.48%. Comparing base (c96790a) to head (b73817e).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/query/app/server.go 85.71% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6063      +/-   ##
==========================================
+ Coverage   96.45%   96.48%   +0.03%     
==========================================
  Files         352      353       +1     
  Lines       20007    20112     +105     
==========================================
+ Hits        19297    19405     +108     
+ Misses        526      523       -3     
  Partials      184      184              
Flag Coverage Δ
badger_v1 8.34% <0.00%> (-0.09%) ⬇️
badger_v2 1.69% <0.00%> (-0.02%) ⬇️
cassandra-4.x-v1 14.43% <0.00%> (-0.14%) ⬇️
cassandra-4.x-v2 1.63% <0.00%> (-0.02%) ⬇️
cassandra-5.x-v1 14.43% <0.00%> (-0.14%) ⬇️
cassandra-5.x-v2 1.63% <0.00%> (-0.02%) ⬇️
elasticsearch-6.x-v1 18.55% <0.00%> (-0.17%) ⬇️
elasticsearch-7.x-v1 18.63% <0.00%> (-0.17%) ⬇️
elasticsearch-8.x-v1 18.79% <0.00%> (-0.20%) ⬇️
elasticsearch-8.x-v2 1.68% <0.00%> (-0.03%) ⬇️
grpc_v1 9.37% <64.00%> (+0.59%) ⬆️
grpc_v2 7.02% <30.00%> (+0.29%) ⬆️
kafka-v1 8.91% <0.00%> (-0.09%) ⬇️
kafka-v2 1.69% <0.00%> (-0.02%) ⬇️
memory_v2 1.69% <0.00%> (-0.01%) ⬇️
opensearch-1.x-v1 18.67% <0.00%> (-0.19%) ⬇️
opensearch-2.x-v1 18.68% <0.00%> (-0.18%) ⬇️
opensearch-2.x-v2 1.69% <0.00%> (-0.02%) ⬇️
tailsampling-processor 0.48% <0.00%> (-0.01%) ⬇️
unittests 95.39% <95.61%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
@yurishkuro yurishkuro changed the title GRPC implementation for bearer token Use GRPC interceptors for bearer token Oct 16, 2024
Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

please add tests and address all comments

pkg/bearertoken/grpc.go Show resolved Hide resolved
pkg/bearertoken/grpc.go Outdated Show resolved Hide resolved
pkg/bearertoken/grpc.go Outdated Show resolved Hide resolved
pkg/bearertoken/grpc.go Show resolved Hide resolved
pkg/bearertoken/grpc.go Outdated Show resolved Hide resolved
pkg/bearertoken/grpc.go Outdated Show resolved Hide resolved
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
@chahatsagarmain
Copy link
Contributor Author

chahatsagarmain commented Oct 19, 2024

@yurishkuro can you review the new changes , I have added tests and made changes to interceptor code .

@yurishkuro
Copy link
Member

please address all comments

@yurishkuro yurishkuro closed this Oct 19, 2024
@yurishkuro yurishkuro reopened this Oct 19, 2024
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
@yurishkuro
Copy link
Member

Please resolve conflicts

Signed-off-by: chahat sagar <109112505+chahatsagarmain@users.noreply.github.com>
pkg/bearertoken/grpc_test.go Outdated Show resolved Hide resolved
pkg/bearertoken/grpc_test.go Outdated Show resolved Hide resolved
pkg/bearertoken/grpc_test.go Outdated Show resolved Hide resolved
pkg/bearertoken/grpc.go Outdated Show resolved Hide resolved
pkg/bearertoken/grpc.go Outdated Show resolved Hide resolved
pkg/bearertoken/grpc.go Outdated Show resolved Hide resolved
pkg/bearertoken/grpc.go Outdated Show resolved Hide resolved
pkg/bearertoken/grpc_test.go Outdated Show resolved Hide resolved
pkg/bearertoken/grpc_test.go Outdated Show resolved Hide resolved
pkg/bearertoken/grpc_test.go Outdated Show resolved Hide resolved
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

almost ready


// NewUnaryClientInterceptor injects the bearer token header into gRPC request metadata.
func NewUnaryClientInterceptor() grpc.UnaryClientInterceptor {
return grpc.UnaryClientInterceptor(func(
Copy link
Member

Choose a reason for hiding this comment

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

unnecessary wrapping

Suggested change
return grpc.UnaryClientInterceptor(func(
return func(

invoker grpc.UnaryInvoker,
opts ...grpc.CallOption,
) error {
var token string
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var token string

streamer grpc.Streamer,
opts ...grpc.CallOption,
) (grpc.ClientStream, error) {
var token string
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var token string

require.ErrorContains(t, err, test.expectedErr)
}

// Stream interceptor test
Copy link
Member

Choose a reason for hiding this comment

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

instead of comments you can wrap into a subtest

t.Run("stream", func...)

}),
expectedErr: "",
wantToken: "valid-token",
},
Copy link
Member

Choose a reason for hiding this comment

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

missing no-context / no-metadata test

expectedErr: "",
expectedMD: metadata.MD{Key: []string{"valid-token"}}, // Valid token setup
},
}
Copy link
Member

Choose a reason for hiding this comment

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

missing no-context / no-metadata test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Implement bearer token auth interceptor
3 participants