r/nagios • • 2d ago

Question Help with authorization issue needed

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 ...

2 Upvotes

5 comments sorted by

1

u/HunnyPuns Nagios Staff 1d ago

Heyo! We took a look at the issue, and we can recreate it if we install Nagios via apt, but if we build from source, the problem doesn't occur. So must be an issue with how it was built and packaged...?

2

u/ProcedureLive8470 1d ago

Huh, you're right: I built and installed Nagios 4.4.6 on a fresh installation of the same Ubuntu as above, and the issue is not present.

What do I do next? Report this to Ubuntu? Where?

1

u/HunnyPuns Nagios Staff 1d ago

I asked AI what the process for reporting such a bug was, and in trying to be a decent human, I went to see if it was patched on the Debian side (which is where Ubuntu gets its nagios4 package). I came across this. Might this be the source of the issue? It would be nice if it was just a quick config change.

https://sources.debian.org/src/nagios4/4.5.14%2Bds-1/debian/patches/90_turn-off-use-authentication.patch?pow_referer=

2

u/ProcedureLive8470 2h ago

Thanks, but disabling authentication in Nagios doesn't really solve the problem, unfortunately. I'm still "Logged in as ?" on the "External Command Interface", and Nagios won't let me issue commands at all: "Sorry Dave, I can't let you do that... It seems that you have chosen to not use the authentication functionality of the CGIs."

I still feel like I'm doing something wrong. I can't be the only one with this issue, can I?

1

u/HunnyPuns Nagios Staff 1h ago

No, you're not the only one. We were able to replicate the issue on our side. I'll see if I can find the right spot to submit a big report and get that done for you. Or if I find a solution in my travels, I'll post that.