Quarkus 整合 Vault KV 引擎
備註
本篇文章內容與實驗會同步 CCH0124 - vault-demo
HashiCorp Vault 屬於 CNCF 的 Key Management 類別的一員。
現今服務開發對於應用程式存取機密性資料相對都是難免,無論是在原始碼、配置檔或是其它位置。如果沒有一個機制來控管授權,想必是相當的可怕隨時都有洩漏危機。透過 Vault 可以集中管理這些機密資源,應用程式或是使用者要存取機密資源都需經過身分驗證來獲取相對應訪問資源,這樣可減少不必要的洩漏。
本文章會學習到以下
- 安裝 Vault
- 使用 Vault Client 交互
- 使用 KV 引擎
- 設置 Vault Auth (Token/Kubernetes)
- 設置 Vault Policy
- Quarkus 框架整合 Vault KV 引擎
實驗環境
- OS: Windows 11 WSL
- Docker Engine: 23.0.5
- k3d version: v5.4.9
- kubectl version: v1.27.1
- Helm version: v3.11.3
- Vault chart version: 0.25.0
環境安裝與配置
安裝完 k3d 後,使用下面 k3d 配置檔案建立一個 Kubernetes 環境 :
## vault-conf.yaml
apiVersion: k3d.io/v1alpha4 # this will change in the future as we make everything more stable
kind: Simple # internally, we also have a Cluster config, which is not yet available externally
metadata:
name: vault-cluster # name that you want to give to your cluster (will still be prefixed with `k3d-`)
servers: 1 # same as `--servers 1`
agents: 2 # same as `--agents 2`
kubeAPI: # same as `--api-port myhost.my.domain:6445` (where the name would resolve to 127.0.0.1)
host: "vault.cch.com" # important for the `server` setting in the kubeconfig
hostIP: "127.0.0.1" # where the Kubernetes API will be listening on
hostPort: "6450"
image: rancher/k3s:v1.23.14-k3s1
network: argo-net
ports:
- port: 8050:80
nodeFilters:
- loadbalancer
- port: 8453:443
nodeFilters:
- loadbalancer
options:
k3s:
extraArgs:
- arg: --disable=traefik
nodeFilters:
- server:*