Cron still attempts mailing job output despite `MAILTO=""` for jobs invoked via `configctl -d --`
Title: cron still attempts mailing job output for any GUI cron job invoked via configctl -d, despite MAILTO="" — breaks remote syslog for all such jobs
Important notices
Before you add a new report, we ask you kindly to acknowledge the following:
- [x] I have read the contributing guidelines at https://github.com/opnsense/core/blob/master/CONTRIBUTING.md
- [x] I am convinced that my issue is new after having checked both open and closed issues at https://github.com/opnsense/core/issues?q=is%3Aissue
- [x] AI tools were used to create at least part of the text submitted herewith.
If AI was used, please disclose:
- Model used: Claude (Anthropic)
- Extent of AI involvement: Investigated the log correlation, identified the UUID/byte-count match and cross-job pattern, and drafted this report text based on findings verified live on the reporter's own system (shell + remote syslog queries). Reviewed and submitted by a human.
Describe the bug
This significantly limits the usefulness of remote syslog for anyone running GUI-managed cron jobs: for every affected job run, the broken mail-attempt log line and the legitimate job-execution log line for that same job arrive as separate syslog entries, and the broken one is malformed badly enough that it loses its structured header entirely on the remote side (see below) — polluting the log stream and making it harder to build reliable alerting or dashboards on cron activity.
Any cron job created via System: Settings: Cron whose action is backed by configctl -d -- <action> can cause cron to attempt mailing job output, even though the generated /var/cron/tabs/<user> crontab already contains MAILTO="" (added upstream to close #10246). This is not limited to one specific action or plugin — we confirmed it for a third-party plugin action (a curl wrapper, run every minute) as well as for core actions (firmware poll, ids update), so it appears to be a general property of configctl -d-invoked cron jobs.
The 37 bytes cron reports mailing corresponds exactly to the UUID that configctl -d echoes to stdout on every invocation (36 hex/dash characters + newline = 37 bytes) before the actual action runs in the background — not any output from the action itself. Since no local MTA is configured, the mail attempt fails and cron logs:
(nobody) MAIL (mailed 37 bytes of output but got status 0x0001
This also reproduces the malformed multi-line syslog message described in #10246 (the log line contains an embedded LF before the closing )), which breaks framing on remote syslog receivers and causes these lines to arrive without a proper hostname/structured header — i.e. they are essentially unusable for filtering or correlation on the receiving end.
Per #10246 the accepted fix was setting MAILTO="" in the cron template, on the assumption this fully suppresses the mail attempt. On our system (see Environment) this is demonstrably not the case.
To Reproduce
- Go to System ‣ Settings ‣ Cron, add a new job with a schedule of
*/1 * * * *and any Command backed byconfigctl(e.g. "Custom CURL call" from a plugin, or a core action). - Confirm the generated crontab already contains
MAILTO="":crontab -l -u nobody | head -5 - After a few minutes, check for mail attempts:
(Note: locally, thegrep -i "mailed" /var/log/system/system_*.logcronfacility does not appear to be written to/var/log/cronat all — point 2 raised in #10246's discussion does not appear to have been addressed by the merged fix. We had to inspect this via a remote syslog target instead.) - Observe recurring
(nobody) MAIL (mailed 37 bytes of output but got status 0x0001entries, intermixed with the normal(nobody) CMD (/usr/local/sbin/configctl -d -- ...)line for the same job. - Jobs that run far less frequently than every minute (e.g. the built-in "Check for new firmware every 4 hours" /
firmware poll, or "ids update") also show this MAIL line on some of their runs, confirming this is not specific to one action.
Expected behavior
With MAILTO="" set, cron should not attempt to mail job output at all (this is the standard/documented cron behavior, and is what #10246 assumed would happen).
Describe alternatives you considered
- Excluding the
cronfacility (9, "clock daemon") from remote syslog: rejected, since that facility also carries the legitimate(user) CMD (...)start-of-job records for every cron job (backups, firmware polls, ACME renewals, etc.) — filtering it out removes far more useful signal than it removes noise. - Adding output-suppressing parameters (e.g.
-s -o /dev/nullfor a curl-based action): does not help, sinceconfigctl -dreturns immediately with only its own UUID on stdout — the wrapped action's own output is captured byconfigdseparately and never reachescron's stdout in the first place. - Suppressing
configctl's UUID output specifically (raised as suggestion 1 in #10246: invoke with-q) was not implemented as part of the merged fix; this may be the more targeted remaining fix, since the UUID is the actual mailed content in every case we observed.
Relevant log files
Sample from remote syslog target (values anonymized) showing a minute with four configctl -d jobs (two custom, two core) and three MAIL attempts — demonstrating this is not limited to one action:
<14>1 ... configd.py ... message ... [<plugin-action> ...] returned OK
<78>1 ... /usr/sbin/cron ... (nobody) CMD (/usr/local/sbin/configctl -d -- <plugin-action> ...)
<78>1 ... /usr/sbin/cron ... (nobody) CMD (/usr/local/sbin/configctl -d -- ids update)
<78>1 ... /usr/sbin/cron ... (nobody) CMD (/usr/local/sbin/configctl -d -- firmware poll)
<78>1 ... /usr/sbin/cron ... (nobody) CMD (/usr/local/sbin/configctl -d -- <plugin-action> ...)
<78>1 ... /usr/sbin/cron ... (nobody) MAIL (mailed 37 bytes of output but got status 0x0001
<78>1 ... /usr/sbin/cron ... (nobody) MAIL (mailed 37 bytes of output but got status 0x0001
<78>1 ... /usr/sbin/cron ... (nobody) MAIL (mailed 37 bytes of output but got status 0x0001
Current crontab excerpt (crontab -l -u nobody):
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
MAILTO=
#minute hour mday month wday command
*/1 * * * * /usr/local/sbin/configctl -d -- <plugin-action> ...
18 1,5,9,13,17,21 * * * /usr/local/sbin/configctl -d -- firmware poll
Additional context
Related: #10246 (closed). That report and its fix (1c5f6b9) addressed the missing MAILTO="" in the generated template, but this report shows the mail attempt still occurs for configctl -d-invoked jobs regardless of which action is wrapped, and the two secondary issues raised in that thread — cron's facility not being logged locally, and the malformed multi-line remote syslog message — appear unresolved.
Environment
OPNsense 26.7.4_1 (amd64).
We're not hearing much from users about this and it would also indicate cron(8) is broken as MAILTO is defined in the manual to be set to null to disable. As far as triage goes this still needs more data to proceed.
Cheers, Franco
Thanks for the quick reply, Franco — fair skepticism. I ran the minimal test you'd want to see: a plain cron job with no configctl involved at all.
Added directly to /var/cron/tabs/nobody (which already has MAILTO= from the existing GUI-generated crontab):
* * * * * echo hello
Result, every single minute since installing it, in the remote syslog stream:
(nobody) CMD (echo hello)
(nobody) MAIL (mailed 6 bytes of output but got status 0x0001
6 bytes = hello\n. So this isn't specific to configctl -d after all — cron(8) on this system is not honoring MAILTO="" for job output at all, for a job as simple as echo hello. Happy to provide more detail (crontab -l -u nobody, OPNsense version, anything else) if that helps narrow it down further.
I think this is the cause, and cron(8) is fine: the MAILTO line in the template lost its quotes.
MAILTO="" was added in 1c5f6b9 for #10246, and 8978c5f ("archaic style on cron file") changed it to MAILTO=. crontab(5) man page documents the empty value as MAILTO="". FreeBSD's cron rejects the unquoted line as a bad entry, so MAILTO is never set and every job with output is mailed.
Reproduced on a stock 26.7.7 VM (15.1-RELEASE-p4, no sendmail):
crontab -u operator <file>refuses the file withMAILTO=:bad minuteanderrors in crontab file, can't install. WithMAILTO=""it installs.- The same file written straight to
/var/cron/tabs/operator, as the template does, with* * * * * echo hello:MAILTO=: onePARSE (bad minute), thenCMD (echo hello)andMAIL (mailed 6 bytes of output but got status 0x0001 )every minuteMAILTO="":CMDonly- no
MAILTOline:CMDandMAIL, the same asMAILTO=
configctl template reload OPNsense/Cronwith the stock template logs(nobody) RELOAD (tabs/nobody)and then(nobody) PARSE (bad minute). With the quotes restored in the template, it logs theRELOADonly.
cron logs these lines at info level, and OPNsense keeps no local cron log, so they only show up in remote syslog. That may be why this went unnoticed.
Fix, in src/opnsense/service/templates/OPNsense/Cron/user.cron:
-MAILTO=
+MAILTO=""
AI disclosure: investigated and drafted with Claude Opus 5.5 (Anthropic). I reviewed it, and the reproduction ran on my own lab VM.
Apparently cron is handrolling environment reading... brrr...
https://github.com/opnsense/src/blob/97a14fd3878f5db14e0a95ef902340eea8f3afec/usr.sbin/cron/lib/env.c#L224