feat: add permissions for ratelimit overrides
What does this PR do?
Fixes # (issue) eng-1336
Type of change
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Chore (refactoring code, technical debt, workflow improvements)
- [ ] Enhancement (small improvements)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
How should this be tested?
Check if I understood the assignment properly.
Checklist
Required
- [x] Filled out the "How to test" section in this PR
- [x] Read Contributing Guide
- [x] Self-reviewed my own code
- [x] Commented on my code in hard-to-understand areas
- [ ] Ran
pnpm build - [ ] Ran
pnpm fmt - [x] Checked for warnings, there are none
- [x] Removed all
console.logs - [x] Merged the latest changes from main onto my branch with
git pull origin main - [x] My changes don't cause any responsiveness issues
Appreciated
- [ ] If a UI change was made: Added a screen recording or screenshots to this PR
- [ ] Updated the Unkey Docs if changes were necessary
Summary by CodeRabbit
Release Notes
-
New Features
- Introduced API routes for managing rate limit overrides: set, delete, and list overrides.
- Added new permissions for rate limiting actions: set_override, read_override, and delete_override.
- Enhanced logging capabilities with new event types related to rate limiting.
- Updated key verification request and response schemas to improve usability.
-
Bug Fixes
- Improved error handling and clarity in request and response schemas for key verification.
⚠️ No Changeset found
Latest commit: 8d82f6595a8468f7dad6661a583a4f4ee6577242
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| dashboard | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Nov 18, 2024 1:52pm |
| engineering | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Nov 18, 2024 1:52pm |
| planetfall | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Nov 18, 2024 1:52pm |
| play | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Nov 18, 2024 1:52pm |
| unkey-engineering | ❌ Failed (Inspect) | Nov 18, 2024 1:52pm | ||
| workflows | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Nov 18, 2024 1:52pm |
| www | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Nov 18, 2024 1:52pm |
📝 Walkthrough
📝 Walkthrough
Walkthrough
The changes in this pull request primarily enhance the rate limiting functionality across various components of the application. Key modifications include the addition of new route handlers for managing rate limit overrides, updates to permissions related to rate limits, and adjustments to logging events. The import paths for certain modules have been corrected, and several tests have been added or modified to ensure proper functionality and error handling for the new rate limit features.
Changes
| File | Change Summary |
|---|---|
| apps/api/src/worker.ts | Updated import path for registerV1RatelimitLimit and added four new rate limit related functions. |
| apps/dashboard/app/(app)/settings/root-keys/[keyId]/permissions/permissions.ts | Added three new permissions (set_override, read_override, delete_override) under the Ratelimit category. |
| internal/schema/src/auditlog.ts | Updated unkeyAuditLogEvents enum by removing three event types and adding three new ones related to rate limits. |
| packages/api/src/client.ts | Commented out four methods related to rate limits in the Unkey class. |
| apps/dashboard/lib/trpc/routers/ratelimit/createOverride.ts | Renamed audit log event for creating a rate limit override. |
| apps/dashboard/lib/trpc/routers/ratelimit/deleteNamespace.ts | Renamed audit log event for deleted rate limit overrides and standardized error handling. |
| apps/dashboard/lib/trpc/routers/ratelimit/deleteOverride.ts | Renamed audit log event for deletion of rate limits. |
| apps/dashboard/lib/trpc/routers/ratelimit/updateOverride.ts | Renamed audit log event for updating rate limits while maintaining existing logic. |
| apps/api/src/pkg/keys/service.ts | Enhanced error handling and logging in the _verifyKey method, particularly for workspace and rate limit management. |
| apps/api/src/routes/v1_ratelimits_deleteOverride.error.test.ts | Introduced a test case for handling requests without namespaceId or namespaceName. |
| apps/api/src/routes/v1_ratelimits_deleteOverride.happy.test.ts | Added a test for successful deletion of rate limit overrides. |
| apps/api/src/routes/v1_ratelimits_deleteOverride.security.test.ts | Introduced tests for role-based access control on the deleteOverride endpoint. |
| apps/api/src/routes/v1_ratelimits_deleteOverride.ts | Added a new route for deleting rate limit overrides with appropriate request validation and error handling. |
| apps/api/src/routes/v1_ratelimits_getOverride.error.test.ts | Introduced a test case for missing namespaceId in the getOverride endpoint. |
| apps/api/src/routes/v1_ratelimits_getOverride.happy.test.ts | Added tests for retrieving rate limit overrides using namespaceId and namespaceName. |
| apps/api/src/routes/v1_ratelimits_getOverride.security.test.ts | Created a test suite for role permissions in the getOverride endpoint. |
| apps/api/src/routes/v1_ratelimits_getOverride.ts | Introduced a new API route for retrieving rate limit overrides with appropriate validation and error handling. |
| apps/api/src/routes/v1_ratelimits_limit.accuracy.test.ts | Updated import paths for rate limit request and response types. |
| apps/api/src/routes/v1_ratelimits_limit.consistency.test.ts.skipped | Updated import paths for rate limit request and response types. |
| apps/api/src/routes/v1_ratelimits_limit.happy.test.ts | Updated import paths for rate limit request and response types. |
| apps/api/src/routes/v1_ratelimits_limit.overrides.test.ts | Updated import paths for rate limit request and response types. |
| apps/api/src/routes/v1_ratelimits_listOverrides.error.test.ts | Introduced a test case for missing namespaceId or namespaceName in the listOverrides endpoint. |
| apps/api/src/routes/v1_ratelimits_listOverrides.happy.test.ts | Added tests for listing rate limit overrides with various scenarios. |
| apps/api/src/routes/v1_ratelimits_listOverrides.security.test.ts | Created a test suite for role permissions in the listOverrides endpoint. |
| apps/api/src/routes/v1_ratelimits_listOverrides.ts | Introduced a new API route for listing rate limit overrides with appropriate validation and error handling. |
| apps/api/src/routes/v1_ratelimits_setOverride.error.test.ts | Added tests for error scenarios in the setOverride endpoint. |
| apps/api/src/routes/v1_ratelimits_setOverride.happy.test.ts | Implemented tests for setting and updating rate limit overrides. |
| apps/api/src/routes/v1_ratelimits_setOverride.security.test.ts | Created a test suite for role permissions in the setOverride endpoint. |
| apps/api/src/routes/v1_ratelimits_setOverride.ts | Introduced a new API route for setting rate limit overrides with appropriate validation and error handling. |
| apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx | Added a useEffect hook to reset form fields related to rate limiting upon component mount. |
| apps/dashboard/app/(app)/settings/root-keys/new/client.tsx | Introduced a useEffect hook to optimize the initialization of selected API permissions. |
| apps/dashboard/app/auth/sign-in/email-signin.tsx | Corrected a typo in a comment related to linting. |
| apps/dashboard/app/auth/sign-up/email-signup.tsx | Enhanced sign-up functionality to process URL parameters and improved error handling. |
| apps/www/components/shiny-card.tsx | Improved formatting of className properties and added mouse position tracking functionality. |
| internal/clickhouse/src/insert_verifications.test.ts | Updated test case to handle new result structure from ClickHouse database. |
| package.json | Modified the test script to enforce single-threaded execution during testing. |
| packages/api/package.json | Added a new pull script for Docker image updates and modified the test script to run the pull script before executing tests. |
| .github/workflows/deploy.yaml | Adjusted job dependencies to streamline the workflow execution sequence. |
| .github/workflows/build.yaml | Modified the Run worker step and added a new Build step to the workflow. |
| .github/workflows/job_test_api_local.yaml | Added a step to delete a specific directory before running tests. |
| deployment/docker-compose.yaml | Commented out configurations for prometheus and grafana services in the deployment setup. |
| .github/workflows/pr.yaml | Updated the test_packages job to use a different workflow file for testing. |
Sequence Diagram(s)
sequenceDiagram
participant User
participant API
participant Database
participant Logger
User->>API: Request to set rate limit override
API->>Database: Validate namespace and identifier
Database-->>API: Return validation result
alt If valid
API->>Database: Create or update override
Database-->>API: Return override details
API->>Logger: Log override action
Logger-->>API: Confirm log entry
API-->>User: Respond with success
else If invalid
API-->>User: Respond with error
end
Possibly related PRs
- #2076: This PR introduces rate limiting functionality to the dashboard, which is directly related to the changes made in the main PR regarding the registration of rate limiting route handlers.
- #2544: This PR implements Cloudflare's ratelimiter, which aligns with the main PR's focus on enhancing rate limiting functionality in the application.
Suggested labels
Feature, 🕹️ oss.gg, :joystick: 300 points, hacktoberfest
Suggested reviewers
- mcstepp
- perkinsjr
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
Thank you for following the naming conventions for pull request titles! 🙏