feat: api egress limiter, resolve user UPN or guid with github support and scope response cache per user - #42
Merged
Merged
Conversation
Add a multi-identifier role lookup in AuthService so roles are merged from any matching allowedUsers entries (e.g., UPN/login and object ID). Authorization now fails only when no identifiers match and AllowAllTenantUsers is false. Update CraftAuthMiddleware to request roles using both the display name and stable object ID, allowing GitHub and Entra users to be authorized by either key.
Replace the role-based cache key component with a stable per-user key derived from the Easy Auth principal so callers with identical roles cannot share cached responses. Update cache profiling and perf-harness terminology to match, and add coverage for key generation and end-to-end cache isolation across authenticated, anonymous, and app-only callers.
Introduce a hosted-only daily API egress cap with configurable settings, persisted ledger state, and middleware that counts response bytes for app-only callers and returns 429 with Retry-After after the budget is exhausted. Wire the feature into startup, document the new configuration, and add tests for settings resolution, ledger persistence/rollover, and middleware behavior.
JohnDuprey
approved these changes
Sep 11, 2026
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.
This pull request introduces a per-instance daily API egress (bandwidth) cap feature, improves user identification for authorization and caching, and refines how cache keys are generated and used. The most significant changes are the addition of egress limiting middleware and configuration, enhanced support for non-Entra (e.g., GitHub) identities, and improved cache key isolation per user.
API Egress Limiting
EgressLimitSettingsand integrated it intoRateLimitSettingsto support a per-instance daily API egress cap, with configuration and environment variable overrides. [1] [2]ApiEgressLimiterMiddleware, which tracks and enforces the daily egress cap for API (app-only) clients, returning HTTP 429 with aRetry-Afterheader when the cap is exceeded.User Identification and Authorization
EasyAuthClaimsto include aLoginfield, allowing non-Entra users (e.g., GitHub users) to be identified and authorized by either their login name or numeric ID, and updated claim extraction logic accordingly. [1] [2] [3] [4]AuthService.GetUserRolesto accept multiple identifiers and union roles from all matches, supporting flexible authorization for users with multiple possible identifiers.Caching Improvements
CacheServiceto use a per-user key (based on user identity, not just roles), ensuring that cached responses are not shared between different users, and updated related documentation and helper methods. [1] [2] [3] [4]