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">

The following table describes attributes that are common to all policy parent elements:

Attribute Description Default Presence
name

The internal name of the policy. The value of the name attribute can contain letters, numbers, spaces, hyphens, underscores, and periods. This value cannot exceed 255 characters.

Optionally, use the <DisplayName> element to label the policy in the management UI proxy editor with a different, natural-language name.

N/A Required
continueOnError

Set to false to return an error when a policy fails. This is expected behavior for most policies.

Set to true to have flow execution continue even after a policy fails. See also:

false Optional
enabled

Set to true to enforce the policy.

Set to false to turn off the policy. The policy will not be enforced even if it remains attached to a flow.

true Optional
async

This attribute is deprecated.

false Deprecated

<DisplayName> element

Use in addition to the name attribute to label the policy in the management UI proxy editor with a different, natural-language name.

<DisplayName>Policy Display Name</DisplayName>
Default

N/A

If you omit this element, the value of the policy's name attribute is used.

Presence Optional
Type String

<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>

错误参考信息

本部分介绍当此政策触发错误时返回的故障代码和错误消息,以及由 Apigee 设置的故障变量。 在开发故障规则以处理故障时,请务必了解此信息。如需了解详情,请参阅您需要了解的有关政策错误的信息和处理故障。

运行时错误

政策执行时可能会发生这些错误。

故障代码 HTTP 状态 原因
steps.verifyiam.CredentialSourceRefUnresolved 400 无法解析凭证源中提供的流变量。
steps.verifyiam.CredentialValueNotProvided 400 找不到凭证。如果未提供凭证源引用,我们会查看默认位置,例如授权标头。
steps.verifyiam.Forbidden 403 由于权限不足或缺少访问权限范围或任何其他相关问题,无法转发请求。
steps.verifyiam.MiscellaneousAuthorizationConfigurationError 500 向 IAM 发出的身份验证请求存在问题。API 提供方需要根据错误响应中的详细信息来修复此错误。
steps.verifyiam.Unauthorized 401 凭证存在问题,例如值无效或已过期。
steps.verifyiam.UnexpectedAuthorizationInfrastructureError 500 内部错误。

部署错误

此政策不会返回任何特定于政策的部署错误。

故障变量

当此政策在运行时触发错误时,将设置这些变量。

变量 其中 示例
fault.name="fault_name" fault_name 是故障名称,如上面的运行时错误表中所列。故障名称是故障代码的最后一部分。 fault.name="Unauthorized"
verifyiam.policy_name.failed policy_name 是抛出故障的政策的用户指定名称。 verifyiam.Verify-IAMToken.failed = true