Mail relay: the access-key field is off by default (mail.relay.accessKeyField)
A token issued by hand is set by a developer: setRelayToken() from a script, or mail.relay.token. The panel field and its route take a token only when the project switches the field on. Docs and AGENT.md say when such a token is needed and how to set it; a token of another host is refused on every way in. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
1a11cefffa
commit
edee3a321f
+3
-3
@@ -101,10 +101,10 @@ once there are more than 20.
|
||||
one visitor; `mail.relay.accountMail`). Limits and the file size come from the service (30 an hour, 200 a day, 10 MB
|
||||
unless Intecion set others); `mailAttachmentLimit` reports the latter.
|
||||
- **Plugin option `mail`**: `mail: { relay: false | { url, host, enrol, token, senderName, kind, accountMail,
|
||||
confirmRateLimit, totalTimeoutMs, timeoutMs, retryBackoffMs, fetchImpl }, graphDeprecationWarning }`; `mailAdapter({ relay })`.
|
||||
confirmRateLimit, accessKeyField, totalTimeoutMs, timeoutMs, retryBackoffMs, fetchImpl }, graphDeprecationWarning }`; `mailAdapter({ relay })`.
|
||||
- **Panel:** the state block on the e-mail tab (transport in effect, the site's state with the service, sender and
|
||||
reply address, what is left of the limits, a replaced sender name; "Check now", "Connect again", "Disconnect",
|
||||
"Enter an access key"); "Sending method" reads "Automatic" / "Microsoft Graph (deprecated)"; the server field reads
|
||||
reply address, what is left of the limits, a replaced sender name; "Check now", "Connect again", "Disconnect";
|
||||
"Enter an access key" for a token issued by hand only with `mail.relay.accessKeyField: true`); "Sending method" reads "Automatic" / "Microsoft Graph (deprecated)"; the server field reads
|
||||
"Own SMTP server"; the test e-mail names the transport it used. New status codes `relay-*` with texts in English
|
||||
and Polish. With `relay: false` the tab is worded as in 1.16.
|
||||
- **Doctor:** `mail-transport`, `mail-relay-state`, `mail-reply-address`, `mail-graph-deprecated`, `mail-relay-route`;
|
||||
|
||||
@@ -1316,6 +1316,7 @@ overrides per adapter; `resolveRelayOptions` reads what is in effect):
|
||||
| `url` | `RELAY_BASE_URL` | a relay of your own (same contract) |
|
||||
| `host` | host of `serverURL` (`relayHost`, `isPublicHost`) | the public host the service calls back |
|
||||
| `enrol` | `'auto'` | `'manual'` (only "Connect again" / `enrolRelay`), `false` (token from `token` / `setRelayToken`) |
|
||||
| `accessKeyField` | `false` | `true`: admins get "Enter an access key" in the state block (a hand-issued token) |
|
||||
| `token` | — | a token from elsewhere; nothing is stored, the site does not enrol |
|
||||
| `senderName` | panel → site name (`relaySenderName`) | fixed name or function |
|
||||
| `kind` | — | kind of a message nobody marked |
|
||||
@@ -1354,6 +1355,14 @@ needs more: Intecion raises the limits, or SMTP.
|
||||
| Constants | `RELAY_BASE_URL`, `RELAY_CONFIRM_PATH`, `RELAY_CONTRACT_VERSION`, `RELAY_DEFAULTS`, `RELAY_KV_KEY`, `RELAY_PRODUCT`, `RELAY_SENDER_ADDRESS`, `RELAY_SERVICE_NAME` |
|
||||
| Tests without the service | `createFakeRelay` (`FakeRelay`, `FakeRelayOptions`, `FakeRelayMail`, `FakeRelayLimits`): `mailAdapter({ relay: { url: fake.url, fetchImpl: fake.fetch } })`, then assert on `fake.outbox` |
|
||||
|
||||
**A token issued by hand** is needed only for a site the service cannot call back (behind a firewall or basic
|
||||
auth, on a private network). Intecion issues it for the site's host; you set it, never the client: once from a
|
||||
script — `await setRelayToken(payload, token)` under `pnpm payload run` (stored in `payload.kv`, rotated by the
|
||||
plugin) — or as the deployment's secret, `mail: { relay: { enrol: false, token: () => process.env.MY_MAIL_TOKEN } }`.
|
||||
The panel has no field for it unless the project sets `mail: { relay: { accessKeyField: true } }`. Such a site
|
||||
cannot heal by itself: after a move to another server it reports `relay-refused` until Intecion adds the address
|
||||
or issues a new token. A token of another host is refused on every way in.
|
||||
|
||||
**Never:** read or print the token (`payload.kv`, key `iapl:mail-relay`); add a field or env variable for it; call
|
||||
the service from a client component; retry a failed send in a loop of your own; mark form mail as `account`.
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ through this procedure. Ask only when you are missing something you cannot get y
|
||||
| state block: "Not connected yet" on the production domain | no e-mail was sent yet | **Send test e-mail** (the site enrols on its first send) or "Connect again" |
|
||||
| `relay-refused` / "The mail service could not reach this site at …" (cause `callback-failed`) | `unreachable` / `timeout`: firewall, private network, wrong public host in `serverURL`; `redirect`: `trailingSlash: true`, apex → `www`, a language redirect; `status`: route blocked, missing (`mail: { relay: false }`?) or another `routes.api`; `confirmation`: a proxy rewrites the answer | `curl -i -X POST https://<host>/api/iapl/mail-relay/confirm -d '{}' -H 'content-type: application/json'` must answer **404 with an empty body, no redirect**; fix `serverURL` / `mail.relay.host`, or ask Intecion to set the site's confirm address (path ending in `/confirm/` with trailing slashes); then "Connect again" (the site does not retry by itself for 15 min). email.md "When the site cannot be confirmed" |
|
||||
| `relay-refused`, cause `host-not-allowed` / "This site has no public address yet" | the site runs on `localhost`, a private name, or `serverURL` is empty | expected in development (use SMTP / Mailpit there); in production set `serverURL` |
|
||||
| `relay-refused` on a site whose token was entered by hand ("does not know the server this site now runs on" / "access key … no longer valid") | the site moved or got a second server, or its token expired; a site with a hand-issued token cannot enrol by itself | Intecion adds the server's address, or issues a new token (state block → "Enter an access key") |
|
||||
| `relay-refused` on a site whose token was entered by hand ("does not know the server this site now runs on" / "access key … no longer valid") | the site moved or got a second server, or its token expired; a site with a hand-issued token cannot enrol by itself | Intecion adds the server's address, or issues a new token — set it with `setRelayToken(payload, token)` from a script (`pnpm payload run`), or in the panel when the project has `mail.relay.accessKeyField: true` (email.md "The token") |
|
||||
| staging sends nothing after its database was copied from production: "Not connected yet" / "waiting for approval" | expected: production's token is tied to production's host and is not used on the copy; the copy enrolled as itself | Intecion approves the staging host, or staging uses SMTP / `mail: { relay: false }` |
|
||||
| `relay-pending` / "waiting for approval" | the host is not on Intecion's list | Intecion approves it on the service; nothing to change on the site; the same token then works |
|
||||
| `relay-suspended` | Intecion stopped the site (abuse, a flood from a form) | contact Intecion; fill in SMTP meanwhile |
|
||||
|
||||
+33
-7
@@ -213,11 +213,35 @@ await runWithMailKind('account', () => sendWelcomeMails(payload, user))
|
||||
`{ revoked }`: when the service could not be reached the site stops using the token at once, but the token
|
||||
**still works at the service** — the panel says "not confirmed" and keeps it so that "Disconnect" can be pressed
|
||||
again; only then is it revoked and forgotten.
|
||||
- **A token of another site is refused.** The access-key field asks the service whose token it is before it stores
|
||||
anything, and a token stored by a script is checked the same way before its first use (`/v1/status` names the
|
||||
host): another site's token is not saved, not used and not revoked.
|
||||
- **A token issued by hand** — for a site the service cannot call back (behind a firewall): Intecion issues one,
|
||||
an admin enters it in the state block ("Enter an access key"), or a script calls `setRelayToken(payload, token)`.
|
||||
- **A token of another site is refused, on every way in.** A token stored by a script is checked with the service
|
||||
before its first use (`/v1/status` names the host), the panel's access-key field asks before it stores anything,
|
||||
and every request names the site, so the service refuses a foreign token from `relay.token` too
|
||||
(`host-mismatch`): another site's token is not saved, not used and not revoked.
|
||||
- **A token issued by hand** — only for a site the service **cannot call back**: behind a firewall or basic auth, on
|
||||
a private network, or one that cannot serve the confirm route. Every other site enrols by itself and needs none.
|
||||
Intecion issues the token for the site's host; **a developer sets it**, one of three ways:
|
||||
|
||||
```ts
|
||||
// 1. once, from a script (recommended): pnpm payload run scripts/set-mail-token.ts
|
||||
// stored in payload-kv like an enrolled token; the plugin rotates it every 90 days
|
||||
import config from '@payload-config'
|
||||
import { setRelayToken } from '@intecion/ipal-kit'
|
||||
import { getPayload } from 'payload'
|
||||
|
||||
const payload = await getPayload({ config })
|
||||
await setRelayToken(payload, process.env.MAIL_TOKEN!) // pass it in the environment of this one run; never commit it
|
||||
process.exit(0)
|
||||
```
|
||||
|
||||
```ts
|
||||
// 2. from the deployment's own secret, on every start: nothing is stored, the site never enrols,
|
||||
// and replacing the token before it runs out is the project's job
|
||||
iapl({ mail: { relay: { enrol: false, token: () => process.env.MY_MAIL_TOKEN } } })
|
||||
```
|
||||
|
||||
3. In the panel, when the project switches the field on: `mail: { relay: { accessKeyField: true } }` adds
|
||||
"Enter an access key" to the state block for admins. **Off by default** — without it the block has no such
|
||||
field and its route takes no token (`403`).
|
||||
**Such a site cannot heal by itself:** it never enrols on its own. When the service no longer knows its server
|
||||
address (after a move, or a second server) or its token, the send reports `relay-refused` and the state block
|
||||
says what to ask Intecion for — the new address added, or a new token.
|
||||
@@ -241,14 +265,15 @@ Site integrations → E-mail sending starts with "How e-mails are sent" (compone
|
||||
rendered by the tab's status banner — **no import-map entry of its own, so nothing to regenerate**): the
|
||||
transport in effect; for the mail service the state (connected, waiting for approval, stopped, not connected and
|
||||
why), the address mail leaves from, where replies go, what is left of the hour and the day, and a sender name the
|
||||
service replaced. Buttons: **Check now**, **Connect again**, **Disconnect**, **Enter an access key**.
|
||||
service replaced. Buttons: **Check now**, **Connect again**, **Disconnect** — and **Enter an access key** only
|
||||
with `mail.relay.accessKeyField: true` ("The token" above).
|
||||
|
||||
Routes (all three need the `admin` role: not logged in → 401, other role → 403; none ever answers with a token):
|
||||
|
||||
| Route | What |
|
||||
|---|---|
|
||||
| `GET /api/iapl/mail-relay/status` | the transport and the stored state; `?refresh=1` asks the service |
|
||||
| `POST /api/iapl/mail-relay/connect` | enrol now; with `{ token }` store a token issued by hand |
|
||||
| `POST /api/iapl/mail-relay/connect` | enrol now; with `{ token }` store a token issued by hand — only with `accessKeyField: true`, otherwise `403` |
|
||||
| `POST /api/iapl/mail-relay/disconnect` | give the token up |
|
||||
| `POST /api/iapl/mail-relay/confirm` | **public** — the service's call-back. `404` and no change unless the site itself started an enrolment in the last 5 minutes; **refused** calls are rate-limited (10 a minute per address, `mail.relay.confirmRateLimit`) — a call that carries the nonce is never turned away by the limit, so junk from the same address cannot keep the site from enrolling |
|
||||
|
||||
@@ -308,6 +333,7 @@ message); "Connect again" asks at once. Other causes: `host-not-allowed` (not a
|
||||
| `url` | `RELAY_BASE_URL` (`https://webservices.intecion.net/mail`) | another base address — a relay of your own that speaks the same contract |
|
||||
| `host` | host of `serverURL` (`relayHost(payload, options)`) | the public host the service calls back |
|
||||
| `enrol` | `'auto'` | `'manual'`: only "Connect again" or `enrolRelay()` enrols. `false`: never (the token comes from `token` or `setRelayToken`) |
|
||||
| `accessKeyField` | `false` | `true` shows "Enter an access key" in the state block and lets its route store a hand-issued token an admin pastes |
|
||||
| `token` | — | a token from elsewhere (`string` or a function): the stored token is not used and the site does not enrol |
|
||||
| `senderName` | panel, then site name | a fixed name, or a function |
|
||||
| `kind` | — | the kind of a message nobody marked |
|
||||
|
||||
+1
-1
@@ -1006,7 +1006,7 @@ token. What protects it, and what the new public route can and cannot do:
|
||||
| **No key in the package** | The plugin carries the service's address and nothing else. A site gets its token by proving it is served at its host: it makes a nonce, the service calls `POST https://<host>/api/iapl/mail-relay/confirm` with the nonce and a token, and only an answer that hashes both makes the token valid |
|
||||
| **Where the token is** | `payload-kv`, key `iapl:mail-relay`. The collection refuses every operation through access control (`read`, `create`, `update`, `delete` are `false`) and is hidden: REST, GraphQL and the panel cannot reach it — an admin included (test: `test/mailRelayHttp.test.ts`). Server code with the Local API can, like `smtpPassword`. It is stored as it is (no encryption at rest), never logged, never sent to a browser, never part of a route's answer |
|
||||
| **A database copied to another host** | both sides hold a token to its host: every request names the site (`X-Intecion-Site`) and the service refuses another host's token (`host-mismatch`); and on the site the token is tied to the host it was issued for: a copy on a staging domain does not use production's token — it forgets it, without revoking it, and enrols as itself |
|
||||
| **A token of another site** (pasted into the access-key field, stored by a script) | refused: the service is asked which host the token is for before it is stored or used; a foreign one is not saved, not used, not revoked |
|
||||
| **A token of another site** (stored by a script, set as `relay.token`, or pasted into the access-key field — which is off unless the project sets `mail.relay.accessKeyField`) | refused: the service is asked which host the token is for before it is stored or used; a foreign one is not saved, not used, not revoked |
|
||||
| **A token read from a database dump** | **works from the same server** (a staging site on the machine production runs on shares its outgoing address) — which is why the store is tied to its host, above. From another server it does not work: the service accepts a token only from the addresses the site enrolled from (IPv6: the same `/64`) and answers anything else "enrol again" — which needs the call-back to the real site. It cannot send as another site, and the limits below apply |
|
||||
| **What a token can do at most** | send within the site's limits (30 an hour, 200 a day, 10 recipients, 10 MB by default) from the service's fixed address, under a sender name the service checks, with `X-Intecion-Site: <host>` on every mail. It cannot set `From`, `Return-Path` or any header, and cannot address a security alert |
|
||||
| **The confirm route** | public by design, `404` with an empty body unless the body carries a nonce **this site** made in the last 5 minutes (kept as a hash, compared in constant time, single use). It stores the delivered token **beside** the one in use and never replaces a working token: a token becomes the one in use only after the service has accepted it — a `200`, or a refusal the service gives after it has checked the token; no answer, an error page or `rate-limited` prove nothing and leave both as they are. **Refused** calls are rate-limited per address (10 a minute, `mail.relay.confirmRateLimit`); the nonce is looked up first, so junk from the address the service shares with others cannot keep the site's own enrolment out. A stranger who calls it learns nothing and changes nothing |
|
||||
|
||||
Reference in New Issue
Block a user