Packages
Native Elixir authentication compatible with datadeft-auth Rust.
Current section
Files
Jump to
Current section
Files
datadeft_auth
IMPLEMENTATION.md
IMPLEMENTATION.md
# Elixir 0.8 implementation checklist
Owner-approved scope: [the plan](../../docs/elixir-0.8-plan.md).
All 0.8 work: [PR #45](https://github.com/DataDeft/datadeft-auth/pull/45)
from `feat/elixir-0.8`; no publication. Includes the foundation commits through
`211b3e3`, moved off `main` with owner approval. See
[release readiness](RELEASE-READINESS.md) for current evidence and blockers.
The package uses the workspace's 0.8.0 version. Publication is separate.
Work one observable feature at a time: failing test, minimal implementation,
green focused suite, then compatibility/regression checks. A green slice is
not a completed authentication system.
## 1. Foundation and reference contract
- [x] Independent Mix package under `hex/datadeft_auth/`; no umbrella, Port or project-owned NIF.
- [x] Package-local format/compile/test tasks and test-only support.
- [x] Shared synthetic vectors asserted by Rust and Elixir.
- [x] Root compatibility gate and shared-table CI task.
- [x] Remove obsolete Port membership/tasks/release checks.
- [x] [Workflow and wire/storage-format inventory](../../spec/compatibility/CONTRACTS.md) for the approved 0.8 scope.
- [x] Verified clean source-archive and consumer Mix release gates.
## 2. Shared DynamoDB data (first priority)
- [x] Storage HMAC domain/framing and redacted 32-byte key.
- [x] Exact email normalization, including Rust Unicode trim and ASCII case policy.
- [x] Canonical user identifiers and redacted account records.
- [x] Keyed email lookup plus authoritative profile read; strongly consistent.
- [x] Reject dangling, corrupt, mismatched and malformed profile/lookup rows.
- [x] Read an account created by the existing Rust login workflow.
- [x] Exact fixed-window and rotation-independent lifetime-counter keys.
- [x] Conditional counters, first-use expiry, TTL saturation and fail-closed errors.
- [x] Shared-table Rust/Elixir quota exhaustion and barrier-started race test.
- [x] Previous-key fallback, email lookup migration and rekeying (including Rust-created dormant accounts).
- [x] Magic-link record encoding/strict decoding, read by both Rust and Elixir.
- [x] Atomic consume + account + session + index transaction.
- [x] Cross-language same-challenge consume/create contention and Rust reads of Elixir-created account/session.
- [x] Distinct-challenge account-creation contention, disable checks and immutable-field binding in DynamoDB Local.
- [x] Distinct-challenge account-creation contention across Rust and Elixir.
- [x] Strongly consistent live session reads, owner watermark checks, and cross-language revocation.
- [x] Audited administration, pagination, stale-enable fencing and mixed-runtime login/disable race.
- [x] Signed DynamoDB adapter with library-managed SSO or instance-role credentials ([AWS-CREDENTIALS.md](AWS-CREDENTIALS.md)).
- [x] SES v2 and Secrets Manager loading/rotation with injected-transport tests.
- [ ] Live AWS acceptance in a maintainer-owned test account.
The IO boundary is injected as `{module, state}`. See [AWS integration](AWS-INTEGRATION.md)
and [audited administration](ADMIN-PARITY.md) for setup and acceptance scope.
## 3. Crypto and pure cores
- [x] OTP-backed JOSE and pure-Elixir BLAKE3 ([provider contract](CRYPTO-DEPENDENCIES.md)).
- [x] Rust-compatible Base62 with grouped encoding, golden vectors and round trips.
- [x] Bounded Branca encode/decode, including canonicality/tamper checks.
- [x] HKDF purpose/key-ID binding, active/verify-only keyrings, and bound envelope.
- [x] Clean Hex source-archive consumer, with no repository-relative dependencies.
- [x] Magic-link grammar, independently drawn selector/verifier, lookup HMACs.
- [x] Confirm/session body framing, expiry, skew and key windows; bidirectional Rust/Elixir cookie checks.
- [x] PoW v1/v2 proof-cookie bodies and bidirectional Rust exchange.
- [x] BLAKE3 PoW identity and exact challenge/tag/work formats.
- [x] Bidirectional cookie/token/proof verification, tamper and rotation checks.
No new formats or algorithm substitutions. The owner approved dropping the
Rustler bridge; the Hex package has no project-owned native code.
## 4. Framework-neutral services
- [x] Request service (consent, locale, keyed request/outbox limits, persist before send).
Plug maps sent and throttled outcomes to the same generic response.
- [x] Landing (selector limit, dummy work, account display, bound flow cookie).
- [x] Read flow state (same binding, limits and terminal-state handling).
- [x] Confirm (nonce/account/verifier binding, one-time atomic commit).
DynamoDB Local covers the framework-neutral request-to-logout flow.
- [x] Live session validation, logout-specific validation, refresh and revoke.
- [x] Exact/grouped trusted-edge country pinning.
- [x] Locale allowlists.
- [x] Account/admin queries and audited mutations, including disable/enable safety.
- [x] Independent proof admission and per-solve policy over the shared DynamoDB budget.
## 5. Plug and delivery
- [x] Magic-link/session body, header and cookie parsing, with fixed refusal bodies.
- [x] Cookie defaults/clearing, same-origin POST/CSRF, fixed redirects and safe headers.
- [x] Standalone Bandit login/logout example with loopback-only demo storage and delivery.
- [x] Independent Plug PoW helpers for challenge creation, validation and budgeted admission.
- [x] The shared browser client in Bandit: Chromium solves, exhausts a budget and solves again.
- [x] Chromium on Axum and Bandit: bidirectional handoff, rolling keys, shared
PoW exhaustion and cross-server revocation against DynamoDB Local.
- [x] Linux/BEAM CI matrix runs package tests and the exact Hex archive smoke
without Rust. See [release readiness](RELEASE-READINESS.md) for run evidence.
- [ ] Independent security/API review and full verification before merge.
## Validation commands
```sh
mise run elixir-verify # package-only verification; no Rust needed
mise run compatibility-test # shared Rust/Elixir vectors
mise run dynamodb-compatibility-test # disposable Docker table + Rust/Elixir
mise run browser-compatibility-test # Chromium + one disposable DynamoDB Local table
mise run verify # full workspace, excluding Docker integration
```
The package-only gate uses OTP and its Hex dependencies. The mixed-language
checks also need the workspace Rust toolchain. No Rust public API changed when
the Rustler bridge was removed.
## Foundation checkpoint
- Package-local verification: 30 tests passed; 4 explicit integration/vector tests
excluded from the standalone gate.
- Shared vectors: Rust reference test passed; Elixir gate ran 32 tests with no
failures (2 Docker-specific tests excluded).
- DynamoDB compatibility: 32 Elixir tests passed (2 vector tests excluded),
including the Rust subprocess sharing the table, quota, race and account.
- Existing Rust DynamoDB Local regression gate: 10 passed, with only the
separately orchestrated mixed-language test filtered out.
- `mise run verify`: passed, including audit, Rust tests/Clippy/docs, browser
package, formal checks, workflow/release checks and shared vectors.
- `git diff --check`: passed.
- Linux floor-runtime image checks were attempted but could not complete due to
image/tool downloads timing out; their orchestration was stopped. Local tests
use Elixir 1.19.5 / OTP 28. The platform matrix remains unverified locally.
- Full auth flows, cookie parity, production AWS delivery, archive/release
consumers and independent security review remain unfinished.
## Rotation increment
Previous-key account reads migrate the current lookup only after validating the
profile. Rekey scans all pages, counts only successful conditional writes and is
idempotent. Unit tests cover outages/corruption and equal-key deduplication;
DynamoDB Local proves login-time migration and dormant-account rekeying over
accounts created by the real Rust workflow. Full workspace verification and the
mixed-language Docker gate passed.
## Magic-link primitive/storage increment
Strict `mlv1` grammar, independently requested entropy, role-bound lookup HMACs,
canonical stored hashes and redacted token/key/record inspection are implemented.
Challenge writes use conditional creation, store keyed material only and retain
Rust's TTL policy. Candidate reads are strongly consistent and side-effect-free;
all required fields and optional consumption timestamps decode strictly.
DynamoDB Local proves Rust reads Elixir-written challenges and vice versa.
The mixed gate reports 50 tests, zero failures, two vector exclusions; full
`mise run verify` passed. Crypto dependency selection remains pending approval.
## Atomic authentication repository increment
One DynamoDB transaction binds every immutable challenge field, checks unconsumed
and unexpired state plus nonzero consent, claims both email keys during rotation,
and creates the keyed session and permanent audit index. Existing profiles must
still be enabled and linked to the exact account; stored consent is preserved.
No raw bearer, session ID, attempt ID or verifier-derived material is persisted
in transaction rows/conditions (the attempt ID is only the idempotency token).
Cancellation attribution and identical-command retry semantics match Rust.
DynamoDB Local proves exact retry succeeds, changed-payload ID reuse fails,
replay cannot create a second session, mixed Rust/Elixir consume has one winner,
and distinct-challenge creation cannot split an account. Tests also reject disabled
profiles, session collisions, stale/expired/changed challenge expectations and
zero consent without partial writes. Rust resolves an Elixir-created account
through its old-key row and reads its session. The mixed gate reports 58 tests,
zero failures, two vector exclusions. Existing Rust DynamoDB regressions and full
workspace verification passed. Framework-neutral authentication orchestration,
cookie minting and production IO remain unimplemented.
## Removal of the Rustler bridge
The initial implementation used a bounded, crypto-only NIF. The owner approved
removing it after a compiler-free probe matched the Branca vectors and Rust
BLAKE3 digests. Grouping Base62 digits removes the measured Branca minting
penalty at typical cookie sizes. See [the crypto contract](CRYPTO-DEPENDENCIES.md)
for providers, failure mapping and the required checks. No artifact was published.