基于角色的访问控制 (RBAC) (proto)
config.rbac.v3.RBAC
基于角色的访问控制 (RBAC) 为服务提供服务级别和方法级别的访问控制。请求根据 action 以及是否找到匹配的策略来允许或拒绝。例如,如果操作是 ALLOW 并且找到匹配的策略,则应允许请求。
RBAC 还可用于通过动态元数据与访问记录器通信来做出访问记录决定。当操作为 LOG 且至少有一个策略匹配时,共享键命名空间“envoy.common”中的 access_log_hint 值将设置为 true,表示应记录请求。
以下是 RBAC 配置的示例。它有两个策略
服务帐户
cluster.local/ns/default/sa/admin对服务拥有完全访问权限,cluster.local/ns/default/sa/superuser也是如此。任何用户都可以读取 (
GET) 前缀为/products的服务的路径,只要目标端口为 80 或 443 即可。
action: ALLOW policies: "service-admin": permissions: - any: true principals: - authenticated: principal_name: exact: "cluster.local/ns/default/sa/admin" - authenticated: principal_name: exact: "cluster.local/ns/default/sa/superuser" "product-viewer": permissions: - and_rules: rules: - header: name: ":method" string_match: exact: "GET" - url_path: path: { prefix: "/products" } - or_rules: rules: - destination_port: 80 - destination_port: 443 principals: - any: true
{
"action": ...,
"policies": {...}
}
- action
(config.rbac.v3.RBAC.Action) 如果策略匹配,要采取的操作。每个操作要么允许要么拒绝请求,并且还可以执行特定于操作的操作。
操作
ALLOW:仅当存在与请求匹配的策略时才允许请求。DENY:仅当没有与请求匹配的策略时才允许请求。LOG:允许所有请求。如果至少有一个策略匹配,则动态元数据键access_log_hint在共享键命名空间envoy.common下设置为值true。如果没有任何策略匹配,则将其设置为false。其他操作不会修改此键。
- policies
(repeated map<string, config.rbac.v3.Policy>) 从策略名称映射到策略。当至少有一个策略与请求匹配时,就会发生匹配。策略按策略名称的字典顺序进行评估。
config.rbac.v3.RBAC.AuditLoggingOptions
枚举 config.rbac.v3.RBAC.AuditLoggingOptions.AuditCondition
[config.rbac.v3.RBAC.AuditLoggingOptions.AuditCondition proto]
这里的拒绝和允许是指 RBAC 决策,而不是操作。
- NONE
(默认) 从不审核。
- ON_DENY
当 RBAC 拒绝请求时进行审核。
- ON_ALLOW
当 RBAC 允许请求时进行审核。
- ON_DENY_AND_ALLOW
审核 RBAC 是否允许或拒绝请求。
枚举 config.rbac.v3.RBAC.Action
[config.rbac.v3.RBAC.Action proto]
我们应该使用安全列表还是阻止列表样式的访问控制?
- ALLOW
(默认) 策略授予主体访问权限。其余的都被拒绝。这是安全列表样式的访问控制。这是默认类型。
- DENY
策略拒绝主体访问权限。其余的都被允许。这是阻止列表样式的访问控制。
- LOG
策略根据请求是否匹配来设置
access_log_hint动态元数据键。所有请求都被允许。
config.rbac.v3.Policy
Policy 指定了一个角色以及被分配/拒绝该角色的主体。当且仅当至少一个权限与正在进行的操作匹配,并且至少一个主体与下游匹配,并且如果指定了条件则条件为真时,策略才匹配。
{
"permissions": [],
"principals": [],
"condition": {...}
}
- permissions
(repeated config.rbac.v3.Permission, 必需) 必需。定义角色的权限集。每个权限都使用 OR 语义与之匹配。要匹配此策略的所有操作,应使用一个具有设置为 true 的
any字段的 Permission。
- principals
(repeated config.rbac.v3.Principal, 必需) 必需。根据“action”分配/拒绝角色的主体集。每个主体都使用 OR 语义与之匹配。要匹配此策略的所有下游,应使用一个具有设置为 true 的
any字段的 Principal。
- condition
(.google.api.expr.v1alpha1.Expr) 指定访问控制 条件 的可选符号表达式。条件与权限和主体结合使用,作为具有 AND 语义的子句。仅当未使用 checked_condition 时才使用。
config.rbac.v3.Permission
[config.rbac.v3.Permission proto]
Permission 定义了主体可以执行的操作(或操作)。
{
"and_rules": {...},
"or_rules": {...},
"any": ...,
"header": {...},
"url_path": {...},
"destination_ip": {...},
"destination_port": ...,
"destination_port_range": {...},
"metadata": {...},
"not_rule": {...},
"requested_server_name": {...},
"matcher": {...},
"uri_template": {...}
}
- and_rules
(config.rbac.v3.Permission.Set) 一组规则,所有规则都必须匹配才能定义操作。
必须设置 and_rules、or_rules、any、header、url_path、destination_ip、destination_port、destination_port_range、metadata、not_rule、requested_server_name、matcher、uri_template 中的其中一个。
- or_rules
(config.rbac.v3.Permission.Set) 一组规则,其中至少一个规则必须匹配才能定义操作。
必须设置 and_rules、or_rules、any、header、url_path、destination_ip、destination_port、destination_port_range、metadata、not_rule、requested_server_name、matcher、uri_template 中的其中一个。
- any
(bool) 当 any 设置时,它匹配任何操作。
必须设置 and_rules、or_rules、any、header、url_path、destination_ip、destination_port、destination_port_range、metadata、not_rule、requested_server_name、matcher、uri_template 中的其中一个。
- header
(config.route.v3.HeaderMatcher) 传入 HTTP 请求中的标头(或伪标头,例如:path 或:method)。仅适用于 HTTP 请求。注意:伪标头:path 包含查询和片段字符串。如果您想匹配不带查询和片段字符串的 URL 路径,请使用
url_path字段。必须设置 and_rules、or_rules、any、header、url_path、destination_ip、destination_port、destination_port_range、metadata、not_rule、requested_server_name、matcher、uri_template 中的其中一个。
- url_path
(type.matcher.v3.PathMatcher) 传入 HTTP 请求中的 URL 路径。仅适用于 HTTP。
必须设置 and_rules、or_rules、any、header、url_path、destination_ip、destination_port、destination_port_range、metadata、not_rule、requested_server_name、matcher、uri_template 中的其中一个。
- destination_ip
(config.core.v3.CidrRange) 描述目标 IP 的 CIDR 块。
必须设置 and_rules、or_rules、any、header、url_path、destination_ip、destination_port、destination_port_range、metadata、not_rule、requested_server_name、matcher、uri_template 中的其中一个。
- destination_port
(uint32) 描述连接到的目标端口的端口号。
必须设置 and_rules、or_rules、any、header、url_path、destination_ip、destination_port、destination_port_range、metadata、not_rule、requested_server_name、matcher、uri_template 中的其中一个。
- destination_port_range
(type.v3.Int32Range) 描述连接到的目标端口范围的端口号范围。
必须设置 and_rules、or_rules、any、header、url_path、destination_ip、destination_port、destination_port_range、metadata、not_rule、requested_server_name、matcher、uri_template 中的其中一个。
- metadata
(type.matcher.v3.MetadataMatcher) 描述操作的其他信息的元数据。
必须设置 and_rules、or_rules、any、header、url_path、destination_ip、destination_port、destination_port_range、metadata、not_rule、requested_server_name、matcher、uri_template 中的其中一个。
- not_rule
(config.rbac.v3.Permission) 否定匹配提供的权限。例如,如果
not_rule的值将匹配,则此权限将不匹配。相反,如果not_rule的值将不匹配,则此权限将匹配。必须设置 and_rules、or_rules、any、header、url_path、destination_ip、destination_port、destination_port_range、metadata、not_rule、requested_server_name、matcher、uri_template 中的其中一个。
- requested_server_name
(type.matcher.v3.StringMatcher) 客户端连接请求中的请求服务器。这通常是 TLS SNI。
注意
此字段的行为可能会受到 Envoy 配置方式的影响,如下所述。
如果未添加 TLS Inspector 过滤器,并且未为 服务器名称 定义
FilterChainMatch,则 TLS 连接的请求 SNI 服务器名称将被视为不存在。一个 侦听器过滤器 可能会覆盖 Envoy 中连接的请求服务器名称。
请参阅 此常见问题解答条目 了解如何设置 SNI。
必须设置 and_rules、or_rules、any、header、url_path、destination_ip、destination_port、destination_port_range、metadata、not_rule、requested_server_name、matcher、uri_template 中的其中一个。
- 匹配器
(config.core.v3.TypedExtensionConfig) 用于为 RBAC 配置自定义匹配器的扩展。
必须设置 and_rules、or_rules、any、header、url_path、destination_ip、destination_port、destination_port_range、metadata、not_rule、requested_server_name、matcher、uri_template 中的其中一个。
- uri_template
(config.core.v3.TypedExtensionConfig) URI 模板路径匹配。
必须设置 and_rules、or_rules、any、header、url_path、destination_ip、destination_port、destination_port_range、metadata、not_rule、requested_server_name、matcher、uri_template 中的其中一个。
config.rbac.v3.Permission.Set
[config.rbac.v3.Permission.Set proto]
用于 and_rules 和 or_rules 字段中的 rule oneof。根据上下文,每个都应用于关联的行为。
{
"rules": []
}
- 规则
(repeated config.rbac.v3.Permission, REQUIRED)
config.rbac.v3.Principal
[config.rbac.v3.Principal proto]
Principal 为下游主体定义一个身份或一组身份。
{
"and_ids": {...},
"or_ids": {...},
"any": ...,
"authenticated": {...},
"source_ip": {...},
"direct_remote_ip": {...},
"remote_ip": {...},
"header": {...},
"url_path": {...},
"metadata": {...},
"filter_state": {...},
"not_id": {...}
}
- and_ids
(config.rbac.v3.Principal.Set) 一组标识符,所有这些标识符都必须匹配才能定义下游。
必须设置 and_ids、or_ids、any、authenticated、source_ip、direct_remote_ip、remote_ip、header、url_path、metadata、filter_state、not_id 中的精确一个。
- or_ids
(config.rbac.v3.Principal.Set) 一组标识符,至少一个必须匹配才能定义下游。
必须设置 and_ids、or_ids、any、authenticated、source_ip、direct_remote_ip、remote_ip、header、url_path、metadata、filter_state、not_id 中的精确一个。
- any
(bool) 当设置 any 时,它匹配任何下游。
必须设置 and_ids、or_ids、any、authenticated、source_ip、direct_remote_ip、remote_ip、header、url_path、metadata、filter_state、not_id 中的精确一个。
- 已认证
(config.rbac.v3.Principal.Authenticated) 用于识别下游的已认证属性。
必须设置 and_ids、or_ids、any、authenticated、source_ip、direct_remote_ip、remote_ip、header、url_path、metadata、filter_state、not_id 中的精确一个。
- 源 IP
(config.core.v3.CidrRange) 描述下游 IP 的 CIDR 块。此地址将遵守代理协议,但不会遵守 XFF。
此字段已弃用;请使用 remote_ip 获取相同行为,或者使用 direct_remote_ip。
必须设置 and_ids、or_ids、any、authenticated、source_ip、direct_remote_ip、remote_ip、header、url_path、metadata、filter_state、not_id 中的精确一个。
- direct_remote_ip
(config.core.v3.CidrRange) 描述下游远程/源地址的 CIDR 块。注意:即使 remote_ip 是从例如 x-forwarder-for 标头、代理协议等推断出来的,这始终是物理对等方。
必须设置 and_ids、or_ids、any、authenticated、source_ip、direct_remote_ip、remote_ip、header、url_path、metadata、filter_state、not_id 中的精确一个。
- 远程 IP
(config.core.v3.CidrRange) 描述下游远程/源地址的 CIDR 块。注意:这可能不是物理对等方,并且可能与 direct_remote_ip 不同。例如,如果远程 IP 是从例如 x-forwarder-for 标头、代理协议等推断出来的。
必须设置 and_ids、or_ids、any、authenticated、source_ip、direct_remote_ip、remote_ip、header、url_path、metadata、filter_state、not_id 中的精确一个。
- header
(config.route.v3.HeaderMatcher) 传入 HTTP 请求中的标头(或伪标头,例如:path 或:method)。仅适用于 HTTP 请求。注意:伪标头:path 包含查询和片段字符串。如果您想匹配不带查询和片段字符串的 URL 路径,请使用
url_path字段。必须设置 and_ids、or_ids、any、authenticated、source_ip、direct_remote_ip、remote_ip、header、url_path、metadata、filter_state、not_id 中的精确一个。
- url_path
(type.matcher.v3.PathMatcher) 传入 HTTP 请求中的 URL 路径。仅适用于 HTTP。
必须设置 and_ids、or_ids、any、authenticated、source_ip、direct_remote_ip、remote_ip、header、url_path、metadata、filter_state、not_id 中的精确一个。
- metadata
(type.matcher.v3.MetadataMatcher) 描述有关主体附加信息的元数据。
必须设置 and_ids、or_ids、any、authenticated、source_ip、direct_remote_ip、remote_ip、header、url_path、metadata、filter_state、not_id 中的精确一个。
- 过滤器状态
(type.matcher.v3.FilterStateMatcher) 使用过滤器状态对象标识主体。
必须设置 and_ids、or_ids、any、authenticated、source_ip、direct_remote_ip、remote_ip、header、url_path、metadata、filter_state、not_id 中的精确一个。
- not_id
(config.rbac.v3.Principal) 否定匹配提供的主体。例如,如果
not_id的值匹配,则此主体将不匹配。相反,如果not_id的值不匹配,则此主体将匹配。必须设置 and_ids、or_ids、any、authenticated、source_ip、direct_remote_ip、remote_ip、header、url_path、metadata、filter_state、not_id 中的精确一个。
config.rbac.v3.Principal.Set
[config.rbac.v3.Principal.Set proto]
用于 and_ids 和 or_ids 字段中的 identifier oneof。根据上下文,每个都应用于关联的行为。
{
"ids": []
}
- ID
(repeated config.rbac.v3.Principal, REQUIRED)
config.rbac.v3.Principal.Authenticated
[config.rbac.v3.Principal.Authenticated proto]
下游的身份验证属性。
{
"principal_name": {...}
}
- 主体名称
(type.matcher.v3.StringMatcher) 主体的名称。如果设置,将按顺序使用证书中的 URI SAN 或 DNS SAN,否则使用主题字段。如果未设置,它适用于任何已认证的用户。
config.rbac.v3.Action
Action 定义当请求匹配匹配器时的允许或拒绝结果。
{
"name": ...,
"action": ...
}
- 姓名
(string, REQUIRED) 名称指示策略名称。
- action
(config.rbac.v3.RBAC.Action) 如果匹配器匹配,要采取的操作。每个操作都允许或拒绝请求,并且还可以执行特定于操作的操作。
操作
ALLOW: 如果请求在 ALLOW 上匹配,则允许。DENY: 如果请求在 DENY 上匹配,则不允许。LOG: 如果请求在 LOG 上匹配,则允许。此外,共享密钥命名空间envoy.common下的动态元数据键access_log_hint将设置为值true。如果请求无法匹配,它将回退到
DENY。
日志行为
如果 RBAC 匹配器包含至少一个 LOG 操作,则将根据请求是否在 LOG 操作上匹配来设置动态元数据键
access_log_hint。