Skip to content

✨ Add Policy Server for Rate Limiting#68

Merged
0x46616c6b merged 4 commits intomainfrom
feature/policy-server-rate-limiting
Feb 22, 2026
Merged

✨ Add Policy Server for Rate Limiting#68
0x46616c6b merged 4 commits intomainfrom
feature/policy-server-rate-limiting

Conversation

@0x46616c6b
Copy link
Copy Markdown
Member

Summary

  • Add a Postfix SMTPD policy delegation server for rate limiting outgoing mail based on per-sender quotas
  • Implement a sliding window rate limiter with per-hour and per-day limits
  • Add GetQuota API endpoint to fetch sender quota limits from Userli

Details

The policy server listens on port 10003 (configurable via POLICY_LISTEN_ADDR) and implements the Postfix SMTPD Policy Delegation Protocol. It:

  1. Processes END-OF-MESSAGE protocol stage requests
  2. Resolves sender identity (prefers SASL username over envelope sender)
  3. Fetches per-hour/per-day quota from the Userli API
  4. Enforces limits using a sliding window rate limiter with automatic cleanup

Commits

Commit Description
✨ GetQuota API Quota struct, GetQuota on UserliService interface + implementation
✨ Rate limiter Sliding window rate limiter with per-sender timestamp tracking
✨ Policy server PolicyServer implementing ConnectionHandler, Prometheus metrics, config, main.go wiring
📝 Documentation README, docker-compose, copilot-instructions

Depends on


This PR was generated with the assistance of OpenCode.

Base automatically changed from refactor/extract-lookup-server to main February 6, 2026 20:27
@0x46616c6b 0x46616c6b changed the title Add Policy Server for Rate Limiting ✨ Add Policy Server for Rate Limiting Feb 6, 2026
@0x46616c6b 0x46616c6b force-pushed the feature/policy-server-rate-limiting branch from ea818be to 8e721ad Compare February 6, 2026 20:28
0x46616c6b and others added 3 commits February 22, 2026 10:40
Add Quota struct and GetQuota method to the UserliService interface
and Userli implementation. This queries the Userli API for per-hour
and per-day sending limits for a given email address, which will be
used by the policy server for rate limiting.

Co-Authored-By: OpenCode <noreply@opencode.ai>
Implement a per-sender rate limiter using a sliding window approach
that tracks message timestamps and enforces per-hour and per-day
sending limits. Includes automatic background cleanup of expired
entries to prevent memory growth.

Co-Authored-By: OpenCode <noreply@opencode.ai>
Implement a Postfix SMTPD policy delegation server that enforces
per-sender rate limits based on quotas from the Userli API. The
server checks the END-OF-MESSAGE protocol stage, resolves the
sender identity (preferring SASL username), fetches quota limits,
and uses the sliding window rate limiter to accept or reject.

- Add PolicyServer implementing ConnectionHandler interface
- Add policy-specific Prometheus metrics (requests, duration, quota)
- Add PolicyListenAddr configuration (default :10003)
- Wire up rate limiter, policy server, and metrics in main.go
- Comprehensive test coverage for all policy scenarios

Co-Authored-By: OpenCode <noreply@opencode.ai>
@0x46616c6b 0x46616c6b force-pushed the feature/policy-server-rate-limiting branch from 8e721ad to 5fb0c2d Compare February 22, 2026 09:41
- Add POLICY_LISTEN_ADDR to README configuration section
- Document rate limiting feature with Postfix integration example
- Add policy/rate limiting metrics documentation
- Expose policy server port in docker-compose.yml
- Update copilot-instructions.md with new architecture overview

Co-Authored-By: OpenCode <noreply@opencode.ai>
@0x46616c6b 0x46616c6b force-pushed the feature/policy-server-rate-limiting branch from 5fb0c2d to defa23e Compare February 22, 2026 09:57
@sonarqubecloud
Copy link
Copy Markdown

@0x46616c6b 0x46616c6b marked this pull request as ready for review February 22, 2026 10:19
@0x46616c6b 0x46616c6b merged commit 2325b29 into main Feb 22, 2026
6 checks passed
@0x46616c6b 0x46616c6b deleted the feature/policy-server-rate-limiting branch February 22, 2026 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant