如果服務嘗試執行的動作未獲授權,就會發生授權違規情形。在標準 permissionsOnly強制執行模式中,軟體定義車輛 (SDV) 架構會檢查主體或其虛擬機器 (VM) 是否具備政策中宣告的必要權限。
您必須根據安全情境評估違規訊息。並非所有違規行為都表示發生錯誤或有人嘗試未經授權存取。
系統會記錄所有授權決策。如要查看這些訊息,請在 logcat 輸出內容中搜尋稽核訊息:
adb -s $SERIAL logcat | grep 'audit message'
授權成功
系統會在 debug 層級記錄檢查結果。
這表示主體已宣告必要權限:
D SdvServiceManagerServer: instance2:com.sdv.google.sample.bar.ServiceBundleBar/instance declares permission to access com.sdv.google.sample.foo.ServiceBundleFoo#foo-rpc, audit message: ...
違規事項和缺少權限
如果缺少權限,就會發生違規情形。
當主體在授權政策中缺少必要權限 (例如 client、server、publisher 或 subscriber),或主體的 VM 在 VM 層級政策中缺少必要權限時,就會發生這種情況。
這項資訊會記錄在 error 層級:
E SdvServiceManagerServer: Authz violation. instance2:com.sdv.google.sample.bar.ServiceBundleBar/instance does not declare permission to access com.sdv.google.sample.foo.ServiceBundleFoo#foo-rpc, audit message: Subject lacks 'client' permission...
修復
記錄的 audit message 通常會提供實用建議,說明需要新增哪些內容才能解決違規問題。
舉例來說,您可能會看到類似以下的權限錯誤:
Subject 'vm:com.client.Bundle/default' lacks 'client' permission for service 'com.server.TargetType' with channel 'my-unit'. Add 'client { service: "com.server.TargetType" channel: "my-unit" }' to the subject's Authz policy
如要修正這個問題,請將規則新增至主體的授權政策 textproto:
client {
service: "com.server.TargetType"
channel: "my-unit"
}
如果錯誤訊息指出主體 VM 中缺少權限,您必須將權限新增至 VM 層級政策,例如 <vm_name>.textproto 或 .default.textproto (位於 com.oem.sdv.authz APEX 中):
allow_server {
service: "com.server.TargetType"
channel: "my-unit"
}
從 ACL 遷移
為確保回溯相容性和遷移作業順利進行,架構支援 ACLs only、Lenient 和 Strict 模式,這些模式會考量先前的存取控管清單 (ACL)。
僅限 ACL 模式
在 ACLs only 模式中,只有在 ACL 允許存取時,系統才會允許存取,並忽略權限。如果 ACL 拒絕存取,系統會記錄錯誤:
E SdvServiceManagerServer: Authz violation. com.sdv.google.sample.foo.ServiceBundleFoo#foo-rpc denies access to instance2:com.sdv.google.sample.bar.ServiceBundleBar/instance, audit message: ...
寬鬆模式
在 Lenient 模式中,只要 ACL 或權限允許,即可存取。如果系統是透過 ACL 授予存取權,但缺少權限,系統就會在 debug 層級記錄為軟性違規,協助您找出缺少的權限,同時維持系統運作:
D SdvServiceManagerServer: Permissions Authz violation (access granted by ACLs): instance2:com.sdv.google.sample.bar.ServiceBundleBar/instance does not declare permission to access com.sdv.google.sample.foo.ServiceBundleFoo#foo-rpc, audit message: ...
如果 ACL 和權限都失敗,系統會將兩者都記錄為錯誤:
E SdvServiceManagerServer: Authz violation. com.sdv.google.sample.foo.ServiceBundleFoo#foo-rpc denies access to instance2:com.sdv.google.sample.bar.ServiceBundleBar/instance, audit message: ...
E SdvServiceManagerServer: Authz violation. instance2:com.sdv.google.sample.bar.ServiceBundleBar/instance does not declare permission to access com.sdv.google.sample.foo.ServiceBundleFoo#foo-rpc, audit message: ...
嚴格模式
在 Strict 模式下,ACL 和權限都必須允許存取。如果 ACL 或權限失敗,系統會拒絕存取並記錄錯誤。