如果系统权限策略不能满足您的要求,您可以创建自定义权限策略实现最小授权。使用自定义权限策略有助于实现权限的精细化管控,是提升资源访问安全的有效手段。本文介绍视觉智能开放平台使用自定义权限策略的场景和策略示例。
什么是自定义权限策略
在基于RAM的访问控制体系中,自定义权限策略是指在系统权限策略之外,您可以自主创建、更新和删除的权限策略。自定义权限策略的版本更新需由您来维护。
创建自定义权限策略后,需为RAM用户、用户组或RAM角色绑定权限策略,这些RAM身份才能获得权限策略中指定的访问权限。
已创建的权限策略支持删除,但删除前需确保该策略未被引用。如果该权限策略已被引用,您需要在该权限策略的引用记录中移除授权。
自定义权限策略支持版本控制,您可以按照RAM规定的版本管理机制来管理您创建的自定义权限策略版本。
操作文档
常见自定义权限策略场景及示例
全部权限
方式一:直接授予用户系统权限策略AliyunVIAPIFullAccess(管理视觉智能API的权限)。
方式二:自定义权限。拥有视觉智能所有能力的全部权限,policy定义如下所示。
{ "Version": "1", "Statement": [ { "Action": [ "viapi-imageenhan:*", "viapi-imagerecog:*", "viapi-imageseg:*", "viapi-ocr:*", "viapi-facebody:*", "viapi-objectdet:*", "viapi-imageaudit:*", "viapi-goodstech:*", "viapi-imgsearch:*", "viapi-videorecog:*", "viapi-videoenhan:*", "viapi-videoseg:*", "viapi-imageprocess:*", "viapi-regen:*", "viapi:*" ], "Resource": "*", "Effect": "Allow" }, { "Action": "ram:PassRole", "Resource": "*", "Effect": "Allow", "Condition": { "StringEquals": { "acs:Service": "viapi.aliyuncs.com" } } } ] }
单个或多个API限制
如果您希望限制RAM用户只能调用单个或多个API,可以通过自定义策略实现。
例如,以下策略限制只能调用RecognizeBankCard和CompareFace。其他能力类似,参考能力开通,找到相关类目英文名Product和相关能力英文名Action,在Statement
的Action
下面增加viapi-<Product>:<Action>
即可。
{
"Version": "1",
"Statement": [
{
"Action": [
"viapi-ocr:RecognizeBankCard",
"viapi-facebody:CompareFace"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": "ram:PassRole",
"Resource": "*",
"Effect": "Allow",
"Condition": {
"StringEquals": {
"acs:Service": "viapi.aliyuncs.com"
}
}
}
]
}
IP/SSL限制
支持带IP/SSL限制的授权。该授权策略在满足以下两个条件时可以访问所有资源。
RAM用户当前的IP网段为42.120.XX.X/24。
RAM用户正在使用HTTPS访问阿里云控制台或OpenAPI。
{
"Statement": [
{
"Effect": "Allow",
"Action": "viapi-imageenhan:*",
"Resource": "acs:viapi-imageenhan:*:*:*",
"Condition": {
"IpAddress": {
"acs:SourceIp": "42.120.99.0/24"
},
"Bool": {
"acs:SecureTransport": "true"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-imagerecog:*",
"Resource": "acs:viapi-imagerecog:*:*:*",
"Condition": {
"IpAddress": {
"acs:SourceIp": "42.120.99.0/24"
},
"Bool": {
"acs:SecureTransport": "true"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-imageseg:*",
"Resource": "acs:viapi-imageseg:*:*:*",
"Condition": {
"IpAddress": {
"acs:SourceIp": "42.120.99.0/24"
},
"Bool": {
"acs:SecureTransport": "true"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-imageaudit:*",
"Resource": "acs:viapi-imageaudit:*:*:*",
"Condition": {
"IpAddress": {
"acs:SourceIp": "42.120.99.0/24"
},
"Bool": {
"acs:SecureTransport": "true"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-ocr:*",
"Resource": "acs:viapi-ocr:*:*:*",
"Condition": {
"IpAddress": {
"acs:SourceIp": "42.120.99.0/24"
},
"Bool": {
"acs:SecureTransport": "true"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-facebody:*",
"Resource": "acs:viapi-facebody:*:*:*",
"Condition": {
"IpAddress": {
"acs:SourceIp": "42.120.99.0/24"
},
"Bool": {
"acs:SecureTransport": "true"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-objectdet:*",
"Resource": "acs:viapi-objectdet:*:*:*",
"Condition": {
"IpAddress": {
"acs:SourceIp": "42.120.99.0/24"
},
"Bool": {
"acs:SecureTransport": "true"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-goodstech:*",
"Resource": "acs:viapi-goodstech:*:*:*",
"Condition": {
"IpAddress": {
"acs:SourceIp": "42.120.99.0/24"
},
"Bool": {
"acs:SecureTransport": "true"
}
}
}
],
"Version": "1"
}
时间限制
以下授权策略的含义为:在北京时间2019年09月25日下午12:30之前,RAM用户拥有viapi的所有权限。
{
"Statement": [
{
"Effect": "Allow",
"Action": "viapi-imageenhan:*",
"Resource": "acs:viapi-imageenhan:*:*:*",
"Condition": {
"DateLessThan": {
"acs:CurrentTime": "2019-09-25T12:30:00+08:00"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-imagerecog:*",
"Resource": "acs:viapi-imagerecog:*:*:*",
"Condition": {
"DateLessThan": {
"acs:CurrentTime": "2019-09-25T12:30:00+08:00"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-imageseg:*",
"Resource": "acs:viapi-imageseg:*:*:*",
"Condition": {
"DateLessThan": {
"acs:CurrentTime": "2019-09-25T12:30:00+08:00"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-imageaudit:*",
"Resource": "acs:viapi-imageaudit:*:*:*",
"Condition": {
"DateLessThan": {
"acs:CurrentTime": "2019-09-25T12:30:00+08:00"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-ocr:*",
"Resource": "acs:viapi-ocr:*:*:*",
"Condition": {
"DateLessThan": {
"acs:CurrentTime": "2019-09-25T12:30:00+08:00"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-facebody:*",
"Resource": "acs:viapi-facebody:*:*:*",
"Condition": {
"DateLessThan": {
"acs:CurrentTime": "2019-09-25T12:30:00+08:00"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-objectdet:*",
"Resource": "acs:viapi-objectdet:*:*:*",
"Condition": {
"DateLessThan": {
"acs:CurrentTime": "2019-09-25T12:30:00+08:00"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-goodstech:*",
"Resource": "acs:viapi-goodstech:*:*:*",
"Condition": {
"DateLessThan": {
"acs:CurrentTime": "2019-09-25T12:30:00+08:00"
}
}
}
],
"Version": "1"
}
MFA
如果一个RAM用户仅被授予该授权策略,那么只有当该RAM用户启用MFA并使用MFA登录时,才具有viapi的权限。此RAM用户的AK也没有权限,需要使用AK+正确的MFA六位Code调用STS服务获取一个临时AK(15分钟失效),此临时AK才具有相应的权限。
{
"Statement": [
{
"Effect": "Allow",
"Action": "viapi-imageenhan:*",
"Resource": "acs:viapi-imageenhan:*:*:*",
"Condition": {
"Bool": {
"acs:MFAPresent": "true"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-imagerecog:*",
"Resource": "acs:viapi-imagerecog:*:*:*",
"Condition": {
"Bool": {
"acs:MFAPresent": "true"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-imageseg:*",
"Resource": "acs:viapi-imageseg:*:*:*",
"Condition": {
"Bool": {
"acs:MFAPresent": "true"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-imageaudit:*",
"Resource": "acs:viapi-imageaudit:*:*:*",
"Condition": {
"Bool": {
"acs:MFAPresent": "true"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-ocr:*",
"Resource": "acs:viapi-ocr:*:*:*",
"Condition": {
"Bool": {
"acs:MFAPresent": "true"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-facebody:*",
"Resource": "acs:viapi-facebody:*:*:*",
"Condition": {
"Bool": {
"acs:MFAPresent": "true"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-objectdet:*",
"Resource": "acs:viapi-objectdet:*:*:*",
"Condition": {
"Bool": {
"acs:MFAPresent": "true"
}
}
},
{
"Effect": "Allow",
"Action": "viapi-goodstech:*",
"Resource": "acs:viapi-goodstech:*:*:*",
"Condition": {
"Bool": {
"acs:MFAPresent": "true"
}
}
}
],
"Version": "1"
}