Envoy(服务网格授权)
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 协议缓冲区定义:
// 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.