Skip to content

Edit only the options block of named.conf, and verify the result - #93

Merged
0kaba0 merged 2 commits into
developfrom
fix/named-conf-options-only
Sep 6, 2026
Merged

0kaba0 merged 2 commits into
developfrom
fix/named-conf-options-only

Conversation

@0kaba0

@0kaba0 0kaba0 commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

Switching the cPanel box to BIND and rerunning the installer broke DNS, and the installer said it had succeeded.

What happened

The insert was:

sed -i "/^[[:space:]]*};/i\\  also-notify { $SECONDARY_IP; };"

That writes before every closing brace in the file. cPanel ships a named.conf with a logging block and three views, so also-notify landed inside logging and inside a log channel:

/etc/named.conf:30: unknown option 'also-notify'
/etc/named.conf:34: unknown option 'also-notify'

named stopped answering queries. The installer printed [+] BIND configured and reloaded.

On a flat named.conf with a single block the same code looks correct — which is why it survived until a panel with views was tried.

Second problem on the same path: cPanel's ACL is quoted, allow-transfer { "none"; };, and the code stripped only an unquoted none;, producing allow-transfer { IP; "none"; }.

Fix

  • the insert is bounded to the options block — DirectAdmin already did this, cPanel and Plesk did not
  • the quoted "none" is removed as well, in all three installers
  • after editing, named-checkconf decides: a config it rejects is restored from the backup and reported, instead of being reloaded under a success message

Verified on the real file

The cPanel named.conf from the live server is kept as a fixture. Applying the new commands to it:

allow-transfer { 203.0.113.9; };     ← "none" gone
also-notify { 203.0.113.9; };        ← once, inside options
logging block: 0 occurrences
named-checkconf: valid

The old commands on the same file produced three inserts, two of them in logging, and a file named could not parse.

Tests

tests/test_named_conf_edit.sh, 19 checks across the installers that edit named.conf: the insert is bounded to options, a quoted "none" is removed, the config is verified before reload, a broken one is reported rather than announced as success, and the backup is restored. Lower bound of 3 installers so a rename fails here instead of matching nothing.

Note

This is the third time this cycle that an installer reported success over a service it had just broken — the CyberPanel PowerDNS restart loop, the DirectAdmin restart without a liveness check (#89), and now this. All three now verify before claiming anything.

Switching the cPanel box to BIND and rerunning the installer broke DNS. The
insert was:

    sed -i "/^[[:space:]]*};/i\\  also-notify { IP; };"

which writes before *every* closing brace in the file. cPanel ships a
named.conf with three views and a logging block, so also-notify landed inside
logging and inside a log channel:

    /etc/named.conf:30: unknown option 'also-notify'
    /etc/named.conf:34: unknown option 'also-notify'

named stopped answering, and the installer printed "[+] BIND configured and
reloaded". On a flat named.conf with one block the same code looked correct,
which is why it survived.

Also, cPanel's ACL is quoted — `allow-transfer { "none"; };` — and the code
stripped only an unquoted `none;`, leaving `{ IP;  "none"; }`.

- the insert is bounded to the options block, as DirectAdmin already did
- the quoted "none" is removed too, in all three installers
- after editing, named-checkconf decides: a config it rejects is restored from
  the backup and reported, instead of reloading and claiming success

Verified against the real cPanel named.conf, kept as a fixture: one
also-notify in options, logging untouched, named-checkconf clean.

tests/test_named_conf_edit.sh asserts, for every installer that edits
named.conf: the insert is bounded to options, a quoted "none" is removed, the
config is verified, a broken one is reported, and the backup is restored.
Lower bound of 3 installers.
@0kaba0hub

Copy link
Copy Markdown
Collaborator

CHANGES REQUESTED, one item. The fix is right — the insert is bounded to the options block, the quoted "none" is removed, and every BIND path now runs named-checkconf with a rollback before it says anything. The test is not: it greps the installers' source for the sed pattern, so it asserts wording, and the fixture cpanel-named.conf (three views, a logging block — the exact shape that broke) is shipped but never used. That is the same trap as checking a comment instead of the lock. Make it behavioural: copy the fixture, run the installer's edit against it (extract the block or call the function), and assert exactly one allow-transfer and one also-notify, both inside the options block and none inside logging or any view, no leftover "none", and brace balance unchanged; mutation: the old unbounded sed → red. The source-grep rows can stay as the cheap ones. CI green, no attribution trailers, comments within two lines apart from the fixture's own BIND comments.

The test asserted the shape of a sed command and left the fixture unused —
checking the wording instead of the lock, and the fixture was the one thing
that reproduced the failure.

The edit is now a function, configure_named_axfr, that the test extracts from
each installer and applies to a copy of the real cPanel named.conf: exactly one
allow-transfer and one also-notify, both inside options, nothing in logging or
any view, no leftover "none", braces balanced, and named-checkconf clean where
it is available. The greps stay as cheap checks that the reload is gated.

Making it callable also made it portable: sed -i and \? are GNU-only, and on
BSD the old commands silently produced 'talso-notify' and left the quoted
"none" in place. The insert is awk now, bounded to the options block.

Mutations: the original unbounded sed writes also-notify 13 times, into
logging and into a view — 3 red; not stripping "none" — 1 red; replacing
'if named-checkconf' with 'if true' — 1 red, after the criterion was narrowed
from the word appearing anywhere to it gating the branch.
@0kaba0

0kaba0 commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator Author

Fixed — the test now runs the edit instead of describing it.

The edit is a function, configure_named_axfr, which the test extracts from each installer and applies to a copy of the fixture — the real cPanel named.conf with three views and a logging block. It then asserts:

  • exactly one allow-transfer and one also-notify carrying the secondary
  • both inside options
  • nothing written into logging or into any view
  • no "none" left beside the address
  • braces balanced
  • named-checkconf clean where the binary is available

34 checks across the three installers. The greps stay as the cheap half: that the reload is gated and the backup restored.

Mutations

mutation result
the original unbounded sed 3 red — also-notify written 13 times, wrote into the logging block, wrote into a view
not stripping "none" 1 red
if named-checkconf → if true 1 red

The last one needed the criterion narrowed first: my check looked for the word named-checkconf anywhere in the file and passed on the mutant, because the string also appears in the "Check: named-checkconf" message. It now looks for it gating the branch. Same trap as the pgrep one in #89 — worth naming.

A second defect surfaced while making it callable. sed -i and \? are GNU-only. On BSD the old commands silently produced talso-notify (the tab and line start lost by i\) and left the quoted "none" in place. The insert is awk now, bounded to the options block, and the whole function is POSIX.

Verified once more against the live server's own named-checkconf: one of each directive, inside options, logging untouched, config valid.

@0kaba0

0kaba0 commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator Author

Verified: the edit now runs on a copy of the cPanel fixture and the rows assert the property — one directive each, both inside options, logging and views untouched, no "none" beside the address, braces balanced, named-checkconf accepting it where available — with the unbounded-sed mutation producing the thirteen inserts that took DNS down; the check-config row is on the branch, not on the word; the insert is awk and POSIX, which is what surfaced the GNU-only sed. CI green, no attribution trailers, the only long comment run is the fixture's own BIND comments. Ready to merge into develop.

@0kaba0
0kaba0 merged commit 76eff85 into develop Sep 6, 2026
1 check passed
@0kaba0
0kaba0 deleted the fix/named-conf-options-only branch September 6, 2026 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants