Skip to content

omd: keep the system Apache configuration root-owned, and add a sudo rule to update it - #251

Open
superbot-helper wants to merge 2 commits into
ConSol-Monitoring:labsfrom
superbot-helper:fix/system-apache-sudo
Open

superbot-helper wants to merge 2 commits into
ConSol-Monitoring:labsfrom
superbot-helper:fix/system-apache-sudo

Conversation

@superbot-helper

Copy link
Copy Markdown

What this changes

The system-wide Apache runs as root and includes configuration files from each
site's home directory. Those files belong to the site user, so a site user can
write directives into them that make the root Apache load code the next time it
reads its configuration.

This branch keeps everything the system Apache reads in a directory written by
root, /omd/apache/<site>.d. The site's own mode.conf, proxy-port.conf and
etc/apache/system.d/*.conf are copied there when the site is created or
updated, with the same content, except that a LoadModule/LoadFile of a file
the site user owns, or an Include that leaves the site tree, is refused and
the last accepted copy stays in place. The hook files in /omd/apache then only
include the root-owned copies. omd update-apache-config <site> refreshes the
copy and reloads the system Apache.

Because that copy is written by root, a change a site user makes under
etc/apache would need a root step again, where before it was picked up at the
next log rotation. The package now installs /etc/sudoers.d/omd, which lets a
member of the omd group (every site user) run exactly
omd update-apache-config <site> for its own site as root:

Cmnd_Alias OMD_UPDATE_APACHE_CONFIG = /usr/bin/omd ^update-apache-config [a-zA-Z_][a-zA-Z_0-9]*$
%omd ALL = (root) NOPASSWD: OMD_UPDATE_APACHE_CONFIG

The regular expression is matched against the whole argument string, so neither
another subcommand nor a second argument can pass it. The command validates the
site name as well and refuses a site other than the caller's own when it is
started through sudo. omd config set WEB_REDIRECT and WEB_ALIAS refresh the
copy themselves when a site user sets them, and the site's own apache init
script does the same on start and reload. Without sudo, or without the rule,
nothing changes: the change needs a root step, and the command says which one.

Why

A site is meant to need no root permissions after omd create, and a change in
the system Apache currently becomes active only when the next log rotation
restarts it. The sudo rule for the new command keeps both properties.

How it was tested

On one Debian 12 machine with systemd as pid 1 and omd 5.80-labs-edition from
the stable repository, with both commits applied to the installed package and
the sudo rule installed the way the package installs it:

  • Before the patch, a site user's LoadModule in etc/apache/system.d was
    loaded by the root Apache on a reload (marker written three times, uid 0).
    With the patch the same directive is refused in three spellings
    (LoadModule, loadmodule, and a backslash-continued LoadMod/ule), the
    site user cannot make it reach the root Apache through the sudo command, and
    no marker is written after a reload, a restart, the distribution's log
    rotation or the creation of another site.
  • An existing site keeps serving after the package update and is staged on its
    first omd update-apache-config; after that a new LoadModule is refused
    while the previously accepted configuration stays in place and the site keeps
    serving.
  • A site user's WEB_REDIRECT and WEB_ALIAS changes are live immediately
    after omd config set, and a hand-written rewrite rule, a site-owned
    Include, a redirect appended to apache-own.conf and the maintenance page
    are served through the root-owned copy.
  • The sudo rule accepts the site user's own site and refuses another site,
    another omd subcommand, a second argument and a different program. A fake
    omd in the site user's own bin directory is refused as well.
  • With sudo removed from the host, omd config set and the site's reload path
    print one line naming the root command to run, and the change stays pending
    until root runs it.
  • The repository's own t/10-omd_testsite.t passes before and after the patch
    (638 tests). t/11-omd_update.t is an author test and does not run without
    TEST_AUTHOR.

Operator-visible change

  • A site user's change under etc/apache is live at once when it is made
    through omd config set WEB_REDIRECT/WEB_ALIAS, or on the site's next
    omd start/omd reload apache.
  • After the package update, existing sites need one
    omd update-apache-config <site> as root (or by the site user through sudo).
  • sudo omd update-apache-config <site> now works for a site user for its own
    site.
  • On a host without sudo the change needs root, as before, and says so.

What this does not cover

  • Releases before 5.70-labs-edition: the include dates from 2018 and was not
    installed or run here.
  • Directives other than LoadModule/LoadFile that can run code from a site
    file: RewriteMap ... prg:, a CGI handler, an ErrorDocument pointing at a
    site CGI.
  • Checkmk's omd fork: its per-site hook is created in its closed binary.
  • sudo older than 1.9.10: the argument pattern is a literal string there, the
    rule does not match, and the change needs root as before.

AI tools were used to write and test this change.

EZO Labs Security added 2 commits November 24, 2026 13:59
The global Apache runs as root and includes configuration files that belong
to each site user. A LoadModule directive in one of those files loads a
shared object the site user wrote into the root parent process, so everything
the global Apache reads is staged below /omd/apache/<site>.d, written and
owned by root. Redirects, rewrite rules and other directives are copied as
they are, an Include of another file in the site's own tree is inlined and
checked the same way, and a file that names a module the site user owns is
refused while the last accepted configuration stays in place.

omd update-apache-config <site> rewrites the staged copy after a site user
changes a setting.
The system Apache reads a root-owned copy of each site's configuration,
so a change below a site's etc/apache directory has to be copied there by
root before it becomes live. That is the root step the previous commit
introduced for existing sites.

Ship /etc/sudoers.d/omd from the package: members of the omd group, which
is every site user, may run exactly omd update-apache-config <site> as
root without a password. The argument pattern is the site-name syntax omd
creates sites with, so the rule admits neither another subcommand nor a
second argument. The command itself validates the name again, and when it
runs through sudo it refuses any site but the caller's own.

WEB_REDIRECT and WEB_ALIAS refresh the copy themselves when a site user
sets them, and the site's own apache init script refreshes it on start and
reload, so a redirect or maintenance page change is live at once instead
of waiting for the next log rotation. Without sudo, or without the
packaged rule, the behaviour is the one from before: the change needs a
root step, and the command names it.

The copy now refuses a site file that a symlink points to outside the
site tree, and the maintenance page does the same, because the rule lets a
site user start the copy while it runs as root.

@sni sni left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good in general. I've got two questions.

Comment thread debian/postrm.in
! test -x /usr/sbin/a2disconf || a2disconf zzz_omd || /bin/true
rm -f "$APACHE_OMD_CONF"
rm -f "$SYSCTL_OMD_CONF"
rm -f /etc/sudoers.d/omd

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should choose a different filename, maybe omd.pkg or omd.auto. Chances are high that there is a file name omd already and it would be overwritten.


case "$1" in
reload|force-reload)
refresh_system_apache

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see no reason to unconditionally refresh the system apache? Why not checking for stale files here as well?

@sni

sni commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

And thanks for this pull request. I think this is a good idea to make root apache things more deterministic.

@superbot-helper

Copy link
Copy Markdown
Author

Thanks for the review.

  1. Agreed on the name. One catch: sudo skips files in /etc/sudoers.d whose names contain a dot (or end in ~), so omd.pkg or omd.auto would be installed but never read. I'd go with omd_auto unless you prefer something else.
  2. Fair point. I'll make reload use the same stale check as start.

I'll also rebase onto the current labs to clear the conflict and push the update here.

@sni

sni commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

omd_auto is fine for me.

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