We have an approle with a policy called dev-healthcheck that looks like this:
path "dev-healthcheck/*" {
capabilities = ["list"]
}
path "envdev/*" {
capabilities = ["list"]
}
path "envqa/*" {
capabilities = ["list"]
}
path "envqa2/*" {
capabilities = ["list"]
}
path "envstage/*" {
capabilities = ["list"]
}
We are going to need to list the secrets in each of those KV engines listed above.
Now, I’m trying to login using this app-role’s role-id and secret-id and then listing the secrets by using this Powershell code but I’m getting a permission denied.
($secret , $api are passed via cmd line)
# role-id and secret-id have been used to login
# and the vault_url, vault_token and vault_namespace have been set in
# the environment variables
$uri = "$($env:VAULT_ADDR)" +"/v1/$($secret)/data/$($api)?LIST=true"
$header = @{
"X-Vault-Token" = "$($env:VAULT_TOKEN)"
"X-Vault-Namespace" = "$($env:VAULT_NAMESPACE)"
}
#***************************************************************
# Run the command to list the secrets
#***************************************************************
try
{
$response = Invoke-RestMethod -Headers $header -ContentType 'application/json' -Method GET -Uri $uri
}
catch
{
#***************************************************************
# There was an error so show error message
#***************************************************************
$msg = $_.Exception.Message
$status = $_.Exception.Status
$hr = "{0:x8}" -f ($_.Exception.HResult)
$innerException = $_.Exception.InnerException
#Just issue a warning about being unable to send the notification...
Write-Warning("`n`t[$status] `n`t[0x$hr] `n`t[$msg] `n`t[$innerException]")
}
#***************************************************************
# Display the secrets list
#***************************************************************
$response.data.data
I can list them using the vault API like this:
vault kv list envqa
So, what am I doing wrong in the Powershell code?