Skip to content

Conversation

@JSv4
Copy link
Collaborator

@JSv4 JSv4 commented Aug 25, 2025

Changes Made

  • Added three rate limiting middlewares to compose/production/traefik/traefik.yml:
    • frontend-ratelimit: 100 req/s avg, 200 burst (static content)
    • api-ratelimit: 30 req/s avg, 60 burst (GraphQL/Admin APIs)
    • flower-ratelimit: 10 req/s avg, 20 burst (monitoring interface)
  • Configured Redis backend for distributed rate limiting:
    • Uses existing redis:6379 service
    • Database 1 for rate limiting data isolation
    • Optimized connection pooling per service tier
  • Applied rate limiting to all routers:
    • Frontend router: Added frontend-ratelimit before CSRF
    • Django/API router: Added api-ratelimit before CSRF
    • Flower router: Added flower-ratelimit

Security Features

  • IP-based rate limiting with X-Forwarded-For support (depth: 1)
  • IPv6 subnet grouping (/64) to prevent address rotation bypasses
  • Graceful fallback to in-memory storage if Redis unavailable

@JSv4 JSv4 linked an issue Aug 25, 2025 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Aug 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

JSv4 and others added 23 commits August 25, 2025 04:10
…ectory handling for self-signed certificates
…ik.yml, update rate limits, and adjust router rules to include localhost. Remove obsolete test files and scripts.
… test script with container status and service health checks
…er, ensuring compatibility and avoiding conflicts with sentence-transformers. Enhance Traefik configuration by adding TLS support for self-signed certificates.
…icates, ensuring a fallback to self-signed certificates. Update rate limiting test script to improve error handling and add certificate checks for better debugging.
…ik container health, processes, and listening ports. Update certificate checks for clearer error messages.
…entation

- Introduced a dedicated migration service in `production.yml` to handle database migrations before starting other services, preventing race conditions.
- Updated the `django` service command to skip the collectstatic step when not using AWS.
- Enhanced documentation in `README.md` and `quick_start.md` to include instructions for running migrations in production.
- Added sample environment files for Django, PostgreSQL, and frontend configurations to facilitate production deployments.
- Added a step to generate self-signed certificates for testing in the production stack workflow.
- Updated the certificate validation step to include checks for generated certificates and their mounts in the Traefik container.
- Improved the `generate-certs.sh` script with additional validation and debugging information for generated certificates.
- Ensured proper permissions for certificate files and corrected IPv6 loopback handling in the certificate generation process.
- Minor formatting adjustments in the `start-no-collectstatic` script and sample environment files.
- Introduced rate limiting decorators for GraphQL mutations and queries, enhancing control over request rates based on user tiers.
- Configured dynamic rate limits for different user types, including superusers, authenticated users, and anonymous users.
- Added a new `ratelimits.py` module to centralize rate limit configurations and utilities.
- Updated existing mutations and queries to include rate limiting, ensuring compliance with defined limits.
- Created detailed documentation on rate limiting implementation, testing strategies, and configuration options.
- Developed test scripts to validate rate limiting functionality in both CI and local environments.
- Adjusted rate limits for various GraphQL queries and mutations, ensuring compliance with user tiers.
- Added dynamic rate limiting decorators to specific queries, enhancing control over request rates.
- Updated the CI rate limiting test script for clearer output and streamlined testing processes.
- Improved the test coverage for rate limiting scenarios, including user-specific limits and error handling.
- Refactored existing tests to utilize Django's test client for better integration with the GraphQL API.
- Improved the GraphQL rate limiting decorator to handle cases where `info` or `request` may be `None`, ensuring robustness in various contexts.
- Updated the CI rate limiting test script to eliminate delays, allowing for faster request processing and clearer rate limit triggering.
- Refactored the test script to store rate limit results in global variables for better clarity in output and summary reporting.
- Added a testing environment flag in the Django settings to facilitate rate limit safety checks.
- Improved the GraphQL rate limiting decorators to log warnings in non-test environments when `info` or `request` contexts are missing, enhancing security monitoring.
- Updated documentation to clarify the implementation and testing of rate limiting at both infrastructure and application levels, including detailed testing instructions and troubleshooting tips.
- Introduced `environ` for environment variable management in `ratelimit.py`, allowing dynamic configuration of rate limiting behavior.
- Updated `RATELIMIT_DISABLE` to default to `False` in non-test environments, enhancing performance during testing.
- Added documentation in `test.py` to clarify the default behavior of rate limiting in tests, allowing individual tests to override settings as needed.
@JSv4 JSv4 merged commit 006d85e into main Sep 1, 2025
12 checks passed
@JSv4 JSv4 deleted the JSv4/add-ratelimits branch September 1, 2025 02:43
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.

[FEATURE] Rate Limiting

2 participants