VerifyIAM 政策

本页面适用于 Apigee,但不适用于 Apigee Hybrid

查看 Apigee Edge 文档。

概览

使用 VerifyIAM 可根据 Google Cloud IAM 强制执行对 API 访问的授权检查。这是 OAuthv2 政策VerifyAPIKey 政策的替代方案。如需了解如何在基于 IAM 的访问权限控制解决方案中添加 VerifyIAM,请参阅基于 IAM 的 API 身份验证概览

此政策为标准政策,可部署到任何环境类型。如需了解政策类型以及在每种环境类型中的可用性,请参阅政策类型

元素参考

此参考文档介绍了“VerifyIAM 政策”的元素和属性。

<VerifyIAM async="false" continueOnError="false" enabled="true" name="MyVerifyIAMPolicy">
    <DisplayName>Custom label used in UI</DisplayName>
    <CredentialSource>flow_variable_name_containing_credential_value</CredentialSource>
</VerifyIAM>

<VerifyIAM> 属性

<VerifyIAM async="false" continueOnError="false" enabled="true" name="MyVerifyIAMPolicy">

下表介绍了所有政策父元素通用的特性:

属性 说明 默认值 状态
name

政策的内部名称。name 属性的值可以包含字母、数字、空格、连字符、下划线和英文句点。此值不能超过 255 个字符。

(可选)使用 <DisplayName> 元素在管理界面代理编辑器中给政策添加不同的自然语言名称标签。

不适用 需要
continueOnError

设置为 false 可在政策失败时返回错误。这是大多数政策的预期行为。

设置为 true,即使在政策失败后,仍可以继续执行流。另请参阅:

false 可选
enabled

设置为 true 可强制执行政策。

设为 false关闭政策。即使政策仍附加到某个流,也不会强制执行该政策。

true 可选
async

此特性已弃用。

false 已弃用

<DisplayName> 元素

用于在 name 属性之外在管理界面代理编辑器中给政策添加不同的自然语言名称标签。

<DisplayName>Policy Display Name</DisplayName>
默认

不适用

如果省略此元素,则会使用政策的 name 属性的值。

状态 可选
类型 字符串

<CredentialSource> 元素

<CredentialSource>flow_variable_name_containing_credential_value</CredentialSource>

此元素指定包含凭据值的流变量,并具有以下特性:

  • 通常,客户端会在查询参数、HTTP 标头或表单参数中发送该值。该字符串必须以 request.queryparam.token 的形式指定相应的流变量。
  • 从引用中读取时,应为直接值。例如,不应将“Bearer”作为前缀。
  • 如果省略,政策执行会假定该值位于授权标头中,且采用标准格式“Bearer xyz”。
默认值 不适用
状态 可选
类型 流变量

示例:

<VerifyIAM async="false" continueOnError="false" enabled="true" name="Verify-IAM-Permissions-1">
    <DisplayName>VerifyIAM policy for flow 1</DisplayName>
    <CredentialSource>request.queryparam.token</CredentialSource>
</VerifyIAM>

错误参考信息

This section describes the fault codes and error messages that are returned and fault variables that are set by Apigee when this policy triggers an error. This information is important to know if you are developing fault rules to handle faults. To learn more, see What you need to know about policy errors and Handling faults.

Runtime errors

These errors can occur when the policy executes.

Fault code HTTP status Cause
steps.verifyiam.CredentialSourceRefUnresolved 400 Flow variable provided inside credential source could not be resolved.
steps.verifyiam.CredentialValueNotProvided 400 Credential not found. If the credential source reference is not provided, we look at the default place like authorization header.
steps.verifyiam.Forbidden 403 Request could not be forwarded due to lack of sufficient permissions or missing access scopes or any other related issues.
steps.verifyiam.MiscellaneousAuthorizationConfigurationError 500 An issue with the authentication request to IAM. The API producer needs to fix this error based on details in the error response.
steps.verifyiam.Unauthorized 401 Problem with the credential, such as the value being invalid or expired.
steps.verifyiam.UnexpectedAuthorizationInfrastructureError 500 Internal error.

Deployment errors

This policy does not return any policy-specific deployment errors.

Fault variables

These variables are set when this policy triggers an error at runtime.

Variables Where Example
fault.name="fault_name" fault_name is the name of the fault, as listed in the Runtime errors table above. The fault name is the last part of the fault code. fault.name="Unauthorized"
verifyiam.policy_name.failed policy_name is the user-specified name of the policy that threw the fault. verifyiam.Verify-IAMToken.failed = true