1
1
# Vault CSI Provider
2
2
3
- 本指南将向你展示, KCL/Kusion 通过集成 Vault CSI Provider,解决敏感信息的传输问题。
4
- 本次演示是将数据库的用户名和密码传输到 Pod 中,涉及 3 个 Kubernetes 内置资源和 1 个 自定义资源:
3
+ This guide will show you that KCL/Kusion solves the secret management problem by integrating Vault CSI Provider.
4
+ We will pass the database username and password into the Pod, involving 3 kubernetes built-in resources and 1 custom resource:
5
5
6
- - 命名空间( Namespace)
7
- - 无状态应用( Deployment)
8
- - 服务账号( ServiceAccount)
9
- - 自定义资源( SecretProviderClass)
6
+ - Namespace
7
+ - Deployment
8
+ - ServiceAccount
9
+ - SecretProviderClass
10
10
11
11
::: tip
12
- 本指南要求你对 Kubernetes 有基本的了解。不清楚相关概念的,可以前往 Kubernetes 官方网站,查看相关说明:
12
+
13
+ This guide requires you to have a basic understanding of Kubernetes.
14
+ If you are not familiar with the relevant concepts, please refer to the links below:
13
15
- [ Learn Kubernetes Basics] ( https://kubernetes.io/docs/tutorials/kubernetes-basics/ )
14
16
- [ Namespace] ( https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ )
15
17
- [ Deployment] ( https://kubernetes.io/docs/concepts/workloads/controllers/deployment/ )
16
18
- [ ServiceAccount] ( https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/ )
17
19
- [ SecretProviderClass] ( https://secrets-store-csi-driver.sigs.k8s.io/concepts.html#custom-resource-definitions-crds )
18
20
:::
19
21
20
- ## 1. 准备开始
21
-
22
- 在开始之前,我们需要做以下准备工作:
22
+ ## Prerequisites
23
23
24
- 1、安装 Kusion 工具链
24
+ Before we start, we need to complete the following steps first:
25
25
26
- 我们推荐使用 kusion 的官方安装工具 ` kusionup ` ,可实现 kusion 多版本管理等关键能力。
27
- 详情信息请参阅[ 下载和安装] ( /docs/user_docs/getting-started/install ) 。
26
+ 1、Install Kusion
28
27
29
- 2、下载开源 Konfig 大库
28
+ We recommend using the official installation tool _ kusionup_ which supports multi-version management.
29
+ See [ Download and Install] ( /docs/user_docs/getting-started/install ) for more details.
30
30
31
- 在本篇指南中,需要用到部分已经抽象实现的 KCL 模型。
32
- 有关 KCL 语言的介绍,可以参考 [ Tour of KCL] ( /reference/lang/lang/tour.md ) 。
31
+ 2、Clone Konfig repo
33
32
34
- 仓库地址: https://github.com/KusionStack/konfig.git
33
+ In this guide, we need some KCL models that [ Konfig] ( https://github.com/KusionStack/konfig.git ) offers.
34
+ For more details on KCL language, please refer to [ Tour of KCL] ( /docs/reference/lang/lang/tour ) .
35
35
36
- 3、可用的 Kubernetes 集群
36
+ 3、Running Kubernetes cluster
37
37
38
- 必须要有一个 Kubernetes 集群,同时 Kubernetes 集群最好带有
39
- [ kubectl] ( https://kubernetes.io/docs/tasks/tools/#kubectl ) 命令行工具。
40
- 如果你还没有集群,你可以通过 [ Minikube] ( https://minikube.sigs.k8s.io/docs/tutorials/multi_node/ )
41
- 构建一个你自己的集群。
38
+ There must be a running Kubernetes cluster and a [ kubectl] ( https://Kubernetes.io/docs/tasks/tools/#kubectl ) command line tool.
39
+ If you don't have a cluster yet, you can use [ Minikube] ( https://minikube.sigs.k8s.io/docs/tutorials/multi_node/ ) to start one of your own.
42
40
43
- 4、可用的 Helm CLI
41
+ 4、Available Helm CLI
44
42
45
- Helm 工具用来部署 Vault Server 和 CSI Driver。
46
- 如果你还没有安装 Helm,请参阅 [ Helm 官方地址 ] ( https://helm.sh/docs/intro/install/ ) 。
43
+ The Helm tool is used to deploy the Vault server and CSI driver.
44
+ If you haven't installed Helm, please refer to [ Install Helm ] ( https://helm.sh/docs/intro/install/ ) .
47
45
48
- ## 2. 安装 Vault 和 CSI Driver
46
+ ## Install Vault server and CSI driver
49
47
50
- 推荐使用 Helm Chart 在 Kubernetes 上部署 Vault Server 和 CSI Driver
51
- [ Helm] ( https://helm.sh/docs/helm/ ) 是一个包管理器,
52
- 它可以安装和配置 Vault 及其相关组件,以不同模式运行。
53
- Helm Chart 实现了模板的条件化和参数化。这些参数可以通过命令行参数设置或在 YAML 中定义。
48
+ We recommend deploying the Vault server and CSI driver on Kubernetes by _ Helm Chart_ .
49
+ [ Helm] ( https://helm.sh/docs/helm/ ) is a package manager,
50
+ which can install and configure Vault and its related components in different modes.
51
+ Helm chart implements conditionalization and parameterization of templates.
52
+ These parameters can be set via command line arguments or defined in YAML files.
54
53
55
- ### 2.1 安装 Vault
54
+ ### Install Vault server
56
55
57
- 1、添加 HashiCorp Helm 存储库:
56
+ 1、Add HashiCorp helm repository:
58
57
``` bash
59
58
helm repo add hashicorp https://helm.releases.hashicorp.com
60
59
```
61
60
62
- 2、更新所有存储库以确保 helm 缓存了最新版本:
61
+ 2、Update to cache HashiCorp's latest version:
63
62
``` bash
64
63
helm repo update
65
64
```
66
65
67
- 3、安装最新版本的 Vault Server,以开发模式运行,禁用 Injector 服务并启用 CSI:
66
+ 3、Install Vault server, start in development mode, disable Injector and enable CSI:
68
67
``` bash
69
68
helm install vault hashicorp/vault \
70
69
--set " server.dev.enabled=true" \
71
70
--set " injector.enabled=false" \
72
71
--set " csi.enabled=true"
73
72
```
74
- ` server.dev.enabled=true ` 表示 Vault 在单 Pod 上以开发者模式启动;
75
- ` injector.enabled=false ` 表示禁用 Injector 服务;
76
- ` csi.enabled=true ` 表示启用 Vault CSI Pod。
77
- 如果你已经安装了 Vault,可以使用 ` helm upgrade ` 命令来更新 Vault 的部署模式。
73
+ ` server.dev.enabled=true ` indicates that Vault is started in developer mode on a single pod.
74
+ ` injector.enabled=false ` indicates that the Injector service is disabled;
75
+ ` csi.enabled=true ` Indicates that the Vault CSI Pod is enabled.
76
+ If you already have Vault installed, you can use the ` helm upgrade ` command to update Vault's deployment mode.
78
77
79
- 4、检查 Default 命名空间中的所有 Pod:
78
+ 4、Check all pods in the default namespace:
80
79
``` bash
81
80
kubectl get pod
82
81
NAME READY STATUS RESTARTS AGE
83
82
vault-0 1/1 Running 0 17m
84
83
vault-csi-provider-456hl 1/1 Running 0 17m
85
84
```
86
- 等到 ` vault-0 ` 的状态是 ` Running ` 并且准备就绪(` 1/1 ` ),再继续本指南。
87
85
88
- ### 2.2 安装 CSI Driver
86
+ Wait until the status of ` vault-0 ` is ` Running ` and ready ( ` 1/1 ` ) before continuing with this guide.
89
87
90
- [ Secrets Store CSI 驱动程序] ( https://secrets-store-csi-driver.sigs.k8s.io/introduction.html )
91
- ` secrets-store.csi.k8s.io ` 允许 Kubernetes 将存储在外部机密存储中的多个机密、密钥和证书作为卷挂载到其 Pod 中。
92
- 附加卷后,其中的数据将被挂载到容器的文件系统中。
88
+ ### Install CSI driver
89
+
90
+ [ Secrets Store CSI Driver] ( https://secrets-store-csi-driver.sigs.k8s.io/introduction.html )
91
+ ` secrets-store.csi.k8s.io ` allows Kubernetes to mount multiple secrets, keys,
92
+ and certs stored in enterprise-grade external secrets stores into their pods as a volume.
93
+ Once the volume is attached, the data in it is mounted into the container’s file system.
93
94
94
95
::: tip
95
- [ 容器存储接口(CSI)] ( https://github.com/container-storage-interface/spec/blob/master/spec.md )
96
- 是一种标准,用于将任意块和文件存储系统暴露给 Kubernetes 等容器编排系统 (CO) 上的容器化工作负载。
97
- 使用 CSI 第三方存储提供商可以编写和部署插件,在 Kubernetes 中公开新的存储系统,而无需接触核心 Kubernetes 代码。
96
+
97
+ The [ Container Storage Interface (CSI)] ( https://github.com/container-storage-interface/spec/blob/master/spec.md )
98
+ is a standard for exposing arbitrary block and file storage systems
99
+ to containerized workloads on Container Orchestration Systems (COs) like Kubernetes.
100
+ Using CSI third-party storage providers can write and deploy plugins exposing new storage systems in Kubernetes
101
+ without ever having to touch the core Kubernetes code.
98
102
:::
99
103
100
- 1、添加 CSI 驱动的 Helm 存储库:
104
+ 1、Add CSI driver helm repository:
101
105
``` bash
102
106
helm repo add secrets-store-csi-driver https://kubernetes-sigs.github.io/secrets-store-csi-driver/charts
103
107
```
104
108
105
- 2、安装最新版本的 Kubernetes-Secrets-Store-CSI-Driver:
109
+ 2、Install Kubernetes-Secrets-Store-CSI-Driver:
106
110
``` bash
107
111
helm install csi secrets-store-csi-driver/secrets-store-csi-driver --namespace kube-system
108
112
```
109
- ` csi-secrets-store-csi-driver ` 是以 DemonSet 形式部署在 ` kube-system ` 命名空间。
110
113
111
- 3、检查 CSI Driver 的 Pod 是否启动:
114
+ 3、Check CSI driver pods:
112
115
``` bash
113
116
kubectl --namespace=kube-system get pods -l " app=secrets-store-csi-driver"
114
117
NAME READY STATUS RESTARTS AGE
115
118
csi-secrets-store-csi-driver-2wl2f 3/3 Running 0 2m
116
119
```
117
- 等待 ` csi-secrets-store-csi-driver-2wl2f ` 的状态是 ` Running ` ,并且已经准备就绪(` 3/3 ` ),再继续本指南。
118
120
119
- ## 3. 配置 Vault
121
+ Wait until the status of pod ` csi-secrets-store-csi-driver-2wl2f ` is ` Running ` and is ready ( ` 3/3 ` ) before continuing with this guide.
120
122
121
- Vault 将机密数据保存在自己的数据库中,用户需要先配置相关机密数据,并启用 Vault 的 Kubernetes 认证。
123
+ ## Configure Vault
122
124
123
- ### 3.1 配置机密数据 {#set-secret- data}
125
+ Vault stores confidential data in its database, and users need to configure the relevant confidential data and enable Vault's Kubernetes authentication.
124
126
125
- 在[ 创建挂载 Vault Secret 的 Pod] ( #create-pod-with-secret-mounted ) 小节,挂载到 Pod 中的卷,
126
- 引用了保存在 ` secret/data/db-pass ` 路径下的 secret 。
127
- Vault 以开发模式运行时,kv 引擎会启用默认路径 ` /secret ` 。
127
+ ### Create a secret
128
128
129
- 1、在 ` vault-0 ` 启动交互式 shell 终端:
129
+ In [ Create a pod with a secret mounted] ( #create-a-pod-with-a-secret-mounted ) section,
130
+ the volume mounted in Pod expects secret stored at path ` secret/data/db-pass ` .
131
+ When Vault is run in development a K/V secret engine is enabled at the path ` /secret ` .
132
+
133
+ 1、start an interactive shell session on the ` vault-0 ` pod:
130
134
``` bash
131
135
kubectl exec -it vault-0 -- /bin/sh
132
136
```
133
137
134
- 2、在 ` secret/db-pass ` 路径创建带有密码的 secret:
138
+ 2、Create a secret at the path ` secret/db-pass ` with a password:
135
139
``` bash
136
140
vault kv put secret/db-pass password=" db-secret-password"
137
141
```
138
142
139
- 输出类似于:
143
+ The output is similar to:
140
144
```
141
145
Key Value
142
146
--- -----
@@ -147,12 +151,12 @@ destroyed false
147
151
version 1
148
152
```
149
153
150
- 3、验证 secret 在路径 ` / secret/db-pass` 上是否可读:
154
+ 3、Verify that the secret is readable at the path ` secret/db-pass ` .
151
155
``` bash
152
156
vault kv get secret/db-pass
153
157
```
154
158
155
- 输出类似于:
159
+ The output is similar to:
156
160
```
157
161
======= Metadata =======
158
162
Key Value
@@ -168,24 +172,24 @@ Key Value
168
172
--- -----
169
173
password db-secret-password
170
174
```
171
- 到此,机密数据创建完毕,暂且不需要退出 Pod。
175
+ For now, the confidential data is created, please don't exit the vault pod immediately.
172
176
173
- ### 3.2 启用 kubernetes 身份认证
177
+ ### Enable Kubernetes authentication
174
178
175
- Vault 提供了 Kubernetes 身份验证方法,使客户端能够使用 Kubernetes ServiceAccount 令牌进行身份验证。
176
- 此令牌在创建时提供给每个 Pod。
179
+ Vault provides a Kubernetes authentication method that enables clients to authenticate with a Kubernetes ServiceAccount Token.
180
+ The Kubernetes resources that access the secret and create the volume authenticate through this method through a ` role ` .
177
181
178
- 1、继续上一小节的 Terminal,启用 Kubernetes 身份验证:
182
+ 1、Continue with the terminal in the previous step, and enable the Kubernetes authentication method:
179
183
``` bash
180
184
vault auth enable kubernetes
181
185
```
182
- 输出类似于:
186
+
187
+ The output is similar to:
183
188
```
184
189
Success! Enabled kubernetes auth method at: kubernetes/
185
190
```
186
191
187
- 2、配置 kubernetes 身份认证规则,依赖 Kubernetes API 地址、ServiceAccount 令牌、
188
- 证书以及 Kubernetes ServiceAccount 的颁发者(Kubernetes 1.21+ 需要):
192
+ 2、Configure authentication rules, depending on the Kubernetes API address, ServiceAccount token, certificate, and the issuer of the Kubernetes ServiceAccount(required for Kubernetes 1.21+):
189
193
``` bash
190
194
vault write auth/kubernetes/config \
191
195
kubernetes_host=" https://$KUBERNETES_PORT_443_TCP_ADDR :443" \
@@ -194,18 +198,15 @@ vault write auth/kubernetes/config \
194
198
issuer=" https://kubernetes.default.svc.cluster.local"
195
199
```
196
200
197
- 输出类似于:
201
+ The output is similar to:
198
202
```
199
203
Success! Data written to: auth/kubernetes/config
200
204
```
201
- Kubernetes 创建容器时,将 ` token_reviewer_jwt ` 和 ` kubernetes_ca_cert ` 挂载到容器中。
202
- 环境变量 ` KUBERNETES_PORT_443_TCP_ADDR ` 引用的是 Kubernetes 主机的内部网络地址。
203
-
204
- 3、设置读权限的 _ policy_
205
205
206
- Kubernetes-Secrets-Store-CSI-Driver 需要读取密钥,保证它对挂载的卷和卷中密钥有读权限。
206
+ When Kubernetes creates pods, mount ` token_reviewer_jwt ` and ` Kubernetes_ca_cert ` into them.
207
+ The environment variable ` KUBERNETES_PORT_443_TCP_ADDR ` references the internal network address of the Kubernetes host.
207
208
208
- 创建名为 ` kcl-vault-csi-policy ` 的 _ policy _ :
209
+ 3、Create a policy named ` kcl-vault-csi-policy ` :
209
210
``` bash
210
211
vault policy write kcl-vault-csi-policy - << EOF
211
212
path "secret/data/db-pass" {
@@ -214,7 +215,9 @@ path "secret/data/db-pass" {
214
215
EOF
215
216
```
216
217
217
- 4、再创建名为 ` kcl-vault-csi-role ` 的 _ role_ ,关联上一步创建的 _ policy_ ,并绑定 Namespace 和 ServiceAccount:
218
+ Kubernetes-Secrets-Store-CSI-Driver needs to read the secret key, which must have read access to the mounted volume.
219
+
220
+ 4、Create a role named ` kcl-vault-csi-role ` :
218
221
``` bash
219
222
vault write auth/kubernetes/role/kcl-vault-csi-role \
220
223
bound_service_account_names=kcl-vault-csi-sa \
@@ -223,28 +226,31 @@ vault write auth/kubernetes/role/kcl-vault-csi-role \
223
226
ttl=24h
224
227
```
225
228
226
- 输出类似于:
229
+ The output is similar to:
227
230
```
228
231
Success! Data written to: auth/kubernetes/role/kcl-vault-csi-role
229
232
```
230
- 该角色将 Kubernetes 服务帐户 _ kcl-vault-csi-sa_ 和命名空间 _ kcl-vault-csi_ 与 Vault 策略 _ kcl-vault-csi-role_ 关联起来。
231
- 此 Kubernetes 服务帐户将会在后面创建。认证成功后返回的令牌有效期为 24 小时。最后,执行 ` exit ` 退出 Pod。
232
233
233
- ## 4. 结果验证 {#verify-result}
234
+ This role associates the Kubernetes service account ` kcl-vault-csi-sa ` and namespace ` kcl-vault-csi ` with the Vault policy ` kcl-vault-csi-role ` .
235
+ This Kubernetes service account will be created later. The token returned after successful authentication is valid for 24 hours.
236
+ Finally, exit the ` vault-0 ` pod.
237
+
238
+ ## Verify Secret
234
239
235
- 上一节我们已经在 Vault 中保存机密数据,并且配置 Vault 角色,完成了 Namespace + ServiceAccount + Policy 的绑定。
236
- 这一节,我们直接使用开源大库中的 Vault 演示项目,部署应用并检验结果。
240
+ In the previous section, we created a secret in the Vault server,
241
+ configured the Vault ` role ` and ` policy ` , and completed the binding of ` Namespace ` and ` ServiceAccount ` .
242
+ In this section, we directly use the Vault demo project ` kcl-vault-csi ` in Konfig to deploy the application and verify the results.
237
243
238
- ### 4.1 创建挂载 Vault Secret 的 Pod {#create-pod-with- secret- mounted}
244
+ ### Create a pod with a secret mounted
239
245
240
- 1、进入开源大库的 Vault 演示项目的 Stack 目录 ` base/examples/kcl-vault-csi/dev ` ,并下发配置:
246
+ 1、Enter stack dir ` base/examples/kcl-vault-csi/dev ` and apply stack configs:
241
247
``` bash
242
248
cd base/examples/kcl-vault-csi/dev && kusion apply --yes=true
243
249
```
244
250
245
- 输出类似于:
251
+ The output is similar to:
246
252
```
247
- SUCCESS Compiling in stack dev...
253
+ SUCCESS Compiling in stack dev...
248
254
249
255
Stack: dev Provider Type Name Plan
250
256
* ├─ kubernetes v1:Namespace kcl-vault-csi[0] Create
@@ -261,29 +267,35 @@ Creating Deployment/kcl-vault-csi-dev [4/4] ████████████
261
267
262
268
Apply complete! Resources: 4 created, 0 updated, 0 deleted.
263
269
```
264
- 四个资源创建成功,待 Deployment 创建出 Pod 后,会将 SecretProviderClass 中声明的卷挂载到容器的文件系统中。
265
270
266
- ### 4.2 校验注入结果
271
+ The four resources are created successfully.
272
+ After the deployment controller finished syncing pods, it will mount the volume declared in SecretProviderClass to the pod's file system.
273
+
274
+ ### Verify mount results
267
275
268
- 1、检查实验 Pod 是否运行:
276
+ 1、Check pod status:
269
277
``` bash
270
278
kubectl get pod -n kcl-vault-csi
271
279
```
272
280
273
- 输出类似于:
281
+ The output is similar to:
274
282
```
275
283
NAME READY STATUS RESTARTS AGE
276
284
kcl-vault-csi-dev-64b66968d8-p27fv 1/1 Running 0 12s
277
285
```
278
286
279
- 2、查看写入 Pod 的文件系统路径 ` /mnt/secrets-store/db-password ` 的内容,
280
- 检查是否是[ 配置机密数据] ( #set-secret-data ) 小节写入的 paasword:
287
+ 2、Read file content from ` /mnt/secrets-store/db-password ` , see if it is the password written in the section [ Create a secret] ( #create-a-secret ) :
281
288
``` bash
282
289
kubectl exec -it kcl-vault-csi-dev-64b66968d8-p27fv -n kcl-vault-csi -- cat /mnt/secrets-store/db-password
283
290
```
284
291
285
- 输出类似于:
292
+ The output is similar to:
286
293
```
287
294
db-secret-password
288
295
```
289
- 可以看到,我们成功地将机密数据 ` password ` 通过 CSI 卷的方式,成功注入到 Pod 的文件系统中,完成了机密信息的传输。
296
+
297
+ It can be seen that we successfully injected the secret data ` password ` into the file system of the pod by the CSI driver.
298
+
299
+ ## What's Next
300
+
301
+ - [ Vault Agent] ( /docs/user_docs/guides/sensitive-data-solution/vault-agent )
0 commit comments