Fluxheim/文档/WASM 扩展

WASM 扩展

基于完整生产配置的专用 Wasm 构建,提供受限的策略钩子,并支持 ACME、指标和 OpenTelemetry

它提供什么

基于完整生产配置的专用 Wasm 构建,提供受限的策略钩子,并支持 ACME、指标和 OpenTelemetry.

功能用于
访问决策实时 native HTTP/1 access-decision hook 使用优先级顺序、first-deny-wins 组合和 fail-closed 行为。
Header hookrequest-headersresponse-headers hook 只能设置或移除白名单内的合成 header,例如 policy-tier 示例。
路由决策route-decision hook 只能继续、拒绝,或选择已配置且匹配的 canarymirror 路由分支。
Cache 决策cache-lookup hooks 可以 continue、pass、bypass 或 deny。cache-store hooks 可以在 memory/disk cache writes 前 continue、skip storage 或 deny。

运行

请使用专用的 profile-wasm 归档或镜像;常规完整构建有意不包含 Wasm。

官方 Wasm 镜像包含运行时,但不包含运维人员的插件。请以只读方式挂载经过审核的模块,并使用 SHA-256 固定每个模块。

podman pull ghcr.io/valkyoth/fluxheim:v1.8.0-wasm

podman run --rm \
  -v ./fluxheim.toml:/etc/fluxheim/fluxheim.toml:ro,Z \
  -v /srv/infra/fluxheim/plugins:/etc/fluxheim/plugins:ro,Z \
  ghcr.io/valkyoth/fluxheim:v1.8.0-wasm

已批准的插件根目录

插件文件必须是位于已批准 root 下、使用 absolute path 的 regular file,不能使用 symlink 或 parent path。

[wasm]
enabled = true
plugin_roots = ["/etc/fluxheim/plugins"]
max_total_concurrent_executions = 256
max_total_preview_concurrent_executions = 32
max_total_cache_concurrent_executions = 256

[[wasm.plugins]]
name = "security_headers"
path = "/etc/fluxheim/plugins/security_headers.wasm"
sha256 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
abi = "fluxheim-policy-v1"
host_call_namespace = "fluxheim-policy-v1"
phases = ["response-headers"]
fail_mode = "fail-closed"

[[wasm.attachments]]
plugin = "security_headers"
vhost = "example"
priority = 100
phases = ["response-headers"]

受限执行

fuel、memory、table、instance、compile-timeout、compile-worker 以及每次调用的 watchdog 限制会约束 sandbox 的执行范围。

[wasm.plugins.limits]
max_module_bytes = "1MiB"
max_compiled_artifact_bytes = "32MiB"
max_memory_bytes = "16MiB"
max_table_elements = 10000
fuel = 5000000
timeout_ms = 50
compile_timeout_ms = 500

生产说明

容器内的只读挂载无法保护主机上的文件。请确保主机配置和插件目录归可信主体所有,并且不可写。

  • 公开清单必须固定 SHA-256 摘要。整个进程最多同时执行两个编译任务;编译产物默认上限为 32 MiB,绝对上限为 256 MiB。
  • config file 及其每一层现有父 directory 都应由可信主体所有,并且 group 或其他 user 不得拥有写权限。
  • 固定 release version 或 image digest。
  • 将 secrets 放在文件、环境变量或 container secrets 中,不要放在公共文档里。

Full docs on GitHub

简体中文