本文為您介紹Action、Resource和Condition的定義以及應用情境。
Action定義
Action是API的名稱,可以根據Action設定開放或限制使用者可以訪問的API。在建立Table Store的授權策略時,每個Action都需要添加ots:
首碼,多個Action以半形逗號(,)分隔,並且支援星號(*)萬用字元(包括首碼匹配和尾碼匹配)。
以下為一些典型的Action定義:
- 單個API
"Action": "ots:GetRow"
- 多個API
"Action": [ "ots:PutRow", "ots:GetRow" ]
- 所有隻讀API
{ "Version": "1", "Statement": [ { "Action": [ "ots:BatchGet*", "ots:Describe*", "ots:Get*", "ots:List*", "ots:Consume*", "ots:Search", "ots:ComputeSplitPointsBySize" ], "Resource": "*", "Effect": "Allow" } ] }
- 所有讀寫API
"Action": "ots:*"
- 所有SQL操作API
"Action": "ots:SQL*"
Resource定義
Table Store的資源由產品、地區、使用者ID、執行個體名和表名多個欄位組成。每個欄位支援星號萬用字元(包括首碼匹配和尾碼匹配),Resource格式如下:
acs:ots:[region]:[user_id]:instance/[instance_name]/table/[table_name]
[xxx]
表示變數,產品固定為ots,地區為英文縮寫(例如cn-hangzhou),使用者ID為阿里雲帳號ID。 acs:ots:[region]:[user_id]:instance/[instance_name]
以下是一些典型的Resource定義:
- 所有地區的所有使用者的所有資源
"Resource": "acs:ots:*:*:*"
- 華東1(杭州)地區,使用者123456的所有執行個體及其下所有的表
"Resource": "acs:ots:cn-hangzhou:123456:instance/*"
- 華東1(杭州)地區,使用者123456的名稱為abc的執行個體及其下所有的表
"Resource": [ "acs:ots:cn-hangzhou:123456:instance/abc", "acs:ots:cn-hangzhou:123456:instance/abc/table/*" ]
- 所有以abc開頭的執行個體及下的所有表
"Resource": "acs:ots:*:*:instance/abc*"
- 所有以abc開頭的執行個體下的所有以xyz開頭的表(不包括執行個體資源,不匹配
acs:ots:*:*:instance/abc*
)"Resource": "acs:ots:*:*:instance/abc*/table/xyz*"
- 所有以abc結尾的Instance及其下的所有以xyz結尾的表
"Resource": [ "acs:ots:*:*:instance/*abc", "acs:ots:*:*:instance/*abc/table/*xyz" ]
Table Store的API類型
目前Table Store包含以下三類API:
- 執行個體管理類API
- 表和資料讀寫類API
- 即時通道管理和讀寫類API
各API的類別詳情請參見下表。
- 管理類API訪問的資源
管理類API主要為執行個體相關的操作,僅由控制台調用。對該類API的Action和Resource定義,將影響使用者使用控制台。以下訪問的資源省略了
acs:ots:[region]:[user_id]:
首碼,只描述執行個體和表部分。API名稱/Action 訪問的資源 ListInstance instance/* InsertInstance instance/[instance_name] GetInstance instance/[instance_name] DeleteInstance instance/[instance_name] - 資料類API訪問的資源
資料類API主要為表和行相關的操作,控制台和SDK都會調用,對該類API的Action和Resource定義,將影響使用者使用控制台。以下訪問的資源省略了
acs:ots:[region]:[user_id]:
首碼,只描述執行個體和表部分。API名稱/Action 訪問的資源 ListTable instance/[instance_name]/table/* CreateTable instance/[instance_name]/table/[table_name] UpdateTable instance/[instance_name]/table/[table_name] DescribeTable instance/[instance_name]/table/[table_name] DeleteTable instance/[instance_name]/table/[table_name] GetRow instance/[instance_name]/table/[table_name] PutRow instance/[instance_name]/table/[table_name] UpdateRow instance/[instance_name]/table/[table_name] DeleteRow instance/[instance_name]/table/[table_name] GetRange instance/[instance_name]/table/[table_name] BatchGetRow instance/[instance_name]/table/[table_name] BatchWriteRow instance/[instance_name]/table/[table_name] ComputeSplitPointsBySize instance/[instance_name]/table/[table_name] StartLocalTransaction instance/[instance_name]/table/[table_name] CommitTransaction instance/[instance_name]/table/[table_name] AbortTransaction instance/[instance_name]/table/[table_name] CreateIndex instance/[instance_name]/table/[table_name] DropIndex instance/[instance_name]/table/[table_name] CreateSearchIndex instance/[instance_name]/table/[table_name] DeleteSearchIndex instance/[instance_name]/table/[table_name] ListSearchIndex instance/[instance_name]/table/[table_name] DescribeSearchIndex instance/[instance_name]/table/[table_name] Search instance/[instance_name]/table/[table_name] CreateTunnel instance/[instance_name]/table/[table_name] DeleteTunnel instance/[instance_name]/table/[table_name] ListTunnel instance/[instance_name]/table/[table_name] DescribeTunnel instance/[instance_name]/table/[table_name] ConsumeTunnel instance/[instance_name]/table/[table_name] BulkImport instance/[instance_name]/table/[table_name] BulkExport instance/[instance_name]/table/[table_name] SQL_Select instance/[instance_name]/table/[table_name] SQL_Create instance/[instance_name]/table/[table_name] SQL_DropMapping instance/[instance_name]/table/[table_name] - Tunnel API訪問的資源
Tunnel API主要為通道相關的操作,控制台和SDK都會調用,對該類API的Action和Resource定義,將影響使用者使用控制台。以下訪問的資源省略了
acs:ots:[region]:[user_id]:
首碼,只描述執行個體和表部分。API 名稱/Action 訪問的資源 ListTable instance/[instance_name] CreateTable instance/[instance_name] UpdateTable instance/[instance_name] DescribeTable instance/[instance_name] DeleteTable instance/[instance_name] GetRow instance/[instance_name] PutRow instance/[instance_name] UpdateRow instance/[instance_name] DeleteRow instance/[instance_name] GetRange instance/[instance_name] BatchGetRow instance/[instance_name] BatchWriteRow instance/[instance_name] ComputeSplitPointsBySize instance/[instance_name] StartLocalTransaction instance/[instance_name] CommitTransaction instance/[instance_name] AbortTransaction instance/[instance_name] CreateIndex instance/[instance_name] DropIndex instance/[instance_name] CreateSearchIndex instance/[instance_name] DeleteSearchIndex instance/[instance_name] ListSearchIndex instance/[instance_name] DescribeSearchIndex instance/[instance_name] Search instance/[instance_name] CreateTunnel instance/[instance_name] DeleteTunnel instance/[instance_name] ListTunnel instance/[instance_name] DescribeTunnel instance/[instance_name] ConsumeTunnel instance/[instance_name] - 常見問題說明
- Policy中Action和Resource通過字串匹配進行驗證的,並且星號萬用字元區分首碼和尾碼匹配。如果Resource定義為
acs:ots:*:*:instance/*/
,則無法匹配acs:ots:*:*:instance/abc
。如果Resource定義為acs:ots:*:*:instance/abc
,則無法匹配acs:ots:*:*:instance/abc/table/xyz
。 - 登入Table Store控制台管理執行個體資源,需要授予使用者
acs:ots:[region]:[user_id]:instance/*
資源的讀取許可權,因為控制台需要擷取執行個體的列表。 - 對於大量操作API(例如BatchGetRow和BatchWriteRow),後端服務會對被訪問的每張表分別鑒權,只有所有表都通過鑒權才能執行操作,否則會返回許可權錯誤。
- Policy中Action和Resource通過字串匹配進行驗證的,並且星號萬用字元區分首碼和尾碼匹配。如果Resource定義為
Condition定義
目前Policy支援訪問IP限制、是否通過HTTPS訪問、是否通過MFA(多因素認證)訪問和訪問時間限制等多種鑒權條件,Table Store所有API都已經支援這些條件。
- 訪問IP限制
存取控制RAM可以限制訪問Table Store的源IP地址,並且支援根據網段進行過濾。以下是一些典型的使用情境:
- 限制多個IP地址。例如只允許IP地址為10.10.XX.XX和10.11.XX.XX的請求訪問。
{ "Statement": [ { "Effect": "Allow", "Action": "ots:*", "Resource": "acs:ots:*:*:*", "Condition": { "IpAddress": { "acs:SourceIp": [ "10.10.XX.XX", "10.11.XX.XX" ] } } } ], "Version": "1" }
- 限制單個IP地址和IP網段。例如只允許IP地址為10.10.XX.XX或10.10.XX.XX/24網段的請求訪問。
{ "Statement": [ { "Effect": "Allow", "Action": "ots:*", "Resource": "acs:ots:*:*:*", "Condition": { "IpAddress": { "acs:SourceIp": [ "10.10.XX.XX", "10.10.XX.XX/24" ] } } } ], "Version": "1" }
- 限制多個IP地址。例如只允許IP地址為10.10.XX.XX和10.11.XX.XX的請求訪問。
- HTTPS訪問限制
存取控制可以限制是否通過HTTPS訪問。
以下是典型的使用情境,限制請求必須通過HTTPS訪問。
{ "Statement": [ { "Effect": "Allow", "Action": "ots:*", "Resource": "acs:ots:*:*:*", "Condition": { "Bool": { "acs:SecureTransport": "true" } } } ], "Version": "1" }
- MFA訪問限制
存取控制可以限制是否通過MFA(多因素認證)訪問。
以下是典型的使用情境,限制請求必須通過MFA訪問。
{ "Statement": [ { "Effect": "Allow", "Action": "ots:*", "Resource": "acs:ots:*:*:*", "Condition": { "Bool": { "acs:MFAPresent ": "true" } } } ], "Version": "1" }
- 訪問時間限制
存取控制可以限制請求的訪問時間,即只允許或拒絕在某個時間點範圍之前的請求。以下是典型的使用情境。
例如北京時間2016年1月1日零點之前使用者可以訪問,之後就不能再訪問。
{ "Statement": [ { "Effect": "Allow", "Action": "ots:*", "Resource": "acs:ots:*:*:*", "Condition": { "DateLessThan": { "acs:CurrentTime": "2016-01-01T00:00:00+08:00" } } } ], "Version": "1" }
典型使用情境
結合對Action、Resource和Condition的定義,以下列出一些典型使用情境的Policy定義和授權方法。
- 多種授權條件
對於訪問IP地址為10.10.XX.XX/24網段的使用者,可以對所有名稱為online-01和online-02的執行個體執行讀或者寫操作(包括執行個體下的所有表),且要求只能在2016-01-01 00:00:00之前訪問和通過HTTPS訪問。
操作步驟如下:
- 使用阿里雲帳號登入存取控制Resource Access Management控制台(預設已開通存取控制服務)。
- 建立權限原則。
- 在左側導覽列,選擇 。
- 在權限原則頁面,單擊建立權限原則。
- 在建立權限原則頁面,單擊指令碼編輯頁簽,並將如下內容填寫到策略內容中。
{ "Statement": [ { "Effect": "Allow", "Action": "ots:*", "Resource": [ "acs:ots:*:*:instance/online-01", "acs:ots:*:*:instance/online-01/table/*", "acs:ots:*:*:instance/online-02", "acs:ots:*:*:instance/online-02/table/*" ], "Condition": { "IpAddress": { "acs:SourceIp": [ "10.10.XX.XX/24" ] }, "DateLessThan": { "acs:CurrentTime": "2016-01-01T00:00:00+08:00" }, "Bool": { "acs:SecureTransport": "true" } } } ], "Version": "1" }
- 單擊繼續編輯基本資料,輸入策略名稱稱和備忘。
- 單擊確定。
- 為RAM使用者授予權限原則。
- 在左側導覽列,選擇 。
- 在使用者頁面,找到需要授權的RAM使用者,單擊使用者操作列的添加許可權。
- 在添加許可權面板,搜尋已建立的策略名稱稱,將該策略添加到已選擇授權策略名稱稱欄。
- 單擊確定。
- 拒絕請求
對於訪問IP地址為10.10.XX.XX的使用者,拒絕對華北2(北京)地區,名稱以online和product開頭的執行個體下的所有表執行寫操作(不包括對執行個體的操作)。
建立自訂授權策略和為RAM使用者授權的步驟同上,只需將如下內容填寫到策略內容即可。
{ "Statement": [ { "Effect": "Deny", "Action": [ "ots:Create*", "ots:Insert*", "ots:Put*", "ots:Update*", "ots:Delete*", "ots:BatchWrite*" ], "Resource": [ "acs:ots:cn-beijing:*:instance/online*/table/*", "acs:ots:cn-beijing:*:instance/product*/table/*" ], "Condition": { "IpAddress": { "acs:SourceIp": [ "10.10.XX.XX" ] } } } ], "Version": "1" }