hvac.api.secrets_engines

Vault secrets engines endpoints

class hvac.api.secrets_engines.Azure(adapter)[source]

Bases: hvac.api.vault_api_base.VaultApiBase

Azure Secrets Engine (API).

Reference: https://www.vaultproject.io/api/secret/azure/index.html

configure(subscription_id, tenant_id, client_id='', client_secret='', environment='AzurePublicCloud', mount_point='azure')[source]

Configure the credentials required for the plugin to perform API calls to Azure.

These credentials will be used to query roles and create/delete service principals. Environment variables will override any parameters set in the config.

Supported methods:
POST: /{mount_point}/config. Produces: 204 (empty body)
Parameters:
  • subscription_id (str | unicode) – The subscription id for the Azure Active Directory
  • tenant_id (str | unicode) – The tenant id for the Azure Active Directory.
  • client_id (str | unicode) – The OAuth2 client id to connect to Azure.
  • client_secret (str | unicode) – The OAuth2 client secret to connect to Azure.
  • environment (str | unicode) – The Azure environment. If not specified, Vault will use Azure Public Cloud.
  • mount_point (str | unicode) – The OAuth2 client secret to connect to Azure.
Returns:

The response of the request.

Return type:

requests.Response

create_or_update_role(name, azure_roles, ttl='', max_ttl='', mount_point='azure')[source]

Create or update a Vault role.

The provided Azure roles must exist for this call to succeed. See the Azure secrets roles docs for more information about roles.

Supported methods:
POST: /{mount_point}/roles/{name}. Produces: 204 (empty body)
Parameters:
  • name (str | unicode) – Name of the role.
  • azure_roles (list(dict)) – List of Azure roles to be assigned to the generated service principal.
  • ttl (str | unicode) – Specifies the default TTL for service principals generated using this role. Accepts time suffixed strings (“1h”) or an integer number of seconds. Defaults to the system/engine default TTL time.
  • max_ttl (str | unicode) – Specifies the maximum TTL for service principals generated using this role. Accepts time suffixed strings (“1h”) or an integer number of seconds. Defaults to the system/engine max TTL time.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

delete_config(mount_point='azure')[source]

Delete the stored Azure configuration and credentials.

Supported methods:
DELETE: /auth/{mount_point}/config. Produces: 204 (empty body)
Parameters:mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:The response of the request.
Return type:requests.Response
generate_credentials(name, mount_point='azure')[source]

Generate a new service principal based on the named role.

Supported methods:
GET: /{mount_point}/creds/{name}. Produces: 200 application/json
Parameters:
  • name (str | unicode) – Specifies the name of the role to create credentials against.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The data key from the JSON response of the request.

Return type:

dict

list_roles(mount_point='azure')[source]

List all of the roles that are registered with the plugin.

Supported methods:
LIST: /{mount_point}/roles. Produces: 200 application/json
Parameters:mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:The data key from the JSON response of the request.
Return type:dict
read_config(mount_point='azure')[source]

Read the stored configuration, omitting client_secret.

Supported methods:
GET: /{mount_point}/config. Produces: 200 application/json
Parameters:mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:The data key from the JSON response of the request.
Return type:dict
class hvac.api.secrets_engines.Identity(adapter)[source]

Bases: hvac.api.vault_api_base.VaultApiBase

Identity Secrets Engine (API).

Reference: https://www.vaultproject.io/api/secret/identity/entity.html

create_or_update_entity(name, entity_id=None, metadata=None, policies=None, disabled=False, mount_point='identity')[source]

Create or update an Entity.

Supported methods:
POST: /{mount_point}/entity. Produces: 200 application/json
Parameters:
  • entity_id (str | unicode) – ID of the entity. If set, updates the corresponding existing entity.
  • name (str | unicode) – Name of the entity.
  • metadata (dict) – Metadata to be associated with the entity.
  • policies (str | unicode) – Policies to be tied to the entity.
  • disabled (bool) – Whether the entity is disabled. Disabled entities’ associated tokens cannot be used, but are not revoked.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response for creates, the generic response object for updates, of the request.

Return type:

dict | requests.Response

create_or_update_entity_alias(name, canonical_id, mount_accessor, alias_id=None, mount_point='identity')[source]

Create a new alias for an entity.

Supported methods:
POST: /{mount_point}/entity-alias. Produces: 200 application/json
Parameters:
  • name (str | unicode) – Name of the alias. Name should be the identifier of the client in the authentication source. For example, if the alias belongs to userpass backend, the name should be a valid username within userpass backend. If alias belongs to GitHub, it should be the GitHub username.
  • alias_id (str | unicode) – ID of the entity alias. If set, updates the corresponding entity alias.
  • canonical_id (str | unicode) – Entity ID to which this alias belongs to.
  • mount_accessor (str | unicode) – Accessor of the mount to which the alias should belong to.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

requests.Response

create_or_update_entity_by_name(name, metadata=None, policies=None, disabled=False, mount_point='identity')[source]

Create or update an entity by a given name.

Supported methods:
POST: /{mount_point}/entity/name/{name}. Produces: 200 application/json
Parameters:
  • name (str | unicode) – Name of the entity.
  • metadata (dict) – Metadata to be associated with the entity.
  • policies (str | unicode) – Policies to be tied to the entity.
  • disabled (bool) – Whether the entity is disabled. Disabled entities’ associated tokens cannot be used, but are not revoked.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response for creates, the generic response of the request for updates.

Return type:

requests.Response | dict

create_or_update_group(name, group_id=None, group_type='internal', metadata=None, policies=None, member_group_ids=None, member_entity_ids=None, mount_point='identity')[source]

Create or update a Group.

Supported methods:
POST: /{mount_point}/group. Produces: 200 application/json
Parameters:
  • group_id (str | unicode) – ID of the group. If set, updates the corresponding existing group.
  • name (str | unicode) – Name of the group.
  • group_type (str | unicode) – Type of the group, internal or external. Defaults to internal.
  • metadata (dict) – Metadata to be associated with the group.
  • policies (str | unicode) – Policies to be tied to the group.
  • member_group_ids (str | unicode) – Group IDs to be assigned as group members.
  • member_entity_ids (str | unicode) – Entity IDs to be assigned as group members.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response where available, otherwise the generic response object, of the request.

Return type:

dict | requests.Response

create_or_update_group_alias(name, alias_id=None, mount_accessor=None, canonical_id=None, mount_point='identity')[source]

Creates or update a group alias.

Supported methods:
POST: /{mount_point}/group-alias. Produces: 200 application/json
Parameters:
  • alias_id (str | unicode) – ID of the group alias. If set, updates the corresponding existing group alias.
  • name (str | unicode) – Name of the group alias.
  • mount_accessor (str | unicode) – Mount accessor to which this alias belongs to
  • canonical_id (str | unicode) – ID of the group to which this is an alias.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

requests.Response

create_or_update_group_by_name(name, group_type='internal', metadata=None, policies=None, member_group_ids=None, member_entity_ids=None, mount_point='identity')[source]

Create or update a group by its name.

Supported methods:
POST: /{mount_point}/group/name/{name}. Produces: 200 application/json
Parameters:
  • name (str | unicode) – Name of the group.
  • group_type (str | unicode) – Type of the group, internal or external. Defaults to internal.
  • metadata (dict) – Metadata to be associated with the group.
  • policies (str | unicode) – Policies to be tied to the group.
  • member_group_ids (str | unicode) – Group IDs to be assigned as group members.
  • member_entity_ids (str | unicode) – Entity IDs to be assigned as group members.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

delete_entity(entity_id, mount_point='identity')[source]

Delete an entity and all its associated aliases.

Supported methods:
DELETE: /{mount_point}/entity/id/:id. Produces: 204 (empty body)
Parameters:
  • entity_id (str) – Identifier of the entity.
  • mount_point (str | unicode) – The “path” the secret engine was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

delete_entity_alias(alias_id, mount_point='identity')[source]

Delete a entity alias.

Supported methods:
DELETE: /{mount_point}/entity-alias/id/{alias_id}. Produces: 204 (empty body)
Parameters:
  • alias_id (str | unicode) – Identifier of the entity.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

delete_entity_by_name(name, mount_point='identity')[source]

Delete an entity and all its associated aliases, given the entity name.

Supported methods:
DELETE: /{mount_point}/entity/name/{name}. Produces: 204 (empty body)
Parameters:
  • name (str | unicode) – Name of the entity.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

delete_group(group_id, mount_point='identity')[source]

Delete a group.

Supported methods:
DELETE: /{mount_point}/group/id/{id}. Produces: 204 (empty body)
Parameters:
  • group_id (str | unicode) – Identifier of the entity.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

delete_group_alias(entity_id, mount_point='identity')[source]

Delete a group alias.

Supported methods:
DELETE: /{mount_point}/group-alias/id/{id}. Produces: 204 (empty body)
Parameters:
  • entity_id (str | unicode) – ID of the group alias.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

delete_group_by_name(name, mount_point='identity')[source]

Delete a group, given its name.

Supported methods:
DELETE: /{mount_point}/group/name/{name}. Produces: 204 (empty body)
Parameters:
  • name (str | unicode) – Name of the group.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

list_entities(method='LIST', mount_point='identity')[source]

List available entities entities by their identifiers.

Parameters:
  • method (str | unicode) – Supported methods: LIST: /{mount_point}/entity/id. Produces: 200 application/json GET: /{mount_point}/entity/id?list=true. Produces: 200 application/json
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

dict

list_entities_by_name(method='LIST', mount_point='identity')[source]

List available entities by their names.

Parameters:
  • method (str | unicode) – Supported methods: LIST: /{mount_point}/entity/name. Produces: 200 application/json GET: /{mount_point}/entity/name?list=true. Produces: 200 application/json
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

dict

list_entity_aliases(method='LIST', mount_point='identity')[source]

List available entity aliases by their identifiers.

Parameters:
  • method (str | unicode) – Supported methods: LIST: /{mount_point}/entity-alias/id. Produces: 200 application/json GET: /{mount_point}/entity-alias/id?list=true. Produces: 200 application/json
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The the JSON response of the request.

Return type:

dict

list_group_aliases(method='LIST', mount_point='identity')[source]

List available group aliases by their identifiers.

Parameters:
  • method (str | unicode) – Supported methods: LIST: /{mount_point}/group-alias/id. Produces: 200 application/json GET: /{mount_point}/group-alias/id?list=true. Produces: 200 application/json
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The “data” key from the JSON response of the request.

Return type:

dict

list_groups(method='LIST', mount_point='identity')[source]

List available groups by their identifiers.

Parameters:
  • method (str | unicode) – Supported methods: LIST: /{mount_point}/group/id. Produces: 200 application/json GET: /{mount_point}/group/id?list=true. Produces: 200 application/json
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

dict

list_groups_by_name(method='LIST', mount_point='identity')[source]

List available groups by their names.

Parameters:
  • method (str | unicode) – Supported methods: LIST: /{mount_point}/group/name. Produces: 200 application/json GET: /{mount_point}/group/name?list=true. Produces: 200 application/json
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

dict

lookup_entity(name=None, entity_id=None, alias_id=None, alias_name=None, alias_mount_accessor=None, mount_point='identity')[source]

Query an entity based on the given criteria.

The criteria can be name, id, alias_id, or a combination of alias_name and alias_mount_accessor.

Supported methods:
POST: /{mount_point}/lookup/entity. Produces: 200 application/json
Parameters:
  • name (str | unicode) – Name of the entity.
  • entity_id (str | unicode) – ID of the entity.
  • alias_id (str | unicode) – ID of the alias.
  • alias_name (str | unicode) – Name of the alias. This should be supplied in conjunction with alias_mount_accessor.
  • alias_mount_accessor (str | unicode) – Accessor of the mount to which the alias belongs to. This should be supplied in conjunction with alias_name.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request if a entity / entity alias is found in the lookup, None otherwise.

Return type:

dict | None

lookup_group(name=None, group_id=None, alias_id=None, alias_name=None, alias_mount_accessor=None, mount_point='identity')[source]

Query a group based on the given criteria.

The criteria can be name, id, alias_id, or a combination of alias_name and alias_mount_accessor.

Supported methods:
POST: /{mount_point}/lookup/group. Produces: 200 application/json
Parameters:
  • name (str | unicode) – Name of the group.
  • group_id (str | unicode) – ID of the group.
  • alias_id (str | unicode) – ID of the alias.
  • alias_name (str | unicode) – Name of the alias. This should be supplied in conjunction with alias_mount_accessor.
  • alias_mount_accessor (str | unicode) – Accessor of the mount to which the alias belongs to. This should be supplied in conjunction with alias_name.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request if a group / group alias is found in the lookup, None otherwise.

Return type:

dict | None

merge_entities(from_entity_ids, to_entity_id, force=False, mount_point='identity')[source]

Merge many entities into one entity.

Supported methods:
POST: /{mount_point}/entity/merge. Produces: 204 (empty body)
Parameters:
  • from_entity_ids (array) – Entity IDs which needs to get merged.
  • to_entity_id (str | unicode) – Entity ID into which all the other entities need to get merged.
  • force (bool) – Setting this will follow the ‘mine’ strategy for merging MFA secrets. If there are secrets of the same type both in entities that are merged from and in entity into which all others are getting merged, secrets in the destination will be unaltered. If not set, this API will throw an error containing all the conflicts.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

read_entity(entity_id, mount_point='identity')[source]

Query an entity by its identifier.

Supported methods:
GET: /auth/{mount_point}/entity/id/{id}. Produces: 200 application/json
Parameters:
  • entity_id (str) – Identifier of the entity.
  • mount_point (str | unicode) – The “path” the secret engine was mounted on.
Returns:

The JSON response of the request.

Return type:

dict

read_entity_alias(alias_id, mount_point='identity')[source]

Query the entity alias by its identifier.

Supported methods:
GET: /{mount_point}/entity-alias/id/{id}. Produces: 200 application/json
Parameters:
  • alias_id (str | unicode) – Identifier of entity alias.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

dict

read_entity_by_name(name, mount_point='identity')[source]

Query an entity by its name.

Supported methods:
GET: /{mount_point}/entity/name/{name}. Produces: 200 application/json
Parameters:
  • name (str | unicode) – Name of the entity.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

requests.Response

read_group(group_id, mount_point='identity')[source]

Query the group by its identifier.

Supported methods:
GET: /{mount_point}/group/id/{id}. Produces: 200 application/json
Parameters:
  • group_id (str | unicode) – Identifier of the group.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

requests.Response

read_group_alias(alias_id, mount_point='identity')[source]

Query the group alias by its identifier.

Supported methods:
GET: /{mount_point}/group-alias/id/:id. Produces: 200 application/json
Parameters:
  • alias_id (str | unicode) – ID of the group alias.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

dict

read_group_by_name(name, mount_point='identity')[source]

Query a group by its name.

Supported methods:
GET: /{mount_point}/group/name/{name}. Produces: 200 application/json
Parameters:
  • name (str | unicode) – Name of the group.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

dict

update_entity(entity_id, name=None, metadata=None, policies=None, disabled=False, mount_point='identity')[source]

Update an existing entity.

Supported methods:
POST: /{mount_point}/entity/id/{id}. Produces: 200 application/json
Parameters:
  • entity_id (str | unicode) – Identifier of the entity.
  • name (str | unicode) – Name of the entity.
  • metadata (dict) – Metadata to be associated with the entity.
  • policies (str | unicode) – Policies to be tied to the entity.
  • disabled (bool) – Whether the entity is disabled. Disabled entities’ associated tokens cannot be used, but are not revoked.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response where available, otherwise the generic response object, of the request.

Return type:

dict | requests.Response

update_entity_alias(alias_id, name, canonical_id, mount_accessor, mount_point='identity')[source]

Update an existing entity alias.

Supported methods:
POST: /{mount_point}/entity-alias/id/{id}. Produces: 200 application/json
Parameters:
  • alias_id (str | unicode) – Identifier of the entity alias.
  • name (str | unicode) – Name of the alias. Name should be the identifier of the client in the authentication source. For example, if the alias belongs to userpass backend, the name should be a valid username within userpass backend. If alias belongs to GitHub, it should be the GitHub username.
  • canonical_id (str | unicode) – Entity ID to which this alias belongs to.
  • mount_accessor (str | unicode) – Accessor of the mount to which the alias should belong to.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response where available, otherwise the generic response object, of the request.

Return type:

dict | requests.Response

update_group(group_id, name, group_type='internal', metadata=None, policies=None, member_group_ids=None, member_entity_ids=None, mount_point='identity')[source]

Update an existing group.

Supported methods:
POST: /{mount_point}/group/id/{id}. Produces: 200 application/json
Parameters:
  • group_id (str | unicode) – Identifier of the entity.
  • name (str | unicode) – Name of the group.
  • group_type (str | unicode) – Type of the group, internal or external. Defaults to internal.
  • metadata (dict) – Metadata to be associated with the group.
  • policies (str | unicode) – Policies to be tied to the group.
  • member_group_ids (str | unicode) – Group IDs to be assigned as group members.
  • member_entity_ids (str | unicode) – Entity IDs to be assigned as group members.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response where available, otherwise the generic response object, of the request.

Return type:

dict | requests.Response

update_group_alias(entity_id, name, mount_accessor='', canonical_id='', mount_point='identity')[source]

Update an existing group alias.

Supported methods:
POST: /{mount_point}/group-alias/id/{id}. Produces: 200 application/json
Parameters:
  • entity_id (str | unicode) – ID of the group alias.
  • name (str | unicode) – Name of the group alias.
  • mount_accessor (str | unicode) – Mount accessor to which this alias belongs toMount accessor to which this alias belongs to.
  • canonical_id (str | unicode) – ID of the group to which this is an alias.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

static validate_member_id_params_for_group_type(group_type, params, member_group_ids, member_entity_ids)[source]

Determine whether member ID parameters can be sent with a group create / update request.

These parameters are only allowed for the internal group type. If they’re set for an external group type, Vault returns a “error” response.

Parameters:
  • group_type (str | unicode) – Type of the group, internal or external
  • params (dict) – Params dict to conditionally add the member entity/group ID’s to.
  • member_group_ids (str | unicode) – Group IDs to be assigned as group members.
  • member_entity_ids (str | unicode) – Entity IDs to be assigned as group members.
Returns:

Params dict with conditionally added member entity/group ID’s.

Return type:

dict

class hvac.api.secrets_engines.Kv(adapter, default_kv_version='2')[source]

Bases: hvac.api.vault_api_base.VaultApiBase

Class containing methods for the key/value secrets_engines backend API routes. Reference: https://www.vaultproject.io/docs/secrets/kv/index.html

__init__(adapter, default_kv_version='2')[source]

Create a new Kv instance.

Parameters:
  • adapter (hvac.adapters.Adapter) – Instance of hvac.adapters.Adapter; used for performing HTTP requests.
  • default_kv_version (str | unicode) – KV version number (e.g., ‘1’) to use as the default when accessing attributes/methods under this class.
allowed_kv_versions = ['1', '2']
default_kv_version
v1

Accessor for kv version 1 class / method. Provided via the hvac.api.secrets_engines.kv_v1.KvV1 class.

Returns:This Kv instance’s associated KvV1 instance.
Return type:hvac.api.secrets_engines.kv_v1.KvV1
v2

Accessor for kv version 2 class / method. Provided via the hvac.api.secrets_engines.kv_v2.KvV2 class.

Returns:This Kv instance’s associated KvV2 instance.
Return type:hvac.api.secrets_engines.kv_v2.KvV2
class hvac.api.secrets_engines.KvV1(adapter)[source]

Bases: hvac.api.vault_api_base.VaultApiBase

KV Secrets Engine - Version 1 (API).

Reference: https://www.vaultproject.io/api/secrets/kv/kv-v1.html

create_or_update_secret(path, secret, method=None, mount_point='secret')[source]

Store a secret at the specified location.

If the value does not yet exist, the calling token must have an ACL policy granting the create capability. If the value already exists, the calling token must have an ACL policy granting the update capability.

Supported methods:
POST: /{mount_point}/{path}. Produces: 204 (empty body) PUT: /{mount_point}/{path}. Produces: 204 (empty body)
Parameters:
  • path (str | unicode) – Specifies the path of the secrets to create/update. This is specified as part of the URL.
  • secret (dict) – Specifies keys, paired with associated values, to be held at the given location. Multiple key/value pairs can be specified, and all will be returned on a read operation. A key called ttl will trigger some special behavior. See the Vault KV secrets engine documentation for details.
  • method (str | unicode) – Optional parameter to explicitly request a POST (create) or PUT (update) request to the selected kv secret engine. If no argument is provided for this parameter, hvac attempts to intelligently determine which method is appropriate.
  • mount_point (str | unicode) – The “path” the secret engine was mounted on.
Returns:

The response of the create_or_update_secret request.

Return type:

requests.Response

delete_secret(path, mount_point='secret')[source]

Delete the secret at the specified location.

Supported methods:
DELETE: /{mount_point}/{path}. Produces: 204 (empty body)
Parameters:
  • path (str | unicode) – Specifies the path of the secret to delete. This is specified as part of the URL.
  • mount_point (str | unicode) – The “path” the secret engine was mounted on.
Returns:

The response of the delete_secret request.

Return type:

requests.Response

list_secrets(path, mount_point='secret')[source]

Return a list of key names at the specified location.

Folders are suffixed with /. The input must be a folder; list on a file will not return a value. Note that no policy-based filtering is performed on keys; do not encode sensitive information in key names. The values themselves are not accessible via this command.

Supported methods:
LIST: /{mount_point}/{path}. Produces: 200 application/json
Parameters:
  • path (str | unicode) – Specifies the path of the secrets to list. This is specified as part of the URL.
  • mount_point (str | unicode) – The “path” the secret engine was mounted on.
Returns:

The JSON response of the list_secrets request.

Return type:

dict

read_secret(path, mount_point='secret')[source]

Retrieve the secret at the specified location.

Supported methods:
GET: /{mount_point}/{path}. Produces: 200 application/json
Parameters:
  • path (str | unicode) – Specifies the path of the secret to read. This is specified as part of the URL.
  • mount_point (str | unicode) – The “path” the secret engine was mounted on.
Returns:

The JSON response of the read_secret request.

Return type:

dict

class hvac.api.secrets_engines.KvV2(adapter)[source]

Bases: hvac.api.vault_api_base.VaultApiBase

KV Secrets Engine - Version 2 (API).

Reference: https://www.vaultproject.io/api/secret/kv/kv-v2.html

configure(max_versions=10, cas_required=None, mount_point='secret')[source]

Configure backend level settings that are applied to every key in the key-value store.

Supported methods:
POST: /{mount_point}/config. Produces: 204 (empty body)
Parameters:
  • max_versions (int) – The number of versions to keep per key. This value applies to all keys, but a key’s metadata setting can overwrite this value. Once a key has more than the configured allowed versions the oldest version will be permanently deleted. Defaults to 10.
  • cas_required (bool) – If true all keys will require the cas parameter to be set on all write requests.
  • mount_point (str | unicode) – The “path” the secret engine was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

create_or_update_secret(path, secret, cas=None, mount_point='secret')[source]

Create a new version of a secret at the specified location.

If the value does not yet exist, the calling token must have an ACL policy granting the create capability. If the value already exists, the calling token must have an ACL policy granting the update capability.

Supported methods:
POST: /{mount_point}/data/{path}. Produces: 200 application/json
Parameters:
  • path (str | unicode) – Path
  • cas (int) – Set the “cas” value to use a Check-And-Set operation. If not set the write will be allowed. If set to 0 a write will only be allowed if the key doesn’t exist. If the index is non-zero the write will only be allowed if the key’s current version matches the version specified in the cas parameter.
  • secret (dict) – The contents of the “secret” dict will be stored and returned on read.
  • mount_point (str | unicode) – The “path” the secret engine was mounted on.
Returns:

The JSON response of the request.

Return type:

dict

delete_latest_version_of_secret(path, mount_point='secret')[source]

Issue a soft delete of the secret’s latest version at the specified location.

This marks the version as deleted and will stop it from being returned from reads, but the underlying data will not be removed. A delete can be undone using the undelete path.

Supported methods:
DELETE: /{mount_point}/data/{path}. Produces: 204 (empty body)
Parameters:
  • path (str | unicode) – Specifies the path of the secret to delete. This is specified as part of the URL.
  • mount_point (str | unicode) – The “path” the secret engine was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

delete_metadata_and_all_versions(path, mount_point='secret')[source]

Delete (permanently) the key metadata and all version data for the specified key.

All version history will be removed.

Supported methods:
DELETE: /{mount_point}/metadata/{path}. Produces: 204 (empty body)
Parameters:
  • path (str | unicode) – Specifies the path of the secret to delete. This is specified as part of the URL.
  • mount_point (str | unicode) – The “path” the secret engine was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

delete_secret_versions(path, versions, mount_point='secret')[source]

Issue a soft delete of the specified versions of the secret.

This marks the versions as deleted and will stop them from being returned from reads, but the underlying data will not be removed. A delete can be undone using the undelete path.

Supported methods:
POST: /{mount_point}/delete/{path}. Produces: 204 (empty body)
Parameters:
  • path (str | unicode) – Specifies the path of the secret to delete. This is specified as part of the URL.
  • versions (int) – The versions to be deleted. The versioned data will not be deleted, but it will no longer be returned in normal get requests.
  • mount_point (str | unicode) – The “path” the secret engine was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

destroy_secret_versions(path, versions, mount_point='secret')[source]

Permanently remove the specified version data and numbers for the provided path from the key-value store.

Supported methods:
POST: /{mount_point}/destroy/{path}. Produces: 204 (empty body)
Parameters:
  • path (str | unicode) – Specifies the path of the secret to destroy. This is specified as part of the URL.
  • versions (list of int) – The versions to destroy. Their data will be permanently deleted.
  • mount_point (str | unicode) – The “path” the secret engine was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

list_secrets(path, mount_point='secret')[source]

Return a list of key names at the specified location.

Folders are suffixed with /. The input must be a folder; list on a file will not return a value. Note that no policy-based filtering is performed on keys; do not encode sensitive information in key names. The values themselves are not accessible via this command.

Supported methods:
LIST: /{mount_point}/metadata/{path}. Produces: 200 application/json
Parameters:
  • path (str | unicode) – Specifies the path of the secrets to list. This is specified as part of the URL.
  • mount_point (str | unicode) – The “path” the secret engine was mounted on.
Returns:

The JSON response of the request.

Return type:

dict

patch(path, secret, mount_point='secret')[source]

Set or update data in the KV store without overwriting.

Parameters:
  • path (str | unicode) – Path
  • secret (dict) – The contents of the “secret” dict will be stored and returned on read.
  • mount_point (str | unicode) – The “path” the secret engine was mounted on.
Returns:

The JSON response of the create_or_update_secret request.

Return type:

dict

read_configuration(mount_point='secret')[source]

Read the KV Version 2 configuration.

Supported methods:
GET: /auth/{mount_point}/config. Produces: 200 application/json
Parameters:mount_point (str | unicode) – The “path” the secret engine was mounted on.
Returns:The JSON response of the request.
Return type:dict
read_secret_metadata(path, mount_point='secret')[source]

Retrieve the metadata and versions for the secret at the specified path.

Supported methods:
GET: /{mount_point}/metadata/{path}. Produces: 200 application/json
Parameters:
  • path (str | unicode) – Specifies the path of the secret to read. This is specified as part of the URL.
  • mount_point (str | unicode) – The “path” the secret engine was mounted on.
Returns:

The JSON response of the request.

Return type:

dict

read_secret_version(path, version=None, mount_point='secret')[source]

Retrieve the secret at the specified location.

Supported methods:
GET: /{mount_point}/data/{path}. Produces: 200 application/json
Parameters:
  • path (str | unicode) – Specifies the path of the secret to read. This is specified as part of the URL.
  • version (int) – Specifies the version to return. If not set the latest version is returned.
  • mount_point (str | unicode) – The “path” the secret engine was mounted on.
Returns:

The JSON response of the request.

Return type:

dict

undelete_secret_versions(path, versions, mount_point='secret')[source]

Undelete the data for the provided version and path in the key-value store.

This restores the data, allowing it to be returned on get requests.

Supported methods:
POST: /{mount_point}/undelete/{path}. Produces: 204 (empty body)
Parameters:
  • path (str | unicode) – Specifies the path of the secret to undelete. This is specified as part of the URL.
  • versions (list of int) – The versions to undelete. The versions will be restored and their data will be returned on normal get requests.
  • mount_point (str | unicode) – The “path” the secret engine was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

update_metadata(path, max_versions=None, cas_required=None, mount_point='secret')[source]

Updates the max_versions of cas_required setting on an existing path.

Supported methods:
POST: /{mount_point}/metadata/{path}. Produces: 204 (empty body)
Parameters:
  • path (str | unicode) – Path
  • max_versions (int) – The number of versions to keep per key. If not set, the backend’s configured max version is used. Once a key has more than the configured allowed versions the oldest version will be permanently deleted.
  • cas_required (bool) – If true the key will require the cas parameter to be set on all write requests. If false, the backend’s configuration will be used.
  • mount_point (str | unicode) – The “path” the secret engine was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

class hvac.api.secrets_engines.Transit(adapter)[source]

Bases: hvac.api.vault_api_base.VaultApiBase

Transit Secrets Engine (API).

Reference: https://www.vaultproject.io/api/secret/transit/index.html

backup_key(name, mount_point='transit')[source]

Return a plaintext backup of a named key.

The backup contains all the configuration data and keys of all the versions along with the HMAC key. The response from this endpoint can be used with the /restore endpoint to restore the key.

Supported methods:
GET: /{mount_point}/backup/{name}. Produces: 200 application/json
Parameters:
  • name (str | unicode) – Name of the key.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

requests.Response

create_key(name, convergent_encryption=False, derived=False, exportable=False, allow_plaintext_backup=False, key_type='aes256-gcm96', mount_point='transit')[source]

Create a new named encryption key of the specified type.

The values set here cannot be changed after key creation.

Supported methods:
POST: /{mount_point}/keys/{name}. Produces: 204 (empty body)
Parameters:
  • name (str | unicode) – Specifies the name of the encryption key to create. This is specified as part of the URL.
  • convergent_encryption (bool) – If enabled, the key will support convergent encryption, where the same plaintext creates the same ciphertext. This requires derived to be set to true. When enabled, each encryption(/decryption/rewrap/datakey) operation will derive a nonce value rather than randomly generate it.
  • derived (bool) – Specifies if key derivation is to be used. If enabled, all encrypt/decrypt requests to this named key must provide a context which is used for key derivation.
  • exportable (bool) – Enables keys to be exportable. This allows for all the valid keys in the key ring to be exported. Once set, this cannot be disabled.
  • allow_plaintext_backup (bool) – If set, enables taking backup of named key in the plaintext format. Once set, this cannot be disabled.
  • key_type (str | unicode) –

    Specifies the type of key to create. The currently-supported types are:

    • aes256-gcm96: AES-256 wrapped with GCM using a 96-bit nonce size AEAD
    • chacha20-poly1305: ChaCha20-Poly1305 AEAD (symmetric, supports derivation and convergent encryption)
    • ed25519: ED25519 (asymmetric, supports derivation).
    • ecdsa-p256: ECDSA using the P-256 elliptic curve (asymmetric)
    • rsa-2048: RSA with bit size of 2048 (asymmetric)
    • rsa-4096: RSA with bit size of 4096 (asymmetric)
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

decrypt_data(name, ciphertext, context='', nonce='', batch_input=None, mount_point='transit')[source]

Decrypt the provided ciphertext using the named key.

Supported methods:
POST: /{mount_point}/decrypt/{name}. Produces: 200 application/json
Parameters:
  • name (str | unicode) – Specifies the name of the encryption key to decrypt against. This is specified as part of the URL.
  • ciphertext (str | unicode) – the ciphertext to decrypt.
  • context (str | unicode) – Specifies the base64 encoded context for key derivation. This is required if key derivation is enabled.
  • nonce (str | unicode) – Specifies a base64 encoded nonce value used during encryption. Must be provided if convergent encryption is enabled for this key and the key was generated with Vault 0.6.1. Not required for keys created in 0.6.2+.
  • batch_input (List[dict]) – Specifies a list of items to be decrypted in a single batch. When this parameter is set, if the parameters ‘ciphertext’, ‘context’ and ‘nonce’ are also set, they will be ignored. Format for the input goes like this: [dict(context=”b64_context”, ciphertext=”b64_plaintext”), …]
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

requests.Response

delete_key(name, mount_point='transit')[source]

Delete a named encryption key.

It will no longer be possible to decrypt any data encrypted with the named key. Because this is a potentially catastrophic operation, the deletion_allowed tunable must be set in the key’s /config endpoint.

Supported methods:
DELETE: /{mount_point}/keys/{name}. Produces: 204 (empty body)
Parameters:
  • name (str | unicode) – Specifies the name of the encryption key to delete. This is specified as part of the URL.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

encrypt_data(name, plaintext, context='', key_version=0, nonce=None, batch_input=None, type='aes256-gcm96', convergent_encryption='', mount_point='transit')[source]

Encrypt the provided plaintext using the named key.

This path supports the create and update policy capabilities as follows: if the user has the create capability for this endpoint in their policies, and the key does not exist, it will be upserted with default values (whether the key requires derivation depends on whether the context parameter is empty or not). If the user only has update capability and the key does not exist, an error will be returned.

Supported methods:
POST: /{mount_point}/encrypt/{name}. Produces: 200 application/json
Parameters:
  • name (str | unicode) – Specifies the name of the encryption key to encrypt against. This is specified as part of the URL.
  • plaintext (str | unicode) – Specifies base64 encoded plaintext to be encoded.
  • context (str | unicode) – Specifies the base64 encoded context for key derivation. This is required if key derivation is enabled for this key.
  • key_version (int) – Specifies the version of the key to use for encryption. If not set, uses the latest version. Must be greater than or equal to the key’s min_encryption_version, if set.
  • nonce (str | unicode) – Specifies the base64 encoded nonce value. This must be provided if convergent encryption is enabled for this key and the key was generated with Vault 0.6.1. Not required for keys created in 0.6.2+. The value must be exactly 96 bits (12 bytes) long and the user must ensure that for any given context (and thus, any given encryption key) this nonce value is never reused.
  • batch_input (List[dict]) – Specifies a list of items to be encrypted in a single batch. When this parameter is set, if the parameters ‘plaintext’, ‘context’ and ‘nonce’ are also set, they will be ignored. The format for the input is: [dict(context=”b64_context”, plaintext=”b64_plaintext”), …]
  • type (str | unicode) – This parameter is required when encryption key is expected to be created. When performing an upsert operation, the type of key to create.
  • convergent_encryption (str | unicode) – This parameter will only be used when a key is expected to be created. Whether to support convergent encryption. This is only supported when using a key with key derivation enabled and will require all requests to carry both a context and 96-bit (12-byte) nonce. The given nonce will be used in place of a randomly generated nonce. As a result, when the same context and nonce are supplied, the same ciphertext is generated. It is very important when using this mode that you ensure that all nonces are unique for a given context. Failing to do so will severely impact the ciphertext’s security.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

requests.Response

export_key(name, key_type, version=None, mount_point='transit')[source]

Return the named key.

The keys object shows the value of the key for each version. If version is specified, the specific version will be returned. If latest is provided as the version, the current key will be provided. Depending on the type of key, different information may be returned. The key must be exportable to support this operation and the version must still be valid.

Supported methods:
GET: /{mount_point}/export/{key_type}/{name}(/{version}). Produces: 200 application/json
Parameters:
  • name (str | unicode) – Specifies the name of the key to read information about. This is specified as part of the URL.
  • key_type (str | unicode) – Specifies the type of the key to export. This is specified as part of the URL. Valid values are: encryption-key signing-key hmac-key
  • version (str | unicode) – Specifies the version of the key to read. If omitted, all versions of the key will be returned. If the version is set to latest, the current key will be returned.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

requests.Response

generate_data_key(name, key_type, context='', nonce='', bits=256, mount_point='transit')[source]

Generates a new high-entropy key and the value encrypted with the named key.

Optionally return the plaintext of the key as well. Whether plaintext is returned depends on the path; as a result, you can use Vault ACL policies to control whether a user is allowed to retrieve the plaintext value of a key. This is useful if you want an untrusted user or operation to generate keys that are then made available to trusted users.

Supported methods:
POST: /{mount_point}/datakey/{key_type}/{name}. Produces: 200 application/json
Parameters:
  • name (str | unicode) – Specifies the name of the encryption key to use to encrypt the datakey. This is specified as part of the URL.
  • key_type (str | unicode) – Specifies the type of key to generate. If plaintext, the plaintext key will be returned along with the ciphertext. If wrapped, only the ciphertext value will be returned. This is specified as part of the URL.
  • context (str | unicode) – Specifies the key derivation context, provided as a base64-encoded string. This must be provided if derivation is enabled.
  • nonce (str | unicode) – Specifies a nonce value, provided as base64 encoded. Must be provided if convergent encryption is enabled for this key and the key was generated with Vault 0.6.1. Not required for keys created in 0.6.2+. The value must be exactly 96 bits (12 bytes) long and the user must ensure that for any given context (and thus, any given encryption key) this nonce value is never reused.
  • bits (int) – Specifies the number of bits in the desired key. Can be 128, 256, or 512.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

requests.Response

generate_hmac(name, hash_input, key_version=None, algorithm='sha2-256', mount_point='transit')[source]

Return the digest of given data using the specified hash algorithm and the named key.

The key can be of any type supported by transit; the raw key will be marshaled into bytes to be used for the HMAC function. If the key is of a type that supports rotation, the latest (current) version will be used.

Supported methods:
POST: /{mount_point}/hmac/{name}(/{algorithm}). Produces: 200 application/json
Parameters:
  • name (str | unicode) – Specifies the name of the encryption key to generate hmac against. This is specified as part of the URL.
  • hash_input – Specifies the base64 encoded input data.
  • key_version (int) – Specifies the version of the key to use for the operation. If not set, uses the latest version. Must be greater than or equal to the key’s min_encryption_version, if set.
  • algorithm (str | unicode) – Specifies the hash algorithm to use. This can also be specified as part of the URL. Currently-supported algorithms are: sha2-224, sha2-256, sha2-384, sha2-512
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

requests.Response

generate_random_bytes(n_bytes=32, output_format='base64', mount_point='transit')[source]

Return high-quality random bytes of the specified length.

Supported methods:
POST: /{mount_point}/random(/{bytes}). Produces: 200 application/json
Parameters:
  • n_bytes (int) – Specifies the number of bytes to return. This value can be specified either in the request body, or as a part of the URL.
  • output_format (str | unicode) – Specifies the output encoding. Valid options are hex or base64.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

requests.Response

hash_data(hash_input, algorithm='sha2-256', output_format='hex', mount_point='transit')[source]

Return the cryptographic hash of given data using the specified algorithm.

Supported methods:
POST: /{mount_point}/hash(/{algorithm}). Produces: 200 application/json
Parameters:
  • hash_input (str | unicode) – Specifies the base64 encoded input data.
  • algorithm (str | unicode) – Specifies the hash algorithm to use. This can also be specified as part of the URL. Currently-supported algorithms are: sha2-224, sha2-256, sha2-384, sha2-512
  • output_format (str | unicode) – Specifies the output encoding. This can be either hex or base64.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

requests.Response

list_keys(mount_point='transit')[source]

List keys.

Only the key names are returned (not the actual keys themselves).

Supported methods:
LIST: /{mount_point}/keys. Produces: 200 application/json
Parameters:mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:The JSON response of the request.
Return type:requests.Response
read_key(name, mount_point='transit')[source]

Read information about a named encryption key.

The keys object shows the creation time of each key version; the values are not the keys themselves. Depending on the type of key, different information may be returned, e.g. an asymmetric key will return its public key in a standard format for the type.

Supported methods:
GET: /{mount_point}/keys/{name}. Produces: 200 application/json
Parameters:
  • name (str | unicode) – Specifies the name of the encryption key to read. This is specified as part of the URL.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the read_key request.

Return type:

requests.Response

restore_key(backup, name=None, force=False, mount_point='transit')[source]

Restore the backup as a named key.

This will restore the key configurations and all the versions of the named key along with HMAC keys. The input to this endpoint should be the output of /backup endpoint. For safety, by default the backend will refuse to restore to an existing key. If you want to reuse a key name, it is recommended you delete the key before restoring. It is a good idea to attempt restoring to a different key name first to verify that the operation successfully completes.

Supported methods:
POST: /{mount_point}/restore(/name). Produces: 204 (empty body)
Parameters:
  • backup (str | unicode) – Backed up key data to be restored. This should be the output from the /backup endpoint.
  • name (str | unicode) – If set, this will be the name of the restored key.
  • force (bool) – If set, force the restore to proceed even if a key by this name already exists.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

rewrap_data(name, ciphertext, context='', key_version=None, nonce='', batch_input=None, mount_point='transit')[source]

Rewrap the provided ciphertext using the latest version of the named key.

Because this never returns plaintext, it is possible to delegate this functionality to untrusted users or scripts.

Supported methods:
POST: /{mount_point}/rewrap/{name}. Produces: 200 application/json
Parameters:
  • name (str | unicode) – Specifies the name of the encryption key to re-encrypt against. This is specified as part of the URL.
  • ciphertext (str | unicode) – Specifies the ciphertext to re-encrypt.
  • context (str | unicode) – Specifies the base64 encoded context for key derivation. This is required if key derivation is enabled.
  • key_version (int) – Specifies the version of the key to use for the operation. If not set, uses the latest version. Must be greater than or equal to the key’s min_encryption_version, if set.
  • nonce (str | unicode) – Specifies a base64 encoded nonce value used during encryption. Must be provided if convergent encryption is enabled for this key and the key was generated with Vault 0.6.1. Not required for keys created in 0.6.2+.
  • batch_input (List[dict]) – Specifies a list of items to be decrypted in a single batch. When this parameter is set, if the parameters ‘ciphertext’, ‘context’ and ‘nonce’ are also set, they will be ignored. Format for the input goes like this: [dict(context=”b64_context”, ciphertext=”b64_plaintext”), …]
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

requests.Response

rotate_key(name, mount_point='transit')[source]

Rotate the version of the named key.

After rotation, new plaintext requests will be encrypted with the new version of the key. To upgrade ciphertext to be encrypted with the latest version of the key, use the rewrap endpoint. This is only supported with keys that support encryption and decryption operations.

Supported methods:
POST: /{mount_point}/keys/{name}/rotate. Produces: 204 (empty body)
Parameters:
  • name (str | unicode) – Specifies the name of the key to read information about. This is specified as part of the URL.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

sign_data(name, hash_input, key_version=None, hash_algorithm='sha2-256', context='', prehashed=False, signature_algorithm='pss', mount_point='transit')[source]

Return the cryptographic signature of the given data using the named key and the specified hash algorithm.

The key must be of a type that supports signing.

Supported methods:
POST: /{mount_point}/sign/{name}(/{hash_algorithm}). Produces: 200 application/json
Parameters:
  • name (str | unicode) – Specifies the name of the encryption key to use for signing. This is specified as part of the URL.
  • hash_input (str | unicode) – Specifies the base64 encoded input data.
  • key_version (int) – Specifies the version of the key to use for signing. If not set, uses the latest version. Must be greater than or equal to the key’s min_encryption_version, if set.
  • hash_algorithm (str | unicode) – Specifies the hash algorithm to use for supporting key types (notably, not including ed25519 which specifies its own hash algorithm). This can also be specified as part of the URL. Currently-supported algorithms are: sha2-224, sha2-256, sha2-384, sha2-512
  • context (str | unicode) – Base64 encoded context for key derivation. Required if key derivation is enabled; currently only available with ed25519 keys.
  • prehashed (bool) – Set to true when the input is already hashed. If the key type is rsa-2048 or rsa-4096, then the algorithm used to hash the input should be indicated by the hash_algorithm parameter. Just as the value to sign should be the base64-encoded representation of the exact binary data you want signed, when set, input is expected to be base64-encoded binary hashed data, not hex-formatted. (As an example, on the command line, you could generate a suitable input via openssl dgst -sha256 -binary | base64.)
  • signature_algorithm (str | unicode) – When using a RSA key, specifies the RSA signature algorithm to use for signing. Supported signature types are: pss, pkcs1v15
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

requests.Response

trim_key(name, min_version, mount_point='transit')[source]

Trims older key versions setting a minimum version for the keyring.

Once trimmed, previous versions of the key cannot be recovered.

Supported methods:
POST: /{mount_point}/keys/{name}/trim. Produces: 200 application/json
Parameters:
  • name (str | unicode) – Specifies the name of the key to be trimmed.
  • min_version (int) – The minimum version for the key ring. All versions before this version will be permanently deleted. This value can at most be equal to the lesser of min_decryption_version and min_encryption_version. This is not allowed to be set when either min_encryption_version or min_decryption_version is set to zero.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

update_key_configuration(name, min_decryption_version=0, min_encryption_version=0, deletion_allowed=False, exportable=False, allow_plaintext_backup=False, mount_point='transit')[source]

Tune configuration values for a given key.

These values are returned during a read operation on the named key.

Supported methods:
POST: /{mount_point}/keys/{name}/config. Produces: 204 (empty body)
Parameters:
  • name (str | unicode) – Specifies the name of the encryption key to update configuration for.
  • min_decryption_version (int) – Specifies the minimum version of ciphertext allowed to be decrypted. Adjusting this as part of a key rotation policy can prevent old copies of ciphertext from being decrypted, should they fall into the wrong hands. For signatures, this value controls the minimum version of signature that can be verified against. For HMACs, this controls the minimum version of a key allowed to be used as the key for verification.
  • min_encryption_version (int) – Specifies the minimum version of the key that can be used to encrypt plaintext, sign payloads, or generate HMACs. Must be 0 (which will use the latest version) or a value greater or equal to min_decryption_version.
  • deletion_allowed (bool) – Specifies if the key is allowed to be deleted.
  • exportable (bool) – Enables keys to be exportable. This allows for all the valid keys in the key ring to be exported. Once set, this cannot be disabled.
  • allow_plaintext_backup (bool) – If set, enables taking backup of named key in the plaintext format. Once set, this cannot be disabled.
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The response of the request.

Return type:

requests.Response

verify_signed_data(name, hash_input, signature=None, hmac=None, hash_algorithm='sha2-256', context='', prehashed=False, signature_algorithm='pss', mount_point='transit')[source]

Return whether the provided signature is valid for the given data.

Supported methods:
POST: /{mount_point}/verify/{name}(/{hash_algorithm}). Produces: 200 application/json
Parameters:
  • name (str | unicode) – Specifies the name of the encryption key that was used to generate the signature or HMAC.
  • hash_input – Specifies the base64 encoded input data.
  • signature (str | unicode) – Specifies the signature output from the /transit/sign function. Either this must be supplied or hmac must be supplied.
  • hmac (str | unicode) – Specifies the signature output from the /transit/hmac function. Either this must be supplied or signature must be supplied.
  • hash_algorithm (str | unicode) – Specifies the hash algorithm to use. This can also be specified as part of the URL. Currently-supported algorithms are: sha2-224, sha2-256, sha2-384, sha2-512
  • context (str | unicode) – Base64 encoded context for key derivation. Required if key derivation is enabled; currently only available with ed25519 keys.
  • prehashed (bool) – Set to true when the input is already hashed. If the key type is rsa-2048 or rsa-4096, then the algorithm used to hash the input should be indicated by the hash_algorithm parameter.
  • signature_algorithm (str | unicode) – When using a RSA key, specifies the RSA signature algorithm to use for signature verification. Supported signature types are: pss, pkcs1v15
  • mount_point (str | unicode) – The “path” the method/backend was mounted on.
Returns:

The JSON response of the request.

Return type:

requests.Response

class hvac.api.secrets_engines.SecretsEngines(adapter)[source]

Bases: hvac.api.vault_api_category.VaultApiCategory

Secrets Engines.

implemented_classes = [<class 'hvac.api.secrets_engines.azure.Azure'>, <class 'hvac.api.secrets_engines.identity.Identity'>, <class 'hvac.api.secrets_engines.kv.Kv'>, <class 'hvac.api.secrets_engines.transit.Transit'>]
unimplemented_classes = ['Ad', 'AliCloud', 'AWS', 'Azure', 'Consul', 'Database', 'Gcp', 'GcpKms', 'Nomad', 'Pki', 'RabbitMq', 'Ssh', 'TOTP', 'Cassandra', 'MongoDb', 'Mssql', 'MySql', 'PostgreSql']