Packages
Native Elixir authentication compatible with datadeft-auth Rust.
Current section
Files
Jump to
Current section
Files
datadeft_auth
AWS-INTEGRATION.md
AWS-INTEGRATION.md
# Production AWS integration
Scope: the owner-approved [0.8 parity plan](../../docs/elixir-0.8-plan.md) and
the owner's instruction to complete all remaining parity features in draft #45.
1. **Problem.** An Elixir deployment needs the same DynamoDB table, SES v2
delivery, and Secrets Manager key documents as a Rust deployment.
2. **Existing implementation.** The Rust AWS adapter defines the operations,
records, and error contract. Elixir already builds DynamoDB requests and
handles ordered cancellation reasons via an injected client.
3. **Gap.** The loopback fixture intentionally has no TLS, signing or credential
provider. It cannot authenticate to AWS or load secrets or send mail.
4. **Smallest solution.** Use the maintained optional `aws_signature` package
for SigV4 and OTP HTTPS for the three AWS protocols. The app supplies the
region and SES rendering; temporary credentials come from a supervised
[credential source](AWS-CREDENTIALS.md) (SSO profile or instance role). No
static keys, unsigned fallback, new DynamoDB schema, or silent retries of
ambiguous writes.
5. **Cost.** One opt-in signing dependency, OTP TLS/HTTP applications, and a
supervised credential source per app. Secret and
signed-request data must not escape in inspection or errors. Keep calls out of
framework-neutral cores.
6. **Proof.** Pin a TLS request and SigV4 golden, exercise typed provider failures,
prove ordered cancellation codes preserve operation positions, and test SES
payloads and current/previous secret documents against the Rust contract.
Run the shared DynamoDB suite. Real account SES/Secrets Manager acceptance
requires a maintainer-owned AWS environment; never use production data in tests.
## Setup
Add `{:aws_signature, "~> 0.4.3"}` to the application's dependencies. Start a
credential source before anything that uses the client, then pass its name.
Set the source explicitly in your application's configuration:
```elixir
# config/runtime.exs for an ECS deployment
config :my_app, :aws_credential_source, :ecs_task_role
```
```elixir
# In the application's supervisor setup
source = Application.fetch_env!(:my_app, :aws_credential_source)
children = [
{DatadeftAuth.AWS.CredentialSource, name: MyApp.AwsCredentials, source: source}
# ... then the children that build and use the client
]
{:ok, client} = DatadeftAuth.AWS.Client.new("eu-central-1", MyApp.AwsCredentials)
```
Choose `:ecs_task_role` on ECS, `:ec2_instance_profile` when running directly
on EC2 (IMDSv2 only), or `{:sso_profile, name}` for an IAM Identity Center
profile and its signed-in token cache. There are no direct keys, no default
source, and no fallback. Watch
`DatadeftAuth.AWS.CredentialSource.status/1` in health checks. See
[AWS-CREDENTIALS.md](AWS-CREDENTIALS.md) for refresh and failure behavior.
Never log credential values, raw Finch telemetry metadata, or wire traffic.
### Keep-alive with Finch
For persistent AWS connections, use the app-managed HTTP/1.1 Finch transport
in the repository's `hex/examples/aws_transports/` example. Add Finch in the
**consuming app**, start one named Finch child per BEAM instance, and pass the
transport function to `DatadeftAuth.AWS.Client.new/3` with `transport:`. Do
not start or configure the pool per request. The example keeps separate pools
per AWS origin, checks TLS peer and hostname, bounds waits and response bytes,
and forwards the signed request without redirects or retries. Finch is not a
dependency of the Hex package.
Keep the usual regional AWS hostnames with private VPC routing. Bound app
admission before the pool: a checkout timeout limits waiting time, not the
number of waiting callers. Start with a small pool; measure checkout wait,
handshakes and tail latency under expected concurrency before increasing it.
### Built-in fallback
Use `DatadeftAuth.AWS.Client.new/2` (region and credential source name) for the
non-pooled OTP HTTPS transport.
It requires inets 9.6.1 or later (OTP 28.4.1 includes it). Older inets can
silently replay authenticated POSTs on `503 Retry-After`; the built-in
transport refuses to run there. This floor applies only to the built-in
transport, not Finch or the rest of the package. Do not enable pooled
`:httpc` for the shared AWS client: on the tested OTP it can resend a POST
after the server reads it and closes without a reply, even with
`autoretry: 0`.
### Wire the service adapters
Both transports use the same signed client and adapters:
- Pass `{DatadeftAuth.AWS.DynamoDB.SignedClient, client}` to
`DatadeftAuth.AWS.DynamoDB.new/3`.
- Use `DatadeftAuth.AWS.SES.new/4` with the app's sender and renderer.
- Resolve the active secret reference and optional same-secret
`AWSPREVIOUS` at setup with `DatadeftAuth.AWS.SecretsManager`. Pass
the loaded previous storage key to `DynamoDB.with_previous_storage_key/2`
and the previous lookup key to the magic-link flow configuration when
present. Pass the loaded previous PoW challenge secret as
`previous_secret:` to `DatadeftAuth.PoW.Plug.new/6`. Challenge freshness
and the shared per-solve budget do not change when the keys rotate.
Run email lookup rekeying before retiring a previous storage key.
The shared local gate exercises the signed request builder and production
DynamoDB response decoder. `mise run aws-transports-verify` also tests socket
reuse, hostname refusal, and no POST replay over loopback TLS. Neither gate
proves AWS IAM, deployed TLS, SES delivery, or Secrets Manager access. For
the live smoke and ECS deployment checks, see
[deployment validation](RELEASE-READINESS.md#deployment-validation).