基於角色的存取控制 (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” 也是如此。任何使用者都可以在路徑前綴為
/products
的路徑上讀取 (GET
) 該服務,只要目的地端口是 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
策略指定角色以及分配/拒絕該角色的主體。當且僅當其至少一個許可權與正在執行的動作匹配,並且其至少一個主體與下游匹配,並且如果指定了條件則該條件為真時,策略才匹配。
{
"permissions": [],
"principals": [],
"condition": {...}
}
- permissions
(repeated config.rbac.v3.Permission, 必填) 必填。定義角色的許可權集。每個許可權都使用 OR 語義進行匹配。若要匹配此策略的所有動作,應使用將
any
欄位設定為 true 的單個許可權。
- principals
(repeated config.rbac.v3.Principal, 必填) 必填。根據「動作」分配/拒絕角色的主體集。每個主體都使用 OR 語義進行匹配。若要匹配此策略的所有下游,應使用將
any
欄位設定為 true 的單個主體。
- condition
(.google.api.expr.v1alpha1.Expr) 一個可選的符號表達式,指定存取控制的 條件。該條件與許可權和主體組合在一起,作為具有 AND 語義的子句。僅在未使用 checked_condition 時使用。
config.rbac.v3.Permission
[config.rbac.v3.Permission proto]
許可權定義主體可以執行的動作(或多個動作)。
{
"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 中的其中一個。
- matcher
(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]
在 rule
oneof 中的 and_rules
和 or_rules
欄位中使用。根據上下文,每個都應用相關的行為。
{
"rules": []
}
- 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 中的其中一項。
- authenticated
(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 中的其中一項。
- source_ip
(config.core.v3.CidrRange) 描述下游 IP 的 CIDR 區塊。此位址將遵循 Proxy Protocol,但不遵循 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 標頭、Proxy Protocol 等推斷而來,這始終是實際的對等節點。
必須設定 and_ids、or_ids、any、authenticated、source_ip、direct_remote_ip、remote_ip、header、url_path、metadata、filter_state、not_id 中的其中一項。
- remote_ip
(config.core.v3.CidrRange) 描述下游遠端/原始位址的 CIDR 區塊。請注意:這可能不是實際的對等節點,並且可能與 direct_remote_ip 不同。例如,如果遠端 IP 是從 x-forwarder-for 標頭、Proxy Protocol 等推斷而來。
必須設定 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 中的其中一項。
- filter_state
(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]
在 identifier
oneof 中的 and_ids
和 or_ids
欄位中使用。根據上下文,每個都應用相關的行為。
{
"ids": []
}
- ids
(repeated config.rbac.v3.Principal, REQUIRED)
config.rbac.v3.Principal.Authenticated
[config.rbac.v3.Principal.Authenticated proto]
下游的驗證屬性。
{
"principal_name": {...}
}
- principal_name
(type.matcher.v3.StringMatcher) 主體的名稱。如果設定,則依序使用憑證中的 URI SAN 或 DNS SAN,否則使用主體欄位。如果未設定,則適用於任何已驗證的使用者。
config.rbac.v3.Action
當請求符合匹配器時,Action 定義允許或拒絕的結果。
{
"name": ...,
"action": ...
}
- name
(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
。