Skip to content

refactor(auth): migrate capability enforcement to native ASP.NET Core authorization - #37

Merged
SiddharthaGF merged 2 commits into
mainfrom
refactor/capability-native-authorization
Aug 6, 2026
Merged

refactor(auth): migrate capability enforcement to native ASP.NET Core authorization#37
SiddharthaGF merged 2 commits into
mainfrom
refactor/capability-native-authorization

Conversation

@SiddharthaGF

Copy link
Copy Markdown
Owner

Summary

  • Migrate the bespoke RequireCapabilityAttribute + CapabilityAuthorizationFilter resolution to the native ASP.NET Core authorization pipeline: CapabilityRequirement (IAuthorizationRequirement), CapabilityAuthorizationHandler (AuthorizationHandler<CapabilityRequirement>), and CapabilityPolicyProvider (IAuthorizationPolicyProvider) that synthesizes a policy per capability code on demand
  • The endpoint filter stays the enforcement boundary but now delegates to IAuthorizationService; denials still raise CapabilityForbiddenException so the 403 problem-details body and access.denied audit are preserved unchanged
  • Enforcement still resolves through the existing IEffectiveCapabilityResolver, keeping the single memoized lookup per request shared by the filter, domain guards, and /api/me/capabilities

Files

File Change
src/Cynara.Api/CapabilityAuthorization/CapabilityRequirement.cs New IAuthorizationRequirement carrying the capability code
src/Cynara.Api/CapabilityAuthorization/CapabilityAuthorizationHandler.cs New handler delegating to IEffectiveCapabilityResolver
src/Cynara.Api/CapabilityAuthorization/CapabilityPolicyProvider.cs New provider synthesizing policies per code without startup enumeration
src/Cynara.Api/CapabilityAuthorization/CapabilityAuthorizationFilter.cs Delegates to IAuthorizationService, keeps CapabilityForbiddenException
src/Cynara.Api/Hosting/ServiceCollectionExtensions.cs Registers authorization + policy provider + handler
tools/Cynara.Seed/Program.cs Register AddLogging() so InitializeDatabaseAsync baseline resolves ILoggerFactory

Test plan

  • dotnet cake --target=Test — full suite green (incl. 28 capability tests)
  • dotnet cake --target=FormatCheck and --target=Lint — green
  • Live HTTP validation: no-actor 403, no-grant 403, read 200, write-while-read-only 403, revoke 403, cross-tenant isolation, access.denied audit rows

Notes

The seed-tool AddLogging() fix is included because it was required to run the migration/seed flow (dotnet cake --target=Seed) against an empty database.

Linear:

… authorization

Replace the bespoke attribute/filter resolution with the framework
pipeline: IAuthorizationRequirement + AuthorizationHandler +
IAuthorizationPolicyProvider, keeping the endpoint filter as the
enforcement boundary and preserving CapabilityForbiddenException (403
problem-details + access.denied audit). The policy provider synthesizes
policies per capability code on demand, so the catalog needs no startup
enumeration.
The seed CLI builds its own ServiceCollection without logging, but
InitializeDatabaseAsync's baseline path resolves ILoggerFactory.
Without AddLogging() the seed tool crashes on startup.
@SiddharthaGF
SiddharthaGF temporarily deployed to refactor/capability-native-authorization - cynara-api PR #37 August 6, 2026 06:41 — with Render Destroyed
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

Neon branch ready.

@SiddharthaGF
SiddharthaGF merged commit cf3760b into main Aug 6, 2026
4 checks passed
@SiddharthaGF
SiddharthaGF deleted the refactor/capability-native-authorization branch August 6, 2026 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant