Skip to content

feat: api egress limiter, resolve user UPN or guid with github support and scope response cache per user - #42

Merged
JohnDuprey merged 4 commits into
mainfrom
dev
Sep 11, 2026
Merged

JohnDuprey merged 4 commits into
mainfrom
dev

Conversation

@Zacgoose

Copy link
Copy Markdown
Contributor

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

  • Added EgressLimitSettings and integrated it into RateLimitSettings to support a per-instance daily API egress cap, with configuration and environment variable overrides. [1] [2]
  • Introduced ApiEgressLimiterMiddleware, which tracks and enforces the daily egress cap for API (app-only) clients, returning HTTP 429 with a Retry-After header when the cap is exceeded.

User Identification and Authorization

  • Enhanced EasyAuthClaims to include a Login field, 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]
  • Updated AuthService.GetUserRoles to accept multiple identifiers and union roles from all matches, supporting flexible authorization for users with multiple possible identifiers.

Caching Improvements

  • Changed cache key generation in CacheService to 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]

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
JohnDuprey merged commit af6cdc4 into main Sep 11, 2026
7 checks passed
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.

2 participants