Envoy (Service Mesh Authorization)
envoy-authz 是一个使用 Casbin 实现 RBAC/ABAC 的 Envoy 外部授权服务。它实现了 Envoy 的外部认证 gRPC API,可以配合 Istio 或任何基于 Envoy 的服务网格使用。
前提条件
- Envoy 1.17 或更高版本
- Istio 或其他基于 Envoy 的服务网格
- gRPC 依赖
依赖通过 go.mod 管理。
工作原理
- 客户端发起 HTTP 请求
- Envoy 拦截请求并转发给 gRPC 授权服务器
- 服务器用 Casbin 策略评估请求
- 通过授权的请求继续,未授权的请求被拦截
gRPC 服务器实现了 Envoy external_auth.proto 中的 protocol buffer 定义:
// A generic interface for performing authorization checks on incoming
// requests to a networked service.
service Authorization {
// Performs an authorization check based on the attributes associated with the
// incoming request and returns a status of `OK` or not `OK`.
rpc Check(v2.CheckRequest) returns (v2.CheckResponse);
}
授权服务器必须实现上面定义的 Check() 方法。
用法
- 按照 Casbin 文档 在配置文件中配置 Casbin 策略。
可以用在线 Casbin 编辑器 测试策略。
- 启动授权服务器:
go build .
./authz
- 应用 Envoy 配置:
envoy -c authz.yaml -l info
Envoy 启动后,会让传入的请求经过授权中间件。
与Istio集成
要启用这个中间件,需要让系统通过 JWT 令牌中的自定义请求头或普通请求头传递用户身份信息。修改请求头的方法见官方 Istio 文档。
Comments are powered by giscus and GitHub Discussions. They load from giscus.app and GitHub only after you click the button below.