feat: per-train authorization, principal injection, and trusted execution#28
Merged
Conversation
…tion Adds the mediator-side infrastructure that Trax.Api builds on: - AuthorizationRegistrationValidator validates that any train declaring [TraxAuthorize] has an ITrainAuthorizationService registered in the container at startup, rather than failing at request time. - Principal scope service lets junctions inject TraxPrincipal directly without IHttpContextAccessor plumbing. - TrustedExecution scope marks internally-initiated train runs (scheduler, workers) as bypassing authorization, since there is no user principal. - Adds per-principal concurrency bucketing surface on TraxMediatorBuilder. - Surfaces TrainAuthorizationException as a first-class mediator type so callers can distinguish authz failures from other exceptions. - Exposes registration metadata (required policies / roles) through TrainRegistration for downstream discovery.
This was referenced Apr 15, 2026
|
This PR is included in version 1.16.0 |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
[TraxAuthorize]fail at startup if noITrainAuthorizationServiceis registered, rather than at request time.TraxPrincipalaccessor so junctions inject the authenticated user directly withoutIHttpContextAccessor.TraxMediatorBuilder.PerPrincipalMaxConcurrentRun(int).TrainAuthorizationExceptionpromoted to a first-class mediator type;TrainRegistrationexposes required policies / roles for discovery consumers.Dependency order
Paired with:
Merge this first; downstream packages reference the new mediator APIs.
Known issue
AuthorizationRegistrationValidatorcurrently resolvesITrainAuthorizationServiceagainst the root provider during startup. ASP.NET Core scope validation (enabled inWebApplicationFactoryE2E tests) flags this as a scoped-from-root violation. GameServer and JobHunt E2E suites fail against this. The fix is small — resolve inside a created scope — but is tracked as a follow-up so this PR can land the broader surface.Test plan
dotnet buildwith zero warningsAuthorizationRegistrationValidatorTests,TrainDiscoveryAuthorizationTests,PerPrincipalConcurrencyTests,TrustedExecutionScopeTests,TrainExecutionServiceLookupTests)