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

Multi Subscription Single Connection #119

Merged
merged 31 commits into from
Jan 15, 2024
Merged

Multi Subscription Single Connection #119

merged 31 commits into from
Jan 15, 2024

Conversation

ErnestKz
Copy link
Contributor

@ErnestKz ErnestKz commented Nov 23, 2023

Current State of Draft

Added 2 additional modules to separate new behaviour from old:

Icepeak.Server.WebsocketServer.HandleClientSingleSubscription
Icepeak.Server.WebsocketServer.HandleClientMultiSubscription

Current draft implements the ability for the client thread to :

  • Client thread to case split on payloads, and sub and un-sub from the subscription tree accordingly.
  • Client thread to receive and read from multiple paths in the subscription tree, and send to socket.
  • Client thread to disconnect, and clean up the subscription tree after itself.

Left to do:

  • Payload parsing.
  • Authenticate the token and path.
  • Handle the un-authorised case.
  • Handle the unrecognised payload case.
  • Dispatch old vs new behaviour based on request.
  • Other protocol specific details.

Copy link
Member

@crtschin crtschin left a comment

Choose a reason for hiding this comment

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

Nice progress already! Left some preliminary comments. Curious to see the rest.

Copy link
Member

@fatho fatho left a comment

Choose a reason for hiding this comment

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

Good start already! I have a few remarks, but overall it looks like it should work

@ErnestKz
Copy link
Contributor Author

Will begin implementing protocol specific details, then circle around and re-visit some of the comments as things begin to take more shape.

@ErnestKz
Copy link
Contributor Author

ErnestKz commented Nov 30, 2023

Currently authorisation is built for:

  • Accepting incoming websocket connection:
    • It inspects the request headers for the token
    • It checks path that it is trying to subscribe to

Most relevant functions are:

  • isRequestAuthorized
    |- getRequestClaim
    |- isAuthorizedByClaim

Can pretty much re-use isAuthorisedByClaim

isAuthorizedByClaim :: IcepeakClaim -> Path -> AccessMode -> Bool

Within getRequestClaim there is:

case maybeSecret of
       Nothing     ->
         -- authorization is enabled, but no secret provided, accept all tokens
         getTokenBytes >>= extractClaimUnverified
       Just secret -> getTokenBytes >>= extractClaim now secret

Will perhaps be re-using:

extractClaim :: POSIXTime -> JWT.VerifySigner -> SBS.ByteString -> Either TokenError IcepeakClaim

The SBS.ByteString is the token.

Can get POSIXTime from:

now <- Clock.getPOSIXTime

Can get the JWT.VerifySigner from the config:

  -- | The secret used for verifying the JWT signatures. If no secret is
  -- specified even though JWT authorization is enabled, tokens will still be
  -- used, but not be verified.
  , configJwtSecret :: Maybe JWT.VerifySigner

New protocol will need to verify a list of paths using the token provided by the subscribe payload.
So it will be an extractClaim followed by an isAuthorizedByClaim. And the Maybe JWT.VerifySigner will be passed into the context of the function.

Presumably the configEnableJwtAuth :: Bool option only makes sense upon connection initalisation? What are the varying degrees of authorisation configurability?

Perhaps we will have to make re-use of extractClaimUnverified?

-- | Extract the icepeak claim from the token without verifying it.
extractClaimUnverified :: SBS.ByteString -> Either TokenError IcepeakClaim

@ErnestKz
Copy link
Contributor Author

ErnestKz commented Dec 4, 2023

So it feels like the core functionality should be there. Steps to see through to the refinement process:

  • Collaborate with frontend to see how the service functions
  • See what kind of tests would be appropriate
  • Split code up further, stick to the single style, address PR comments
  • Request feedback on functionality, style, and code structure

@ErnestKz
Copy link
Contributor Author

ErnestKz commented Dec 4, 2023

@crtschin How does it sound? Also, any suggestions for the direction on code structure? Particularly the chunky onPayload

@crtschin
Copy link
Member

crtschin commented Dec 5, 2023

Discussed offline, splitting up the onPayload and adding tests are the next steps.

@ErnestKz ErnestKz marked this pull request as ready for review December 15, 2023 16:06
@ErnestKz
Copy link
Contributor Author

This PR should be ready for review! Overall since last time, made big refactors, added tests, adjusted endpoint entrypoint to accept re-usable connections.

@crtschin crtschin self-requested a review December 18, 2023 08:56
Copy link
Member

@crtschin crtschin left a comment

Choose a reason for hiding this comment

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

Nice, I have some notes and suggestions. Might be good to setup your editor to work with fourmolu. The codestyle is quite inconsistent, and there quite some trailing whitespace strewn about.

docs/IcepeakProtocolMultiSub.md Show resolved Hide resolved
docs/IcepeakProtocolMultiSub.md Outdated Show resolved Hide resolved
docs/IcepeakProtocolMultiSub.md Outdated Show resolved Hide resolved
docs/IcepeakProtocolMultiSub.md Show resolved Hide resolved
docs/IcepeakProtocolMultiSub.md Outdated Show resolved Hide resolved
server/tests/Icepeak/Server/MultiSubscriptionSpec.hs Outdated Show resolved Hide resolved
server/tests/Icepeak/Server/MultiSubscriptionSpec.hs Outdated Show resolved Hide resolved
server/tests/Icepeak/Server/MultiSubscriptionSpec.hs Outdated Show resolved Hide resolved
crtschin

This comment was marked as duplicate.

crtschin

This comment was marked as duplicate.

@ErnestKz
Copy link
Contributor Author

Made a first pass over the PR comments, and pushed commits for them, the outstanding things yet to be addressed are:
General:

  • Metrics for the new protocol

Implementation:

Tests:

@ErnestKz ErnestKz mentioned this pull request Jan 4, 2024
@ErnestKz
Copy link
Contributor Author

ErnestKz commented Jan 9, 2024

I've added a subscription deadline timeout mechanism, and added more descriptive tests.

I think we can begin gradually rolling this out.

We can write a list of items that we may want to be wary of and come back to and implement if we see that they are needed as we roll out.

@crtschin

@ErnestKz ErnestKz requested a review from crtschin January 9, 2024 10:53
Copy link
Member

@fatho fatho left a comment

Choose a reason for hiding this comment

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

Good work! I have a few smaller remarks, but overall looking good 👍

@ErnestKz ErnestKz merged commit c973053 into master Jan 15, 2024
0 of 2 checks passed
@ErnestKz ErnestKz deleted the single-conn-multi-sub branch January 15, 2024 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants