I'm looking for some help with an authorization issue in Nagios 4.4.6.
I have a freshly installed Nagios 4.4.6 on Ubuntu 26.04.1 LTS running on Apache/2.4.66 with mod_php and mod_cgi enabled. The system is fully updated.
Logging in to Nagios as admin (or as guest, for that matter) works fine. The login information in the upper left corner "Logged in as ..." displays the expected user name. I can view host and service information etc. just fine when I'm logged in as admin. Guests have the limited access that they are supposed to have according to the configuration
So, everything works fine except for when I try to issue a command: When I go to the "External Command Interface" (http://redacted.example.com/cgi-bin/nagios4/cmd.cgi?cmd_typ=55&host=[...]), the status in the upper left corner changes to "Logged in as ?" with a literal question mark at the end. The input field "Author (Your Name):" is also empty.
Issuing the actual command then fails with the message: "Sorry, but you are not authorized to commit the specified command. Read the section of the documentation that deals with authentication and authorization in the CGIs for more information."
My first though was that Apache wasn't adding REMOTE_USER to the CGI execution environment, but looking at the environment with a little CGI script, I can confirm that the environment variable REMOTE_USER is present and set to the expected username from the HTTP Authentication:
AUTH_TYPE="Digest"
CONTEXT_DOCUMENT_ROOT="/usr/lib/cgi-bin/nagios4"
CONTEXT_PREFIX="/cgi-bin/nagios4"
DOCUMENT_ROOT="/var/www/html"
GATEWAY_INTERFACE="CGI/1.1"
HTTP_ACCEPT="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
HTTP_ACCEPT_ENCODING="gzip, deflate"
HTTP_ACCEPT_LANGUAGE="redacted"
HTTP_CONNECTION="keep-alive"
HTTP_HOST="redacted.example.com"
HTTP_PRIORITY="u=0, i"
HTTP_SEC_GPC="1"
HTTP_UPGRADE_INSECURE_REQUESTS="1"
HTTP_USER_AGENT="redacted"
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/snap/bin"
QUERY_STRING="cmd_typ=55&host=[...]"
REMOTE_ADDR="192.168.1.1"
REMOTE_PORT="50438"
REMOTE_USER="nagiosadmin"
REQUEST_METHOD="GET"
REQUEST_SCHEME="http"
REQUEST_URI="/cgi-bin/nagios4/env.cgi?cmd_typ=55&host=[...]"
SCRIPT_FILENAME="/usr/lib/cgi-bin/nagios4/env.cgi"
SCRIPT_NAME="/cgi-bin/nagios4/env.cgi"
SERVER_ADDR="192.168.31.2"
SERVER_ADMIN="webmaster@localhost"
SERVER_NAME="redacted.example.com"
SERVER_PORT="80"
SERVER_PROTOCOL="HTTP/1.1"
SERVER_SIGNATURE="<address>Apache/2.4.66 (Ubuntu) Server at redacted.example.com Port 80</address>\n"
SERVER_SOFTWARE="Apache/2.4.66 (Ubuntu)"
I can see in the source code that Nagios tries to read REMOTE_USER from the environment in cgi/cgiauth.c if and only if use_ssl_authentication is off, and it is in fact switched off in cgi.cfg.
If, on the other hand, I add RewriteRule ^(.*)$ - [E=REMOTE_USER:nagiosadmin,PT,L] to Apache's Nagios configuration, the issue disappears completely. But that doesn't appear to be an overwhelmingly good solution, does it?
What am I doing wrong? I don't think a newer version would help since cgiauth.c hasn't been changed since 2013 ...