mirror of https://github.com/istio/istio.io.git
[zh] improve integrations/spire (#13930)
Signed-off-by: xin.li <xin.li@daocloud.io>
This commit is contained in:
parent
cd4fcc2c57
commit
54c8aaaa9f
|
@ -8,7 +8,11 @@ owner: istio/wg-networking-maintainers
|
|||
test: yes
|
||||
---
|
||||
|
||||
[SPIRE](https://spiffe.io/docs/latest/spire-about/spire-concepts/) 是 SPIFFE 规范的一个可用于生产环境的实现,它执行节点和工作负载的认证,以便在异构环境中安全地为运行的工作负载颁发加密身份。通过与 [Envoy 的 SDS API](https://www.envoyproxy.io/docs/envoy/latest/configuration/security/secret) 集成,可以将 SPIRE 配置为 Istio 工作负载的加密身份源。Istio 可以检测到实现了 Envoy SDS API 的 UNIX 域套接字的存在,并允许 Envoy 直接从其中通信并获取身份。
|
||||
[SPIRE](https://spiffe.io/docs/latest/spire-about/spire-concepts/) 是 SPIFFE
|
||||
规范的一个可用于生产环境的实现,它执行节点和工作负载的认证,以便在异构环境中安全地为运行的工作负载颁发加密身份。
|
||||
通过与 [Envoy 的 SDS API](https://www.envoyproxy.io/docs/envoy/latest/configuration/security/secret)
|
||||
集成,可以将 SPIRE 配置为 Istio 工作负载的加密身份源。Istio 可以检测到实现了 Envoy SDS API 的 UNIX 域套接字的存在,
|
||||
并允许 Envoy 直接从其中通信并获取身份。
|
||||
|
||||
与默认的 Istio 身份管理相比,与 SPIRE 的集成提供了灵活的认证选项。例如,SPIRE 的插件架构使您可以选择 Kubernetes
|
||||
命名空间和服务账户认证之外的多样化工作负载认证选项。SPIRE 的节点认证将认证扩展到工作负载所运行的物理或虚拟硬件上。
|
||||
|
@ -33,7 +37,7 @@ $ kubectl apply -f @samples/security/spire/spire-quickstart.yaml@
|
|||
|
||||
这将在您的集群中部署 SPIRE,以及下述两个附加组件:
|
||||
|
||||
- [SPIFFE CSI 驱动](https://github.com/spiffe/spiffe-csi),用于与节点中的其他 Pod 共享 SPIRE 代理的 UNIX 域套接字;
|
||||
- [SPIFFE CSI 驱动](https://github.com/spiffe/spiffe-csi),用于与节点中的其他 Pod 共享 SPIRE 代理的 UNIX 域套接字。
|
||||
- [SPIRE Controller Manager](https://github.com/spiffe/spire-controller-manager),它负责注册工作负载并在
|
||||
Kubernetes 中建立联合关系。请参阅[安装 Istio](#install-istio) 以配置 Istio 并集成 SPIFFE CSI 驱动。
|
||||
|
||||
|
@ -47,27 +51,33 @@ $ kubectl apply -f @samples/security/spire/spire-quickstart.yaml@
|
|||
|
||||
要将您的 SPIRE 部署与 Istio 集成,需要配置 SPIRE:
|
||||
|
||||
1. 访问 [SPIRE 代理参考](https://spiffe.io/docs/latest/deploying/spire_agent/#agent-configuration-file) 并将 SPIRE 代理套接字路径配置为与 Envoy SDS 定义的套接字路径匹配。
|
||||
1. 访问 [SPIRE 代理参考](https://spiffe.io/docs/latest/deploying/spire_agent/#agent-configuration-file)并将
|
||||
SPIRE 代理套接字路径配置为与 Envoy SDS 定义的套接字路径匹配。
|
||||
|
||||
{{< text plain >}}
|
||||
socket_path = "/run/secrets/workload-spiffe-uds/socket"
|
||||
{{< /text >}}
|
||||
|
||||
1. 通过部署 [SPIFFE CSI 驱动](https://github.com/spiffe/spiffe-csi) 与节点内的 Pod 共享 SPIRE 代理套接字,通过设置驱动程序的 `-workload-api-socket-dir` 参数来指定套接字目录的挂载位置。
|
||||
1. 通过部署 [SPIFFE CSI 驱动](https://github.com/spiffe/spiffe-csi)与节点内的 Pod 共享 SPIRE 代理套接字,
|
||||
通过设置驱动程序的 `-workload-api-socket-dir` 参数来指定套接字目录的挂载位置。
|
||||
|
||||
请参阅 [安装 Istio](#install-istio) 以配置 Istio 以集成 SPIFFE CSI 驱动。
|
||||
请参阅[安装 Istio](#install-istio) 以配置 Istio 以集成 SPIFFE CSI 驱动。
|
||||
|
||||
{{< tip >}}
|
||||
如果在 Istio 代理启动之前 SPIRE 尚未创建套接字,则 Istio 将成为 Envoy SDS 监听器。此时的时间由自定义 IstioOperator 控制。
|
||||
如果在 Istio 代理启动之前 SPIRE 尚未创建套接字,则 Istio 将成为 Envoy SDS 监听器。
|
||||
此时的时间由自定义 IstioOperator 控制。
|
||||
{{< /tip >}}
|
||||
|
||||
## 安装 Istio {#install-istio}
|
||||
|
||||
### 选项 1:使用 SPIRE Controller Manager 配置工作负载注册 {#option-1-configuration-for-workload-registration-with-the-spire-controller-manager}
|
||||
|
||||
通过部署 [SPIRE Controller Manager](https://github.com/spiffe/spire-controller-manager) 和 SPIRE 服务器,可以自动为与 [ClusterSPIFFEID](https://github.com/spiffe/spire-controller-manager/blob/main/docs/clusterspiffeid-crd.md) 自定义资源中定义的选择器匹配的每个新 Pod 进行注册。
|
||||
通过部署 [SPIRE Controller Manager](https://github.com/spiffe/spire-controller-manager)
|
||||
和 SPIRE 服务器,可以自动为与 [ClusterSPIFFEID](https://github.com/spiffe/spire-controller-manager/blob/main/docs/clusterspiffeid-crd.md)
|
||||
自定义资源中定义的选择器匹配的每个新 Pod 进行注册。
|
||||
|
||||
必须在安装 Istio 之前应用 ClusterSPIFFEID。此外,必须配置 Ingress-gateway pod 以匹配 ClusterSPIFFEID 中定义的选择器。如果在安装期间未自动创建 Ingress Gateway 工作负载的注册条目,则工作负载将无法达到 `Ready` 状态。
|
||||
必须在安装 Istio 之前应用 ClusterSPIFFEID。此外,必须配置 Ingress-gateway Pod 以匹配 ClusterSPIFFEID
|
||||
中定义的选择器。如果在安装期间未自动创建 Ingress Gateway 工作负载的注册条目,则工作负载将无法达到 `Ready` 状态。
|
||||
|
||||
1. 创建 ClusterSPIFFEID 示例:
|
||||
|
||||
|
@ -85,11 +95,13 @@ $ kubectl apply -f @samples/security/spire/spire-quickstart.yaml@
|
|||
EOF
|
||||
{{< /text >}}
|
||||
|
||||
示例 ClusterSPIFFEID 允许自动注册所有具有 `spiffe.io/spire-managed-identity: "true"` 标签的工作负载。对于具有此标签的 Pod,将提取 `spiffeIDTemplate` 中指定的值以形成 SPIFFE ID。
|
||||
示例 ClusterSPIFFEID 允许自动注册所有具有 `spiffe.io/spire-managed-identity: "true"` 标签的工作负载。
|
||||
对于具有此标签的 Pod,将提取 `spiffeIDTemplate` 中指定的值以形成 SPIFFE ID。
|
||||
|
||||
1. [下载 Istio](/zh/docs/setup/getting-started/#download)。
|
||||
|
||||
1. 创建具有自定义补丁的 Ingress Gateway 和 istio-proxy 的 Istio 配置。Ingress Gateway 组件包括 `spiffe.io/spire-managed-identity: "true"` 标签。
|
||||
1. 创建具有自定义补丁的 Ingress Gateway 和 istio-proxy 的 Istio 配置。Ingress Gateway 组件包括
|
||||
`spiffe.io/spire-managed-identity: "true"` 标签。
|
||||
|
||||
{{< text syntax=bash snip_id=define_istio_operator_for_auto_registration >}}
|
||||
$ cat <<EOF > ./istio.yaml
|
||||
|
@ -182,15 +194,16 @@ $ kubectl apply -f @samples/security/spire/spire-quickstart.yaml@
|
|||
istiod-989f54d9c-sg7sn 1/1 Running 0 23s
|
||||
{{< /text >}}
|
||||
|
||||
由于与之对应的注册条目已在 SPIRE 服务器上自动创建,Ingress-gateway pod 状态为 `Ready`。Envoy 能够从 SPIRE 获取加密身份。
|
||||
由于与之对应的注册条目已在 SPIRE 服务器上自动创建,Ingress-gateway Pod 状态为 `Ready`。Envoy 能够从 SPIRE 获取加密身份。
|
||||
|
||||
请注意,在[快速入门](#option-1-quick-start) 部分中使用了 `SPIRE Controller Manager`。
|
||||
请注意,在[快速入门](#option-1-quick-start)部分中使用了 `SPIRE Controller Manager`。
|
||||
|
||||
### 选项 2:手动工作负载注册 {#option-2-configuration-for-manual-workload-registration-with-spire}
|
||||
|
||||
1. [下载 Istio](/zh/docs/setup/getting-started/#download)。
|
||||
|
||||
1. 在[部署 SPIRE](#install-spire)到您的环境并确保所有部署都处于 `Ready` 状态后,配置 Istio ,包括对 Ingress-gateway 和 istio-proxy 的自定义补丁。
|
||||
1. 在[部署 SPIRE](#install-spire) 到您的环境并确保所有 Deployment 都处于 `Ready` 状态后,
|
||||
使用 Ingress-gateway 和 istio-proxy 的自定义补丁来配置 Istio。
|
||||
|
||||
创建 Istio 配置:
|
||||
|
||||
|
@ -275,7 +288,7 @@ $ kubectl apply -f @samples/security/spire/spire-quickstart.yaml@
|
|||
$ istioctl install --skip-confirmation -f ./istio.yaml
|
||||
{{< /text >}}
|
||||
|
||||
1. 检查 Ingress-gateway pod 状态:
|
||||
1. 检查 Ingress-gateway Pod 状态:
|
||||
|
||||
{{< text syntax=bash snip_id=none >}}
|
||||
$ kubectl get pods -n istio-system
|
||||
|
@ -284,11 +297,12 @@ $ kubectl apply -f @samples/security/spire/spire-quickstart.yaml@
|
|||
istiod-989f54d9c-sg7sn 1/1 Running 0 25s
|
||||
{{< /text >}}
|
||||
|
||||
只有在 SPIRE 服务器上为 Ingress-gateway pod 和数据平面容器创建了相应的注册条目后,它们才会达到 `Ready` 状态。
|
||||
只有在 SPIRE 服务器上为 Ingress-gateway Pod 和数据平面容器创建了相应的注册条目后,它们才会达到 `Ready` 状态。
|
||||
接着,Envoy 将能够从 SPIRE 中获取加密身份信息。
|
||||
请参阅[注册工作负载](#register-workloads)以为您的网格中的服务注册条目。
|
||||
|
||||
Istio 配置与入口网关以及将要注入到工作负载 Pod 上的 Sidecar 共享 `spiffe-csi-driver`,从而使它们能够访问 SPIRE 代理的 UNIX 域套接字。
|
||||
Istio 配置与入口网关以及将要注入到工作负载 Pod 上的 Sidecar 共享 `spiffe-csi-driver`,
|
||||
从而使它们能够访问 SPIRE 代理的 UNIX 域套接字。
|
||||
|
||||
此配置还向网关添加了一个 initContainer,它将等待 SPIRE 创建 UNIX 域套接字,然后再启动 istio-proxy。
|
||||
如果 SPIRE 代理尚未准备好,或者尚未使用相同的套接字路径正确配置,Ingress 网关的 initContainer 将永远处于等待状态。
|
||||
|
@ -299,8 +313,10 @@ Istio 配置与入口网关以及将要注入到工作负载 Pod 上的 Sidecar
|
|||
|
||||
### 选项1:使用 SPIRE 控制器管理器进行注册 {#option-1-registration-using-the-spire-controller-manager}
|
||||
|
||||
将为与 [ClusterSPIFFEID](https://github.com/spiffe/spire-controller-manager/blob/main/docs/clusterspiffeid-crd.md)自定义资源中定义的选择器匹配的每个新 Pod 自动注册新条目。
|
||||
请参阅[使用 SPIRE 控制器管理器进行工作负载注册的配置](#option-1-configuration-for-workload-registration-with-the-spire-controller-manager)以获取示例 ClusterSPIFFEID 配置。
|
||||
将为与 [ClusterSPIFFEID](https://github.com/spiffe/spire-controller-manager/blob/main/docs/clusterspiffeid-crd.md)
|
||||
自定义资源中定义的选择器匹配的每个新 Pod 自动注册新条目。
|
||||
请参阅[使用 SPIRE 控制器管理器进行工作负载注册的配置](#option-1-configuration-for-workload-registration-with-the-spire-controller-manager)以获取
|
||||
ClusterSPIFFEID 示例配置。
|
||||
|
||||
1. 部署示例工作负载:
|
||||
|
||||
|
@ -308,7 +324,9 @@ Istio 配置与入口网关以及将要注入到工作负载 Pod 上的 Sidecar
|
|||
$ istioctl kube-inject --filename @samples/security/spire/sleep-spire.yaml@ | kubectl apply -f -
|
||||
{{< /text >}}
|
||||
|
||||
除了需要 `spiffe.io/spire-managed-identity` 标签之外,工作负载还需要使用 SPIFFE CSI 驱动器卷来访问 SPIRE 代理套接字。为了实现这一点,您可以利用[安装 Istio](#install-istio) 部分中的 `spire` Pod 注解模板,或者将 CSI 卷添加到您的工作负载的部署规范中。这两种方法都在下面的示例片段中进行了突出显示:
|
||||
除了需要 `spiffe.io/spire-managed-identity` 标签之外,工作负载还需要使用 SPIFFE CSI
|
||||
驱动器卷来访问 SPIRE 代理套接字。为了实现这一点,您可以利用[安装 Istio](#install-istio) 部分中的
|
||||
`spire` Pod 注解模板,或者将 CSI 卷添加到您的工作负载的部署规范中。这两种方法都在下面的示例片段中进行了突出显示:
|
||||
|
||||
{{< text syntax=yaml snip_id=none >}}
|
||||
apiVersion: apps/v1
|
||||
|
@ -325,7 +343,7 @@ Istio 配置与入口网关以及将要注入到工作负载 Pod 上的 Sidecar
|
|||
labels:
|
||||
app: sleep
|
||||
spiffe.io/spire-managed-identity: "true"
|
||||
# Injects custom sidecar template
|
||||
# 注入自定义 Sidecar 模板
|
||||
annotations:
|
||||
inject.istio.io/templates: "sidecar,spire"
|
||||
spec:
|
||||
|
@ -369,7 +387,7 @@ Istio 配置与入口网关以及将要注入到工作负载 Pod 上的 Sidecar
|
|||
$ INGRESS_POD_UID=$(kubectl get pods -n istio-system "$INGRESS_POD" -o jsonpath='{.metadata.uid}')
|
||||
{{< /text >}}
|
||||
|
||||
1. 获取 spire-server pod:
|
||||
1. 获取 spire-server Pod:
|
||||
|
||||
{{< text syntax=bash snip_id=set_spire_server_pod_name_var >}}
|
||||
$ SPIRE_SERVER_POD=$(kubectl get pod -l app=spire-server -n spire -o jsonpath="{.items[0].metadata.name}")
|
||||
|
@ -396,7 +414,7 @@ Istio 配置与入口网关以及将要注入到工作负载 Pod 上的 Sidecar
|
|||
Selector : k8s_psat:cluster:demo-cluster
|
||||
{{< /text >}}
|
||||
|
||||
1. 为 Ingress-gateway pod 注册一个条目:
|
||||
1. 为 Ingress-gateway Pod 注册一个条目:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec -n spire "$SPIRE_SERVER_POD" -- \
|
||||
|
@ -428,7 +446,9 @@ Istio 配置与入口网关以及将要注入到工作负载 Pod 上的 Sidecar
|
|||
$ istioctl kube-inject --filename @samples/security/spire/sleep-spire.yaml@ | kubectl apply -f -
|
||||
{{< /text >}}
|
||||
|
||||
请注意,工作负载需要使用 SPIFFE CSI 驱动器卷来访问 SPIRE 代理套接字。为了实现这一点,您可以利用[安装 Istio](#install-istio)部分中的 `spire` pod 注解模板,或者将 CSI 卷添加到您的工作负载的部署规范中。这两种方法都在下面的示例片段中进行了突出显示:
|
||||
请注意,工作负载需要使用 SPIFFE CSI 驱动器卷来访问 SPIRE 代理套接字。为了实现这一点,
|
||||
您可以使用[安装 Istio](#install-istio) 部分中的 `spire` Pod 注解模板,或者将 CSI
|
||||
卷添加到您的工作负载的部署规范中。这两种方法都在下面的示例片段中进行了突出显示:
|
||||
|
||||
{{< text syntax=yaml snip_id=none >}}
|
||||
apiVersion: apps/v1
|
||||
|
@ -444,7 +464,7 @@ Istio 配置与入口网关以及将要注入到工作负载 Pod 上的 Sidecar
|
|||
metadata:
|
||||
labels:
|
||||
app: sleep
|
||||
# Injects custom sidecar template
|
||||
# 注入自定义 Sidecar 模板
|
||||
annotations:
|
||||
inject.istio.io/templates: "sidecar,spire"
|
||||
spec:
|
||||
|
@ -470,7 +490,7 @@ Istio 配置与入口网关以及将要注入到工作负载 Pod 上的 Sidecar
|
|||
readOnly: true
|
||||
{{< /text >}}
|
||||
|
||||
1. 获取 pod 信息:
|
||||
1. 获取 Pod 信息:
|
||||
|
||||
{{< text syntax=bash snip_id=set_sleep_pod_vars >}}
|
||||
$ SLEEP_POD=$(kubectl get pod -l app=sleep -o jsonpath="{.items[0].metadata.name}")
|
||||
|
@ -491,12 +511,13 @@ Istio 配置与入口网关以及将要注入到工作负载 Pod 上的 Sidecar
|
|||
{{< /text >}}
|
||||
|
||||
{{< warning >}}
|
||||
工作负载的 SPIFFE ID 必须遵循 Istio SPIFFE ID 规范: `spiffe://<trust.domain>/ns/<namespace>/sa/<service-account>`
|
||||
工作负载的 SPIFFE ID 必须遵循 Istio SPIFFE ID 规范:`spiffe://<trust.domain>/ns/<namespace>/sa/<service-account>`
|
||||
{{< /warning >}}
|
||||
|
||||
请参阅 [SPIRE 注册工作负载的帮助文档](https://spiffe.io/docs/latest/deploying/registering/),了解如何为工作负载创建新条目,并使用多个选择器进行认证以加强认证标准。
|
||||
请参阅 [SPIRE 注册工作负载的帮助文档](https://spiffe.io/docs/latest/deploying/registering/),了解如何为工作负载创建新条目,
|
||||
并使用多个选择器进行认证以加强认证标准。
|
||||
|
||||
## 验证工作负载的身份是否已创建
|
||||
## 验证工作负载的身份是否已创建 {#verifying-that-identities-were-created-for-workloads}
|
||||
|
||||
请使用以下命令确认是否已为工作负载创建了身份:
|
||||
|
||||
|
@ -520,7 +541,7 @@ JWT-SVID TTL : default
|
|||
Selector : k8s:pod-uid:ee490447-e502-46bd-8532-5a746b0871d6
|
||||
{{< /text >}}
|
||||
|
||||
检查 Ingress-gateway pod 状态:
|
||||
检查 Ingress-gateway Pod 状态:
|
||||
|
||||
{{< text syntax=bash snip_id=none >}}
|
||||
$ kubectl get pods -n istio-system
|
||||
|
@ -533,7 +554,7 @@ istiod-989f54d9c-sg7sn 1/1 Running 0 45s
|
|||
|
||||
### 检查工作负载身份是否由 SPIRE 颁发 {#check-that-the-workload-identity-was-issued-by-spire}
|
||||
|
||||
1. 使用 istioctl proxy-config secret 命令检索 sleep 的 SVID 身份文档:
|
||||
1. 使用 `istioctl proxy-config secret` 命令检索 sleep 的 SVID 身份文档:
|
||||
|
||||
{{< text syntax=bash snip_id=get_sleep_svid >}}
|
||||
$ istioctl proxy-config secret "$SLEEP_POD" -o json | jq -r \
|
||||
|
@ -551,19 +572,24 @@ istiod-989f54d9c-sg7sn 1/1 Running 0 45s
|
|||
|
||||
SPIRE 服务器能够对来自不同信任域的 SPIFFE 身份进行认证,这被称为 SPIFFE 联邦。
|
||||
|
||||
可以配置 SPIRE 代理通过 Envoy SDS API 向 Envoy 推送联邦捆绑包,从而使 Envoy 能够使用[验证上下文](https://spiffe.io/docs/latest/microservices/envoy/#validation-context)来验证对等证书并信任来自另一个信任域的工作负载。
|
||||
要使 Istio 能够通过 SPIRE 集成实现 SPIFFE 身份联合,请参阅 [SPIRE 代理 SDS 配置](https://github.com/spiffe/spire/blob/main/doc/spire_agent.md#sds-configuration),并为您的 SPIRE 代理配置文件设置以下 SDS 配置值。
|
||||
可以配置 SPIRE 代理通过 Envoy SDS API 向 Envoy 推送联邦捆绑包,从而使 Envoy
|
||||
能够使用[验证上下文](https://spiffe.io/docs/latest/microservices/envoy/#validation-context)来验证对等证书并信任来自另一个信任域的工作负载。
|
||||
要使 Istio 能够通过 SPIRE 集成实现 SPIFFE 身份联合,请参阅
|
||||
[SPIRE 代理 SDS 配置](https://github.com/spiffe/spire/blob/main/doc/spire_agent.md#sds-configuration),
|
||||
并为您的 SPIRE 代理配置文件设置以下 SDS 配置值。
|
||||
|
||||
| 配置 | 描述 | 资源名称 |
|
||||
| -------------------------- | ------------------------------------------------------- | ------------- |
|
||||
| `default_svid_name` | 用于 Envoy SDS 的默认 `X509-SVID` 的 TLS 证书资源名称 | 默认 |
|
||||
| `default_bundle_name` | 用于 Envoy SDS 的默认 X.509 bundle 的验证上下文资源名称 | 空 |
|
||||
| `default_all_bundles_name` | 用于 Envoy SDS 的所有 bundle(包括联邦的)的验证上下文资源名称 | ROOTCA |
|
||||
|
||||
| 配置 | 描述 | 资源名称 |
|
||||
| -------------------------- | --------------------------------------------------- | ------------- |
|
||||
| `default_svid_name` | 用于 Envoy SDS 的默认 `X509-SVID` 的 TLS 证书资源名称 | 默认 |
|
||||
| `default_bundle_name` | 用于 Envoy SDS 的默认 X.509 bundle 的验证上下文资源名称 | 空 |
|
||||
| `default_all_bundles_name` | 用于 Envoy SDS 的所有 bundle(包括联邦的)的验证上下文资源名称 | ROOTCA |
|
||||
这将允许 Envoy 直接从 SPIRE 获取联邦 bundle。
|
||||
|
||||
### 创建联邦注册条目 {#create-federated-registration-entries}
|
||||
|
||||
- 如果使用 SPIRE Controller Manager,请通过将 [ClusterSPIFFEID CR](https://github.com/spiffe/spire-controller-manager/blob/main/docs/clusterspiffeid-crd.md) 的 `federatesWith` 字段设置为您希望 pod 与之联邦的信任域来为工作负载创建联邦条目:
|
||||
- 如果使用 SPIRE Controller Manager,请通过将 [ClusterSPIFFEID CR](https://github.com/spiffe/spire-controller-manager/blob/main/docs/clusterspiffeid-crd.md)
|
||||
的 `federatesWith` 字段设置为您希望 Pod 与之联邦的信任域来为工作负载创建联邦条目:
|
||||
|
||||
{{< text syntax=yaml snip_id=none >}}
|
||||
apiVersion: spire.spiffe.io/v1alpha1
|
||||
|
|
Loading…
Reference in New Issue