{"id":22616148,"url":"https://github.com/systemli/userli-postfix-adapter","last_synced_at":"2026-04-30T14:00:47.852Z","repository":{"id":264411533,"uuid":"864864607","full_name":"systemli/userli-postfix-adapter","owner":"systemli","description":null,"archived":false,"fork":false,"pushed_at":"2026-04-22T14:32:02.000Z","size":207,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-04-22T16:27:08.057Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/systemli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-09-29T11:24:48.000Z","updated_at":"2026-04-22T14:31:16.000Z","dependencies_parsed_at":"2024-11-24T05:16:05.187Z","dependency_job_id":"a5a04c3d-29d2-4ab8-9707-013287ee9b34","html_url":"https://github.com/systemli/userli-postfix-adapter","commit_stats":null,"previous_names":["systemli/userli-postfix-adapter"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/systemli/userli-postfix-adapter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemli%2Fuserli-postfix-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemli%2Fuserli-postfix-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemli%2Fuserli-postfix-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemli%2Fuserli-postfix-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/systemli","download_url":"https://codeload.github.com/systemli/userli-postfix-adapter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemli%2Fuserli-postfix-adapter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32466333,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"ssl_error","status_checked_at":"2026-04-30T13:12:06.837Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-08T19:11:03.394Z","updated_at":"2026-04-30T14:00:47.846Z","avatar_url":"https://github.com/systemli.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# userli-postfix-adapter\n\n[![Integration](https://github.com/systemli/userli-postfix-adapter/actions/workflows/integration.yml/badge.svg)](https://github.com/systemli/userli-postfix-adapter/actions/workflows/integration.yml) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=systemli_userli-postfix-adapter\u0026metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=systemli_userli-postfix-adapter) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=systemli_userli-postfix-adapter\u0026metric=alert_status)](https://sonarcloud.io/summary/new_code?id=systemli_userli-postfix-adapter) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=systemli_userli-postfix-adapter\u0026metric=coverage)](https://sonarcloud.io/summary/new_code?id=systemli_userli-postfix-adapter)\n\nThis is a postfix socketmap adapter for the [userli](https://github.com/systemli/userli) project.\nIt implements the [socketmap protocol](https://www.postfix.org/socketmap_table.5.html) to provide dynamic lookups for aliases, domains, mailboxes, and senders.\n\n## Configuration\n\nThe adapter is configured via environment variables:\n\n- `USERLI_TOKEN`: The token to authenticate against the userli API.\n- `USERLI_BASE_URL`: The base URL of the userli API.\n- `POSTFIX_RECIPIENT_DELIMITER`: The recipient delimiter used in Postfix (e.g., `+`). Default: empty.\n- `SOCKETMAP_LISTEN_ADDR`: The address to listen on for socketmap requests. Default: `:10001`.\n- `POLICY_LISTEN_ADDR`: The address to listen on for policy requests (rate limiting). Default: `:10003`.\n- `METRICS_LISTEN_ADDR`: The address to listen on for metrics. Default: `:10002`.\n- `RATE_LIMIT_MESSAGE`: The rejection message returned when a sender exceeds their quota. Default: `Rate limit exceeded, please try again later`.\n- `REDIS_URL`: Connection URL for Redis (required). Format follows [`redis.ParseURL`](https://pkg.go.dev/github.com/redis/go-redis/v9#ParseURL), e.g. `redis://[user:password@]host:port/db`. Rate-limit state is stored in Redis so it survives restarts.\n- `LOOKUP_CACHE_TTL`: TTL for cached successful (`OK`) lookup responses in Redis. Accepts any [Go duration](https://pkg.go.dev/time#ParseDuration) (e.g. `300s`, `5m`). Default: `300s`. Set to `0` to disable the cache. `NOTFOUND`/`TEMP`/`PERM` responses are never cached.\n\nIn Postfix, you can configure the adapter using the socketmap protocol like this:\n\n```text\nvirtual_alias_maps = socketmap:inet:localhost:10001:alias\nvirtual_mailbox_domains = socketmap:inet:localhost:10001:domain\nvirtual_mailbox_maps = socketmap:inet:localhost:10001:mailbox\nsmtpd_sender_login_maps = socketmap:inet:localhost:10001:senders\n```\n\n### Rate Limiting (Policy Server)\n\nThe adapter also provides a Postfix SMTP Access Policy Delegation server for rate limiting outgoing mail.\nIt queries the Userli API for per-user quotas and enforces sending limits.\n\nConfigure in Postfix `main.cf`:\n\n```text\nsmtpd_end_of_data_restrictions = check_policy_service inet:localhost:10003\n```\n\nThe Userli API endpoint `/api/postfix/smtp_quota/{email}` returns:\n\n```json\n{\n    \"per_hour\": 100,\n    \"per_day\": 1000\n}\n```\n\nWhere `0` means unlimited. If the API is unreachable, messages are allowed (fail-open).\n\nRate-limit state is persisted to Redis (`REDIS_URL`) so it survives restarts. If Redis is unreachable, messages are also allowed (fail-open) and the `userli_postfix_adapter_ratelimit_backend_errors_total` counter is incremented.\n\n## Docker\n\nYou can run the adapter using Docker.\nA `docker-compose.yml` file is provided for convenience.\n\n```bash\ndocker compose up -d\n\n# Create the database and load fixtures\ndocker compose exec userli bin/console doctrine:schema:create\ndocker compose exec userli bin/console doctrine:fixtures:load --no-debug\n\ndocker compose exec postfix postmap -q \"example.org\" socketmap:inet:adapter:10001:domain\n```\n\nThe socketmap names supported are:\n\n- `alias` - For virtual alias lookups\n- `domain` - For virtual domain lookups\n- `mailbox` - For virtual mailbox lookups\n- `senders` - For sender login map lookups\n\n## Usage Example\n\nYou can test the socketmap adapter using `postmap`:\n\n```bash\n# Test alias lookup\npostmap -q \"test@example.com\" socketmap:inet:localhost:10001:alias\n\n# Test domain lookup\npostmap -q \"example.com\" socketmap:inet:localhost:10001:domain\n\n# Test mailbox lookup\npostmap -q \"user@example.com\" socketmap:inet:localhost:10001:mailbox\n\n# Test sender lookup\npostmap -q \"sender@example.com\" socketmap:inet:localhost:10001:senders\n```\n\n### Docker Usage\n\n```bash\n# Build and run with docker-compose\ndocker-compose up --build\n\n# Or build manually\ndocker build -t userli-postfix-adapter .\ndocker run -e USERLI_TOKEN=your_token -e USERLI_BASE_URL=http://your-userli-instance -p 10001:10001 -p 10002:10002 userli-postfix-adapter\n```\n\n## Protocol Details\n\nThe adapter implements the Postfix socketmap protocol using netstrings for encoding. Each request and response is formatted as:\n\n```text\n[length]:[data],\n```\n\nWhere:\n\n- `length` is the decimal length of the data\n- `:` is a delimiter\n- `data` is the actual request or response content\n- `,` is the terminating comma\n\n### Request Format\n\n```text\n[length]:[mapname key],\n```\n\nExamples:\n\n- `22:alias test@example.com,` - Look up alias for \u003ctest@example.com\u003e\n- `18:domain example.com,` - Check if domain example.com exists\n- `23:mailbox user@example.com,` - Check if mailbox \u003cuser@example.com\u003e exists\n- `24:senders user@example.com,` - Get senders for \u003cuser@example.com\u003e\n\n### Response Format\n\nThe adapter returns one of these response types:\n\n- `OK [data]` - Successful lookup with data\n- `NOTFOUND` - No data found for the key\n- `TEMP [reason]` - Temporary error (retry later)\n- `PERM [reason]` - Permanent error (don't retry)\n\nExamples:\n\n- `19:OK dest@example.com,` - Alias found, destination is \u003cdest@example.com\u003e\n- `4:OK 1,` - Domain/mailbox exists\n- `8:NOTFOUND,` - No data found\n- `20:TEMP Service error,` - Temporary service error\n\n## Observability\n\nThe adapter exposes Prometheus metrics on `/metrics` (port 10002) and provides health check endpoints.\n\n### Metrics\n\n**Socketmap Metrics:**\n\n- `userli_postfix_adapter_request_duration_seconds` - Request duration histogram\n- `userli_postfix_adapter_requests_total` - Total request counter\n- `userli_postfix_adapter_active_connections` - Active connections gauge\n- `userli_postfix_adapter_connection_pool_usage` - Connection pool usage (0-500)\n\n**HTTP Client Metrics:**\n\n- `userli_postfix_adapter_http_client_duration_seconds` - Userli API request duration\n- `userli_postfix_adapter_http_client_requests_total` - Userli API request counter\n\n**Health:**\n\n- `userli_postfix_adapter_health_check_status` - Health check status (1=healthy, 0=unhealthy)\n\n**Policy/Rate Limiting Metrics:**\n\n- `userli_postfix_adapter_policy_active_connections` - Active policy connections gauge\n- `userli_postfix_adapter_policy_requests_total` - Total policy request counter\n- `userli_postfix_adapter_policy_request_duration_seconds` - Policy request duration histogram\n- `userli_postfix_adapter_quota_exceeded_total` - Total messages rejected due to quota\n- `userli_postfix_adapter_quota_checks_total` - Total quota checks performed\n- `userli_postfix_adapter_ratelimit_backend_errors_total` - Total Redis errors hit by the rate limiter, labelled by `operation`\n\nAll metrics include relevant labels (handler, status, endpoint, etc.).\n\n### Health Endpoints\n\n- **`/health`** - Liveness probe (always returns 200 OK)\n- **`/ready`** - Readiness probe (checks Userli API connectivity)\n\nExample Kubernetes configuration:\n\n```yaml\nlivenessProbe:\n  httpGet:\n    path: /health\n    port: 10002\nreadinessProbe:\n  httpGet:\n    path: /ready\n    port: 10002\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsystemli%2Fuserli-postfix-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsystemli%2Fuserli-postfix-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsystemli%2Fuserli-postfix-adapter/lists"}