Hashicorp Key Management
Configuring TDE in MariaDB Using Hashicorp Key Management Plugin
Requirements
Steps
vault secrets enable -path /mariadb -version=2 kvvault kv put /mariadb/1 data="$(openssl rand -hex 32)" vault kv put /mariadb/2 data="$(openssl rand -hex 32)"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"] } EOFvault token create -policy mariadbKey Value --- ----- token EXAMPLE_TOKEN token_accessor utFtmh98YAAJyYdxEVN3SFQA token_duration 768h token_renewable true token_policies ["default" "mariadb"] identity_policies [] policies ["default" "mariadb"]export TOKEN="EXAMPLE_TOKEN" kubeclt create secret generic mariadb-vault-token --from-literal=token="$TOKEN"kubectl create secret generic vault-tls --from-file=./ca.crt--- 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 run mariadb-connect --rm -it --image=mariadb:11.4 -- bash -c "mariadb -u root -p'MariaDB11!' --ssl=false -h mariadb"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)]>SELECT * from information_schema.INNODB_TABLESPACES_ENCRYPTION;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 | +-----------------+-------------------+-----------------+---------------------+----------------+----------------------+
Day-2 Operations
Rotating Secrets
Rotating Token
Known Issues/Limitations
Vault Not Being Accessible Will Result In MariaDB Not Working
Deleting The Decryption Key Will Make Your Data Inaccessible.
Decryption Key Must Be Hexadecimal
Rotating The Decryption Key Before A Previous Re-Encryption Has Finished, Will Result In Data Corruption.
Last updated
Was this helpful?

