MySQL encryption / TLS / key management 的核心責任是把資料庫保護拆成儲存加密、傳輸加密、金鑰生命週期與連線憑證治理。Encryption 是多層保護設計;它涵蓋 InnoDB tablespace、redo / undo、binary log、backup artifact、client connection 與 keyring。

本文的判讀錨點是:加密要服務於 threat model。若風險是磁碟遺失,at-rest encryption 是重點;若風險是網路攔截,TLS 是重點;若風險是內部濫用,還需要 role、audit、masking 與 SIEM。

官方文件路由的核心責任是固定 MySQL 8.4 security claim。實作前先查 InnoDB data-at-rest encryptionMySQL keyringSHOW BINARY LOG STATUS;本文最後檢查日是 2026-05-22。

Protection Layers

Protection layers 的核心責任是把保護面分層。

層級主要責任Evidence
At-rest encryptiondata file、redo、undo、tempencryption setting、keyring status
In-transit TLSclient / replica / admin connectionTLS mode、certificate、cipher
Backup encryptiondump、snapshot、physical backupencrypted artifact、restore drill
Key managementkey generation、rotation、accessKMS / keyring log、rotation record
Credential governanceuser password、secret、rotationgrant review、secret age

這些層級要一起設計。資料檔加密後,backup 若以明文落到 object storage,保護鏈仍然破洞;TLS 開啟後,client 若允許 insecure fallback,也會失去網路保護。

Keyring Boundary

Keyring boundary 的核心責任是定義 MySQL 如何取得與保護 encryption key。MySQL 支援 keyring component / plugin 與外部 KMS 整合;managed MySQL 可能由 provider 接管 key storage。

部署型態key 責任審查問題
Self-managed自行部署 keyring / KMSkey file permission、backup、rotation
Managed MySQLprovider KMS / customer-managed keyregion、rotation、audit、restore
Container labdev-only keyring避免和 production policy 混用

Keyring 要進入 backup / restore drill。還原 database 時,只有 data file 而沒有對應 key,restore 會失敗;runbook 要保存 key dependency 與 emergency access。

TLS Policy

TLS policy 的核心責任是讓 client connection、replication connection 與 admin connection 都有明確安全等級。

連線類型建議檢查
Applicationrequire SSL、verify CA / identity
Replicationsource / replica TLS、cert expiry
Adminbastion / VPN / TLS、least privilege
Backup toolencrypted transport、secret scope

TLS 驗證要包含 certificate rotation。過期憑證造成的 downtime 很常見;runbook 要記錄 CA、server cert、client cert、rotation window 與 reload / restart 條件。

1SHOW VARIABLES LIKE 'require_secure_transport';
2SHOW STATUS LIKE 'Ssl_cipher';

這些查詢只能提供 connection 層 evidence。正式驗證還要從 client 設定確認 ssl-mode 是否驗證 CA / identity。

Backup and Binlog Encryption

Backup and binlog encryption 的核心責任是保護資料離開 primary 後的生命週期。MySQL backup、binlog、logical dump、object storage、replica seed 都可能含敏感資料。

Artifact保護方式
Logical dumpclient-side encryption、storage policy
Physical backupbackup tool encryption、KMS
Binlogencrypted storage、restricted access
Snapshotvolume encryption、snapshot policy
Restore copyisolated environment、secret scoping

Restore drill 要確認加密 artifact 可被解密並啟動。只有成功產出 encrypted backup,還不足以證明災難時能恢復。

Rotation Runbook

Rotation runbook 的核心責任是讓 key、certificate、password 都可定期更換。

  1. Inventory:列出 DB user、TLS cert、KMS key、backup key。
  2. Impact:確認哪些 client / replica / backup job 使用它。
  3. Staging:先在 staging 旋轉並跑 smoke test。
  4. Rollout:使用雙憑證 / 雙 secret window。
  5. Validation:查連線、replication、backup、restore。
  6. Cleanup:移除舊 key / cert / secret。

Rotation 要設 calendar 與 owner。安全設定長期無人輪替時,incident 後會難以判斷 exposure window。

Failure Modes

Failure modes 的核心責任是提前列出加密常見事故。

Failure mode判讀訊號修正方向
TLS fallbackclient 仍可明文連線require secure transport、client verify
Cert expiryapplication connection failurerotation alert、dual cert window
Missing keyringrestore / startup failurekey backup、KMS access drill
Plain backupstorage artifact 未加密backup pipeline policy
Overbroad secretadmin / app 共用 credentialrole split、secret rotation

安全 runbook 要和 audit log 串接。Key rotation、failed TLS、privilege change、restore access 都應留下可追溯紀錄。

下一步路由

Encryption / TLS / key management 完成後,操作證據讀 Audit Log + SIEM;備份恢復讀 PITR / Backup;資料保護治理讀 Data Protection