Skip to content

M8a Mail: Postfix + DKIM/DMARC implementation with integration tests#11

Closed
aidankhogg wants to merge 7 commits into
mainfrom
claude/admiring-lamport-4av0c6
Closed

M8a Mail: Postfix + DKIM/DMARC implementation with integration tests#11
aidankhogg wants to merge 7 commits into
mainfrom
claude/admiring-lamport-4av0c6

Conversation

@aidankhogg

Copy link
Copy Markdown
Contributor

M8a Mail Implementation: Complete ✅

Overview

Full production-ready implementation of Phase 8a (Mail Services) with Postfix SMTP server, DKIM/DMARC signing, and org-specific email infrastructure provisioning.

Changes

Mail Handler (netengine/handlers/mail_handler.py)

  • Postfix container deployment at configured IP (10.0.0.13)
  • RSA 2048-bit DKIM key generation using cryptography library
  • Per-org DNS record injection (SPF, DKIM, DMARC, MX)
  • Virtual mailbox map creation for org users
  • Status health check implementation

Phase Services Handler (netengine/phases/phase_services.py)

  • M8 orchestration: Mail + Storage service deployment
  • Prerequisite validation for M1-M7 phases
  • Event emission (services.ready) for downstream consumers
  • Background org admission event consumer
  • Fixed RuntimeState attribute naming (identity_platform_output)

Integration Tests (tests/integration/test_m8_mail.py)

  • 21 comprehensive tests covering:
    • Interface compliance (BasePhaseHandler contract)
    • Prerequisite validation (M1-M7 blocking)
    • Postfix deployment verification
    • DKIM/DMARC configuration
    • DNS record injection (SPF/DKIM/DMARC/MX)
    • Virtual mailbox provisioning
    • Health checks
    • Idempotence

Bug Fixes

  • ✅ Fixed MailConfig attribute access: mailbox_policy.dmarc_default (not mail_config.dmarc_default)
  • ✅ Fixed RuntimeState reference: identity_platform_output (not platform_identity_output)
  • ✅ Proper Pydantic v2 model instantiation for test fixtures
  • ✅ Async mock setup for handler integration tests

Test Results

M1-M7 (existing):  52 passed ✅
M6 (In-World):    16 passed ✅
M7 (ANDs):        21 passed ✅
M8a Mail (new):   21 passed ✅
Orchestrator:      8 passed ✅
─────────────────────────────
Total:           118 passed, 2 skipped ✅

Key Design Decisions

DKIM Implementation

  • RSA 2048-bit keypair generation on each deployment
  • Private key stored in container config, public key in DNS TXT records
  • Milter protocol for transparent signing of outbound mail

DNS Records per Org

  • SPF record: v=spf1 mx -all (default, configurable)
  • DKIM record: v=DKIM1; k=rsa; p=<public_key> at _dkim._domainkey.<org>.internal
  • DMARC record: v=DMARC1; p=reject (default, configurable)
  • MX record: Points to mail.internal (10.0.0.13)

Virtual Mailbox Isolation

  • Per-org domain provisioning from spec
  • Per-user mailbox creation from M6 identity provisioning
  • Quota enforcement via mailbox_policy

Files Modified

  • netengine/handlers/mail_handler.py (rewrite: 45 → 322 lines)
  • netengine/phases/phase_services.py (enhance: 64 → 342 lines)
  • tests/integration/test_m8_mail.py (new: 545 lines, 21 tests)

Code Quality

  • ✅ Black formatted
  • ✅ isort organized imports
  • ✅ Proper type hints throughout
  • ✅ Comprehensive docstrings
  • ✅ Production-quality error handling

Ready For

  • ✅ Code review
  • ✅ CI/CD pipeline validation
  • ✅ Merge to main
  • ✅ Proceed to M8b Storage or M8c Org Apps

🤖 Generated with Claude Code
https://claude.ai/code/session_01VuzisGGSVDnV8fTHVsxjkv


Generated by Claude Code

claude added 5 commits June 21, 2026 23:50
**Changes:**

1. **M1-M2 DNS Enhancement**
   - Add auth.internal, ca.internal, registry.internal stubs to root zone
   - Pre-registers L1 service records (best practice for M6+ DNS)
   - All M1-M2 tests still passing

2. **M6 Complete Rewrite (from skeleton to production-ready)**
   - Per-org Keycloak realms (maximum isolation)
   - User provisioning: seed from spec + event-driven org.admitted events
   - OIDC client credentials stored in Supabase for durability
   - Proper error handling, prerequisite validation, idempotence
   - Background event consumer for dynamic org provisioning
   - Comprehensive health checks with SSL verification
   - Event emission for causal tracing

3. **Architecture Improvements**
   - Proper spec model usage (spec.identity_inworld - not dict access)
   - Full context/DI pattern (no ad-hoc task creation)
   - Correct handler initialization (PKIHandler, DockerHandler, OIDCHandler)
   - Proper SSL context for OIDC discovery endpoint
   - Graceful degradation when pgmq unavailable (M1-M5 testing)

4. **Test Suite**
   - 16 new M6 integration tests (interface, prerequisites, realm creation, user provisioning, healthcheck, idempotence, events)
   - Updated M4-M5 skeleton tests to use new completion tracking API
   - All 68 M1-M6 tests passing

**Design Decisions Locked:**
- One realm per org (isolation)
- User provisioning: seed from spec + event-driven
- OIDC credentials: Supabase storage
- DNS: auth.internal pre-registered by M1-M2 (not managed by M6)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VuzisGGSVDnV8fTHVsxjkv
- Implement Phase 7 Administrative Network Domain provisioning
- Per-org AND creation with strict profile validation
- Docker bridge network management with nftables rule application
- Deterministic CIDR allocation for MVP
- Event-driven provisioning for org.admitted events
- 21 comprehensive integration tests with full coverage
- Dual state tracking (RuntimeState + Supabase)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VuzisGGSVDnV8fTHVsxjkv
Implementation:
- Mail handler: Full Postfix deployment with DKIM key generation (RSA 2048-bit)
- DNS integration: SPF, DKIM, DMARC, MX record injection per org
- Virtual mailbox provisioning for org users
- Phase services: Enhanced M8 orchestration with mail/storage deployment
- 21 comprehensive integration tests covering all mail functionality

Fixes:
- RuntimeState attribute correction: identity_platform_output (not platform_identity_output)
- MailConfig DMARC default access: mailbox_policy.dmarc_default (not mail_config.dmarc_default)
- Proper Pydantic v2 model instantiation for StorageConfig in tests

Tests:
- 21 M8a mail tests: All passing
- 118 total integration tests: All passing (M1-M8, orchestrator)
- No regressions in existing functionality

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VuzisGGSVDnV8fTHVsxjkv
@aidankhogg aidankhogg self-assigned this Jun 22, 2026
@aidankhogg aidankhogg added bug Something isn't working enhancement New feature or request labels Jun 22, 2026
@aidankhogg

Copy link
Copy Markdown
Contributor Author

Merged into ded/alpha (6c31513)

@aidankhogg aidankhogg closed this Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants