Search code examples
azurezabbixazure-keyvault

provide Azure Key Vault password to Zabbix login API


how to pass in password to Zabbix API json login script, as password is saved in Azure Key Vault as secret.

$json_login = '
            {
                "jsonrpc": "2.0",
                "method": "user.login",
                "params": {
                    "user": "ZabbixUser",
                    "password": "**Need to getfrom Azure Key Vault secret**"
                },
                "id": 1,
                "auth": null
                }'

$output = Invoke-RestMethod -ContentType application/json -Method Post -Uri $uri -Body $json_login
Write-Output $output

Using below is not secure, as provides as a plain text:

$Password = (Get-AzKeyVaultSecret -VaultName "MyVault" -Name "MySecretName").SecretValueText

Calling login to Zabbix from powershell.

Thank you!


Solution

  • You could modify the format of your request body $json_login like below, after running $Password = (Get-AzKeyVaultSecret -VaultName "MyVault" -Name "MySecretName").SecretValueText, pass the $Password directly to the body, then there will not be a plain text, it is secure, because only people with secret get permission in the access policy of your keyvault can get it from Get-AzKeyVaultSecret.

    $json_login = @{
                    jsonrpc = "2.0"
                    method = "user.login"
                    params = @{
                        user = "ZabbixUser"
                        password= $Password
                    }
                    id = "1"
                    auth= "null"
                    }
    

    For more details about the usage, see Example 2 in this link.