[ZBXNEXT-5948] Cannot setup working SAML behind nginx reverse proxy providing https Created: 2020 May 13  Updated: 2022 Feb 02  Resolved: 2021 May 31

Status: Closed
Project: ZABBIX FEATURE REQUESTS
Component/s: Frontend (F)
Affects Version/s: 5.0.0
Fix Version/s: None

Type: Change Request Priority: Trivial
Reporter: Patrik Pekarčík Assignee: Zabbix Development Team
Resolution: Duplicate Votes: 11
Labels: SAML, authentication, frontend
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates ZBX-19320 SAML advanced configuration ignores b... Closed
duplicates ZBX-18594 Zabbix5.2 SAML Access Relay URL Error... Closed
Sprint: Sprint 74 (Mar 2021), Sprint 75 (Apr 2021)

 Description   

I have tried to setup SAML using 2.0 protocol and our installed keycloak solution.

After setting up certificates i will be redirected to SAML correctly but instead of correct redirect url, i've got url from zabbix web instalation.

This is what i get 
AssertionConsumerServiceURL="http://zabbix.example.eu:8080/index_sso.php?acs"

This is expexted
AssertionConsumerServiceURL="https://zabbix.example.eu/index_sso.php?acs"

 



 Comments   
Comment by Nicolas Le Gras [ 2020 May 15 ]

I'm having the same issue.

A solution would be to authorize customizing zabbix front end baseurl setting

raw fix : edit the index_sso.php file

set the baseurl variable to your fqdn

add the following variable in the $settings array : $settings['baseurl'] = $baseurl;

Comment by Patrik Pekarčík [ 2020 May 15 ]

Thank you for fast fix i will try it.

 

On sites we are using docker deployment, is there any way to set it via environment?

Comment by Nicolas Le Gras [ 2020 May 15 ]

I'm surcharging the index_sso.php file and mounting it as a readonly volume in the container :

/path/to/index_sso.php:/usr/share/zabbix/index_sso.php:ro

 

Comment by Patrik Pekarčík [ 2020 May 18 ]

I have tied your solution but i have found few problems.

I have found that $baseurl uses Utils class from OneLogin plugin and that my X-Forwarded headers was wrong. My solutions was changing X-forwarding headers accordingly

$_SERVER['HTTPS'] = 'on';
$_SERVER['HTTP_X_FORWARDED_PROTO'] = "https";
$_SERVER['HTTP_X_FORWARDED_PORT'] = 443;
$_SERVER['HTTP_X_FORWARDED_HOST'] = "zabbix.example.com";
Utils::setProxyVars(true);
Comment by Fabien Brachere [ 2020 Jun 11 ]

Hi,

Same problem here, I've a front reverse proxy (HAproxy) for zabbix like this:

Web browser — https ---> Haproxy — http ---> zabbix.

I needed to patch the index_sso.php file to add:
Utils::setProxyVars(true);
Otherwise, firefox would send me an alert when returning from keycloak.

Comment by Andrew Boling [ 2020 Jun 16 ]

The Utils::setProxyVars(true) workaround helped me as well. Some additional clarity:

  • If you are using this solution, do not make any changes to the $settings array. It is not necessary to insert the "baseurl" key with this method. If you combine the methods described in this thread you may see an error about the SAML reply being received at the wrong URL.
  • If you are using the docker container, copy the file out of the container to modify it:
    docker exec -u 0 zabbix-web cp /usr/share/zabbix/index_sso.php /usr/share/zabbix/index_sso.php.backup
    docker cp zabbix-web:/usr/share/zabbix/index_sso.php /tmp
    
  • Insert your changes immediately prior to the definition of the $baseurl definition, like so:
    $_SERVER['HTTPS'] = 'on';
    $_SERVER['HTTP_X_FORWARDED_PROTO'] = "https";
    $_SERVER['HTTP_X_FORWARDED_PORT'] = 443;
    $_SERVER['HTTP_X_FORWARDED_HOST'] = "yourzabbix.example.com";
    Utils::setProxyVars(true);
    $baseurl = Utils::getSelfURLNoQuery();
    
  • If you are using the docker container, copy the modified file back into the container and restart it.
    docker cp /tmp/index_sso.php zabbix-web:/usr/share/zabbix/index_sso.php
    docker restart zabbix-web
    
Comment by Michał Gawryś [ 2020 Jul 11 ]

As I faced same problem recently, I sumbitted PR to zabbix repo to fix the issue: https://github.com/zabbix/zabbix/pull/22

 

Comment by Jay Dawes [ 2020 Jul 15 ]

Hi,

I had similar issues with Okta and the official zabbix-web-nginx-mysql container.  I'm running behind an NGINX reverse proxy, with zabbix at https://<base url>/zabbix

The URL that was passed from the container to Okta had "RelayState" set to the the base path of "/" and the port of 8443.  The value of RelayState was eventually used in a test against what the actual connection from the browser was, which would have been the https://<base url>/zabbix.  so both the port number and the base path mismatched.

I had gone in and manully changed things in the SAML php scripts to get things working, but finaly settled on created a file that I would mount inside the container (via the volumes section in my yaml file for docker-compose).

      - /opt/docker/zabbix-web/config/SAML_settings.php:/usr/share/zabbix/vendor/php-saml/src/Saml2/settings.php:ro

Like above, I was using the function calls that the SAML library made available.  But this way, I didn't need to modify any files inside the container.  I had to do one additional function call besides setProxyVars to describe my base path of "/zabbix/".

 

The SAML_settings.php file I created is as follows:

 

<?php
\OneLogin\Saml2\Utils::setProxyVars(true);
\OneLogin\Saml2\Utils::setBaseURLPath("/zabbix/");

 

 

With that file called settings.php, the SAML library would include those function calls, call them in the right namespace and the value of RelatState now matched the URL I would be connecting to from my browser.

 

I was working with 5.0.1 when I had the issue and I saw changes in git for index_sso.php related to Okta and pulled that file to try it, but it didn't solve the issue of having the container at a different base URL like I did, so I'm still using the method I'm describing with 5.0.2 and it works fine.

 

It took a long time to figure all of this out and I didn't find this thread until I had things working, but I thought I'd share my thoughts in the hopes it will save someone else some time.

 

I just looked at the pull request above; if that added ability to call the function  setBaseURLPath, it might eliminate the need to mount the  settings.php file like I described.

Comment by Alexander Vladishev [ 2021 May 31 ]

Closed as duplicate of ZBX-19320.

Generated at Fri Apr 25 08:07:28 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.