This section contains best practices for setting up a PostgreSQL database in a secure way.
For an easy setup, it is recommended to follow the default PostgreSQL database creation instructions, which include creating the 'zabbix' user with full privileges on the Zabbix database. This user is the database owner that also has the necessary privileges for modifying the database structure when upgrading Zabbix.
To improve security, configuring a secure schema usage pattern, as well as creating additional database roles and users with minimal privileges is recommended. These roles and users should be configured based on the principle of least privilege, that is, they should only have privileges that are essential for performing the intended functions.
Create the user that will be the database owner, and create the Zabbix database; the database owner is the user that is specified on database creation:
createuser -U postgres -h localhost --pwprompt usr_owner
createdb -U postgres -h localhost -O usr_owner -E Unicode -T template0 zabbix
The following commands on this page must be executed while the connection to PostgreSQL is made specifically to the zabbix
database.
Create the zabbix
schema and set the database owner (usr_owner
) to be the owner of this schema:
The right to drop a database object or alter its definition is a privilege that is inherent to the database owner and that cannot be granted or revoked. Therefore, a clean install or upgrade has to be performed by the database owner.
Configure a secure schema usage pattern:
revoke create on schema public from public;
revoke all on database zabbix from public;
-- Note: search_path should point to the "zabbix" schema:
alter role all in database zabbix set search_path = "zabbix";
After setting up the database, proceed to creating user roles.
Create the following roles with the corresponding privileges:
create role zbx_srv;
grant connect on database zabbix to zbx_srv;
grant usage on schema zabbix to zbx_srv;
alter default privileges for role usr_owner in schema zabbix grant delete, insert, select, update on tables to zbx_srv;
alter default privileges for role usr_owner in schema zabbix grant select, update, usage on sequences to zbx_srv;
create role zbx_web;
grant connect on database zabbix to zbx_web;
grant usage on schema zabbix to zbx_web;
alter default privileges for role usr_owner in schema zabbix grant delete, insert, select, update on tables to zbx_web;
alter default privileges for role usr_owner in schema zabbix grant select, update, usage on sequences to zbx_web;
create role zbx_bckp;
grant connect on database zabbix to zbx_bckp;
grant usage on schema zabbix to zbx_bckp;
alter default privileges for role usr_owner in schema zabbix grant select on tables to zbx_bckp;
alter default privileges for role usr_owner in schema zabbix grant select, update, usage on sequences to zbx_bckp;
Table restoration is possible only by the database owner.
After creating roles, they can be assigned to users.
To assign the created user roles, create users and assign the relevant roles to them. Replace <user>
, <role>
, and <password>
as necessary.
For example, to create and assign the role for running Zabbix server and proxy:
Database partitioning is facilitated by TimescaleDB. To utilize TimescaleDB, Zabbix server requires database owner privileges.
If the PostgreSQL zabbix
schema has already been created in the zabbix
database, you can enable TimescaleDB with the following command: