---
title: Charmhub | Deploy Vault using Charmhub - The Open Operator Collection
description: Deploy the latest version of Vault as a Kubernetes Operator on any cloud.
url: https://charmhub.io/vault-k8s/libraries/vault
---

# Vault

[Canonical Telco](https://charmhub.io/publisher/telco-charmers "View all packages from Canonical Telco")

* [Canonical Telco](https://charmhub.io/publisher/telco-charmers "View all packages from Canonical Telco")

Platform:

2.0/stable 565

```
juju deploy vault-k8s --channel 2.0/stable
```

[Learn to deploy on juju >](https://juju.is/docs/juju/manage-applications)

[Toggle side navigation](https://charmhub.io/vault-k8s/libraries/vault#drawer)

## charms.vault\_k8s.v0.vault

* [*Docstrings*Docstrings](https://charmhub.io/vault-k8s/libraries/vault)
  [*Code*Source code](https://charmhub.io/vault-k8s/libraries/vault/source-code)
* + Download

    Fetch library

    ```
    charmcraft fetch-lib charms.vault_k8s.v0.vault
    ```

    [Download vault.py](https://charmhub.io/vault-k8s/libraries/vault/download)
  + *Last updated* 27 Jan 2024
  + *Revision* Library version 0.1

Library for interacting with a Vault cluster.

This library shares operations that interact with Vault through its API. It is
intended to be used by charms that need to manage a Vault cluster.

---

Index

* [class Vault](https://charmhub.io/vault-k8s/libraries/vault#vault)
* + [def \_\_init\_\_(
    self,
    url,
    ca\_cert\_path)](https://charmhub.io/vault-k8s/libraries/vault#vault-__init__)
* + [def initialize(
    self,
    secret\_shares,
    secret\_threshold)](https://charmhub.io/vault-k8s/libraries/vault#vault-initialize)
* + [def is\_initialized(
    self)](https://charmhub.io/vault-k8s/libraries/vault#vault-is_initialized)
* + [def is\_sealed(
    self)](https://charmhub.io/vault-k8s/libraries/vault#vault-is_sealed)
* + [def is\_active(
    self)](https://charmhub.io/vault-k8s/libraries/vault#vault-is_active)
* + [def is\_api\_available(
    self)](https://charmhub.io/vault-k8s/libraries/vault#vault-is_api_available)
* + [def unseal(
    self,
    unseal\_keys)](https://charmhub.io/vault-k8s/libraries/vault#vault-unseal)
* + [def set\_token(
    self,
    token)](https://charmhub.io/vault-k8s/libraries/vault#vault-set_token)
* + [def remove\_raft\_node(
    self,
    node\_id)](https://charmhub.io/vault-k8s/libraries/vault#vault-remove_raft_node)
* + [def is\_node\_in\_raft\_peers(
    self,
    node\_id)](https://charmhub.io/vault-k8s/libraries/vault#vault-is_node_in_raft_peers)
* + [def get\_num\_raft\_peers(
    self)](https://charmhub.io/vault-k8s/libraries/vault#vault-get_num_raft_peers)
* + [def enable\_approle\_auth(
    self)](https://charmhub.io/vault-k8s/libraries/vault#vault-enable_approle_auth)
* + [def configure\_kv\_mount(
    self,
    name)](https://charmhub.io/vault-k8s/libraries/vault#vault-configure_kv_mount)
* + [def configure\_kv\_policy(
    self,
    policy,
    mount)](https://charmhub.io/vault-k8s/libraries/vault#vault-configure_kv_policy)
* + [def audit\_device\_enabled(
    self,
    device\_type,
    path)](https://charmhub.io/vault-k8s/libraries/vault#vault-audit_device_enabled)
* + [def enable\_audit\_device(
    self,
    device\_type,
    path)](https://charmhub.io/vault-k8s/libraries/vault#vault-enable_audit_device)
* + [def create\_snapshot(
    self)](https://charmhub.io/vault-k8s/libraries/vault#vault-create_snapshot)
* + [def restore\_snapshot(
    self,
    snapshot)](https://charmhub.io/vault-k8s/libraries/vault#vault-restore_snapshot)
* + [def configure\_approle(
    self,
    name,
    cidrs,
    policies)](https://charmhub.io/vault-k8s/libraries/vault#vault-configure_approle)
* + [def generate\_role\_secret\_id(
    self,
    name,
    cidrs)](https://charmhub.io/vault-k8s/libraries/vault#vault-generate_role_secret_id)
* + [def read\_role\_secret(
    self,
    name,
    id)](https://charmhub.io/vault-k8s/libraries/vault#vault-read_role_secret)
* + [def get\_raft\_cluster\_state(
    self)](https://charmhub.io/vault-k8s/libraries/vault#vault-get_raft_cluster_state)
* + [def is\_raft\_cluster\_healthy(
    self)](https://charmhub.io/vault-k8s/libraries/vault#vault-is_raft_cluster_healthy)

#### class Vault

Description

Class to interact with Vault through its API. None

Methods

Vault.
\_\_init\_\_(

*self*

,
url: str

,
ca\_cert\_path: str
)

Vault.
initialize(

*self*

,
secret\_shares: int

,
secret\_threshold: int
)

Initialize Vault.

Returns

A tuple containing the root token and the unseal keys.

Vault.
is\_initialized(

*self*
)

Description

Returns whether Vault is initialized. None

Vault.
is\_sealed(

*self*
)

Description

Returns whether Vault is sealed. None

Vault.
is\_active(

*self*
)

Returns the health status of Vault.

Returns

True if initialized, unsealed and active, False otherwise.
Will return True if Vault is in standby mode too (standby\_ok=True).

Vault.
is\_api\_available(

*self*
)

Description

Returns whether Vault is available. None

Vault.
unseal(

*self*

,
unseal\_keys
)

Description

Unseal Vault. None

Vault.
set\_token(

*self*

,
token: str
)

Description

Sets the Vault token for authentication. None

Vault.
remove\_raft\_node(

*self*

,
node\_id: str
)

Description

Remove raft peer. None

Vault.
is\_node\_in\_raft\_peers(

*self*

,
node\_id: str
)

Description

Check if node is in raft peers. None

Vault.
get\_num\_raft\_peers(

*self*
)

Description

Returns the number of raft peers. None

Vault.
enable\_approle\_auth(

*self*
)

Description

Enable the AppRole authentication method in Vault, if not already enabled. None

Vault.
configure\_kv\_mount(

*self*

,
name: str
)

Description

Ensure a KV mount is enabled. None

Vault.
configure\_kv\_policy(

*self*

,
policy: str

,
mount: str
)

Description

Create/update a policy within vault to access the KV mount. None

Vault.
audit\_device\_enabled(

*self*

,
device\_type: str

,
path: str
)

Description

Check if audit device is enabled. None

Vault.
enable\_audit\_device(

*self*

,
device\_type: str

,
path: str
)

Description

Enable a new audit device at the supplied path. None

Vault.
create\_snapshot(

*self*
)

Description

Create a snapshot of the Vault data. None

Vault.
restore\_snapshot(

*self*

,
snapshot: bytes
)

Restore a snapshot of the Vault data.

Description

Uses force\_restore\_raft\_snapshot to restore the snapshot
even if the unseal key used at backup time is different from the current one.

Vault.
configure\_approle(

*self*

,
name: str

,
cidrs

,
policies
)

Description

Create/update a role within vault associating the supplied policies. None

Vault.
generate\_role\_secret\_id(

*self*

,
name: str

,
cidrs
)

Description

Generate a new secret tied to an AppRole. None

Vault.
read\_role\_secret(

*self*

,
name: str

,
id: str
)

Description

Get definition of a secret tied to an AppRole. None

Vault.
get\_raft\_cluster\_state(

*self*
)

Description

Get raft cluster state. None

Vault.
is\_raft\_cluster\_healthy(

*self*
)

Description

Check if raft cluster is healthy. None
