Wasm 插件
WasmPlugins 提供了一种机制,可以通过 WebAssembly 过滤器扩展 Istio 代理提供的功能。
执行顺序(作为 Envoy 过滤器链的一部分)由阶段和优先级设置决定,允许配置用户提供的 WasmPlugins 和 Istio 内部过滤器之间复杂的交互。
示例
部署到 ingress-gateway 的 AuthN 过滤器,它实现了一个 OpenID 流程,并使用 JWT 填充 Authorization
标头,供 Istio AuthN 使用。
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
name: openid-connect
namespace: istio-ingress
spec:
selector:
matchLabels:
istio: ingressgateway
url: file:///opt/filters/openid.wasm
sha256: 1ef0c9a92b0420cf25f7fe5d481b231464bc88f486ca3b9c83ed5cc21d2f6210
phase: AUTHN
pluginConfig:
openid_server: authn
openid_realm: ingress
这与上一个示例相同,但使用 OCI 镜像。
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
name: openid-connect
namespace: istio-ingress
spec:
selector:
matchLabels:
istio: ingressgateway
url: oci://private-registry:5000/openid-connect/openid:latest
imagePullPolicy: IfNotPresent
imagePullSecret: private-registry-pull-secret
phase: AUTHN
pluginConfig:
openid_server: authn
openid_realm: ingress
这与上一个示例相同,但使用 VmConfig 在虚拟机中配置环境变量。
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
name: openid-connect
namespace: istio-ingress
spec:
selector:
matchLabels:
istio: ingressgateway
url: oci://private-registry:5000/openid-connect/openid:latest
imagePullPolicy: IfNotPresent
imagePullSecret: private-registry-pull-secret
phase: AUTHN
pluginConfig:
openid_server: authn
openid_realm: ingress
vmConfig:
env:
- name: POD_NAME
valueFrom: HOST
- name: TRUST_DOMAIN
value: "cluster.local"
这也与上一个示例相同,但 Wasm 模块通过 https 拉取,并在每次更改此插件资源时更新。
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
name: openid-connect
namespace: istio-ingress
spec:
selector:
matchLabels:
istio: ingressgateway
url: https://private-bucket/filters/openid.wasm
imagePullPolicy: Always
phase: AUTHN
pluginConfig:
openid_server: authn
openid_realm: ingress
vmConfig:
env:
- name: POD_NAME
valueFrom: HOST
- name: TRUST_DOMAIN
value: "cluster.local"
以及一个更复杂的示例,它部署了三个 WasmPlugins 并使用 phase
和 priority
对其排序。 (假设的)设置是 openid-connect
过滤器执行 OpenID Connect 流程来对用户进行身份验证,将签名的 JWT 写入请求的 Authorization 标头,Istio authn 插件可以验证该标头。然后,acl-check
插件启动,将 JWT 传递给策略服务器,该服务器依次响应一个签名的令牌,其中包含有关系统哪些文件和函数可用于先前经过身份验证的用户的信息。acl-check
过滤器将此令牌写入标头。最后,check-header
过滤器验证该标头中的令牌,并确保令牌的内容(允许的“函数”)与其插件配置匹配。
生成的过滤器链如下所示: -> openid-connect -> istio.authn -> acl-check -> check-header -> router
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
name: openid-connect
namespace: istio-ingress
spec:
selector:
matchLabels:
istio: ingressgateway
url: oci://private-registry:5000/openid-connect/openid:latest
imagePullPolicy: IfNotPresent
imagePullSecret: private-registry-pull-secret
phase: AUTHN
pluginConfig:
openid_server: authn
openid_realm: ingress
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
name: acl-check
namespace: istio-ingress
spec:
selector:
matchLabels:
istio: ingressgateway
url: oci://private-registry:5000/acl-check/acl:latest
imagePullPolicy: Always
imagePullSecret: private-registry-pull-secret
phase: AUTHZ
priority: 1000
pluginConfig:
acl_server: some_server
set_header: authz_complete
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
name: check-header
namespace: istio-ingress
spec:
selector:
matchLabels:
istio: ingressgateway
url: oci://private-registry:5000/check-header:latest
imagePullPolicy: IfNotPresent
imagePullSecret: private-registry-pull-secret
phase: AUTHZ
priority: 10
pluginConfig:
read_header: authz_complete
verification_key: a89gAzxvls0JKAKIJSBnnvvvkIO
function: read_data
WasmPlugin
WasmPlugins 提供了一种机制,可以通过 WebAssembly 过滤器扩展 Istio 代理提供的功能。
VmConfig
Wasm VM 的配置。更多详细信息请参见 此处。
EnvVar
WasmPlugin.TrafficSelector
TrafficSelector 提供了一种机制来选择将为此 Wasm 插件启用的特定流量流。当 TrafficSelector 中的所有子条件都满足时,将选择流量。
PluginType
PluginType 指示要使用的 Wasm 扩展的类型。扩展有两种类型:HTTP
和 NETWORK
。
HTTP
扩展在第 7 层工作(例如,作为 Envoy 中的 HTTP 过滤器)。详细的 HTTP 接口可以在这里找到
NETWORK
扩展在第 4 层工作(例如,作为 Envoy 中的网络过滤器)。详细的 NETWORK
接口可以在这里找到
NETWORK
扩展也可以应用于 HTTP 流量。
名称 | 描述 |
---|---|
UNSPECIFIED_PLUGIN_TYPE | 默认为 HTTP。 |
HTTP | 使用 HTTP Wasm 扩展。 |
NETWORK | 使用网络 Wasm 扩展。 |
插件阶段
插件将在过滤器链中的哪个阶段注入。
名称 | 描述 |
---|---|
UNSPECIFIED_PHASE | 控制平面决定在哪里插入插件。这通常在过滤器链的末尾,紧接在路由器之前。如果插件独立于其他插件,请不要指定 |
AUTHN | 在 Istio 身份验证过滤器之前插入插件。 |
AUTHZ | 在 Istio 授权过滤器之前以及 Istio 身份验证过滤器之后插入插件。 |
STATS | 在 Istio 统计信息过滤器之前以及 Istio 授权过滤器之后插入插件。 |
拉取策略
获取 Wam 模块时要应用的拉取行为,反映 K8s 行为。
名称 | 描述 |
---|---|
UNSPECIFIED_POLICY | 默认为 |
IfNotPresent | 如果之前已拉取镜像的现有版本,则将使用该版本。如果本地不存在镜像的任何版本,我们将拉取最新版本。 |
Always | 更改此插件时,我们将始终拉取镜像的最新版本。请注意,更改还包括 |
环境变量源
名称 | 描述 |
---|---|
INLINE | 显式给出的键值对将注入此 VM |
HOST | Istio-proxy 的环境变量暴露给此 VM。 |
失败策略
名称 | 描述 |
---|---|
FAIL_CLOSE | 二进制文件获取过程中或插件执行期间的致命错误会导致所有后续请求都失败并返回 5xx。 |
FAIL_OPEN | 为 Wasm 插件致命错误启用故障转移行为,以绕过插件执行。致命错误可能是无法获取远程二进制文件、异常或 VM 上的 abort()。此标志不推荐用于身份验证或授权插件。 |