-
Notifications
You must be signed in to change notification settings - Fork 4
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
Explore CallCredentials
and SessionCredentials
for GRPC
#230
Comments
SessionCredentials
: https://gitlab.com/MatrixAI/Engineering/Polykey/js-polykey/-/merge_requests/207#note_652476363 and https://gitlab.com/MatrixAI/Engineering/Polykey/js-polykey/-/merge_requests/207#note_652440417SessionCredentials
SessionCredentials
CallCredentials
and SessionCredentials
for GRPC
@DrFacepalm can you take over this issue this week/weekend? |
Taking a look, im not too sure what we'd prefer here. We have two options here, either something like: // Option 1
const pCall = grpcClient.vaultsCreate(
vaultMessage, // Message Type
await client.session.createCallCredentials(), // grpc.CallOptions
); or // Option 2
const pCall = grpcClient.vaultsCreate(
vaultMessage, // Message Type
meta, // grpc.Metadata
await client.session.createCallCredentials(), // grpc.CallOptions
); Option 2 seems more robust simply because it seems more supported by the grpc library. In the generated code: public vaultsCreate(request: Client_pb.VaultMessage, callback: (error: grpc.ServiceError | null, response: Client_pb.VaultMessage) => void): grpc.ClientUnaryCall;
public vaultsCreate(request: Client_pb.VaultMessage, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: Client_pb.VaultMessage) => void): grpc.ClientUnaryCall;
public vaultsCreate(request: Client_pb.VaultMessage, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: Client_pb.VaultMessage) => void): grpc.ClientUnaryCall; The last overload shows that the function call takes: @CMCDragonkai mentioned before that maybe, the only reason Option 1 had worked as because we had removed typings from the call by using The strange thing is that the exist function overloads that match Option 1 for the stream based grpc calls. public vaultsList(request: Client_pb.EmptyMessage, options?: Partial<grpc.CallOptions>): grpc.ClientReadableStream<Client_pb.VaultListMessage>;
public vaultsList(request: Client_pb.EmptyMessage, metadata?: grpc.Metadata, options?: Partial<grpc.CallOptions>): grpc.ClientReadableStream<Client_pb.VaultListMessage>; The first one takes a With that, honestly it seems like the best approach is to use the calls with |
Try doing option 2 for unary calls. And for streams leave it as is. I reckon we should matching the call signature even if it is weird. |
Looking into the For example, if we provide the JWT token metadata to the client as a I'll look deeper into this once I've completed #229 |
Yep the grpc documentation is quite light. I had to delve into the
source code to see how to make use of it. In VSCode this was easy enough
by jumping between the type definitions. But I had to clone the grpc
source code and match up the type signatures to the TS code internally
as well.
…On 8/30/21 1:08 PM, Brian Botha wrote:
Looking into the |callCredentials| that you can create when setting up
a client connection. I think it's possible for the client to provide
metadata for each call automatically.
For example, if we provide the JWT token metadata to the client as a
|callCredential| it should provide that each time we make a call. so
we don't need to provide it each time we make the call. the
documentation on this is very light so I need to do some testing to
confirm this,
I'll look deeper into this once I've completed #229
<#229>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#230 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAE4OHJXTMQ434Z4BQVU3KLT7LY3DANCNFSM5CLFEFMQ>.
|
I've done some testing now. Looks like you can provide a metadataGenerator to the callCredentials. This will generate new metadata each time a call is done add that to the metadata of the call. Using this we can get the JWT token from the session manager and provide that for each call automatically. This way we don't have to provide the session token metadata explicitly for each call. if the token gets updated in the session manager this should be reflected in future calls. This only solves half of the problem here. The server side still needs to verify the metadata for each call. I don't see a way around that however. but it does give the freedom to decide if the token is required on a call per call basis. |
Just remember that `SessionManager` is used by the agent side not
directly from the client side. The client uses the token in its
`Session` state (provided by a lockfile). It then updates the session
state based on return information from the agent which may have been
supplied with info from `SessionManager`.
…On 8/30/21 2:50 PM, Brian Botha wrote:
I've done some testing now. Looks like you can provide a
metadataGenerator to the callCredentials. This will generate new
metadata each time a call is done add that to the metadata of the
call. Using this we can get the JWT token from the session manager and
provide that for each call automatically.
This way we don't have to provide the session token metadata
explicitly for each call. if the token gets updated in the session
manager this should be reflected in future calls.
This only solves half of the problem here. The server side still needs
to verify the metadata for each call. I don't see a way around that
however. but it does give the freedom to decide if the token is
required on a call per call basis.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#230 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAE4OHOMDSVLFJKTYC7LBVDT7MEZVANCNFSM5CLFEFMQ>.
|
I have a functioning example of this working now. We wont need to provide the token for every call now. If you do try to manually provide the token with this enabled then you'll get a error I can proceed with updating the code to use this change. |
That's great. Are you sure you want to pass the entire |
This way if we update the token inside the |
Fixed all the GRPC calls by removing the call Credentials and metadata where relevant. All tests are passing, linted and checked that it builds. Unless I'm missing anything this issue should be done. Refer to this commit for the changes. 70bdcfb, d977f6a This will be done when https://gitlab.com/MatrixAI/Engineering/Polykey/js-polykey/-/merge_requests/210 is merged |
Awesome. Although in the future, make sure to plan out the tasks before hand in the issue before starting on it. |
Done now. |
Specification
Check the robustness of the usage of call credentials and
SessionCredentials
.Additional context
Reference https://gitlab.com/MatrixAI/Engineering/Polykey/js-polykey/-/merge_requests/207#note_652476363 and https://gitlab.com/MatrixAI/Engineering/Polykey/js-polykey/-/merge_requests/207#note_652440417
An MR has been created for this issue.
https://gitlab.com/MatrixAI/Engineering/Polykey/js-polykey/-/merge_requests/210
Tasks
The text was updated successfully, but these errors were encountered: