Skip to content

Per-module-instance access tokens and client identit - #1530

Open
Sziszka90 wants to merge 1 commit into
mainfrom
feature/permodule-instance-access-token
Open

Sziszka90 wants to merge 1 commit into
mainfrom
feature/permodule-instance-access-token

Conversation

@Sziszka90

Copy link
Copy Markdown

Issue tokens per module instance and add message router client identity

Summary

  • Per-module-instance access tokens. Previously the shell handed every module the same message router access token (App.MessageRouterAccessToken, marked TODO: Assign a unique token for each module). Each module instance now gets its own random 256-bit token, issued by a new ModuleTokenStore when the module is configured. The web and native module configurators request the token for the instance and inject it into the page or the environment variables. Re-issuing for the same instance returns the same token.
  • Client identity on the router. Added an IClientAuthenticator abstraction and MessageRouterServerBuilder.UseClientAuthenticator(...). MessageRouterServer calls it on connect and stores the resulting ClaimsPrincipal on the client, so identity is available for later authorization. The shell's ModuleTokenClientAuthenticator maps a token to claims: composeui:identity-type (module or host), composeui:module-instance-id and composeui:module-id. IAccessTokenValidator is unchanged, and clients are only authenticated when an authenticator is registered.
  • Separate host token. The shell's in-process client and the services built on it (for example the FDC3 desktop agent) connect with a dedicated host token. It differs from every module token and is valid for the lifetime of the store.
  • Revocation and token handling. ModuleTokenRevocationService revokes a module instance's token when the module stops. It subscribes in the constructor so no lifetime event is missed. Token comparison uses CryptographicOperations.FixedTimeEquals and checks every entry, so timing doesn't reveal which token matched.

Behavior changes

  • A module token is only valid for that module instance and stops working when the instance stops.
  • App.MessageRouterAccessToken is removed. It was internal, and the shell was its only consumer.
  • MessageRouterStartupAction now requires an IModuleTokenStore, and the module configurators have an internal constructor that takes one.

Test plan

  • dotnet test for the message router server tests (MessageRouterServer.Tests.cs: authenticator is invoked, the principal is stored, authentication failures reject the connection)
  • dotnet test for the new shell tests: ModuleTokenStore, ModuleTokenClientAuthenticator, ModuleTokenRevocationService, ModuleMessageRouterConfigurators and GlobalAccessToken
  • Manual: start the shell with a web module and a native module, and check that each connects to the message router
  • Manual: stop a module, then confirm that reconnecting with its old token is rejected
  • Manual: confirm FDC3 desktop agent messaging still works (it uses the host token)

@Sziszka90
Sziszka90 requested a review from a team as a code owner November 11, 2026 09:52
@Sziszka90
Sziszka90 force-pushed the feature/permodule-instance-access-token branch from 805be09 to b7f2d08 Compare November 11, 2026 09:59
@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.2%. Comparing base (48eae1f) to head (a5865ea).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #1530     +/-   ##
=======================================
+ Coverage   69.2%   70.2%   +1.0%     
=======================================
  Files        308     313      +5     
  Lines       8890    9023    +133     
  Branches    1151    1163     +12     
=======================================
+ Hits        6157    6340    +183     
+ Misses      2382    2340     -42     
+ Partials     351     343      -8     
Files with missing lines Coverage Δ
...essaging/dotnet/src/Core/Exceptions/ThrowHelper.cs 54.5% <100.0%> (+4.5%) ⬆️
...ng/dotnet/src/ModuleAccessTokens/ModuleIdentity.cs 100.0% <100.0%> (ø)
...duleAccessTokens/ModuleTokenClientAuthenticator.cs 100.0% <100.0%> (ø)
...ModuleAccessTokens/ModuleTokenRevocationService.cs 100.0% <100.0%> (ø)
.../dotnet/src/ModuleAccessTokens/ModuleTokenStore.cs 100.0% <100.0%> (ø)
.../ModuleAccessTokens/ServiceCollectionExtensions.cs 100.0% <100.0%> (ø)
.../DependencyInjection/MessageRouterServerBuilder.cs 62.9% <100.0%> (+6.4%) ⬆️
...ng/dotnet/src/Server/Server/MessageRouterServer.cs 77.3% <100.0%> (+0.8%) ⬆️
...c/Server/Server/MessageRouterServerDependencies.cs 100.0% <100.0%> (ø)
...ng/js/composeui-messaging-client/src/ErrorNames.ts 100.0% <100.0%> (ø)
... and 5 more

... and 15 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

DavidNemeth
DavidNemeth previously approved these changes Nov 11, 2026

@DavidNemeth DavidNemeth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I found one small thing worth fixing before merge.

The token is issued in Configure, but it only gets revoked when a Stopped event arrives. If the module fails to start after that point (the runner's Start throws), the loader never emits Stopped, so the token stays valid even though the module never ran. I checked this with the real ModuleLoader and ModuleTokenRevocationService: after a failed start, TryValidate(token) still returns true. Revoking the token in a catch around the start should cover it.

Also, heads-up: this conflicts with #1531 in MessageRouterServer.cs, so whichever of the two merges second will need a rebase.

@Sziszka90
Sziszka90 force-pushed the feature/permodule-instance-access-token branch from b7f2d08 to 548d1a4 Compare November 16, 2026 08:26
@Sziszka90

Copy link
Copy Markdown
Author

I found one small thing worth fixing before merge.

The token is issued in Configure, but it only gets revoked when a Stopped event arrives. If the module fails to start after that point (the runner's Start throws), the loader never emits Stopped, so the token stays valid even though the module never ran. I checked this with the real ModuleLoader and ModuleTokenRevocationService: after a failed start, TryValidate(token) still returns true. Revoking the token in a catch around the start should cover it.

Also, heads-up: this conflicts with #1531 in MessageRouterServer.cs, so whichever of the two merges second will need a rebase.

@DavidNemeth I fixed

@Sziszka90
Sziszka90 force-pushed the feature/permodule-instance-access-token branch 4 times, most recently from aedf2a8 to d0a86a3 Compare November 18, 2026 09:38
@Sziszka90
Sziszka90 force-pushed the feature/permodule-instance-access-token branch 2 times, most recently from 4ecf732 to 8038c68 Compare November 19, 2026 11:38
@Sziszka90
Sziszka90 force-pushed the feature/permodule-instance-access-token branch from 8038c68 to a5865ea Compare November 23, 2026 08:32

This branch has not been deployed

No deployments
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.

3 participants