http-auth
The http-auth filter sends the username and password of the AUTH command to an HTTP endpoint. The
authentication is accepted when the endpoint answers with a 2xx status and, with json_result, when the JSON
response holds the expected value. Otherwise the flow is dropped, and the client gets 535 only if no other
flow is left: an OR flow or a flow without an AUTH filter lets the credentials through (see
server options).
When to use it
Section titled “When to use it”When the accounts live in another system: an identity provider, an application that already checks passwords, a small service in front of a user database. For one shared account, static-auth needs no endpoint.
How the credentials are sent
Section titled “How the credentials are sent”credentialsMethod selects the request:
credentialsMethod |
Request | Default method |
|---|---|---|
BASIC_AUTH (default) |
Authorization: Basic <base64 of username:password> header, no body |
GET |
JSON |
JSON body, the username at userField ($.username) and the password at passwordField ($.password) |
POST |
FORM_URLENCODED |
application/x-www-form-urlencoded body, fields userField (username) and passwordField (password) |
POST |
With JSON, the fields are dot separated paths: $.user.login sends {"user": {"login": "…"}}. GET is only
possible with BASIC_AUTH; the server does not start with another combination.
With json_result (only with JSON), a 2xx answer is not enough: the response is read as JSON, and the value at
json_result.path must equal json_result.value. The comparison is strict and value is a string: a JSON true in
the response does not equal "true".
Signing the requests
Section titled “Signing the requests”With hmac, each request carries two headers so the endpoint can check that it comes from smtp-relay:
X-SMTP-RELAY-TIME: the time of the request, in milliseconds since the epoch;X-SMTP-RELAY(or the name inhmac.header): the hex HMAC, withhmac.secretandhmac.algo(sha256by default), of<url>\n<method>\n<time>, followed by\n<body>when the request has a body.
The endpoint recomputes the HMAC and should also refuse old times, so a captured request cannot be replayed.
Making authentication required
Section titled “Making authentication required”As with every AUTH filter, whether clients must authenticate is set by options.authOptional, and
authentication needs TLS unless options.allowInsecureAuth is true. See
static-auth.
Options
Section titled “Options”Example
Section titled “Example”{ "$schema": "https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json", "flows": { "relay": { "filters": [ { "type": "http-auth", "url": "https://auth.example.com/smtp/login", "credentialsMethod": "JSON", // Sends {"login": "...", "secret": "..."} "userField": "$.login", "passwordField": "$.secret", // Accept only if the response is {"result": {"allowed": "yes"}} "json_result": { "path": "$.result.allowed", "value": "yes" }, "hmac": { "secret": "change-me" } } ], "outputs": [{ "type": "aws", "ses": true }] } }, "bind": "0.0.0.0", "options": { "allowInsecureAuth": false }}