访问控制(RAM)是阿里云提供的管理用户身份与资源访问权限的服务。使用 RAM 可以让您避免与其他用户共享阿里云账号密钥,并可按需为用户授予最小权限。RAM 中使用权限策略描述授权的具体内容。
本文为您介绍 API 网关 为 RAM 权限策略定义的操作(Action)、资源(Resource)和条件(Condition)。 API 网关 的 RAM 代码(RamCode)为 apig ,支持的授权粒度为 资源级 。
权限策略通用结构
权限策略支持 JSON 格式,其通用结构如下:
{
"Version": "1",
"Statement": [
{
"Effect": "<Effect>",
"Action": "<Action>",
"Resource": "<Resource>",
"Condition": {
"<Condition_operator>": {
"<Condition_key>": [
"<Condition_value>"
]
}
}
}
]
} 各字段含义如下:
Effect:权限策略效果。取值:Allow(允许)、Deny(拒绝)。
Action:授予允许或拒绝权限的具体操作。具体信息,请参见操作(Action)。
Resource:受操作影响的具体对象,您可以使用资源 ARN 来描述指定资源。具体信息,请参见资源(Resource)。
Condition:指授权生效的条件。可选字段。具体信息,请参见条件(Condition)。
Condition_operator:条件运算符,不同类型的条件对应不同的条件运算符。具体信息,请参见权限策略基本元素。
Condition_key:条件关键字。
Condition_value:条件关键字对应的值。
操作(Action)
下表是API 网关定义的操作,这些操作可以在 RAM 权限策略语句的Action元素中使用,用来授予执行该操作的权限。下面对表中的具体项提供说明:
操作:是指具体的权限点。
API:是指操作对应的 API 接口。
访问级别:是指每个操作的访问级别,取值为写入(Write)、读取(Read)或列出(List)。
资源类型:是指操作中支持授权的资源类型。具体说明如下:
对于必选的资源类型,用前面加 * 表示。
对于不支持资源级授权的操作,用
全部资源表示。
条件关键字:是指云产品自身定义的条件关键字。该列不体现适用于任何操作的通用条件关键字。
关联操作:是指成功执行操作所需要的其他权限。操作者必须同时具备关联操作的权限,操作才能成功。
|
操作 |
API |
访问级别 |
资源类型 |
条件关键字 |
关联操作 |
| apig:CreatePolicy | CreatePolicy | none |
*全部资源
|
无 | 无 |
| apig:BatchDeleteConsumerAuthorizationRule | BatchDeleteConsumerAuthorizationRule | none |
*全部资源
|
无 | 无 |
| apig:ImportHttpApi | ImportHttpApi | none |
*全部资源
|
无 | 无 |
| apig:DeleteSource | DeleteSource | none |
*Source
|
无 | 无 |
| apig:DeleteHttpApiRoute | DeleteHttpApiRoute | none |
*HttpApi
|
无 | 无 |
| apig:UpdateSecret | UpdateSecret | none |
*Domain
|
无 | 无 |
| apig:ListMcpServers | ListMcpServers | none |
*全部资源
|
无 | 无 |
| apig:UnDeployMcpServer | UnDeployMcpServer | none |
*全部资源
|
无 | 无 |
| apig:CreatePolicyAttachment | CreatePolicyAttachment | create |
*全部资源
|
无 | 无 |
| apig:GetSecret | GetSecret | none |
*Domain
|
无 | 无 |
| apig:GetPolicy | GetPolicy | get |
*Policy
|
无 | 无 |
| apig:CreateHttpApiOperation | CreateHttpApiOperation | create |
*HttpApi
|
无 | 无 |
| apig:UpdateGatewayName | UpdateGatewayName | update |
*Gateway
|
无 | 无 |
| apig:ExportHttpApi | ExportHttpApi | none |
*HttpApi
|
无 | 无 |
| apig:CreateConsumerAuthorizationRules | CreateConsumerAuthorizationRules | none |
*全部资源
|
无 | 无 |
| apig:GetDashboard | GetDashboard | get |
*全部资源
|
无 | 无 |
| apig:CreatePluginAttachment | CreatePluginAttachment | none |
*全部资源
|
无 | 无 |
| apig:ListGateways | ListGateways | list |
*Gateway
|
无 | 无 |
| apig:DeployMcpServer | DeployMcpServer | none |
*全部资源
|
无 | 无 |
| apig:ListPolicyClasses | ListPolicyClasses | none |
*全部资源
|
无 | 无 |
| apig:CreateHttpApi | CreateHttpApi | create |
*HttpApi
|
无 | 无 |
| apig:UpdateGatewayFeature | UpdateGatewayFeature | none |
*Gateway
|
无 | 无 |
| apig:UpdateAndAttachPolicy | UpdateAndAttachPolicy | none |
*Policy
|
无 | 无 |
| apig:GetTraceConfig | GetTraceConfig | get |
*全部资源
|
无 | 无 |
| apig:UpdateConsumer | UpdateConsumer | none |
*Domain
|
无 | 无 |
| apig:ListDomains | ListDomains | none |
*Domain
|
无 | 无 |
| apig:GetHttpApi | GetHttpApi | get |
*HttpApi
|
无 | 无 |
| apig:InstallPlugin | InstallPlugin | none |
*全部资源
|
无 | 无 |
| apig:ListPluginClasses | ListPluginClasses | none |
*全部资源
|
无 | 无 |
| apig:DeleteGateway | DeleteGateway | delete |
*Gateway
|
无 | 无 |
| apig:ListConsumerAuthorizationRules | ListConsumerAuthorizationRules | none |
*Domain
|
无 | 无 |
| apig:DeleteConsumer | DeleteConsumer | none |
*Domain
|
无 | 无 |
| apig:ListZones | ListZones | none |
*全部资源
|
无 | 无 |
| apig:DeleteDomain | DeleteDomain | none |
*Domain
|
无 | 无 |
| apig:UpgradeGateway | UpgradeGateway | none |
*Gateway
|
无 | 无 |
| apig:CreateHttpApiRoute | CreateHttpApiRoute | none |
*HttpApi
|
无 | 无 |
| apig:GetDomain | GetDomain | get |
*Domain
|
无 | 无 |
| apig:DeletePluginAttachment | DeletePluginAttachment | none |
*全部资源
|
无 | 无 |
| apig:UpdateMcpServer | UpdateMcpServer | none |
*全部资源
|
无 | 无 |
| apig:GetHttpApiOperation | GetHttpApiOperation | get |
*HttpApi
|
无 | 无 |
| apig:ListPluginAttachments | ListPluginAttachments | none |
*全部资源
|
无 | 无 |
| apig:DeletePolicyAttachment | DeletePolicyAttachment | delete |
*全部资源
|
无 | 无 |
| apig:GetEnvironment | GetEnvironment | none |
*Environment
|
无 | 无 |
| apig:DeleteService | DeleteService | none |
*Service
|
无 | 无 |
| apig:CreateDomain | CreateDomain | create |
*Domain
|
无 | 无 |
| apig:UpdateDomain | UpdateDomain | none |
*Domain
|
无 | 无 |
| apig:QueryConsumerAuthorizationRules | QueryConsumerAuthorizationRules | none |
*全部资源
|
无 | 无 |
| apig:CreateConsumer | CreateConsumer | create |
*全部资源
|
无 | 无 |
| apig:UpdateHttpApiOperation | UpdateHttpApiOperation | update |
*HttpApi
|
无 | 无 |
| apig:GetHttpApiRoute | GetHttpApiRoute | none |
*HttpApi
|
无 | 无 |
| apig:CreateAndAttachPolicy | CreateAndAttachPolicy | none |
*Policy
|
无 | 无 |
| apig:RestartGateway | RestartGateway | none |
*Gateway
|
无 | 无 |
| apig:RemoveConsumerAuthorizationRule | RemoveConsumerAuthorizationRule | none |
*全部资源
|
无 | 无 |
| apig:UpdateHttpApiRoute | UpdateHttpApiRoute | none |
*HttpApi
|
无 | 无 |
| apig:GetPluginAttachment | GetPluginAttachment | get |
*全部资源
|
无 | 无 |
| apig:CreateSource | CreateSource | none |
*全部资源
|
无 | 无 |
| apig:CreateConsumerAuthorizationRule | CreateConsumerAuthorizationRule | none |
*Domain
|
无 | 无 |
| apig:UninstallPlugin | UninstallPlugin | none |
*全部资源
|
无 | 无 |
| apig:ChangeResourceGroup | ChangeResourceGroup | none |
*全部资源
|
无 | 无 |
| apig:ListPolicies | ListPolicies | none |
*全部资源
|
无 | 无 |
| apig:CreateEnvironment | CreateEnvironment | none |
*Environment
|
无 | 无 |
| apig:GetSecretValue | GetSecretValue | none |
*全部资源
|
无 | 无 |
| apig:UpdatePolicy | UpdatePolicy | update |
*全部资源
|
无 | 无 |
| apig:GetPolicyAttachment | GetPolicyAttachment | get |
*全部资源
|
无 | 无 |
| apig:GetSource | GetSource | get |
*全部资源
|
apig:GatewayId |
无 |
| apig:DeleteSecret | DeleteSecret | none |
*Domain
|
无 | 无 |
| apig:ListHttpApiRoutes | ListHttpApiRoutes | list |
*HttpApi
|
无 | 无 |
| apig:GetService | GetService | none |
*Service
|
apig:GatewayId |
无 |
| apig:CreateMcpServer | CreateMcpServer | none |
*全部资源
|
无 | 无 |
| apig:CreateGateway | CreateGateway | create |
*Gateway
|
无 | 无 |
| apig:SyncMCPServers | SyncMCPServers | none |
*全部资源
|
无 | 无 |
| apig:GetMcpServer | GetMcpServer | none |
*全部资源
|
无 | 无 |
| apig:ListGatewayFeatures | ListGatewayFeatures | none |
*Gateway
|
无 | 无 |
| apig:CreateServiceVersion | CreateServiceVersion | create |
*全部资源
|
无 | 无 |
| apig:ListHttpApis | ListHttpApis | list |
*HttpApi
|
无 | 无 |
| apig:UpdateEnvironment | UpdateEnvironment | none |
*Environment
|
无 | 无 |
| apig:GetResourceOverview | GetResourceOverview | get |
*全部资源
|
无 | 无 |
| apig:ListSecretReferences | ListSecretReferences | list |
*Domain
|
无 | 无 |
| apig:ListSslCerts | ListSslCerts | none |
*全部资源
|
无 | 无 |
| apig:UpdateServiceVersion | UpdateServiceVersion | update |
*Service
|
无 | 无 |
| apig:UpdateService | UpdateService | none |
*Service
|
无 | 无 |
| apig:DeleteGatewaySecurityGroupRule | DeleteGatewaySecurityGroupRule | none |
*Gateway
|
无 | 无 |
| apig:ListConsumers | ListConsumers | list |
*全部资源
|
无 | 无 |
| apig:ListSecrets | ListSecrets | list |
*全部资源
|
无 | 无 |
| apig:UpdateHttpApi | UpdateHttpApi | update |
*HttpApi
|
无 | 无 |
| apig:CreateSecret | CreateSecret | create |
*全部资源
|
无 | 无 |
| apig:DeleteHttpApi | DeleteHttpApi | delete |
*HttpApi
|
无 | 无 |
| apig:CreateService | CreateService | none |
*Service
|
无 | 无 |
| apig:UpdateConsumerAuthorizationRule | UpdateConsumerAuthorizationRule | none |
*Domain
|
无 | 无 |
| apig:ListPlugins | ListPlugins | none |
*全部资源
|
无 | 无 |
| apig:UpdatePluginAttachment | UpdatePluginAttachment | none |
*全部资源
|
无 | 无 |
| apig:GetGateway | GetGateway | get |
*Gateway
|
无 | 无 |
| apig:DeletePolicy | DeletePolicy | delete |
*全部资源
|
无 | 无 |
| apig:UndeployHttpApi | UndeployHttpApi | none |
*HttpApi
|
无 | 无 |
| apig:DeleteMcpServer | DeleteMcpServer | none |
*全部资源
|
无 | 无 |
| apig:DeleteServiceVersion | DeleteServiceVersion | delete |
*Service
|
无 | 无 |
| apig:DeleteConsumerAuthorizationRule | DeleteConsumerAuthorizationRule | none |
*Domain
|
无 | 无 |
| apig:ListEnvironments | ListEnvironments | list |
*Environment
|
无 | 无 |
| apig:DeployHttpApi | DeployHttpApi | none |
*HttpApi
|
无 | 无 |
| apig:GetConsumerAuthorizationRule | GetConsumerAuthorizationRule | none |
*Domain
|
无 | 无 |
| apig:ListServices | ListServices | none |
*Service
|
无 | 无 |
| apig:AddGatewaySecurityGroupRule | AddGatewaySecurityGroupRule | none |
*Gateway
|
无 | 无 |
| apig:DeleteHttpApiOperation | DeleteHttpApiOperation | delete |
*HttpApi
|
无 | 无 |
| apig:GetConsumer | GetConsumer | none |
*Domain
|
无 | 无 |
| apig:DeleteEnvironment | DeleteEnvironment | none |
*Environment
|
无 | 无 |
| apig:ListHttpApiOperations | ListHttpApiOperations | list |
*HttpApi
|
无 | 无 |
资源(Resource)
下表是API 网关定义的资源,这些资源可以在 RAM 权限策略语句的Resource元素中使用,用来授予对该资源执行具体操作的权限。 其中,资源 ARN 是资源在阿里云上的唯一标识。具体说明如下:
{#}为变量标识,需要您替换为实际值。例如:{#ramcode}需要您替换为实际的云服务RAM代码。*表示全部。例如:{#resourceType}为*时:表示全部资源。{#regionId}为*时:表示全部地域。{#accountId}为*时:表示全部阿里云账号。
资源类型 |
资源 ARN |
| Policy |
|
| ConsumerAuthorizationRule |
|
| HttpApi |
|
| Source |
|
| Domain |
|
| Gateway |
|
| Environment |
|
| Service |
|
条件(Condition)
下表是API 网关 定义的产品级条件关键字,这些条件关键字可以在 RAM 权限策略语句的Condition元素中使用,用来描述授予权限的条件。以下仅列举产品级的条件关键字,阿里云定义的通用条件关键字也同样适用API 网关。
其中,数据类型决定了您可以使用哪些条件运算符将请求中的值与权限策略语句中的值进行比较。您必须使用与数据类型匹配的条件运算符,否则无法匹配策略语句,授权行为无效。数据类型与条件运算符的对应关系,请参见条件操作类型。
条件关键字 |
描述 |
类型 |
| apig:GatewayId | 网关ID |
Array |
| apig:NetworkType | 网络类型 |
Array |
相关操作
您可以创建自定义权限策略,并将权限策略授予 RAM 用户、RAM 用户组或 RAM 角色。具体操作如下: