Skip to content

Commit 6ec02e6

Browse files
committed
en: information security with vault and csi driver
1 parent 2c8dec8 commit 6ec02e6

File tree

1 file changed

+111
-97
lines changed

1 file changed

+111
-97
lines changed
Lines changed: 111 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,148 @@
11
# Vault CSI Provider
22

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 built-in resources and 1 custom resource:
55

6-
- 命名空间(Namespace
7-
- 无状态应用(Deployment
8-
- 服务账号(ServiceAccount
9-
- 自定义资源(SecretProviderClass
6+
- Namespace
7+
- Deployment
8+
- ServiceAccount
9+
- SecretProviderClass
1010

1111
:::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 Kubernetes official website to read the relevant instructions:
1315
- [Learn Kubernetes Basics](https://kubernetes.io/docs/tutorials/kubernetes-basics/)
1416
- [Namespace](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/)
1517
- [Deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/)
1618
- [ServiceAccount](https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/)
1719
- [SecretProviderClass](https://secrets-store-csi-driver.sigs.k8s.io/concepts.html#custom-resource-definitions-crds)
1820
:::
1921

20-
## 1. 准备开始
21-
22-
在开始之前,我们需要做以下准备工作:
22+
## Prerequisites
2323

24-
1、安装 Kusion 工具链
24+
Before we start, we need to complete the following steps:
2525

26-
我们推荐使用 kusion 的官方安装工具 `kusionup`,可实现 kusion 多版本管理等关键能力。
27-
详情信息请参阅[下载和安装](/docs/user_docs/getting-started/install)
26+
1、Install Kusion
2827

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.
3030

31-
在本篇指南中,需要用到部分已经抽象实现的 KCL 模型。
32-
有关 KCL 语言的介绍,可以参考 [Tour of KCL](/reference/lang/lang/tour.md)
31+
2、Clone Konfig repo
3332

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).
3535

36-
3、可用的 Kubernetes 集群
36+
3、Running Kubernetes cluster
3737

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.
4240

43-
4、可用的 Helm CLI
41+
4、Available Helm CLI
4442

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/).
4745

48-
## 2. 安装 Vault CSI Driver
46+
## Install Vault server and CSI driver
4947

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.
5453

55-
### 2.1 安装 Vault
54+
### Install Vault server
5655

57-
1、添加 HashiCorp Helm 存储库:
56+
1、Add HashiCorp helm repository:
5857
```bash
5958
helm repo add hashicorp https://helm.releases.hashicorp.com
6059
```
6160

62-
2、更新所有存储库以确保 helm 缓存了最新版本:
61+
2、Update to cache HashiCorp's latest version:
6362
```bash
6463
helm repo update
6564
```
6665

67-
3、安装最新版本的 Vault Server,以开发模式运行,禁用 Injector 服务并启用 CSI
66+
3、Install Vault server, start in development mode, disable Injector and enable CSI:
6867
```bash
6968
helm install vault hashicorp/vault \
7069
--set "server.dev.enabled=true" \
7170
--set "injector.enabled=false" \
7271
--set "csi.enabled=true"
7372
```
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.
7877

79-
4、检查 Default 命名空间中的所有 Pod:
78+
4、Check all pods in the default namespace:
8079
```bash
8180
kubectl get pod
8281
NAME READY STATUS RESTARTS AGE
8382
vault-0 1/1 Running 0 17m
8483
vault-csi-provider-456hl 1/1 Running 0 17m
8584
```
86-
等到 `vault-0` 的状态是 `Running` 并且准备就绪(`1/1`),再继续本指南。
8785

88-
### 2.2 安装 CSI Driver
86+
Wait until the status of `vault-0` is `Running` and ready (`1/1`) before continuing with this guide.
8987

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.
9394

9495
:::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.
98102
:::
99103

100-
1、添加 CSI 驱动的 Helm 存储库:
104+
1、Add CSI driver helm repository:
101105
```bash
102106
helm repo add secrets-store-csi-driver https://kubernetes-sigs.github.io/secrets-store-csi-driver/charts
103107
```
104108

105-
2、安装最新版本的 Kubernetes-Secrets-Store-CSI-Driver:
109+
2、Install Kubernetes-Secrets-Store-CSI-Driver:
106110
```bash
107111
helm install csi secrets-store-csi-driver/secrets-store-csi-driver --namespace kube-system
108112
```
109-
`csi-secrets-store-csi-driver` 是以 DemonSet 形式部署在 `kube-system` 命名空间。
110113

111-
3、检查 CSI Driver 的 Pod 是否启动:
114+
`csi-secrets-store-csi-driver` is a `DaemonSet` in `kube-system` namespace。
115+
116+
3、Check CSI driver pods:
112117
```bash
113118
kubectl --namespace=kube-system get pods -l "app=secrets-store-csi-driver"
114119
NAME READY STATUS RESTARTS AGE
115120
csi-secrets-store-csi-driver-2wl2f 3/3 Running 0 2m
116121
```
117-
等待 `csi-secrets-store-csi-driver-2wl2f` 的状态是 `Running`,并且已经准备就绪(`3/3`),再继续本指南。
118122

119-
## 3. 配置 Vault
123+
Wait until the status of `csi-secrets-store-csi-driver-2wl2f` is `Running` and is ready (`3/3`) before continuing with this guide.
124+
125+
## Configure Vault
120126

121-
Vault 将机密数据保存在自己的数据库中,用户需要先配置相关机密数据,并启用 Vault 的 Kubernetes 认证。
127+
Vault stores confidential data in its database, and users need to configure the relevant confidential data and enable Vault's Kubernetes authentication.
122128

123-
### 3.1 配置机密数据 {#set-secret-data}
129+
### Create a secret
124130

125-
[创建挂载 Vault Secret 的 Pod](#create-pod-with-secret-mounted)小节,挂载到 Pod 中的卷,
126-
引用了保存在 `secret/data/db-pass` 路径下的 secret 。
127-
Vault 以开发模式运行时,kv 引擎会启用默认路径 `/secret`
131+
In [Create a pod with a secret mounted](#create-a-pod-with-a-secret-mounted) section,
132+
the volume mounted in Pod expects secret stored at path `secret/data/db-pass`.
133+
When Vault is run in development a K/V secret engine is enabled at the path `/secret`.
128134

129-
1、`vault-0` 启动交互式 shell 终端:
135+
1、start an interactive shell session on the `vault-0` pod:
130136
```bash
131137
kubectl exec -it vault-0 -- /bin/sh
132138
```
133139

134-
2、`secret/db-pass` 路径创建带有密码的 secret:
140+
2、Create a secret at the path `secret/db-pass` with a password:
135141
```bash
136142
vault kv put secret/db-pass password="db-secret-password"
137143
```
138144

139-
输出类似于:
145+
The output is similar to:
140146
```
141147
Key Value
142148
--- -----
@@ -147,12 +153,12 @@ destroyed false
147153
version 1
148154
```
149155

150-
3、验证 secret 在路径 `/secret/db-pass` 上是否可读:
156+
3、Verify that the secret is readable at the path `secret/db-pass`.
151157
```bash
152158
vault kv get secret/db-pass
153159
```
154160

155-
输出类似于:
161+
The output is similar to:
156162
```
157163
======= Metadata =======
158164
Key Value
@@ -168,24 +174,24 @@ Key Value
168174
--- -----
169175
password db-secret-password
170176
```
171-
到此,机密数据创建完毕,暂且不需要退出 Pod。
177+
For now, the confidential data is created, please don't exit the vault pod immediately.
172178

173-
### 3.2 启用 kubernetes 身份认证
179+
### Enable Kubernetes authentication
174180

175-
Vault 提供了 Kubernetes 身份验证方法,使客户端能够使用 Kubernetes ServiceAccount 令牌进行身份验证。
176-
此令牌在创建时提供给每个 Pod。
181+
Vault provides a Kubernetes authentication method that enables clients to authenticate with a Kubernetes ServiceAccount Token.
182+
The Kubernetes resources that access the secret and create the volume authenticate through this method through a `role`.
177183

178-
1、继续上一小节的 Terminal,启用 Kubernetes 身份验证:
184+
1、Continue with the terminal in the previous step, enable the Kubernetes authentication method:
179185
```bash
180186
vault auth enable kubernetes
181187
```
182-
输出类似于:
188+
189+
The output is similar to:
183190
```
184191
Success! Enabled kubernetes auth method at: kubernetes/
185192
```
186193

187-
2、配置 kubernetes 身份认证规则,依赖 Kubernetes API 地址、ServiceAccount 令牌、
188-
证书以及 Kubernetes ServiceAccount 的颁发者(Kubernetes 1.21+ 需要):
194+
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+):
189195
```bash
190196
vault write auth/kubernetes/config \
191197
kubernetes_host="https://$KUBERNETES_PORT_443_TCP_ADDR:443" \
@@ -194,18 +200,15 @@ vault write auth/kubernetes/config \
194200
issuer="https://kubernetes.default.svc.cluster.local"
195201
```
196202

197-
输出类似于:
203+
The output is similar to:
198204
```
199205
Success! Data written to: auth/kubernetes/config
200206
```
201-
Kubernetes 创建容器时,将 `token_reviewer_jwt``kubernetes_ca_cert` 挂载到容器中。
202-
环境变量 `KUBERNETES_PORT_443_TCP_ADDR` 引用的是 Kubernetes 主机的内部网络地址。
203207

204-
3、设置读权限的 _policy_
208+
When Kubernetes creates pods, mount `token_reviewer_jwt` and `Kubernetes_ca_cert` into them.
209+
The environment variable `KUBERNETES_PORT_443_TCP_ADDR` references the internal network address of the Kubernetes host.
205210

206-
Kubernetes-Secrets-Store-CSI-Driver 需要读取密钥,保证它对挂载的卷和卷中密钥有读权限。
207-
208-
创建名为 `kcl-vault-csi-policy`_policy_
211+
3、Create a policy named `kcl-vault-csi-policy`:
209212
```bash
210213
vault policy write kcl-vault-csi-policy - <<EOF
211214
path "secret/data/db-pass" {
@@ -214,7 +217,9 @@ path "secret/data/db-pass" {
214217
EOF
215218
```
216219

217-
4、再创建名为 `kcl-vault-csi-role`_role_ ,关联上一步创建的 _policy_,并绑定 Namespace 和 ServiceAccount:
220+
Kubernetes-Secrets-Store-CSI-Driver needs to read the secret key, which must have read access to the mounted volume.
221+
222+
4、Create a role named `kcl-vault-csi-role`:
218223
```bash
219224
vault write auth/kubernetes/role/kcl-vault-csi-role \
220225
bound_service_account_names=kcl-vault-csi-sa \
@@ -223,28 +228,31 @@ vault write auth/kubernetes/role/kcl-vault-csi-role \
223228
ttl=24h
224229
```
225230

226-
输出类似于:
231+
The output is similar to:
227232
```
228233
Success! Data written to: auth/kubernetes/role/kcl-vault-csi-role
229234
```
230-
该角色将 Kubernetes 服务帐户 _kcl-vault-csi-sa_ 和命名空间 _kcl-vault-csi_ 与 Vault 策略 _kcl-vault-csi-role_ 关联起来。
231-
此 Kubernetes 服务帐户将会在后面创建。认证成功后返回的令牌有效期为 24 小时。最后,执行 `exit` 退出 Pod。
232235

233-
## 4. 结果验证 {#verify-result}
236+
This role associates the Kubernetes service account `kcl-vault-csi-sa` and namespace `kcl-vault-csi` with the Vault policy `kcl-vault-csi-role`.
237+
This Kubernetes service account will be created later. The token returned after successful authentication is valid for 24 hours.
238+
Finally, exit the `vault-0` pod.
234239

235-
上一节我们已经在 Vault 中保存机密数据,并且配置 Vault 角色,完成了 Namespace + ServiceAccount + Policy 的绑定。
236-
这一节,我们直接使用开源大库中的 Vault 演示项目,部署应用并检验结果。
240+
## Verify Secret
237241

238-
### 4.1 创建挂载 Vault Secret 的 Pod {#create-pod-with-secret-mounted}
242+
In the previous section, we created a secret in the Vault server,
243+
configured the Vault `role` and `policy`, and completed the binding of `Namespace` and `ServiceAccount`.
244+
In this section, we directly use the Vault demo project `kcl-vault-csi` in Konfig to deploy the application and verify the results.
239245

240-
1、进入开源大库的 Vault 演示项目的 Stack 目录 `base/examples/kcl-vault-csi/dev`,并下发配置:
246+
### Create a pod with a secret mounted
247+
248+
1、Enter stack dir `base/examples/kcl-vault-csi/dev` and apply stack configs:
241249
```bash
242250
cd base/examples/kcl-vault-csi/dev && kusion apply --yes=true
243251
```
244252

245-
输出类似于:
253+
The output is similar to:
246254
```
247-
SUCCESS Compiling in stack dev...
255+
SUCCESS Compiling in stack dev...
248256
249257
Stack: dev Provider Type Name Plan
250258
* ├─ kubernetes v1:Namespace kcl-vault-csi[0] Create
@@ -261,29 +269,35 @@ Creating Deployment/kcl-vault-csi-dev [4/4] ████████████
261269
262270
Apply complete! Resources: 4 created, 0 updated, 0 deleted.
263271
```
264-
四个资源创建成功,待 Deployment 创建出 Pod 后,会将 SecretProviderClass 中声明的卷挂载到容器的文件系统中。
265272

266-
### 4.2 校验注入结果
273+
The four resources are created successfully.
274+
After the deployment controller finished syncing pods, it will mount the volume declared in SecretProviderClass to the pod's file system.
275+
276+
### Verify mount results
267277

268-
1、检查实验 Pod 是否运行:
278+
1、Check pod status:
269279
```bash
270280
kubectl get pod -n kcl-vault-csi
271281
```
272282

273-
输出类似于:
283+
The output is similar to:
274284
```
275285
NAME READY STATUS RESTARTS AGE
276286
kcl-vault-csi-dev-64b66968d8-p27fv 1/1 Running 0 12s
277287
```
278288

279-
2、查看写入 Pod 的文件系统路径 `/mnt/secrets-store/db-password` 的内容,
280-
检查是否是[配置机密数据](#set-secret-data) 小节写入的 paasword:
289+
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):
281290
```bash
282291
kubectl exec -it kcl-vault-csi-dev-64b66968d8-p27fv -n kcl-vault-csi -- cat /mnt/secrets-store/db-password
283292
```
284293

285-
输出类似于:
294+
The output is similar to:
286295
```
287296
db-secret-password
288297
```
289-
可以看到,我们成功地将机密数据 `password` 通过 CSI 卷的方式,成功注入到 Pod 的文件系统中,完成了机密信息的传输。
298+
299+
It can be seen that we successfully injected the secret data `password` into the file system of the pod by the CSI driver.
300+
301+
## What's Next
302+
303+
- [Vault Agent](/docs/user_docs/guides/sensitive-data-solution/vault-agent)

0 commit comments

Comments
 (0)