This is a translation of the original English documentation page. Help us make it better.

2 HashiCorpの設定

概要

このセクションでは、HashiCorp Vault KV Secrets Engine バージョン 2 からシークレットを取得するための Zabbix の設定方法について説明します。

Vault は、HashiCorp 公式ドキュメント の説明に従ってデプロイおよび設定する必要があります。

Zabbix での TLS 設定については、シークレットの保存 を参照してください。

Database credentials

Access to a secret with database credentials is configured for each Zabbix component separately.

Server and proxies

To obtain database credentials for Zabbix server or proxy from the vault, specify the following configuration parameters in the configuration file:

  • Vault - specifies which vault provider should be used.
  • VaultToken - vault authentication token (see Zabbix server/proxy configuration file for details).
  • VaultURL - vault server HTTP[S] URL.
  • VaultDBPath - path to the vault secret containing database credentials. Zabbix server or proxy will retrieve the credentials by keys 'password' and 'username'.

Zabbix server also uses these configuration parameters (except VaultDBPath) for vault authentication when processing vault secret macros.

Zabbix server and Zabbix proxy read the vault-related configuration parameters from zabbix_server.conf and zabbix_proxy.conf upon startup.

Zabbix server and Zabbix proxy will additionally read "VAULT_TOKEN" environment variable once during startup and unset it so that it would not be available through forked scripts; it is an error if both VaultToken and VAULT_TOKEN contain value.

Example

In zabbix_server.conf, specify:

Vault=HashiCorp
       VaultToken=hvs.CAESIIG_PILmULFYOsEyWHxkZ2mF2a8VPKNLE8eHqd4autYGGh4KHGh2cy5aeTY0NFNSaUp3ZnpWbDF1RUNjUkNTZEg
       VaultURL=https://127.0.0.1:8200
       VaultDBPath=secret/zabbix/database

Run the following CLI commands to create required secret in the vault:

# Enable "secret/" mount point if not already enabled, note that "kv-v2" must be used
       $ vault secrets enable -path=secret/ kv-v2
       
       # Put new secrets with keys username and password under mount point "secret/" and path "secret/zabbix/database"
       $ vault kv put secret/zabbix/database username=zabbix password=<password>
       
       # Test that secret is successfully added
       $ vault kv get secret/zabbix/database
       
       # Finally test with Curl, note that "data" need to be manually added after mount point and "/v1" before the mount point, also see --capath parameter
       $ curl --header "X-Vault-Token: <VaultToken>" https://127.0.0.1:8200/v1/secret/data/zabbix/database

As a result of this configuration, Zabbix server will retrieve the following credentials for database authentication:

  • Username: zabbix
  • Password: <password>

Frontend

To obtain database credentials for Zabbix frontend from the vault, specify required settings during frontend installation.

At the Configure DB Connection step, set Store credentials in parameter to HashiCorp Vault.

Then, fill in additional parameters:

Parameter Mandatory Default value Description
Vault API endpoint yes https://localhost:8200 Specify the URL for connecting to the vault in the format scheme://host:port
Vault secret path no A path to the secret from where credentials for the database shall be retrieved by the keys 'password' and 'username'
Example: secret/zabbix/database_frontend
Vault authentication token no Provide an authentication token for read-only access to the secret path.

See HashiCorp documentation for information about creating tokens and vault policies.

User macro values

To use HashiCorp Vault for storing Vault secret user macro values, make sure that:

  • The Vault provider parameter in the Administration -> General -> Other web interface section is set to HashiCorp Vault (default).

  • Zabbix server is configured to work with HashiCorp Vault.

The macro value should contain a reference path (as path:key, for example, secret/zabbix:password). The authentication token specified during Zabbix server configuration (by 'VaultToken' parameter) must provide read-only access to this path.

See Vault secret macros for detailed information about macro value processing by Zabbix.

パス構文

スラッシュ ("/") とコロン (":") は予約語です。

スラッシュは、マウントポイントとパスを区切る場合にのみ使用できます (例: secret/zabbix の場合、マウントポイントは"secret"、パスは"zabbix"です)。Vault マクロの場合、コロンはパス/クエリとキーを区切る場合にのみ使用できます。

マウントポイント名をスラッシュで区切って作成する必要がある場合 (例: foo/bar/zabbix の場合、マウントポイントは"foo/bar"、パスは"zabbix"です)、およびマウントポイント名またはパスにコロンを含める必要がある場合は、スラッシュとコロンを URL エンコードできます。

  1. Zabbix で、タイプが"Vault secret"で値が macros:password であるユーザーマクロ {$PASSWORD} を追加します。

  1. 以下の CLI コマンドを実行して、Vault に必要なシークレットを作成します。
# マウントポイント"secret/"がまだ有効になっていない場合は有効にします。"kv-v2"を使用する必要があります。
       vault secrets enable -path=secret/ kv-v2
       
       # キー"password"の新しい秘密文を、マウントポイント"secret/"、パス"zabbix/macros"に配置します。
       vault kv put -mount=secret zabbix/macros password=<password>
       
       # 秘密文が正常に追加されたことをテストします。
       vault kv get secret/zabbix/macros
       
       # 最後に Curl でテストします。マウントポイントの後に"data"を手動で追加し、マウントポイントの前に"/v1"を追加する必要があることに注意してください。--capath パラメータも参照してください。
       curl --header "X-Vault-Token: <VaultToken>" https://127.0.0.1:8200/v1/secret/data/zabbix/macros
  1. 結果として、Zabbix はマクロ {$PASSWORD} を <password> という値に解決します。

Update existing configuration

To update an existing configuration for retrieving secrets from a HashiCorp Vault:

  1. Update the Zabbix server or proxy configuration file parameters as described in the Database credentials section.

  2. Update the DB connection settings by reconfiguring Zabbix frontend and specifying the required parameters as described in the Frontend section. To reconfigure Zabbix frontend, open the frontend setup URL in the browser:

  • for Apache: http://<server_ip_or_name>/zabbix/setup.php
  • for Nginx: http://<server_ip_or_name>/setup.php

Alternatively, these parameters can be set in the frontend configuration file (zabbix.conf.php):

$DB['VAULT']                    = 'HashiCorp';
       $DB['VAULT_URL']                = 'https://localhost:8200';
       $DB['VAULT_DB_PATH']            = 'secret/zabbix/database';
       $DB['VAULT_TOKEN']              = '<mytoken>';
       $DB['VAULT_CERT_FILE']          = '';
       $DB['VAULT_KEY_FILE']           = '';
  1. Configure user macros as described in the User macro values section, if necessary.

To update an existing configuration for retrieving secrets from a CyberArk Vault, see CyberArk configuration.