Page MenuHomePhabricator

[services] Tunnelbroker - Adding of the client authentication by the `sessionID` from metadata
ClosedPublic

Authored by max on Nov 2 2022, 2:50 PM.
Tags
None
Referenced Files
F2173014: D5528.id18654.diff
Tue, Jul 2, 9:17 PM
F2167361: D5528.id18076.diff
Tue, Jul 2, 6:11 AM
Unknown Object (File)
Mon, Jul 1, 5:33 PM
Unknown Object (File)
Sun, Jun 30, 3:40 PM
Unknown Object (File)
Fri, Jun 28, 11:50 AM
Unknown Object (File)
Wed, Jun 26, 3:17 PM
Unknown Object (File)
Tue, Jun 25, 11:54 PM
Unknown Object (File)
Tue, Jun 25, 11:54 PM

Details

Summary

This diff introduces using of the metadata to provide the sessionID by the client for the client authentication in the gRPC MessagesStream bidirectional stream.

We are making the following security checks with the sessionID:

  • Check if the sessionID is provided in metadata;
  • Check the sessionID format validity;
  • Check if the sessionID exists in the database session table.

Linear task: ENG-1359

Test Plan
  • Opening a MessagesStream from the gRPC client without providing the sessionID in metadata results in gRPC invalid argument error.
  • Opening a MessagesStream from the gRPC client providing the sessionID in a wrong format in metadata results in gRPC unauthenticated error.
  • Opening a MessagesStream from the gRPC client providing the unexistent sessionID in metadata results in gRPC unauthenticated error.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

max held this revision as a draft.
max published this revision for review.Nov 2 2022, 4:30 PM
max edited the summary of this revision. (Show Details)
max edited the test plan for this revision. (Show Details)
max added a reviewer: marcin. max added 1 blocking reviewer(s): jon.
services/tunnelbroker/src/libcpp/Tunnelbroker.cpp
148 ↗(On Diff #18042)
services/tunnelbroker/src/server/mod.rs
87 ↗(On Diff #18042)

not a big fan of unwraps

94–97 ↗(On Diff #18042)

in the future, might be nice to have a facade around the cxx_bridge stuff so we can have cleaner rust code base

Small changes based on comments.

max added inline comments.
services/tunnelbroker/src/server/mod.rs
87 ↗(On Diff #18042)

not a big fan of unwraps

Makes sense to use expect here. Changed!

94–97 ↗(On Diff #18042)

in the future, might be nice to have a facade around the cxx_bridge stuff so we can have cleaner rust code base

We have only two C++ functions that can return compatible to Tonic gRPC responses. Most part of them should return different results and we will process them on the Rust side in the following bidirectional messages stream handler. Not sure it makes sense for two requests.
I've shortened the calls by moving the cxx_bridge::ffi to use as we have a lot of calls for it, this increases readability a bit.

jon added inline comments.
services/tunnelbroker/src/server/mod.rs
94–97 ↗(On Diff #18042)

We have only two C++ functions that can return compatible to Tonic gRPC responses. Most part of them should return different results and we will process them on the Rust side in the following bidirectional messages stream handler. Not sure it makes sense for two requests.

Makes sense, if they are the exception.

This revision is now accepted and ready to land.Nov 4 2022, 10:59 AM
This revision now requires review to proceed.Nov 8 2022, 7:07 AM
max marked 2 inline comments as done.

Rebasing on master changes, small refactoring ot use let ... match.

Rebasing on parent changes.

Fixing int variable casting based on D5560

tomek added inline comments.
services/tunnelbroker/src/libcpp/Tunnelbroker.cpp
154 ↗(On Diff #18230)

Why is this cast required?

This revision is now accepted and ready to land.Nov 9 2022, 8:50 AM

Rebasing on master and parents changes.

max added inline comments.
services/tunnelbroker/src/libcpp/Tunnelbroker.cpp
154 ↗(On Diff #18230)

Why is this cast required?

The compiler forces us to use casting for the enum -> int:

Tunnelbroker.cpp:168:21: error: non-constant-expression cannot be narrowed from type 'size_t' (aka 'unsigned long') to '::std::int32_t' (aka 'int') in initializer list [-Wc++11-narrowing]
  cargo:warning=      .deviceType = sessionItem->getDeviceType(),
  cargo:warning=                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  cargo:warning=src/libcpp/Tunnelbroker.cpp:168:21: note: insert an explicit cast to silence this issue
  cargo:warning=      .deviceType = sessionItem->getDeviceType(),
  cargo:warning=                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  cargo:warning=                    static_cast<int32_t>(       )
max marked an inline comment as done.

Fix merging.