You are browsing documentation for an outdated version. See the latest documentation here.
kong.vault
This module can be used to resolve, parse, and verify vault references.
kong.vault.is_reference(reference)
Checks if the passed in reference looks like a reference. Valid references start with {vault:// and end with }.
If you need more thorough validation, use kong.vault.parse_reference.
Parameters
- reference (
string): reference to check
Returns
boolean:trueis the passed in reference looks like a reference, otherwisefalse
Usage
kong.vault.is_reference("{vault://env/key}") -- truekong.vault.is_reference("not a reference") -- false
kong.vault.parse_reference(reference)
Parses and decodes the passed in reference and returns a table containing its components.
Given a following resource:
"{vault://env/cert/key?prefix=SSL_#1}"
This function will return following table:
{name = "env", -- name of the Vault entity or Vault strategyresource = "cert", -- resource where secret is storedkey = "key", -- key to lookup if the resource is secret objectconfig = { -- if there are any config options specifiedprefix = "SSL_"},version = 1 -- if the version is specified}
Parameters
- reference (
string): reference to parse
Returns
table|nil: a table containing each component of the reference, ornilon errorstring|nil: error message on failure, otherwisenil
Usage
local ref, err = kong.vault.parse_reference("{vault://env/cert/key?prefix=SSL_#1}") -- table
kong.vault.get(reference)
Resolves the passed in reference and returns the value of it.
Parameters
- reference (
string): reference to resolve
Returns
string|nil: resolved value of the referencestring|nil: error message on failure, otherwisenil
Usage
local value, err = kong.vault.get("{vault://env/cert/key}")
kong.vault.try(callback, options)
Helper function for automatic secret rotation. Currently experimental.
Parameters
- callback (
function): callback function - options (
table): options containing credentials and references
Returns
string|nil: return value of the callback functionstring|nil: error message on failure, otherwisenil
Usage
local function connect(options)return database_connect(options)endlocal connection, err = kong.vault.try(connect, {username = "john",password = "doe",["$refs"] = {username = "{vault://aws/database-username}",password = "{vault://aws/database-password}",}})