java.lang.Object
de.stklcode.jvault.connector.HTTPVaultConnector
- All Implemented Interfaces:
VaultConnector
,Serializable
,AutoCloseable
Vault Connector implementation using Vault's HTTP API.
- Since:
- 0.1
- Author:
- Stefan Kalscheuer
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionfinal AuthResponse
authAppRole
(String roleID, String secretID) Authorize to Vault using AppRole method.final TokenResponse
Authorize to Vault using token.final AuthResponse
authUserPass
(String username, String password) Authorize to Vault using username and password.static HTTPVaultConnectorBuilder
builder()
Get a new builder for a connector.static HTTPVaultConnectorBuilder
Get a new builder for a connector.static HTTPVaultConnectorBuilder
Get a new builder for a connector.final void
close()
final boolean
createAppRole
(AppRole role) Register a new AppRole role from given metamodel.final AppRoleSecretResponse
createAppRoleSecret
(String roleName, AppRoleSecret secret) Register new AppRole secret with custom ID.boolean
createOrUpdateTokenRole
(String name, TokenRole role) Create a new or update an existing token role.final AuthResponse
createToken
(Token token) Create a new token.final AuthResponse
createToken
(Token token, boolean orphan) Create a new token.final AuthResponse
createToken
(Token token, String role) Create a new token for specific role.final void
Delete key from Vault.final void
deleteAllSecretVersions
(String mount, String key) Delete latest version of a secret from Vault.final boolean
deleteAppRole
(String roleName) Delete AppRole role from Vault.final void
deleteLatestSecretVersion
(String mount, String key) Delete latest version of a secret from Vault.final void
deleteSecretVersions
(String mount, String key, int... versions) Delete secret versions from Vault.boolean
deleteTokenRole
(String name) Delete a token role.final boolean
destroyAppRoleSecret
(String roleName, String secretID) Destroy an AppRole secret.final void
destroySecretVersions
(String mount, String key, int... versions) Destroy secret versions from Vault.final String
getAppRoleID
(String roleName) Retrieve ID for an AppRole role.final List
<AuthBackend> Get all available authentication backends.Query server health information.final boolean
Get authorization status.List available nodes from Vault.List existing (accessible) AppRole roles.listAppRoleSecrets
(String roleName) List existing (accessible) secret IDs for AppRole role.List available token roles from Vault.final AppRoleResponse
lookupAppRole
(String roleName) Lookup an AppRole role.final AppRoleSecretResponse
lookupAppRoleSecret
(String roleName, String secretID) Lookup an AppRole secret.final TokenResponse
lookupToken
(String token) Lookup token information.final SecretResponse
Retrieve any nodes content from Vault.final MetadataResponse
readSecretMetadata
(String mount, String key) Retrieve secret metadata from Vault.final SecretResponse
readSecretVersion
(String mount, String key, Integer version) Retrieve secret data from Vault.readTokenRole
(String name) Lookup token information.final SecretResponse
Renew lease with given ID.final void
Reset authorization information.final void
Revoke given lease immediately.final void
seal()
Seal vault.final SealResponse
Retrieve status of vault seal.final boolean
setAppRoleID
(String roleName, String roleID) Set custom ID for an AppRole role.final void
undeleteSecretVersions
(String mount, String key, int... versions) Undelete (restore) secret versions from Vault.final SealResponse
Unseal vault.void
updateSecretMetadata
(String mount, String key, Integer maxVersions, boolean casRequired) Update secret metadata.final void
Write value to Vault.final SecretVersionResponse
Write secret to Vault.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface de.stklcode.jvault.connector.VaultConnector
authAppRole, createAppRole, createAppRole, createAppRole, createAppRole, createAppRoleSecret, createAppRoleSecret, createOrUpdateTokenRole, readDbCredentials, readMongoDbCredentials, readMsSqlCredentials, readMySqlCredentials, readPostgreSqlCredentials, readSecretData, renew, unseal, write, write, writeSecretData
-
Method Details
-
builder
Get a new builder for a connector.- Returns:
- Builder instance.
- Since:
- 0.9.5
-
builder
Get a new builder for a connector.- Parameters:
baseURL
- Base URL.- Returns:
- Builder instance.
- Throws:
URISyntaxException
- Invalid URI syntax.- Since:
- 1.0
-
builder
Get a new builder for a connector.- Parameters:
baseURL
- Base URL.- Returns:
- Builder instance.
- Since:
- 1.0
-
resetAuth
public final void resetAuth()Description copied from interface:VaultConnector
Reset authorization information.- Specified by:
resetAuth
in interfaceVaultConnector
-
sealStatus
Description copied from interface:VaultConnector
Retrieve status of vault seal.- Specified by:
sealStatus
in interfaceVaultConnector
- Returns:
- Seal status
- Throws:
VaultConnectorException
- on error
-
seal
Description copied from interface:VaultConnector
Seal vault.- Specified by:
seal
in interfaceVaultConnector
- Throws:
VaultConnectorException
- on error
-
unseal
Description copied from interface:VaultConnector
Unseal vault.- Specified by:
unseal
in interfaceVaultConnector
- Parameters:
key
- A single master share keyreset
- Discard previously provided keys (optional)- Returns:
- Response with seal status
- Throws:
VaultConnectorException
- on error
-
getHealth
Description copied from interface:VaultConnector
Query server health information.- Specified by:
getHealth
in interfaceVaultConnector
- Returns:
- Health information.
- Throws:
VaultConnectorException
- on error
-
isAuthorized
public final boolean isAuthorized()Description copied from interface:VaultConnector
Get authorization status.- Specified by:
isAuthorized
in interfaceVaultConnector
- Returns:
- TRUE, if successfully authorized
-
getAuthBackends
Description copied from interface:VaultConnector
Get all available authentication backends.- Specified by:
getAuthBackends
in interfaceVaultConnector
- Returns:
- List of backends
- Throws:
VaultConnectorException
- on error
-
authToken
Description copied from interface:VaultConnector
Authorize to Vault using token.- Specified by:
authToken
in interfaceVaultConnector
- Parameters:
token
- The token- Returns:
- Token response
- Throws:
VaultConnectorException
- on error
-
authUserPass
public final AuthResponse authUserPass(String username, String password) throws VaultConnectorException Description copied from interface:VaultConnector
Authorize to Vault using username and password.- Specified by:
authUserPass
in interfaceVaultConnector
- Parameters:
username
- The usernamepassword
- The password- Returns:
- Authorization result
- Throws:
VaultConnectorException
- on error
-
authAppRole
public final AuthResponse authAppRole(String roleID, String secretID) throws VaultConnectorException Description copied from interface:VaultConnector
Authorize to Vault using AppRole method.- Specified by:
authAppRole
in interfaceVaultConnector
- Parameters:
roleID
- The role IDsecretID
- The secret ID- Returns:
- The
AuthResponse
- Throws:
VaultConnectorException
- on error
-
createAppRole
Description copied from interface:VaultConnector
Register a new AppRole role from given metamodel.- Specified by:
createAppRole
in interfaceVaultConnector
- Parameters:
role
- The role- Returns:
true
on success- Throws:
VaultConnectorException
- on error
-
lookupAppRole
Description copied from interface:VaultConnector
Lookup an AppRole role.- Specified by:
lookupAppRole
in interfaceVaultConnector
- Parameters:
roleName
- The role name- Returns:
- Result of the lookup
- Throws:
VaultConnectorException
- on error
-
deleteAppRole
Description copied from interface:VaultConnector
Delete AppRole role from Vault.- Specified by:
deleteAppRole
in interfaceVaultConnector
- Parameters:
roleName
- The role name- Returns:
true
on success- Throws:
VaultConnectorException
- on error
-
getAppRoleID
Description copied from interface:VaultConnector
Retrieve ID for an AppRole role.- Specified by:
getAppRoleID
in interfaceVaultConnector
- Parameters:
roleName
- The role name- Returns:
- The role ID
- Throws:
VaultConnectorException
- on error
-
setAppRoleID
Description copied from interface:VaultConnector
Set custom ID for an AppRole role.- Specified by:
setAppRoleID
in interfaceVaultConnector
- Parameters:
roleName
- The role nameroleID
- The role ID- Returns:
true
on success- Throws:
VaultConnectorException
- on error
-
createAppRoleSecret
public final AppRoleSecretResponse createAppRoleSecret(String roleName, AppRoleSecret secret) throws VaultConnectorException Description copied from interface:VaultConnector
Register new AppRole secret with custom ID.- Specified by:
createAppRoleSecret
in interfaceVaultConnector
- Parameters:
roleName
- The role namesecret
- The secret meta object- Returns:
- The secret ID
- Throws:
VaultConnectorException
- on error
-
lookupAppRoleSecret
public final AppRoleSecretResponse lookupAppRoleSecret(String roleName, String secretID) throws VaultConnectorException Description copied from interface:VaultConnector
Lookup an AppRole secret.- Specified by:
lookupAppRoleSecret
in interfaceVaultConnector
- Parameters:
roleName
- The role namesecretID
- The secret ID- Returns:
- Result of the lookup
- Throws:
VaultConnectorException
- on error
-
destroyAppRoleSecret
public final boolean destroyAppRoleSecret(String roleName, String secretID) throws VaultConnectorException Description copied from interface:VaultConnector
Destroy an AppRole secret.- Specified by:
destroyAppRoleSecret
in interfaceVaultConnector
- Parameters:
roleName
- The role namesecretID
- The secret meta object- Returns:
- The secret ID
- Throws:
VaultConnectorException
- on error
-
listAppRoles
Description copied from interface:VaultConnector
List existing (accessible) AppRole roles.- Specified by:
listAppRoles
in interfaceVaultConnector
- Returns:
- List of roles
- Throws:
VaultConnectorException
- on error
-
listAppRoleSecrets
Description copied from interface:VaultConnector
List existing (accessible) secret IDs for AppRole role.- Specified by:
listAppRoleSecrets
in interfaceVaultConnector
- Parameters:
roleName
- The role name- Returns:
- List of roles
- Throws:
VaultConnectorException
- on error
-
read
Description copied from interface:VaultConnector
Retrieve any nodes content from Vault.- Specified by:
read
in interfaceVaultConnector
- Parameters:
key
- Secret identifier- Returns:
- Secret response
- Throws:
VaultConnectorException
- on error
-
readSecretVersion
public final SecretResponse readSecretVersion(String mount, String key, Integer version) throws VaultConnectorException Description copied from interface:VaultConnector
Retrieve secret data from Vault.
Path<mount>/data/<key>
is read here. Only available for KV v2 secrets.- Specified by:
readSecretVersion
in interfaceVaultConnector
- Parameters:
mount
- Secret store mount point (without leading or trailing slash).key
- Secret identifierversion
- Version to read. Ifnull
or zero, the latest version will be returned.- Returns:
- Secret response.
- Throws:
VaultConnectorException
- on error
-
readSecretMetadata
public final MetadataResponse readSecretMetadata(String mount, String key) throws VaultConnectorException Description copied from interface:VaultConnector
Retrieve secret metadata from Vault.
Path<mount>/metadata/<key>
is read here. Only available for KV v2 secrets.- Specified by:
readSecretMetadata
in interfaceVaultConnector
- Parameters:
mount
- Secret store mount point (without leading or trailing slash).key
- Secret identifier- Returns:
- Metadata response
- Throws:
VaultConnectorException
- on error
-
updateSecretMetadata
public void updateSecretMetadata(String mount, String key, Integer maxVersions, boolean casRequired) throws VaultConnectorException Description copied from interface:VaultConnector
Update secret metadata.
Path<mount>/metadata/<key>
is written here. Only available for KV v2 secrets.- Specified by:
updateSecretMetadata
in interfaceVaultConnector
- Parameters:
mount
- Secret store mount point (without leading or trailing slash).key
- Secret identifiermaxVersions
- Maximum number of versions (fallback to backend default ifnull
)casRequired
- Specify if Check-And-Set is required for this secret.- Throws:
VaultConnectorException
- on error
-
writeSecretData
public final SecretVersionResponse writeSecretData(String mount, String key, Map<String, Object> data, Integer cas) throws VaultConnectorExceptionDescription copied from interface:VaultConnector
Write secret to Vault.
Path<mount>/data/<key>
is written here. Only available for KV v2 secrets.- Specified by:
writeSecretData
in interfaceVaultConnector
- Parameters:
mount
- Secret store mount point (without leading or trailing slash).key
- Secret identifierdata
- Secret content. Value must be be JSON serializable.cas
- Use Check-And-Set operation, i.e. only allow writing if current version matches this value.- Returns:
- Metadata for the created/updated secret.
- Throws:
VaultConnectorException
- on error
-
list
Description copied from interface:VaultConnector
List available nodes from Vault.- Specified by:
list
in interfaceVaultConnector
- Parameters:
path
- Root path to search- Returns:
- List of secret keys
- Throws:
VaultConnectorException
- on error
-
write
public final void write(String key, Map<String, Object> data, Map<String, throws VaultConnectorExceptionObject> options) Description copied from interface:VaultConnector
Write value to Vault.- Specified by:
write
in interfaceVaultConnector
- Parameters:
key
- Secret pathdata
- Secret content. Value must be be JSON serializable.options
- Secret options (optional).- Throws:
VaultConnectorException
- on error
-
delete
Description copied from interface:VaultConnector
Delete key from Vault.- Specified by:
delete
in interfaceVaultConnector
- Parameters:
key
- Secret path- Throws:
VaultConnectorException
- on error
-
deleteLatestSecretVersion
public final void deleteLatestSecretVersion(String mount, String key) throws VaultConnectorException Description copied from interface:VaultConnector
Delete latest version of a secret from Vault.
Only available for KV v2 stores.- Specified by:
deleteLatestSecretVersion
in interfaceVaultConnector
- Parameters:
mount
- Secret store mount point (without leading or trailing slash).key
- Secret path.- Throws:
VaultConnectorException
- on error
-
deleteAllSecretVersions
Description copied from interface:VaultConnector
Delete latest version of a secret from Vault.
Prefixsecret/
is automatically added to path. Only available for KV v2 stores.- Specified by:
deleteAllSecretVersions
in interfaceVaultConnector
- Parameters:
mount
- Secret store mount point (without leading or trailing slash).key
- Secret path.- Throws:
VaultConnectorException
- on error
-
deleteSecretVersions
public final void deleteSecretVersions(String mount, String key, int... versions) throws VaultConnectorException Description copied from interface:VaultConnector
Delete secret versions from Vault.
Only available for KV v2 stores.- Specified by:
deleteSecretVersions
in interfaceVaultConnector
- Parameters:
mount
- Secret store mount point (without leading or trailing slash).key
- Secret path.versions
- Versions of the secret to delete.- Throws:
VaultConnectorException
- on error
-
undeleteSecretVersions
public final void undeleteSecretVersions(String mount, String key, int... versions) throws VaultConnectorException Description copied from interface:VaultConnector
Undelete (restore) secret versions from Vault. Only available for KV v2 stores.- Specified by:
undeleteSecretVersions
in interfaceVaultConnector
- Parameters:
mount
- Secret store mount point (without leading or trailing slash).key
- Secret path.versions
- Versions of the secret to undelete.- Throws:
VaultConnectorException
- on error
-
destroySecretVersions
public final void destroySecretVersions(String mount, String key, int... versions) throws VaultConnectorException Description copied from interface:VaultConnector
Destroy secret versions from Vault. Only available for KV v2 stores.- Specified by:
destroySecretVersions
in interfaceVaultConnector
- Parameters:
mount
- Secret store mount point (without leading or trailing slash).key
- Secret path.versions
- Versions of the secret to destroy.- Throws:
VaultConnectorException
- on error
-
revoke
Description copied from interface:VaultConnector
Revoke given lease immediately.- Specified by:
revoke
in interfaceVaultConnector
- Parameters:
leaseID
- the lease ID- Throws:
VaultConnectorException
- on error
-
renew
Description copied from interface:VaultConnector
Renew lease with given ID.- Specified by:
renew
in interfaceVaultConnector
- Parameters:
leaseID
- the lase IDincrement
- number of seconds to extend lease time- Returns:
- Renewed lease
- Throws:
VaultConnectorException
- on error
-
createToken
Description copied from interface:VaultConnector
Create a new token.- Specified by:
createToken
in interfaceVaultConnector
- Parameters:
token
- the token- Returns:
- the result response
- Throws:
VaultConnectorException
- on error
-
createToken
Description copied from interface:VaultConnector
Create a new token.- Specified by:
createToken
in interfaceVaultConnector
- Parameters:
token
- the tokenorphan
- create orphan token- Returns:
- the result response
- Throws:
VaultConnectorException
- on error
-
createToken
Description copied from interface:VaultConnector
Create a new token for specific role.- Specified by:
createToken
in interfaceVaultConnector
- Parameters:
token
- the tokenrole
- the role name- Returns:
- the result response
- Throws:
VaultConnectorException
- on error
-
close
public final void close()- Specified by:
close
in interfaceAutoCloseable
-
lookupToken
Description copied from interface:VaultConnector
Lookup token information.- Specified by:
lookupToken
in interfaceVaultConnector
- Parameters:
token
- the token- Returns:
- the result response
- Throws:
VaultConnectorException
- on error
-
createOrUpdateTokenRole
Description copied from interface:VaultConnector
Create a new or update an existing token role.- Specified by:
createOrUpdateTokenRole
in interfaceVaultConnector
- Parameters:
name
- the role name (overrides name possibly set in role entity)role
- the role entity- Returns:
true
on success- Throws:
VaultConnectorException
- on error
-
readTokenRole
Description copied from interface:VaultConnector
Lookup token information.- Specified by:
readTokenRole
in interfaceVaultConnector
- Parameters:
name
- the role name- Returns:
- the result response
- Throws:
VaultConnectorException
- on error
-
listTokenRoles
Description copied from interface:VaultConnector
List available token roles from Vault.- Specified by:
listTokenRoles
in interfaceVaultConnector
- Returns:
- List of token roles
- Throws:
VaultConnectorException
- on error
-
deleteTokenRole
Description copied from interface:VaultConnector
Delete a token role.- Specified by:
deleteTokenRole
in interfaceVaultConnector
- Parameters:
name
- the role name to delete- Returns:
true
on success- Throws:
VaultConnectorException
- on error
-