[ZBX-16629] On ubuntu home environment variable is not set for user zabbix Created: 2019 Sep 12 Updated: 2024 Apr 10 Resolved: 2020 Jul 28 |
|
| Status: | Closed |
| Project: | ZABBIX BUGS AND ISSUES |
| Component/s: | Agent (G), Proxy (P), Server (S) |
| Affects Version/s: | 4.2.6 |
| Fix Version/s: | 5.2 (plan) |
| Type: | Problem report | Priority: | Trivial |
| Reporter: | Aleksandrs Larionovs (Inactive) | Assignee: | Jurijs Klopovskis |
| Resolution: | Won't fix | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||
| Team: | |||||||||||||||||
| Sprint: | Sprint 56 (Sep 2019), Sprint 57 (Oct 2019), Sprint 58 (Nov 2019), Sprint 59 (Dec 2019), Sprint 60 (Jan 2020), Sprint 61 (Feb 2020), Sprint 62 (Mar 2020), Sprint 63 (Apr 2020), Sprint 64 (May 2020), Sprint 65 (Jun 2020), Sprint 66 (Jul 2020) | ||||||||||||||||
| Story Points: | 1 | ||||||||||||||||
| Description |
|
On ubuntu home environment variable is not set for user zabbix. When running sudo -u zabbix env | grep HOME command on debian the output is HOME=/var/lib/zabbix, but on ubuntu it is HOME=/root . debian: # sudo -u zabbix env | grep HOME HOME=/var/lib/zabbix ubuntu: # sudo -u zabbix env | grep HOME HOME=/root |
| Comments |
| Comment by Jurijs Klopovskis [ 2019 Sep 18 ] | |||||||||
|
This is due to different behavior of sudo on debian vs ubuntu and has nothing to do with user creation or packages. When using sudo on debian the HOME variable is set to the one of the target user, but on ubuntu the caller's home variable is used. # sudo -Hu zabbix env | grep HOME HOME=/var/lib/zabbix/ vzhuravlev: I think that sudo was given as an example, but there is no sudo in use, when mysql client or other shell command is run under user zabbix, right? So the problem should be something else, why HOME is not set to /var/lib/zabbix when command is executed under under zabbix user.
| |||||||||
| Comment by Aleksandrs Larionovs (Inactive) [ 2019 Sep 18 ] | |||||||||
|
Is it possible to make sure that zabbix agent can locate and use the home directory to read the configuration file? For Mysql/PostgreSQL templates login/password are stored in ~/.my.cnf file and zabbix-agent is not reading it. #For OS Linux: You need create .my.cnf in zabbix-agent home directory (/var/lib/zabbix by default) | |||||||||
| Comment by Aleksandrs Larionovs (Inactive) [ 2019 Sep 18 ] | |||||||||
|
Eg. This user parameter runs fine on Centos and Debian as it is checking for ~/.my.cnf UserParameter=mysql.get_status_variables[*], mysql -h"$1" -P"$2" -sNX -e "show global status" but it is not checked on Ubuntu, yurii do you have ideas on how to make agent behave consistent on different Linux distributive? | |||||||||
| Comment by dimir [ 2019 Sep 20 ] | |||||||||
|
I thought we agreed to use specific file with MySQL credentials for agent. Something like /etc/zabbix/userparameters-mysql.conf . Did something change and we decided to stick with default file in user home directory called .my.cnf ? This is not good as this file may be used by other programs. What if a user wants to use different account for Zabbix agent? Depending on any environment variables is always a security risk for Zabbix agent. If we go for a separate file we do not depend on HOME variable at all and this issue could be closed. | |||||||||
| Comment by Aleksandrs Larionovs (Inactive) [ 2019 Sep 20 ] | |||||||||
|
vzhuravlev has pointed out that if we use custom path, it breaks compatibility with other OS (eg. Windows) as we need to provide full path to config. Additionally while it was a trivial fix for MySQL it is problematic to use it for PostgreSQL. <dimir> I don't agree: $ PGPASSFILE=/etc/zabbix/userparameters-pgsql.conf strace psql 2>&1 | grep userparameter
stat("/etc/zabbix/userparameters-pgsql.conf", 0x7ffc8d954190) = -1 ENOENT (No such file or directory)
$ strace mysql --defaults-extra-file=/etc/zabbix/userparameter-mysql.conf 2>&1 | grep userparameter
stat("/etc/zabbix/userparameter-mysql.conf", 0x7ffce9646610) = -1 ENOENT (No such file or directory)
Absolutely the same thing with Windows, see here. Now all these auto-connects from Zabbix agent is mess. So I propose stop it and standardize paths to configuration files:
Document it and starting from 4.4 there will be no more questions on how to set up auto-connect to the database on Zabbix agent host. | |||||||||
| Comment by dimir [ 2019 Sep 25 ] | |||||||||
|
How was this issue resolved? | |||||||||
| Comment by Maxim Chudinov (Inactive) [ 2019 Oct 04 ] | |||||||||
|
The problem is with all agents for ubuntu from zabbix repo. They return the value Tested on Ubuntu 18.04. After installing 4.2.7-1+bionic from repo.zabbix.com, adding UPD: after adding User=zabbix in /usr/lib/systemd/system/zabbix-agent.service root@debian10:~# zabbix_get -s 127.0.0.1 -k system.run["env"] at the same time on CentOS without any manipulation [mchudinov@c7amd64-dock ~]$ zabbix_get -s 127.0.0.1 -k system.run["env"] | |||||||||
| Comment by dimir [ 2019 Oct 07 ] | |||||||||
|
Why don't we define and use specific file for the database credentials and not depend on the HOME variable? If users would like to use it from home directory of zabbix they can just create a symlink. Our packages already contain config files in a specific static locations, in absolute paths, no home directory is needed: # dpkg -L zabbix-agent | grep /etc/zabbix/ /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.d /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf Let's not depend on the home directory at all, and add two more files /etc/zabbix/userparameter.my.cnf /etc/zabbix/userparameter.pgpass to the package, with contents: # ls -l /etc/zabbix/userparameter.pgpass -r-------- 1 zabbix zabbix 41 Oct 7 13:37 /etc/zabbix/userparameter.pgpass # cat /etc/zabbix/userparameter.pgpass hostname:port:database:username:password ~# ls -l /etc/zabbix/userparameter.my.cnf -r-------- 1 zabbix zabbix 47 Oct 7 13:41 /etc/zabbix/userparameter.my.cnf # cat /etc/zabbix/userparameter.my.cnf [client] user=mysqluser password=mysqlpassword and after installation user will just edit those files. Keep in mind that it would be best (security wise) if Zabbix agent process would start with no environment variables at all. | |||||||||
| Comment by dimir [ 2019 Oct 18 ] | |||||||||
|
kodai suggests that it may be that HOME is not set on Debian/Ubuntu because we use Type=forking Listing available Type values: simple - A long-running process that does not background its self and stays attached to the shell. forking - A typical daemon that forks itself detaching it from the process that ran it, effectively backgrounding itself. oneshot - A short-lived process that is expected to exit. dbus - Like simple, but notification of processes startup finishing is sent over dbus. notify - Like simple, but notification of processes startup finishing is sent over inotify. idle - Like simple, but the binary is started after the job has been dispatched. Continue to quoting kodai:
Perhaps switching to simple would solve that issue? | |||||||||
| Comment by Jurijs Klopovskis [ 2019 Oct 18 ] | |||||||||
|
I've tried it. Seems to make no difference. Setting User=zabbix in the service file fixes the issue regardless of Type being Simple or Forking. | |||||||||
| Comment by dimir [ 2019 Oct 18 ] | |||||||||
|
Ah, right, because for Type=simple to work we have to set the User= anyway. | |||||||||
| Comment by Maxim Chudinov (Inactive) [ 2019 Oct 18 ] | |||||||||
|
HOME is not setting because we use forking into the agent code. Not only on Debian/Ubuntu. Probably on all OS. | |||||||||
| Comment by Jurijs Klopovskis [ 2019 Nov 05 ] | |||||||||
|
Changes are in https://git.zabbix.com/projects/ZBX/repos/zabbix/pull-requests/652/diff <dimir> No go from my side. Zabbix agent itself does not need this environment variables, so no sense in setting those. If anything around agent needs those, that thing should set it around for itself. | |||||||||
| Comment by Glebs Ivanovskis [ 2019 Nov 08 ] | |||||||||
Makes total sense! Here are a couple of quotes from Debian Wiki on Environment Variables and RedHat 7 System Administrator's Guide, respectively:
| |||||||||
| Comment by Jurijs Klopovskis [ 2019 Nov 08 ] | |||||||||
|
Please note, that the proposed solution only affects the situation when the User setting in zabbix_agentd.conf file is used to change the user. An alternative solution is to set User and Group in the systemd service file for the user, as was proposed before. This is known to fix the issue with HOME variable as well as completely bypasses the custom logic of changing users implemented by zabbix. This is the case with the new agent, since it lacks the aforementioned logic for switching users to begin with. This has to be decided upon. | |||||||||
| Comment by dimir [ 2019 Nov 08 ] | |||||||||
|
Thanks, cyclone. The case with Debian is clear. There's systemd and it should be used. So no need to change agent code. The issue is with *NIX systems that don't have or have poor init mechanism. It is still bad to run user as root, so what could we do?
To me, #3 is the best option. | |||||||||
| Comment by Glebs Ivanovskis [ 2019 Nov 24 ] | |||||||||
|
5. Pass --login-path option to MySQL client explicitly in UserParameters or ask users to set MYSQL_TEST_LOGIN_FILE environment variable? I think templates are not well thought through if they require changes in Zabbix agent code. | |||||||||
| Comment by Robin Roevens [ 2020 Jan 15 ] | |||||||||
|
I see the same problem in CentOS 7 with zabbix-agent 4.2.8. Also, on CentOS/RedHat SELinux by default prohibits Zabbix Agent from reading in /var/lib en would require an extra rule: The version of MariaDB I currently have (5.5.60) however does not seem to support the --login-path option. but with --defaults-extra-file I can point mysql to the correct .cnf file containing username and password which then can be placed in /etc/zabbix, circumventing SELinux problems on reading that file. |