Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
fa19ad7
docs: Fixed example to point to the correct secret.
mariadb-stefangenov Sep 16, 2025
7f38a1c
docs: New Section For Hashicorp Plugin
mariadb-stefangenov Sep 16, 2025
744d9cc
docs: Modified docker images to point to the hashicorp ones
mariadb-stefangenov Sep 16, 2025
f3a18b4
docs: Add details for tls
mariadb-stefangenov Sep 18, 2025
139c870
docs: finalized docs for hashicorp-key-management, also updated other…
mariadb-stefangenov Sep 19, 2025
a0d818d
Update tools/mariadb-enterprise-operator/plugins/hashicorp-key-manage…
mariadb-stefangenov Sep 19, 2025
4cb6f04
Update tools/mariadb-enterprise-operator/plugins/hashicorp-key-manage…
mariadb-stefangenov Sep 19, 2025
bce98c7
Update tools/mariadb-enterprise-operator/plugins/hashicorp-key-manage…
mariadb-stefangenov Sep 19, 2025
c05d622
Update tools/mariadb-enterprise-operator/plugins/hashicorp-key-manage…
mariadb-stefangenov Sep 19, 2025
6e0eb0a
Update tools/mariadb-enterprise-operator/plugins/hashicorp-key-manage…
mariadb-stefangenov Sep 19, 2025
697077b
Update tools/mariadb-enterprise-operator/plugins/hashicorp-key-manage…
mariadb-stefangenov Sep 19, 2025
1ce8e7b
Update tools/mariadb-enterprise-operator/plugins/hashicorp-key-manage…
mariadb-stefangenov Sep 19, 2025
4886709
Update tools/mariadb-enterprise-operator/plugins/hashicorp-key-manage…
mariadb-stefangenov Sep 19, 2025
3f7fdb7
Merge branch 'main' into docs/hashicorp-key-management.md
mariadb-stefangenov Sep 19, 2025
f32aa14
docs: removed confusing example
mariadb-stefangenov Sep 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The plugin supports the following parameters, which must be set in advance and c

#### `hashicorp-key-management-token`

* Description: Authentication token that passed to the Hashicorp Vault in the request header. By default, this parameter contains an empty string, so you must specify the correct value for it, otherwise the Hashicorp Vault server will refuse authorization.
* Description: Authentication token that passed to the Hashicorp Vault in the request header. By default, this parameter contains an empty string, so you must specify the correct value for it, otherwise the Hashicorp Vault server will refuse authorization. Alternatively, you can define an environment variable `VAULT_TOKEN` and store the token there.
* Commandline: `--[loose-]hashicorp-key-management-token="<token>"`

#### `hashicorp-key-management-vault-ca`
Expand Down
1 change: 1 addition & 0 deletions tools/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* [Plugins](mariadb-enterprise-operator/plugins/README.md)
* [Supported Docker Images](mariadb-enterprise-operator/plugins/supported-docker-images.md)
* [PAM](mariadb-enterprise-operator/plugins/pam.md)
* [Hashicorp Key Management](mariadb-enterprise-operator/plugins/hashicorp-key-management.md)
* [API Reference](mariadb-enterprise-operator/api-reference.md)
* [Examples Catalog](mariadb-enterprise-operator/examples-catalog.md)
* [Migrations](mariadb-enterprise-operator/migrations/README.md)
Expand Down
2 changes: 1 addition & 1 deletion tools/mariadb-enterprise-operator/docker-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ MariaDB Enterprise Operator is compatible with the following Docker images:
|-----------|-------|----------------|------------------|
| MariaDB Enterprise Operator (ppc64le support) | docker.mariadb.com/mariadb-enterprise-operator | 25.8.0 <br> | amd64 <br> arm64 <br> ppc64le <br> |
| MariaDB Enterprise Operator | docker.mariadb.com/mariadb-enterprise-operator | 1.0.0 <br> | amd64 <br> arm64 <br> |
| MariaDB Enterprise Server (ppc64le support) | docker.mariadb.com/enterprise-server | 11.4.7-4.2 <br> 11.4.7-4.1 <br> 11.4 <br> 10.6.22-18.1 <br> 10.6 <br> | amd64 <br> arm64 <br> ppc64le <br> |
| MariaDB Enterprise Server (ppc64le support) | docker.mariadb.com/enterprise-server | 11.4.7-4.3 <br> 11.4.7-4.2 <br> 11.4.7-4.1 <br> 11.4 <br> 10.6.22-18.1 <br> 10.6 <br> | amd64 <br> arm64 <br> ppc64le <br> |
| MariaDB Enterprise Server | docker.mariadb.com/enterprise-server | 11.4.5-3 <br> 11.4.4-2 <br> 10.6.21-17 <br> 10.6.20-16.1 <br> 10.6.19-15.1 <br> 10.6.18-14.2 <br> 10.6.17-13.2 <br> | amd64 <br> arm64 <br> |
| MaxScale Enterprise (ppc64le support) | docker.mariadb.com/maxscale | 25.01.3-1 <br> 25.01 <br> | amd64 <br> arm64 <br> ppc64le <br> |
| MaxScale Enterprise | docker.mariadb.com/maxscale-enterprise | 25.01.2 <br> 25.01.1 <br> | amd64 <br> arm64 <br> |
Expand Down
300 changes: 300 additions & 0 deletions tools/mariadb-enterprise-operator/plugins/hashicorp-key-management.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
# Hashicorp Key Management Plugin

The [Hashicorp Key Management Pugin](../../../server/security/securing-mariadb/encryption/data-at-rest-encryption/key-management-and-encryption-plugins/hashicorp-key-management-plugin.md) is used to implement encryption using keys stored in the Hashicorp Vault KMS.

{% hint style="info" %}
For more information about configuring the plugin as well as different capabilities, please check the [documentation](../../../server/security/securing-mariadb/encryption/data-at-rest-encryption/key-management-and-encryption-plugins/hashicorp-key-management-plugin.md). This guide will cover a minimal example for configuring the plugin with the operator.
{% endhint %}

## Configuring TDE in MariaDB Using Hashicorp Key Management Plugin

Transparent Data Encryption (TDE) can be configured in MariaDB leveraging the Hashicorp Key Management Plugin.

### Requirements

- Running and accessible Vault KMS setup with a valid SSL certificate.
- Vault is unsealed and you've logged in to it with `vault login $AUTH_TOKEN`, where $AUTH_TOKEN is an authentication token given to you by an administrator
- `openssl` for generating secrets

### Steps

1. **Creating A New Key-Value Store In Vault.**
Create a new key-value store and take note of the `path`. In our example we will use `mariadb`.
```sh
vault secrets enable -path /mariadb -version=2 kv
```

2. **Adding necessary secrets.**
We will put 2 secrets with ids `1` and `2`. `2` will be used for temporary files, while `1` will be used for everything else. It is not
neccessary to create 2 of them and in that case, temporary files will use `1`.

Note: Here you should use the `path` we chose in the previous step.
```sh
vault kv put /mariadb/1 data="$(openssl rand -hex 32)"
vault kv put /mariadb/2 data="$(openssl rand -hex 32)"
```

3. **(Optional) Create An Authentication Token With Policy.**
This step can be skipped if you want to use your own token. Consult with a Vault administrator regarding this.
Policies are Vault's way to restrict access to what you are allowed to do. The following is a policy that should be used by the token following the least permission principle.
```sh
cat <<'EOF' | vault policy write -non-interactive mariadb -
# Allow access to MariaDB secrets
path "mariadb/*" {
capabilities = ["create", "read", "update", "delete", "list"]
}

# Allow reading the mount configuration
path "sys/mounts/mariadb/tune" {
capabilities = ["read"]
}
EOF
```
After which, we can create a new token with the given policy.
```sh
vault token create -policy mariadb
```
You will see output similar to:
```
Key Value
--- -----
token EXAMPLE_TOKEN
token_accessor utFtmh98YAAJyYdxEVN3SFQA
token_duration 768h
token_renewable true
token_policies ["default" "mariadb"]
identity_policies []
policies ["default" "mariadb"]
```
Your new token is: `EXAMPLE_TOKEN`.

4. **Create A `Secret` For the vault token.**
Now that you've either created a new token, or are using an existing one, we need to create a secret with it.
```sh
export TOKEN="EXAMPLE_TOKEN"
kubeclt create secret generic mariadb-vault-token --from-literal=token="$TOKEN"
```

5. **Create a Secret for the Certificate Authority (CA) used to issue the Vault certificate.**
For further information, consult [the docs](../../../server/security/securing-mariadb/encryption/data-at-rest-encryption/key-management-and-encryption-plugins/hashicorp-key-management-plugin.md#hashicorp-key-management-vault-ca)
If you have the certificate locally in a file called `ca.crt` you can run:

```sh
kubectl create secret generic vault-tls --from-file=./ca.crt
```

5. **Create A MariaDB Custom Resource.**
The final step is creating a new MariaDB instance.

**mariadb-vault.yaml**
```yaml
---
apiVersion: v1
kind: Secret
metadata:
name: mariadb # Used to hold the mariadb and root user passwords
labels:
enterprise.mariadb.com/watch: ""
stringData:
password: MariaDB11!
root-password: MariaDB11!
---
apiVersion: enterprise.mariadb.com/v1alpha1
kind: MariaDB
metadata:
name: mariadb
spec:
image: docker.mariadb.com/enterprise-server:11.4.7-4.3
rootPasswordSecretKeyRef:
name: mariadb
key: password

username: mariadb
passwordSecretKeyRef:
name: mariadb-password
key: password
generate: true
database: mariadb

port: 3306

storage:
size: 1Gi
# storageClassName: csi-hostpath-sc

myCnf: |
[mariadb]
bind-address=*
default_storage_engine=InnoDB
binlog_format=row
innodb_autoinc_lock_mode=2
innodb_buffer_pool_size=800M
max_allowed_packet=256M

plugin_load_add = hashicorp_key_management
hashicorp-key-management-vault-url=https://vault-0.vault-internal.default.svc.cluster.local:8200/v1/mariadb
hashicorp-key-management-caching-enabled=ON
hashicorp-key-management-vault-ca=/etc/vault/certs/ca.crt

innodb_encrypt_tables = FORCE
innodb_encrypt_log = ON
innodb_encrypt_temporary_tables = ON
encrypt_tmp_disk_tables = ON
encrypt_tmp_files = ON
encrypt_binlog = ON
aria_encrypt_tables = ON

innodb_encryption_threads = 4
innodb_encryption_rotation_iops = 2000

env:
- name: VAULT_TOKEN # This is where our token is defined!
valueFrom:
secretKeyRef:
name: mariadb-vault-token
key: token

resources:
requests:
cpu: 100m
memory: 128Mi
limits:
memory: 1Gi

metrics:
enabled: true

volumes:
- name: vault-certificates
secret:
secretName: vault-tls
defaultMode: 0600
volumeMounts:
- name: vault-certificates
mountPath: /etc/vault/certs/
```
`kubectl apply -f mariadb-vault.yaml`

6. **Verify Encryption Works.**
```sh
kubectl run mariadb-connect --rm -it --image=mariadb:11.4 -- bash -c "mariadb -u root -p'MariaDB11!' --ssl=false -h mariadb"
```

You should see something along the lines of:

```
If you don't see a command prompt, try pressing enter.
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 95
Server version: 11.4.7-4-MariaDB-enterprise MariaDB Enterprise Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>
```

At this point, you can check the encryption status:
```sql
SELECT * from information_schema.INNODB_TABLESPACES_ENCRYPTION;
```

If you create a new database and then table, the above query should return additional information about them. Something like:
```sql
MariaDB [my_db]> SELECT * from information_schema.INNODB_TABLESPACES_ENCRYPTION;
+-----------------+-------------------+-----------------+---------------------+----------------+----------------------+
| NAME | ENCRYPTION_SCHEME | MIN_KEY_VERSION | CURRENT_KEY_VERSION | CURRENT_KEY_ID | ROTATING_OR_FLUSHING |
+-----------------+-------------------+-----------------+---------------------+----------------+----------------------+
| innodb_system | 1 | 1 | 1 | 1 | 0 |
| innodb_undo001 | 1 | 1 | 1 | 1 | 0 |
| innodb_undo002 | 1 | 1 | 1 | 1 | 0 |
| innodb_undo003 | 1 | 1 | 1 | 1 | 0 |
| mysql/innodb_ta | 1 | 1 | 1 | 1 | 0 |
| mysql/innodb_in | 1 | 1 | 1 | 1 | 0 |
| mysql/gtid_slav | 1 | 1 | 1 | 1 | 0 |
| mysql/transacti | 1 | 1 | 1 | 1 | 0 |
| my_db/people | 1 | 1 | 1 | 1 | 0 |
+-----------------+-------------------+-----------------+---------------------+----------------+----------------------+
```
Note: The above query is truncated. In reality, you will see a few more columns.

## Day-2 Operations

### Rotating Secrets

1. **Put A New Secret In Vault.**
After logging in to vault, you can run again:
```sh
vault kv put /mariadb/1 data="$(openssl rand -hex 32)"
vault kv put /mariadb/2 data="$(openssl rand -hex 32)"
```
This will start re-encrypting data.

2. **Monitor Re-Encryption.**
```sh
kubectl run mariadb-connect --rm -it --image=mariadb:11.4 -- bash -c "mariadb -u root -p'MariaDB11!' --ssl=false -h mariadb"
```
If you check the encrpytion status again:
```sql
SELECT * from information_schema.INNODB_TABLESPACES_ENCRYPTION;
```
You should see `CURRENT_KEY_VERSION` column start getting updated to point to the new key version.
```sql
MariaDB [my_db]> SELECT * from information_schema.INNODB_TABLESPACES_ENCRYPTION;
+-----------------+-------------------+-----------------+---------------------+----------------+----------------------+
| NAME | ENCRYPTION_SCHEME | MIN_KEY_VERSION | CURRENT_KEY_VERSION | CURRENT_KEY_ID | ROTATING_OR_FLUSHING |
+-----------------+-------------------+-----------------+---------------------+----------------+----------------------+
| innodb_system | 1 | 1 | 2 | 1 | 0 |
| innodb_undo001 | 1 | 1 | 2 | 1 | 0 |
| innodb_undo002 | 1 | 1 | 2 | 1 | 0 |
| innodb_undo003 | 1 | 1 | 2 | 1 | 0 |
| mysql/innodb_ta | 1 | 1 | 2 | 1 | 0 |
| mysql/innodb_in | 1 | 1 | 2 | 1 | 0 |
| mysql/gtid_slav | 1 | 1 | 2 | 1 | 0 |
| mysql/transacti | 1 | 1 | 2 | 1 | 0 |
| my_db/people | 1 | 1 | 2 | 1 | 0 |
+-----------------+-------------------+-----------------+---------------------+----------------+----------------------+
```

### Rotating Token
Make sure when rotating the token, to do so in advance of the token expiring.

1. **Acquire a new token and update the secret.**

```sh
export TOKEN="EXAMPLE_TOKEN"
kubeclt create secret generic mariadb-vault-token --from-literal=token="$TOKEN"
```

2. **Restart The MariaDB StatefulSet.**
MariaDB will continue using the old token until the StatefulSet is restarted. If the name of the `MariaDB` CR is `mariadb` (as per the example above), then:
```sh
kubectl rollout restart statefulset mariadb
```

## Known Issues/Limitations

### **Vault Not Being Accessible Will Result In MariaDB Not Working**

As MariaDB uses Vault to fetch it's decryption key, in case that Vault becomes unavailable, it will result in MariaDB not being able to fetch the decryption key and hence stop working. While the Hashicorp plugin has a configurable cache, that should be set and will result in MariaDB still working for a few seconds to minutes, depending on configuration, the cache is not reliable as it's ephemeral and short lived.

### **Deleting The Decryption Key Will Make Your Data Inaccessible.**

It is recommended to back up the decryption key so accidental deletions will not result in issues.

### **Decryption Key Must Be Hexadecimal**

Use the following to generate correct decryption keys.
```sh
openssl rand -hex 32
```

### **Rotating The Decryption Key Before A Previous Re-Encryption Has Finished, Will Result In Data Corruption.**
To check the re-encryption progress, you can run:

```sql
SELECT * from information_schema.INNODB_TABLESPACES_ENCRYPTION;
```

Look for the `CURRENT_KEY_VERSION` and make sure they are in sync with the latest version you have in Vault.
6 changes: 2 additions & 4 deletions tools/mariadb-enterprise-operator/plugins/pam.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ kind: Secret
type: Opaque
metadata:
name: mariadb-nslcd-secret
labels:
enterprise.mariadb.com/watch: ""
stringData:
nslcd.conf: |
# /etc/nslcd.conf: Configuration file for nslcd(8)
Expand Down Expand Up @@ -179,11 +177,11 @@ metadata:
spec:
rootPasswordSecretKeyRef:
name: mariadb
key: password
key: root-password

username: mariadb
passwordSecretKeyRef:
name: mariadb-password
name: mariadb
key: password
generate: true
database: mariadb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Each supported plugin will have a section on how to install it.

| Component | Image | Supported Tags | CPU Architecture |
|-----------|-------|----------------|------------------|
| MariaDB Enterprise Server (ppc64le support) | docker.mariadb.com/enterprise-server | 11.4.7-4.2 <br> 11.4 <br> | amd64 <br> arm64 <br> ppc64le <br> |
| MariaDB Enterprise Server (ppc64le support) | docker.mariadb.com/enterprise-server | 11.4.7-4.3 <br> 11.4 <br> | amd64 <br> arm64 <br> ppc64le <br> |

{% include "https://app.gitbook.com/s/SsmexDFPv2xG2OTyO5yV/~/reusable/pNHZQXPP5OEz2TgvhFva/" %}

Expand Down