emailengine-app 2.79.9 → 2.80.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +49 -0
- package/config/default.toml +5 -1
- package/data/google-crawlers.json +1 -1
- package/encrypt.js +43 -0
- package/lib/account/account-state.js +62 -0
- package/lib/account.js +34 -2
- package/lib/api-routes/account-routes.js +20 -0
- package/lib/api-routes/index.js +1 -1
- package/lib/api-routes/settings-routes.js +17 -2
- package/lib/autodetect-imap-settings.js +349 -47
- package/lib/cert-handler.js +62 -0
- package/lib/consts.js +50 -6
- package/lib/db.js +12 -0
- package/lib/egress-fetch.js +21 -9
- package/lib/email-client/base-client.js +234 -66
- package/lib/email-client/credential-errors.js +118 -0
- package/lib/email-client/gmail/gmail-api.js +2 -1
- package/lib/email-client/gmail-client.js +70 -64
- package/lib/email-client/imap/connection-errors.js +52 -0
- package/lib/email-client/imap/listing-diff.js +47 -6
- package/lib/email-client/imap/mailbox.js +457 -379
- package/lib/email-client/imap/subconnection.js +15 -11
- package/lib/email-client/imap/sync-operations.js +46 -59
- package/lib/email-client/imap-client.js +136 -95
- package/lib/email-client/message-builder.js +11 -11
- package/lib/email-client/outlook/graph-api.js +2 -1
- package/lib/email-client/outlook-client.js +219 -106
- package/lib/imap-proxy-auth.js +58 -3
- package/lib/imapproxy/imap-server.js +53 -62
- package/lib/lua/h-del-if-equals.lua +39 -0
- package/lib/lua/h-set-if-equals.lua +39 -0
- package/lib/routes-ui.js +4 -34
- package/lib/schemas.js +32 -0
- package/lib/security-headers.js +15 -0
- package/lib/tls/context.js +376 -0
- package/lib/tls/der.js +223 -0
- package/lib/tls/provision.js +555 -0
- package/lib/tls/self-signed.js +282 -0
- package/lib/tls/status.js +431 -0
- package/lib/tls/store.js +666 -0
- package/lib/tools.js +72 -27
- package/lib/ui-routes/account-routes.js +43 -30
- package/lib/ui-routes/admin-config-routes.js +22 -1
- package/lib/ui-routes/auth-routes.js +16 -1
- package/lib/ui-routes/internals-routes.js +3 -5
- package/lib/ui-routes/network-config-routes.js +54 -45
- package/lib/ui-routes/tls-config-routes.js +581 -0
- package/lib/utils/mailbox-path.js +51 -0
- package/lib/utils/severity.js +31 -0
- package/package.json +4 -4
- package/sbom.json +1 -1
- package/server.js +16 -0
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +11 -0
- package/static/js/app.js +34 -0
- package/static/js/public.js +6 -2
- package/static/js/ui.js +8 -25
- package/static/licenses.html +328 -1257
- package/translations/messages.pot +87 -87
- package/views/account/login-redirect.hbs +22 -0
- package/views/config/imap-proxy.hbs +0 -3
- package/views/config/smtp.hbs +0 -3
- package/views/config/tls-upload.hbs +81 -0
- package/views/config/tls.hbs +492 -0
- package/views/partials/side_menu.hbs +1 -0
- package/views/partials/tls_security_card.hbs +25 -53
- package/views/partials/ui/alert-banner.hbs +3 -2
- package/views/partials/ui/badge.hbs +6 -2
- package/views/partials/ui/btn.hbs +5 -2
- package/workers/api.js +93 -134
- package/workers/imap-proxy.js +4 -1
- package/workers/smtp.js +51 -44
- package/views/partials/tls_security_js.hbs +0 -64
- package/views/partials/tls_security_modal.hbs +0 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.80.0](https://github.com/postalsys/emailengine/compare/v2.79.9...v2.80.0) (2026-09-09)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **tls:** manage certificates on their own page, with a real self-signed fallback ([42a1546](https://github.com/postalsys/emailengine/commit/42a154616fdb63b7c3c38de89cffd73110a45526))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **accounts:** keep the authentication server's status out of API and IMAP proxy answers ([79264b0](https://github.com/postalsys/emailengine/commit/79264b0ce471b0dcbc6764e7b1b51b637d2b49f7))
|
|
14
|
+
* **accounts:** stop a credential-service blip from flooding auth webhooks ([51f4f35](https://github.com/postalsys/emailengine/commit/51f4f35c95b6527a9c93ef30eda8b55c629369fc))
|
|
15
|
+
* **admin:** let the account page re-authenticate an OAuth2 account again ([56245f7](https://github.com/postalsys/emailengine/commit/56245f7224eaa998143773a6847d83a9cb39b108))
|
|
16
|
+
* **admin:** stop forced SSO from silently swallowing admin form submissions ([9653c2d](https://github.com/postalsys/emailengine/commit/9653c2db2c1ed6ef0557396b673b2b8a32c94af0))
|
|
17
|
+
* **api:** reload the TLS listeners only when a settings write changed a value ([b2052ac](https://github.com/postalsys/emailengine/commit/b2052acb52cec2063b66af00dab94246edcfffeb))
|
|
18
|
+
* **autodiscovery:** keep a usable server entry when a hostless sibling follows it ([3796668](https://github.com/postalsys/emailengine/commit/37966686762ce7435314e8da25d7ba26add42c6f))
|
|
19
|
+
* **autodiscovery:** make Exchange autodiscovery work at all ([271d85c](https://github.com/postalsys/emailengine/commit/271d85c76349c5ee7259dd18da9d4a132caee0c1))
|
|
20
|
+
* **autodiscovery:** stop a result that names no server from ending a lookup ([e698c3c](https://github.com/postalsys/emailengine/commit/e698c3c2737f464e1d10be2099fb18a8640c7708))
|
|
21
|
+
* **deps:** update @bull-board/api and @bull-board/hapi to 9.9.0 ([14720fb](https://github.com/postalsys/emailengine/commit/14720fbd84a58d405119f865715a672f9b319091))
|
|
22
|
+
* **deps:** update @postalsys/certs to 1.2.1 ([eb2c958](https://github.com/postalsys/emailengine/commit/eb2c9580e2437a317eeea8742ddf9af5c88434e5))
|
|
23
|
+
* **deps:** update @postalsys/certs to 1.3.0 ([08c2d1b](https://github.com/postalsys/emailengine/commit/08c2d1b27ed4aa13bb8130a611dfa73ab164d82b))
|
|
24
|
+
* **gmail:** clear a stale watch failure once push is no longer configured ([b5884fe](https://github.com/postalsys/emailengine/commit/b5884fe886260cb6578db91a7425a37be7261f34))
|
|
25
|
+
* **gmail:** report no watch for an account whose application has no Pub/Sub app ([7e53a20](https://github.com/postalsys/emailengine/commit/7e53a20c45017e8a6484910507ecfd72c0ef75c6))
|
|
26
|
+
* **gmail:** stop a dead Pub/Sub watch from being invisible and self-perpetuating ([206e17d](https://github.com/postalsys/emailengine/commit/206e17da9c74ce10146df51ba40db7dab94aa273))
|
|
27
|
+
* **imap:** announce a folder that appeared while the primary was down ([2afd207](https://github.com/postalsys/emailengine/commit/2afd2070d69e6bb3b791a06a8a14b40ea0696641))
|
|
28
|
+
* **imap:** announce the deletion of a tracked folder missing from the stored listing ([2ead02f](https://github.com/postalsys/emailengine/commit/2ead02f858ac3472f1e86a2984d6fdaf0163a33f))
|
|
29
|
+
* **imap:** answer a malformed message identifier instead of throwing at it ([9be0c9c](https://github.com/postalsys/emailengine/commit/9be0c9ca12a2e7c960b25eb971e405756a766ab6))
|
|
30
|
+
* **imap:** collect the connection-closed error and the attachment download ([8d0e589](https://github.com/postalsys/emailengine/commit/8d0e58946b47054aaac626ec72b0a59ad0f0682a))
|
|
31
|
+
* **imap:** keep a folder found by a pass that could not register it ([0971a4d](https://github.com/postalsys/emailengine/commit/0971a4dee15c7d10dc31f02b5e01e67bb8192e3d))
|
|
32
|
+
* **imap:** match configured folder paths against the spelling the server reports ([328e56a](https://github.com/postalsys/emailengine/commit/328e56a3684530b94b056abbf25d7881417cd470))
|
|
33
|
+
* **imap:** restore the first-sync backfill and the return to the main mailbox ([b0b229c](https://github.com/postalsys/emailengine/commit/b0b229c12f41a0a8313462bafc638e22020673f0))
|
|
34
|
+
* **imap:** stop a disconnect mid-sync from announcing a message without its images ([fab2c15](https://github.com/postalsys/emailengine/commit/fab2c1560a1782e708967afb8bf916bd5e634574))
|
|
35
|
+
* **imap:** stop a read-only folder listing from swallowing the mailboxNew event ([ab76f0d](https://github.com/postalsys/emailengine/commit/ab76f0ddc77bbcc321d1cb207695a2d4e145ecba))
|
|
36
|
+
* **imap:** stop the duplicate mailboxDeleted and the dropped inbox counters ([edd0b0c](https://github.com/postalsys/emailengine/commit/edd0b0cf9e7d2073ab7623bcd6e7fe60bf5dc4c1))
|
|
37
|
+
* **outlook:** keep retrying a subscription the fast retries gave up on ([9583780](https://github.com/postalsys/emailengine/commit/9583780427310e9acdbdbf8351edfc7d5e97bf3d))
|
|
38
|
+
* **outlook:** report an account that can no longer subscribe to changes ([9da07ad](https://github.com/postalsys/emailengine/commit/9da07adc5f9b21aab827f609c6ae1cb98120cdbe))
|
|
39
|
+
* **outlook:** stop a subscription recovery from dropping a newer failure ([bd613fe](https://github.com/postalsys/emailengine/commit/bd613fe829bfa0dd51875752d584947ed623956f))
|
|
40
|
+
* **outlook:** take a subscription report back when the subscription is healthy, keep it across a login ([9bccba8](https://github.com/postalsys/emailengine/commit/9bccba8537c3da969588a0b720b8f5fa2413b3d5))
|
|
41
|
+
* **tls:** let an operator point ACME at a different CA without editing source ([13b382f](https://github.com/postalsys/emailengine/commit/13b382f6e501a3ec34985b3dd3f0c4c542d8716f))
|
|
42
|
+
* **tls:** order a first certificate only for a listener that would serve it ([950185f](https://github.com/postalsys/emailengine/commit/950185fbaed09f050020f136d6673f4e4cf83fc8))
|
|
43
|
+
* **tls:** read the failed renewal from the certificate library instead of inferring it ([c0e4bfd](https://github.com/postalsys/emailengine/commit/c0e4bfd167b3783dcb9d25db9b83a15208779d53))
|
|
44
|
+
* **tls:** redesign the certificates page around what each listener serves ([7dc42ba](https://github.com/postalsys/emailengine/commit/7dc42ba524f91310a36d991d7535e8a0837d6537))
|
|
45
|
+
* **tls:** replace the abandoned ACME stack and ask the CA when to renew ([9364eeb](https://github.com/postalsys/emailengine/commit/9364eebb30921675f3b3f95a03de66504e9ef342))
|
|
46
|
+
* **tls:** report a failed renewal, converge concurrent self-signed replacement ([b1ac9e3](https://github.com/postalsys/emailengine/commit/b1ac9e3102827036a717de695f5c24697f51c5b3))
|
|
47
|
+
* **tls:** report a half-set ACME override, drop the unused listener restart ([fe7771e](https://github.com/postalsys/emailengine/commit/fe7771eb38e2d8cdfb62353d1375d0b52df90eac))
|
|
48
|
+
* **tls:** say plainly that the API listener serves HTTP by default ([31e75ae](https://github.com/postalsys/emailengine/commit/31e75ae8f0a124890b6727e733cdaa17ddda5ec4))
|
|
49
|
+
* **tls:** serve an encrypted operator key, keep the listener settings on reload ([75d16d9](https://github.com/postalsys/emailengine/commit/75d16d93527606708cf0b19ba89288f54382b4e6))
|
|
50
|
+
* **tls:** stop a repeated request from starting a second order, report the listener's own state ([845d4e7](https://github.com/postalsys/emailengine/commit/845d4e7729ff05c8e042607c4639b2c808f88d10))
|
|
51
|
+
|
|
3
52
|
## [2.79.9](https://github.com/postalsys/emailengine/compare/v2.79.8...v2.79.9) (2026-09-07)
|
|
4
53
|
|
|
5
54
|
|
package/config/default.toml
CHANGED
|
@@ -28,7 +28,11 @@ maxSize = "5M" # maximum size of an attachment when submitting or uploading
|
|
|
28
28
|
#maxPayloadTimeout = "10s" # how long to wait for a request body to arrive
|
|
29
29
|
#proxy = false # trust X-Forwarded-For from a reverse proxy (restrict the peers with EENGINE_API_PROXY_ADDRESSES)
|
|
30
30
|
#cspMode = "enforce" # Content-Security-Policy delivery: "enforce", "report-only" (violations are only reported to the browser console) or "off"
|
|
31
|
-
# Serve the API over HTTPS by pointing at a certificate and key
|
|
31
|
+
# Serve the API over HTTPS by pointing at a certificate and key. Anything left unset falls back to
|
|
32
|
+
# what EmailEngine manages itself (an uploaded certificate, a Let's Encrypt one, or a self-signed
|
|
33
|
+
# certificate), so this section is only needed to pin a specific certificate here.
|
|
34
|
+
# The SMTP server and the IMAP proxy take the same values through EENGINE_SMTP_TLS_* and
|
|
35
|
+
# EENGINE_IMAPPROXY_TLS_* (use the _FILE suffix to read one from a file).
|
|
32
36
|
#[api.tls]
|
|
33
37
|
#certPath = "/path/to/cert.pem"
|
|
34
38
|
#keyPath = "/path/to/key.pem"
|
package/encrypt.js
CHANGED
|
@@ -20,6 +20,7 @@ const msgpack = require('./lib/msgpack');
|
|
|
20
20
|
|
|
21
21
|
const { REDIS_PREFIX, ENCRYPTED_APP_KEYS } = require('./lib/consts');
|
|
22
22
|
const { Settings: CertSettings } = require('@postalsys/certs/lib/settings');
|
|
23
|
+
const { TLS_KEY } = require('./lib/tls/store');
|
|
23
24
|
|
|
24
25
|
const DECRYPT_PASSWORDS = [].concat(config.decrypt || []);
|
|
25
26
|
|
|
@@ -310,6 +311,48 @@ async function main() {
|
|
|
310
311
|
}
|
|
311
312
|
|
|
312
313
|
console.log(`Updated ${updatedCerts} TLS private keys`);
|
|
314
|
+
|
|
315
|
+
// TLS material EmailEngine manages itself: the certificate an operator uploaded through the
|
|
316
|
+
// admin UI, and the self-signed certificate a listener falls back to. Both live in the `tls`
|
|
317
|
+
// hash as JSON with an encrypted `privateKey` field, and both need the same pass - an uploaded
|
|
318
|
+
// certificate that could not be decrypted after a rotation would take the listener down at the
|
|
319
|
+
// next restart, and there is no way to regenerate one.
|
|
320
|
+
let updatedTlsRecords = 0;
|
|
321
|
+
let tlsKey = TLS_KEY;
|
|
322
|
+
let tlsEntries = await redis.hgetall(tlsKey);
|
|
323
|
+
for (let field of Object.keys(tlsEntries || {})) {
|
|
324
|
+
let record;
|
|
325
|
+
try {
|
|
326
|
+
record = JSON.parse(tlsEntries[field]);
|
|
327
|
+
} catch (err) {
|
|
328
|
+
console.log(`TLS entry ${field}: failed to parse`);
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (!record || !record.privateKey) {
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
try {
|
|
337
|
+
let updated = await processSecret(record.privateKey, encryptSecret);
|
|
338
|
+
if (updated === record.privateKey) {
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
record.privateKey = updated;
|
|
342
|
+
|
|
343
|
+
let result = await redis.hmset(tlsKey, { [field]: JSON.stringify(record) });
|
|
344
|
+
if (result === 'OK') {
|
|
345
|
+
console.log(`TLS entry ${field}: updated`);
|
|
346
|
+
} else {
|
|
347
|
+
console.log(`TLS entry ${field}: Unexpected response from DB: ${result}`);
|
|
348
|
+
}
|
|
349
|
+
updatedTlsRecords++;
|
|
350
|
+
} catch (err) {
|
|
351
|
+
console.error(`Could not process "${field}". Check decryption secrets.`);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
console.log(`Updated ${updatedTlsRecords} stored TLS certificates`);
|
|
313
356
|
}
|
|
314
357
|
|
|
315
358
|
main()
|
|
@@ -188,6 +188,67 @@ async function resetStateCount(redis, account, state) {
|
|
|
188
188
|
return result >= 0;
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
// A stored timestamp is only as good as whatever wrote it: a corrupt or hand-edited record must
|
|
192
|
+
// degrade to null rather than fail the response schema and 500 the endpoint
|
|
193
|
+
function isoOrNull(date) {
|
|
194
|
+
return date && date.toString() !== 'Invalid Date' ? date.toISOString() : null;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* The state of a Gmail account's Pub/Sub watch, for whoever has to answer "is push working right
|
|
199
|
+
* now". Derived rather than stored: the account keeps the last successful arm (`lastWatch`,
|
|
200
|
+
* `watchResponse`, `watchExpiration`) and the last failure (`watchFailure`) as separate records,
|
|
201
|
+
* and neither answers the question on its own.
|
|
202
|
+
*
|
|
203
|
+
* Everything here is a timestamp or an enum EmailEngine produced, and nothing the provider wrote is
|
|
204
|
+
* quoted. The stored failure carries plenty that is: `req.response` is Google's body verbatim, and
|
|
205
|
+
* `err` is `formatTokenError()` output whenever the failure was a token fetch, which interpolates
|
|
206
|
+
* the provider's `error_description`. GET /v1/account/{id} is reachable by an account-bound tenant
|
|
207
|
+
* token, by an MCP token whose contents reach an LLM, and by a session token that lives in page
|
|
208
|
+
* HTML, so the reason a watch failed stays on the account page - behind an admin session, reading
|
|
209
|
+
* the stored record directly.
|
|
210
|
+
*
|
|
211
|
+
* A dead watch is not an error state: the Gmail client keeps syncing on its fallback poller, so
|
|
212
|
+
* mail is delayed rather than lost. That is why this is a field to read and not a webhook.
|
|
213
|
+
*
|
|
214
|
+
* @param {Object} accountData - Account data object
|
|
215
|
+
* @returns {Object|null} Watch state, or null for an account that has never armed one
|
|
216
|
+
*/
|
|
217
|
+
function formatGmailWatch(accountData) {
|
|
218
|
+
if (!accountData || (!accountData.watchResponse && !accountData.watchFailure)) {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Push is configured on the linked application. An account whose application has no Pub/Sub
|
|
223
|
+
// app has no watch to report, whatever an earlier configuration left behind: the Gmail client
|
|
224
|
+
// clears that record when it next arms a watch, but a send-only or parked account never
|
|
225
|
+
// arms one, and its months-old failure would otherwise read as the current state.
|
|
226
|
+
if (accountData._app && !accountData._app.pubSubApp) {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const failure = accountData.watchFailure;
|
|
231
|
+
|
|
232
|
+
// The response of the arm that is actually live wins. `watchExpiration` rides the default
|
|
233
|
+
// serializer branch, which skips a null, so a success that carried no expiration leaves the
|
|
234
|
+
// previous arm's number in place and preferring it would report a lapsed watch as active
|
|
235
|
+
const expiration = (accountData.watchResponse && accountData.watchResponse.expiration) || accountData.watchExpiration;
|
|
236
|
+
const expires = isoOrNull(expiration && new Date(Number(expiration)));
|
|
237
|
+
|
|
238
|
+
// The failure carries its own attempt time because a failed renewal no longer moves lastWatch -
|
|
239
|
+
// doing so used to buy a broken watch a full day of silence, whatever the retry timer wanted
|
|
240
|
+
const lastCheck = (failure && isoOrNull(failure.time && new Date(failure.time))) || isoOrNull(accountData.lastWatch && new Date(accountData.lastWatch));
|
|
241
|
+
|
|
242
|
+
let state = 'expired';
|
|
243
|
+
if (failure) {
|
|
244
|
+
state = 'error';
|
|
245
|
+
} else if (expires && new Date(expires) > new Date()) {
|
|
246
|
+
state = 'active';
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return { state, lastCheck, expires };
|
|
250
|
+
}
|
|
251
|
+
|
|
191
252
|
/**
|
|
192
253
|
* Formats the last error for API responses
|
|
193
254
|
* Returns null if account is connected or no error exists
|
|
@@ -246,6 +307,7 @@ module.exports = {
|
|
|
246
307
|
setLastErrorState,
|
|
247
308
|
clearLastErrorState,
|
|
248
309
|
formatLastError,
|
|
310
|
+
formatGmailWatch,
|
|
249
311
|
|
|
250
312
|
// State counters
|
|
251
313
|
getStateCount,
|
package/lib/account.js
CHANGED
|
@@ -39,6 +39,7 @@ const { checkAccountScopes: checkScopes } = require('./oauth/scope-checker');
|
|
|
39
39
|
const { ACCOUNT_STATES, ERROR_STATES, calculateEffectiveState, validateAccountState, getDisplayState, formatLastError } = require('./account/account-state');
|
|
40
40
|
const { decodeStoredMailboxEntry } = require('./email-client/imap/listing-diff');
|
|
41
41
|
const { readImapData } = require('./account/imap-data');
|
|
42
|
+
const { isTransientCredentialError, credentialErrorStatus } = require('./email-client/credential-errors');
|
|
42
43
|
|
|
43
44
|
// Shared Lock instance to prevent Redis connection leak (one subscriber per Lock instance)
|
|
44
45
|
// Previously, each Account created its own Lock, causing ~30k connections with 30k accounts
|
|
@@ -1739,7 +1740,12 @@ class Account {
|
|
|
1739
1740
|
if (entry.status) {
|
|
1740
1741
|
delete entry.status.path;
|
|
1741
1742
|
}
|
|
1742
|
-
|
|
1743
|
+
// Keyed the way the stored listing is keyed, because that is what the lookup
|
|
1744
|
+
// below uses. A server that spells the inbox "Inbox" reports it that way in
|
|
1745
|
+
// every LIST response while the stored hash holds the case-folded "INBOX", so
|
|
1746
|
+
// an unnormalized key silently dropped the live counters for the one folder
|
|
1747
|
+
// every account has.
|
|
1748
|
+
mailboxListingMap.set(normalizePath(entry.path), entry);
|
|
1743
1749
|
}
|
|
1744
1750
|
}
|
|
1745
1751
|
|
|
@@ -3162,7 +3168,33 @@ class Account {
|
|
|
3162
3168
|
if (await useAuthServerForOAuth2(accountData.oauth2, this.logger, { account: this.account, target: 'api' })) {
|
|
3163
3169
|
// resolve credentials
|
|
3164
3170
|
|
|
3165
|
-
let authData
|
|
3171
|
+
let authData;
|
|
3172
|
+
try {
|
|
3173
|
+
authData = await resolveCredentials(this.account, 'api');
|
|
3174
|
+
} catch (err) {
|
|
3175
|
+
// The authentication server's own HTTP status must not become EmailEngine's, which
|
|
3176
|
+
// is why resolveCredentials() keeps it in an `authRequest` record rather than on
|
|
3177
|
+
// err.statusCode. It is translated into a status of EmailEngine's own here:
|
|
3178
|
+
// returning it verbatim told an API client holding a perfectly valid EmailEngine
|
|
3179
|
+
// token that its token was rejected (401) or that the account does not exist (404).
|
|
3180
|
+
let transient = isTransientCredentialError(err);
|
|
3181
|
+
|
|
3182
|
+
this.logger.error({
|
|
3183
|
+
msg: 'Failed to resolve credentials from the authentication server',
|
|
3184
|
+
account: this.account,
|
|
3185
|
+
target: 'api',
|
|
3186
|
+
status: credentialErrorStatus(err) || undefined,
|
|
3187
|
+
transient,
|
|
3188
|
+
err
|
|
3189
|
+
});
|
|
3190
|
+
|
|
3191
|
+
let error = Boom.boomify(err, { statusCode: transient ? 503 : 403 });
|
|
3192
|
+
error.output.payload.code = transient ? 'AuthServerUnavailable' : 'AuthServerError';
|
|
3193
|
+
if (!transient) {
|
|
3194
|
+
error.output.payload.authenticationFailed = true;
|
|
3195
|
+
}
|
|
3196
|
+
throw error;
|
|
3197
|
+
}
|
|
3166
3198
|
|
|
3167
3199
|
return {
|
|
3168
3200
|
account: accountData.account,
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const crypto = require('crypto');
|
|
4
4
|
const { redis } = require('../db');
|
|
5
5
|
const { Account, accountExists, authFailureDisabledAt } = require('../account');
|
|
6
|
+
const { formatGmailWatch } = require('../account/account-state');
|
|
6
7
|
const getSecret = require('../get-secret');
|
|
7
8
|
const { oauth2Apps, SERVICE_ACCOUNT_PROVIDERS } = require('../oauth2-apps');
|
|
8
9
|
const settings = require('../settings');
|
|
@@ -1034,6 +1035,11 @@ async function init(args) {
|
|
|
1034
1035
|
result.lastError = accountData.state === 'connected' ? null : accountData.lastErrorState;
|
|
1035
1036
|
}
|
|
1036
1037
|
|
|
1038
|
+
let gmailWatch = formatGmailWatch(accountData);
|
|
1039
|
+
if (gmailWatch) {
|
|
1040
|
+
result.gmailWatch = gmailWatch;
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1037
1043
|
// Stated rather than inferred; see the field's description in lib/schemas.js
|
|
1038
1044
|
result.authFailureDisabledAt = authFailureDisabledAt(accountData);
|
|
1039
1045
|
|
|
@@ -1177,6 +1183,20 @@ async function init(args) {
|
|
|
1177
1183
|
.description('Information about the last SMTP connection attempt. Null when no SMTP connection has been attempted')
|
|
1178
1184
|
.label('SMTPInfoStatus'),
|
|
1179
1185
|
|
|
1186
|
+
gmailWatch: Joi.object({
|
|
1187
|
+
state: Joi.string()
|
|
1188
|
+
.valid('active', 'expired', 'error')
|
|
1189
|
+
.example('active')
|
|
1190
|
+
.description('Whether the Pub/Sub watch is armed, lapsed, or failed to renew')
|
|
1191
|
+
.label('AccountGmailWatchState'),
|
|
1192
|
+
lastCheck: Joi.date().iso().allow(null).example('2021-07-08T07:06:34.336Z').description('When the watch was last renewed or attempted'),
|
|
1193
|
+
expires: Joi.date().iso().allow(null).example('2021-07-15T07:06:34.336Z').description('When the current watch lapses')
|
|
1194
|
+
})
|
|
1195
|
+
.description(
|
|
1196
|
+
'State of the Gmail Pub/Sub watch (Gmail API accounts only). A watch that is not active does not stop the account syncing - the client falls back to polling, so new mail is delayed rather than lost. Why a renewal failed is shown on the account page rather than here, because that text is written by the provider'
|
|
1197
|
+
)
|
|
1198
|
+
.label('AccountGmailWatch'),
|
|
1199
|
+
|
|
1180
1200
|
syncError: Joi.object({
|
|
1181
1201
|
path: Joi.string().example('INBOX').description('Mailbox folder path where the error occurred'),
|
|
1182
1202
|
time: Joi.date().iso().example('2021-07-08T07:06:34.336Z').description('When the error occurred'),
|
package/lib/api-routes/index.js
CHANGED
|
@@ -128,7 +128,7 @@ async function registerApiRoutes(args) {
|
|
|
128
128
|
await mailboxRoutes({ server, call, CORS_CONFIG, FLAG_SORT_ORDER });
|
|
129
129
|
|
|
130
130
|
// setup settings routes
|
|
131
|
-
await settingsRoutes({ server, notify, CORS_CONFIG });
|
|
131
|
+
await settingsRoutes({ server, call, notify, CORS_CONFIG });
|
|
132
132
|
|
|
133
133
|
// setup stats route
|
|
134
134
|
await statsRoutes({ server, call, CORS_CONFIG });
|
|
@@ -4,7 +4,8 @@ const Joi = require('joi');
|
|
|
4
4
|
const { QUEUES_BY_NAME } = require('../db');
|
|
5
5
|
const settings = require('../settings');
|
|
6
6
|
const consts = require('../consts');
|
|
7
|
-
const { failAction } = require('../tools');
|
|
7
|
+
const { failAction, maybeReloadTlsCertificates, TLS_MATERIAL_SETTINGS } = require('../tools');
|
|
8
|
+
const { tlsSettingChanged } = require('../tls/store');
|
|
8
9
|
const { queueStats } = require('../queue-stats');
|
|
9
10
|
const Boom = require('@hapi/boom');
|
|
10
11
|
const { handleError, maskSecrets, containsMaskedSecret, isMaskedRoundTrip, MASKED } = require('./route-helpers');
|
|
@@ -32,7 +33,7 @@ settingsOutputSchema.eventTypes = Joi.array()
|
|
|
32
33
|
.label('EventTypesList');
|
|
33
34
|
|
|
34
35
|
async function init(args) {
|
|
35
|
-
const { server, notify, CORS_CONFIG } = args;
|
|
36
|
+
const { server, call, notify, CORS_CONFIG } = args;
|
|
36
37
|
|
|
37
38
|
server.route({
|
|
38
39
|
method: 'GET',
|
|
@@ -117,6 +118,8 @@ async function init(args) {
|
|
|
117
118
|
|
|
118
119
|
async handler(request) {
|
|
119
120
|
let applied = {};
|
|
121
|
+
// Only the keys whose value actually changed, unlike `applied` - see tlsSettingChanged()
|
|
122
|
+
let tlsChanged = [];
|
|
120
123
|
try {
|
|
121
124
|
for (let key of Object.keys(request.payload)) {
|
|
122
125
|
let value = request.payload[key];
|
|
@@ -141,6 +144,10 @@ async function init(args) {
|
|
|
141
144
|
await settings.clear('webhookErrorFlag');
|
|
142
145
|
}
|
|
143
146
|
|
|
147
|
+
if (TLS_MATERIAL_SETTINGS.includes(key) && tlsSettingChanged(key, await settings.get(key), value)) {
|
|
148
|
+
tlsChanged.push(key);
|
|
149
|
+
}
|
|
150
|
+
|
|
144
151
|
await settings.set(key, value);
|
|
145
152
|
applied[key] = value;
|
|
146
153
|
}
|
|
@@ -154,6 +161,14 @@ async function init(args) {
|
|
|
154
161
|
// key fails, the earlier ones are already stored and the other workers still have
|
|
155
162
|
// to reload for them, or they keep running on settings Redis no longer holds.
|
|
156
163
|
notify('settings', applied);
|
|
164
|
+
|
|
165
|
+
// What a listener serves is not carried by that broadcast, and no worker acts on
|
|
166
|
+
// it. Until this was here, an instance switched to "self-signed only" through the
|
|
167
|
+
// API went on offering its Let's Encrypt certificate, and a name added to
|
|
168
|
+
// tlsHostnames was answered with the certificate that predates it, until something
|
|
169
|
+
// restarted the workers. Each command reports its own failure, so this cannot mask
|
|
170
|
+
// the error being thrown out of the catch.
|
|
171
|
+
await maybeReloadTlsCertificates(call, request.logger, tlsChanged, { action: 'settings' });
|
|
157
172
|
}
|
|
158
173
|
|
|
159
174
|
return { updated: Object.keys(applied) };
|