secure-api
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSecure API
保护 API
Overview
概述
Applies a security or traffic management policy to an API and deploys it to a self-managed Omni Gateway, walking through the full process from identifying the target API to selecting a policy, configuring it, and deploying. Supports multiple starting points depending on what the user already has set up — an API Manager instance, an Exchange asset, or just an API URL.
What you'll build: A fully configured policy enforced on your API instance, deployed to a Omni Gateway
将安全或流量管理策略应用到 API,并将其部署到自托管的 Omni Gateway;完整流程包括确定目标 API、选择策略、配置策略和执行部署。根据用户已有的配置,支持多种起始方式:API Manager 实例、Exchange asset,或仅有一个 API URL。
你将构建: 在 API 实例上强制执行且已部署到 Omni Gateway 的完整配置策略
Architecture
架构
mermaid
sequenceDiagram
participant User
participant Exchange
participant API Manager
participant Omni Gateway
participant Policy Catalog
User->>Exchange: Publish API spec
User->>API Manager: Create Instance
API Manager-->>User: instanceId
User->>Omni Gateway: Deploy Instance
Omni Gateway-->>User: Deployment active
User->>Policy Catalog: Browse compatible policies
Policy Catalog-->>User: Policy template + config schema
User->>API Manager: Apply policy with config
API Manager-->>Omni Gateway: Policy enforcedmermaid
sequenceDiagram
participant User
participant Exchange
participant API Manager
participant Omni Gateway
participant Policy Catalog
User->>Exchange: Publish API spec
User->>API Manager: Create Instance
API Manager-->>User: instanceId
User->>Omni Gateway: Deploy Instance
Omni Gateway-->>User: Deployment active
User->>Policy Catalog: Browse compatible policies
Policy Catalog-->>User: Policy template + config schema
User->>API Manager: Apply policy with config
API Manager-->>Omni Gateway: Policy enforcedPrerequisites
前提条件
Before starting, ensure you have:
-
Authentication ready
- Valid Bearer token for Anypoint Platform. If you only have username/password, call (
createLogin) from thePOST /accounts/loginAPI with bodyurn:api:access-managementto obtain a Bearer token first.{"username":"...","password":"..."} - API Manager permissions: View APIs Configuration and Manage Policies scopes
- Valid Bearer token for Anypoint Platform. If you only have username/password, call
-
Organization Id
- Call (
listMe) fromGET /accounts/api/meto get your organization IDurn:api:access-management - Extract from
organizationIdin the response$.user.organization.id - This is used to list environments, browse the policy catalog, check Exchange, etc.
- Call
-
One of the following
- An API instance already in API Manager (skip to Step 6)
- An Exchange asset ready to be promoted to API Manager (skip to Step 2)
- An API specification or URL that needs to be published first (start at Step 1)
开始前,请确保具备以下条件:
-
身份验证已就绪
- Anypoint Platform 的有效 Bearer token。如果你只有用户名/密码,请先调用 API 的
urn:api:access-management(createLogin),请求体为POST /accounts/login,以获取 Bearer token。{"username":"...","password":"..."} - API Manager 权限:View APIs Configuration 和 Manage Policies 范围
- Anypoint Platform 的有效 Bearer token。如果你只有用户名/密码,请先调用
-
组织 ID
- 调用 的
urn:api:access-management(listMe)以获取组织 IDGET /accounts/api/me - 从响应中的 提取
$.user.organization.idorganizationId - 该 ID 用于列出环境、浏览策略目录、检查 Exchange 等
- 调用
-
以下内容之一
- API Manager 中已有的 API 实例(跳至步骤 6)
- 准备好可提升至 API Manager 的 Exchange asset(跳至步骤 2)
- 需要先发布的 API 规范或 URL(从步骤 1 开始)
Choose Your Path
选择你的路径
mermaid
flowchart TD
Start{What do you have?} -->|API spec only| Full[Full Setup]
Start -->|Asset in Exchange| FromExchange[From Exchange]
Start -->|API Manager instance| PolicyOnly[Apply Policy Only]
Full --> S1[Step 1: Publish to Exchange]
S1 --> S2[Step 2: Select Environment]
FromExchange --> S2
S2 --> S3[Step 3: Select Gateway Target]
S3 --> S4[Step 4: Create API Instance]
S4 --> S5[Step 5: Deploy to Gateway]
PolicyOnly --> S2b[Step 2: Select Environment]
S2b --> S6[Step 6: Browse Policies]
S5 --> S6
S6 --> S7[Step 7: Apply Policy]
S7 --> Done[✓ API Secured]mermaid
flowchart TD
Start{What do you have?} -->|API spec only| Full[Full Setup]
Start -->|Asset in Exchange| FromExchange[From Exchange]
Start -->|API Manager instance| PolicyOnly[Apply Policy Only]
Full --> S1[Step 1: Publish to Exchange]
S1 --> S2[Step 2: Select Environment]
FromExchange --> S2
S2 --> S3[Step 3: Select Gateway Target]
S3 --> S4[Step 4: Create API Instance]
S4 --> S5[Step 5: Deploy to Gateway]
PolicyOnly --> S2b[Step 2: Select Environment]
S2b --> S6[Step 6: Browse Policies]
S5 --> S6
S6 --> S7[Step 7: Apply Policy]
S7 --> Done[✓ API Secured]Execution Paths
执行路径
This skill has multiple execution paths depending on what you already have:
-
Full setup: Steps 1, 2, 3, 4, 5, 6, 7
- When: You have an API specification file and need to publish it to Exchange first
- You'll need: , API specification file
organizationId
-
From Exchange asset: Steps 2, 3, 4, 5, 6, 7
- When: You already have an Exchange asset and need to create an API Manager instance
- You'll need: ,
organizationId,groupId,assetIdassetVersion
-
Apply policy only: Steps 2, 6, 7
- When: You already have an API Manager instance and want to apply a policy
- You'll need: ,
organizationId,environmentIdenvironmentApiId
此 skill 有多条执行路径,具体取决于你已有的内容:
-
完整设置:步骤 1、2、3、4、5、6、7
- 适用情况:你有 API 规范文件,且需要先将其发布到 Exchange
- 你需要:、API 规范文件
organizationId
-
从 Exchange asset 开始:步骤 2、3、4、5、6、7
- 适用情况:你已有 Exchange asset,并需要创建 API Manager 实例
- 你需要:、
organizationId、groupId、assetIdassetVersion
-
仅应用策略:步骤 2、6、7
- 适用情况:你已有 API Manager 实例,并希望应用策略
- 你需要:、
organizationId、environmentIdenvironmentApiId
Step 1: Publish API to Exchange
步骤 1:将 API 发布到 Exchange
Publishes your API specification to Exchange as a reusable asset. This makes it available for API Manager to create managed instances from it.
What you'll need:
- Organization ID
- API specification file (OAS or RAML)
- Asset name, groupId, assetId, and version
Action: Create a new asset in Exchange with your API specification.
yaml
api: urn:api:exchange-experience
operationId: uploadAsset
inputs:
organizationId:
from:
api: urn:api:access-management
operation: listMe
field: $.user.organization.id
description: Your organization's Business Group GUID
groupId:
userProvided: true
description: The group ID for the asset (typically matches your organization ID)
example: "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
assetId:
userProvided: true
description: A unique identifier for the asset in kebab-case
example: "inventory-api"
version:
userProvided: true
description: Semantic version for the asset
example: "1.0.0"
outputs:
- name: groupId
path: $.groupId
description: The group ID of the published asset
- name: assetId
path: $.assetId
description: The asset ID of the published asset
- name: assetVersion
path: $.version
description: The version of the published assetWhat happens next: Your API specification is now available in Exchange. Next, you'll create an API Manager instance from this asset so you can apply policies to it.
将 API 规范发布到 Exchange,使其成为可复用的 asset。这样,API Manager 就可以基于该 asset 创建托管实例。
你需要:
- 组织 ID
- API 规范文件(OAS 或 RAML)
- asset 名称、、
groupId和版本assetId
操作: 使用 API 规范在 Exchange 中创建新 asset。
yaml
api: urn:api:exchange-experience
operationId: uploadAsset
inputs:
organizationId:
from:
api: urn:api:access-management
operation: listMe
field: $.user.organization.id
description: Your organization's Business Group GUID
groupId:
userProvided: true
description: The group ID for the asset (typically matches your organization ID)
example: "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
assetId:
userProvided: true
description: A unique identifier for the asset in kebab-case
example: "inventory-api"
version:
userProvided: true
description: Semantic version for the asset
example: "1.0.0"
outputs:
- name: groupId
path: $.groupId
description: The group ID of the published asset
- name: assetId
path: $.assetId
description: The asset ID of the published asset
- name: assetVersion
path: $.version
description: The version of the published asset接下来: 你的 API 规范现在可在 Exchange 中使用。接下来,你将基于此 asset 创建 API Manager 实例,以便向其应用策略。
Step 2: List Environments
步骤 2:列出环境
List all environments in the organization so you can confirm or select the one where your API instance lives.
What you'll need:
- Organization ID
Action: List available environments and select the target.
yaml
api: urn:api:access-management
operationId: listEnvironments
inputs:
organizationId:
from:
api: urn:api:access-management
operation: listMe
field: $.user.organization.id
description: Organization ID from Prerequisites
outputs:
- name: environmentId
path: $.data[*].id
labels: $.data[*].name
description: Selected environment ID (e.g., Production, Sandbox)What happens next: With the environment selected, you can create an API instance or browse policies.
列出组织中的所有环境,以便确认或选择 API 实例所在的环境。
你需要:
- 组织 ID
操作: 列出可用环境并选择目标环境。
yaml
api: urn:api:access-management
operationId: listEnvironments
inputs:
organizationId:
from:
api: urn:api:access-management
operation: listMe
field: $.user.organization.id
description: Organization ID from Prerequisites
outputs:
- name: environmentId
path: $.data[*].id
labels: $.data[*].name
description: Selected environment ID (e.g., Production, Sandbox)接下来: 环境选定后,你可以创建 API 实例或浏览策略。
Step 3: Select Deployment Target
步骤 3:选择部署目标
List available gateway targets registered in the environment. You need the target ID and gateway version before creating the API instance, because the deployment configuration is set via a PATCH after creation.
What you'll need:
- Organization ID and Environment ID
Action: List gateway targets and select the Omni Gateway where the API will run. Prefer a target with .
status: "RUNNING"yaml
api: urn:api:api-portal-xapi
operationId: getGatewayTargets
inputs:
organizationId:
from:
api: urn:api:access-management
operation: listMe
field: $.user.organization.id
description: Organization ID
environmentId:
from:
variable: environmentId
description: Environment ID from Step 2
outputs:
- name: targetId
path: $.rows[*].id
labels: $.rows[*].name
description: Selected gateway target ID
- name: targetName
path: $.rows[*].name
description: Name of the selected gateway target
- name: gatewayVersion
value: "1.0.0"
description: Gateway version to use for deployment. The targets response may return "-" instead of a real version; use "1.0.0" as the default.What happens next: You have a deployment target and its gateway version. Next, create the API instance and then configure its deployment target.
列出环境中已注册的所有 gateway target。创建 API 实例前需要 target ID 和 gateway version,因为部署配置会在创建后通过 PATCH 设置。
你需要:
- 组织 ID 和环境 ID
操作: 列出 gateway target 并选择 API 将运行所在的 Omni Gateway。优先选择 的 target。
status: "RUNNING"yaml
api: urn:api:api-portal-xapi
operationId: getGatewayTargets
inputs:
organizationId:
from:
api: urn:api:access-management
operation: listMe
field: $.user.organization.id
description: Organization ID
environmentId:
from:
variable: environmentId
description: Environment ID from Step 2
outputs:
- name: targetId
path: $.rows[*].id
labels: $.rows[*].name
description: Selected gateway target ID
- name: targetName
path: $.rows[*].name
description: Name of the selected gateway target
- name: gatewayVersion
value: "1.0.0"
description: Gateway version to use for deployment. The targets response may return "-" instead of a real version; use "1.0.0" as the default.接下来: 你已获得部署 target 及其 gateway version。接下来,创建 API 实例,然后配置其部署 target。
Step 4: Create API Manager Instance
步骤 4:创建 API Manager 实例
Creates a managed API instance in API Manager from your Exchange asset. This creates the API configuration; deployment to the Omni Gateway happens in Step 5.
Important: For Omni Gateway instances, must be (not ). Setting it to causes a validation error.
isCloudHubnullfalsefalseWhat you'll need:
- Organization ID and Environment ID
- Exchange asset coordinates (groupId, assetId, version)
Action: Create an API instance in the target environment.
yaml
api: urn:api:api-manager
operationId: createApiInstance
inputs:
organizationId:
from:
api: urn:api:access-management
operation: listMe
field: $.user.organization.id
description: Your organization's Business Group GUID
environmentId:
from:
variable: environmentId
description: Target environment ID from Step 2
groupId:
from:
variable: groupId
description: Exchange asset group ID from Step 1
assetId:
from:
variable: assetId
description: Exchange asset ID from Step 1
assetVersion:
from:
variable: assetVersion
description: Exchange asset version from Step 1
instanceLabel:
userProvided: true
description: A human-readable label for this API instance (e.g., "cars-api-v1")
example: "cars-api-v1"
technology:
value: "flexGateway"
description: Gateway technology — this skill targets Omni Gateway deployments
endpoint.isCloudHub:
value: null
description: "Must be null for flexGateway technology (not false — false causes a validation error)"
endpoint.proxyUri:
userProvided: true
description: "The proxy listener URI. Ask the user which port the Omni Gateway should listen on, then use http://0.0.0.0:<port>/"
example: "http://0.0.0.0:8081/"
endpoint.uri:
userProvided: true
optional: true
description: The upstream backend URL for the API. Ask the user if they want to provide it now or configure it later.
example: "https://backend.example.com/api/v1"
outputs:
- name: environmentApiId
path: $.id
description: The API instance ID in API ManagerWhat happens next: The API instance exists but is not yet deployed. Next, deploy it to the Omni Gateway target selected in Step 3.
基于 Exchange asset 在 API Manager 中创建托管 API 实例。这将创建 API 配置;部署到 Omni Gateway 会在步骤 5 中进行。
重要: 对于 Omni Gateway 实例, 必须为 (不能为 )。将其设为 会导致验证错误。
isCloudHubnullfalsefalse你需要:
- 组织 ID 和环境 ID
- Exchange asset 坐标(、
groupId、版本)assetId
操作: 在目标环境中创建 API 实例。
yaml
api: urn:api:api-manager
operationId: createApiInstance
inputs:
organizationId:
from:
api: urn:api:access-management
operation: listMe
field: $.user.organization.id
description: Your organization's Business Group GUID
environmentId:
from:
variable: environmentId
description: Target environment ID from Step 2
groupId:
from:
variable: groupId
description: Exchange asset group ID from Step 1
assetId:
from:
variable: assetId
description: Exchange asset ID from Step 1
assetVersion:
from:
variable: assetVersion
description: Exchange asset version from Step 1
instanceLabel:
userProvided: true
description: A human-readable label for this API instance (e.g., "cars-api-v1")
example: "cars-api-v1"
technology:
value: "flexGateway"
description: Gateway technology — this skill targets Omni Gateway deployments
endpoint.isCloudHub:
value: null
description: "Must be null for flexGateway technology (not false — false causes a validation error)"
endpoint.proxyUri:
userProvided: true
description: "The proxy listener URI. Ask the user which port the Omni Gateway should listen on, then use http://0.0.0.0:<port>/"
example: "http://0.0.0.0:8081/"
endpoint.uri:
userProvided: true
optional: true
description: The upstream backend URL for the API. Ask the user if they want to provide it now or configure it later.
example: "https://backend.example.com/api/v1"
outputs:
- name: environmentApiId
path: $.id
description: The API instance ID in API Manager接下来: API 实例已存在,但尚未部署。接下来,将其部署到步骤 3 中选择的 Omni Gateway target。
Step 5: Deploy to Omni Gateway
步骤 5:部署到 Omni Gateway
Deploys the API instance to the selected Omni Gateway target. This uses the Proxies API deployment endpoint with flat top-level fields — do not use the nested object, which requires additional fields that are not needed for self-managed Omni Gateway deployments.
targetWhat you'll need:
- Organization ID, Environment ID, and API instance ID from Step 4
- Deployment target ID and gateway version from Step 3
Action: Create a deployment for the API instance on the selected Omni Gateway.
yaml
api: urn:api:proxies-xapi
operationId: createProxyDeployment
inputs:
organizationId:
from:
api: urn:api:access-management
operation: listMe
field: $.user.organization.id
description: Organization ID
environmentId:
from:
variable: environmentId
description: Environment ID from Step 2 (used in both the URL path and the request body for HY deployment type)
environmentApiId:
from:
variable: environmentApiId
description: API instance ID from Step 4
type:
value: "HY"
description: "Deployment type for self-managed Omni Gateway (HY = Hybrid)"
targetId:
from:
variable: targetId
description: Omni Gateway target ID from Step 3
targetName:
from:
variable: targetName
description: Omni Gateway target name from Step 3
gatewayVersion:
value: "1.0.0"
description: "Gateway version for deployment. Use \"1.0.0\" as the default."
overwrite:
value: false
description: "Whether to overwrite an existing deployment"
outputs:
- name: deploymentId
path: $.id
description: The ID of the proxy deploymentRequest body structure: Use flat top-level fields, not the nested object:
targetjson
{
"type": "HY",
"targetId": "<from Step 3>",
"targetName": "<from Step 3>",
"gatewayVersion": "1.0.0",
"environmentId": "<from Step 2>",
"overwrite": false
}What happens next: The API instance is now deployed to the Omni Gateway. Next, browse the policy catalog to select which policy to apply.
Common issues:
- : The
"Field environmentId is required for deployment type HY"must be in the request body, not just the URL path parameter.environmentId - : Use the version from the
"Field gatewayVersion is required for deployment type HY"response (Step 3). Using an incorrect version causes policy implementation errors.getGatewayTargets - : The
"Policy implementations cannot be set because runtime version is unknown"value doesn't match a known Omni Gateway version. Verify the version from the target's actual runtime version in Step 3.gatewayVersion - 409 Conflict: The API may already be deployed to this target. List existing deployments with first to check.
GET .../deployments
将 API 实例部署到选定的 Omni Gateway target。此步骤使用 Proxies API deployment endpoint,并采用扁平顶层字段——不要使用嵌套的 对象,因为该对象需要自托管 Omni Gateway 部署不需要的额外字段。
target你需要:
- 步骤 4 中的组织 ID、环境 ID 和 API 实例 ID
- 步骤 3 中的部署 target ID 和 gateway version
操作: 在选定的 Omni Gateway 上为 API 实例创建 deployment。
yaml
api: urn:api:proxies-xapi
operationId: createProxyDeployment
inputs:
organizationId:
from:
api: urn:api:access-management
operation: listMe
field: $.user.organization.id
description: Organization ID
environmentId:
from:
variable: environmentId
description: Environment ID from Step 2 (used in both the URL path and the request body for HY deployment type)
environmentApiId:
from:
variable: environmentApiId
description: API instance ID from Step 4
type:
value: "HY"
description: "Deployment type for self-managed Omni Gateway (HY = Hybrid)"
targetId:
from:
variable: targetId
description: Omni Gateway target ID from Step 3
targetName:
from:
variable: targetName
description: Omni Gateway target name from Step 3
gatewayVersion:
value: "1.0.0"
description: "Gateway version for deployment. Use \"1.0.0\" as the default."
overwrite:
value: false
description: "Whether to overwrite an existing deployment"
outputs:
- name: deploymentId
path: $.id
description: The ID of the proxy deployment请求体结构: 使用扁平顶层字段,而不是嵌套的 对象:
targetjson
{
"type": "HY",
"targetId": "<from Step 3>",
"targetName": "<from Step 3>",
"gatewayVersion": "1.0.0",
"environmentId": "<from Step 2>",
"overwrite": false
}接下来: API 实例现已部署到 Omni Gateway。接下来,浏览策略目录以选择要应用的策略。
常见问题:
- :
"Field environmentId is required for deployment type HY"必须包含在请求体中,而不能只放在 URL 路径参数中。environmentId - :使用
"Field gatewayVersion is required for deployment type HY"响应中的版本(步骤 3)。使用错误版本会导致策略实施出错。getGatewayTargets - :
"Policy implementations cannot be set because runtime version is unknown"值与已知 Omni Gateway 版本不匹配。请根据步骤 3 中 target 的实际运行时版本进行验证。gatewayVersion - 409 Conflict:API 可能已部署到此 target。请先使用 列出已有 deployment,以检查情况。
GET .../deployments
Step 6: Browse Exchange Policy Catalog
步骤 6:浏览 Exchange 策略目录
List all available policy templates from Exchange for your organization. This endpoint returns the full Exchange coordinates (, , ) and gateway-compatible configuration for each template — these are required when applying a policy.
groupIdassetIdassetVersionImportant: Use the endpoint () instead of the generic endpoint. The generic endpoint does not return Exchange coordinates or gateway-specific configuration property names, which are required for the apply step.
api-portal-xapigetExchangePolicyTemplateslistPolicyTemplatesWhat you'll need:
- Organization ID
- Environment ID and API instance ID (to filter for compatible templates)
Action: List Exchange policy templates and select the one to apply. Pass and to filter for templates compatible with your API's gateway type (e.g., Omni Gateway, Mule Gateway).
apiInstanceIdenvironmentIdyaml
api: urn:api:api-portal-xapi
operationId: getExchangePolicyTemplates
inputs:
organizationId:
from:
api: urn:api:access-management
operation: listMe
field: $.user.organization.id
description: Organization ID
apiInstanceId:
from:
variable: environmentApiId
description: API instance ID from Step 4 (filters for compatible templates)
environmentId:
from:
variable: environmentId
description: Environment ID from Step 2
latest:
value: "true"
description: Return only the latest version of each template
includeConfiguration:
value: "true"
description: Include the configuration schema for each template
outputs:
- name: policyGroupId
path: $[*].groupId
labels: $[*].assetId
description: Exchange group ID of the selected policy template
- name: policyAssetId
path: $[*].assetId
description: Exchange asset ID of the selected policy template
- name: policyAssetVersion
path: $[*].version
description: Exchange version of the selected policy template (gateway-compatible)
- name: policyConfiguration
path: $[*].configuration
description: Configuration schema with gateway-compatible property names and defaultsWhat happens next: You have the policy template's Exchange coordinates and its configuration schema with the correct property names for your gateway type. Review the output to understand what settings the policy accepts before applying it.
policyConfigurationCommon issues:
- Empty list: Pass and
apiInstanceIdto get templates compatible with your gateway type. Without these filters, some templates may not appear.environmentId - Wrong config property names: Always use the configuration from this endpoint — the generic endpoint may return different (non-gateway-compatible) property names and defaults.
listPolicyTemplates
列出组织中所有可用的 Exchange 策略模板。此端点会返回每个模板的完整 Exchange 坐标(、、)和 gateway 兼容配置——应用策略时需要这些信息。
groupIdassetIdassetVersion重要: 使用 端点(),而不是通用的 端点。通用端点不会返回 Exchange 坐标或 gateway 特定的配置属性名,而应用步骤需要这些信息。
api-portal-xapigetExchangePolicyTemplateslistPolicyTemplates你需要:
- 组织 ID
- 环境 ID 和 API 实例 ID(用于筛选兼容模板)
操作: 列出 Exchange 策略模板并选择要应用的模板。传入 和 ,以筛选与 API 的 gateway 类型(例如 Omni Gateway、Mule Gateway)兼容的模板。
apiInstanceIdenvironmentIdyaml
api: urn:api:api-portal-xapi
operationId: getExchangePolicyTemplates
inputs:
organizationId:
from:
api: urn:api:access-management
operation: listMe
field: $.user.organization.id
description: Organization ID
apiInstanceId:
from:
variable: environmentApiId
description: API instance ID from Step 4 (filters for compatible templates)
environmentId:
from:
variable: environmentId
description: Environment ID from Step 2
latest:
value: "true"
description: Return only the latest version of each template
includeConfiguration:
value: "true"
description: Include the configuration schema for each template
outputs:
- name: policyGroupId
path: $[*].groupId
labels: $[*].assetId
description: Exchange group ID of the selected policy template
- name: policyAssetId
path: $[*].assetId
description: Exchange asset ID of the selected policy template
- name: policyAssetVersion
path: $[*].version
description: Exchange version of the selected policy template (gateway-compatible)
- name: policyConfiguration
path: $[*].configuration
description: Configuration schema with gateway-compatible property names and defaults接下来: 你已获得策略模板的 Exchange 坐标及其配置 schema,其中包含适用于你 gateway 类型的正确属性名。查看 输出,了解该策略接受哪些设置,然后再应用策略。
policyConfiguration常见问题:
- 列表为空:传入 和
apiInstanceId以获取与 gateway 类型兼容的模板。如果不使用这些筛选条件,部分模板可能不会显示。environmentId - 配置属性名错误:始终使用此端点返回的 configuration——通用 端点可能返回不同的(非 gateway 兼容)属性名和默认值。
listPolicyTemplates
Step 7: Apply Policy to API Instance
步骤 7:将策略应用到 API 实例
Apply the selected policy to your API instance with the appropriate configuration. Use the Exchange coordinates and configuration property names from Step 6.
What you'll need:
- Organization ID, Environment ID, and API instance ID
- Policy Exchange coordinates (groupId, assetId, assetVersion) from Step 6
- Policy configuration based on the schema from Step 6's output
policyConfiguration
Action: Apply the policy to your API instance. Build the object using the property names from Step 6's configuration schema. For each configuration property, present the user with the property name, its description, and the default value, then ask if they want to keep the default or provide a custom value. If a property has no default, always ask the user for a value.
configurationDatayaml
api: urn:api:api-manager
operationId: applyApiInstancePolicy
inputs:
organizationId:
from:
api: urn:api:access-management
operation: listMe
field: $.user.organization.id
description: Organization ID
environmentId:
from:
variable: environmentId
description: Environment ID from Step 2
environmentApiId:
from:
variable: environmentApiId
description: API instance ID from Step 4 (or provided manually)
groupId:
from:
variable: policyGroupId
description: Policy Exchange group ID from Step 6
assetId:
from:
variable: policyAssetId
description: Policy Exchange asset ID from Step 6
assetVersion:
from:
variable: policyAssetVersion
description: Policy Exchange version from Step 6
outputs:
- name: policyId
path: $.id
description: The ID of the applied policy instanceWhat happens next: Your API is now protected with the selected policy. Since the API instance was configured with deployment information in Step 5, the policy is active and enforcing on the Omni Gateway.
Common issues:
- 400 Bad Request — missing groupId/assetId/assetVersion: The apply endpoint requires full Exchange coordinates, not just a template ID. Make sure you used (Step 6) to get these values.
getExchangePolicyTemplates - 400 Bad Request — invalid configurationData: The configuration property names differ between gateway types. Use the property names from Step 6's output, not from the generic template endpoint. For example, Omni Gateway uses
policyConfigurationwhile the generic template usescredentialsOriginHasHttpBasicAuthenticationHeader.credentialsOrigin - 409 Conflict: A policy of this type may already be applied to the API instance. List existing policies first to check, or add to the request URL to apply a second instance of the same policy type.
?allowDuplicated=true - 403 Forbidden: You need Manage Policies permission in the target environment.
使用适当的配置将选定策略应用到 API 实例。使用步骤 6 中的 Exchange 坐标和配置属性名。
你需要:
- 组织 ID、环境 ID 和 API 实例 ID
- 步骤 6 中的策略 Exchange 坐标(、
groupId、assetId)assetVersion - 根据步骤 6 的 输出 schema 生成的策略配置
policyConfiguration
操作: 将策略应用到 API 实例。使用步骤 6 配置 schema 中的属性名构建 对象。对于每个配置属性,向用户展示属性名、说明和默认值,然后询问用户是保留默认值还是提供自定义值。如果某个属性没有默认值,始终要求用户提供值。
configurationDatayaml
api: urn:api:api-manager
operationId: applyApiInstancePolicy
inputs:
organizationId:
from:
api: urn:api:access-management
operation: listMe
field: $.user.organization.id
description: Organization ID
environmentId:
from:
variable: environmentId
description: Environment ID from Step 2
environmentApiId:
from:
variable: environmentApiId
description: API instance ID from Step 4 (or provided manually)
groupId:
from:
variable: policyGroupId
description: Policy Exchange group ID from Step 6
assetId:
from:
variable: policyAssetId
description: Policy Exchange asset ID from Step 6
assetVersion:
from:
variable: policyAssetVersion
description: Policy Exchange version from Step 6
outputs:
- name: policyId
path: $.id
description: The ID of the applied policy instance接下来: 你的 API 现在已受到所选策略的保护。由于 API 实例已在步骤 5 中配置了部署信息,因此策略会在 Omni Gateway 上激活并执行。
常见问题:
- 400 Bad Request — 缺少 groupId/assetId/assetVersion:应用端点需要完整的 Exchange 坐标,而不只是模板 ID。请确保使用 (步骤 6)获取了这些值。
getExchangePolicyTemplates - 400 Bad Request — configurationData 无效:不同 gateway 类型的配置属性名不同。请使用步骤 6 的 输出中的属性名,而不是通用模板端点返回的属性名。例如,Omni Gateway 使用
policyConfiguration,而通用模板使用credentialsOriginHasHttpBasicAuthenticationHeader。credentialsOrigin - 409 Conflict:API 实例上可能已经应用了此类型的策略。请先列出已有策略以检查情况,或在请求 URL 中添加 ,以应用同一策略类型的第二个实例。
?allowDuplicated=true - 403 Forbidden:你需要目标环境中的 Manage Policies 权限。
Completion Checklist
完成检查清单
After completing all steps, verify:
- API instance is bound to the Omni Gateway target (deployment info visible in API Manager)
- Policy appears in the API instance's policy list
- Policy status shows as "Active"
- API requests are being evaluated against the policy rules
- Policy configuration matches your requirements
完成所有步骤后,请验证:
- API 实例已绑定至 Omni Gateway target(API Manager 中可见部署信息)
- 策略出现在 API 实例的策略列表中
- 策略状态显示为 "Active"
- API 请求正在依据策略规则进行评估
- 策略配置符合你的要求
What You've Built
你构建的内容
Your API is now protected with:
✅ Policy enforcement
- Selected policy is active on your API instance
- All incoming traffic is evaluated against policy rules
✅ Bound to Omni Gateway
- API instance is created with deployment configuration targeting a self-managed Omni Gateway
- The Omni Gateway picks up the configuration automatically
✅ Managed configuration
- Policy settings are version-controlled in API Manager
- Configuration can be updated without redeploying the API
你的 API 现在受到以下保护:
✅ 策略执行
- 所选策略已在 API 实例上激活
- 所有传入流量都会依据策略规则进行评估
✅ 绑定至 Omni Gateway
- API 实例已创建,并带有指向自托管 Omni Gateway 的部署配置
- Omni Gateway 会自动获取该配置
✅ 托管配置
- 策略设置在 API Manager 中进行版本控制
- 无需重新部署 API 即可更新配置
Next Steps
后续步骤
-
Test the policy
- Send test requests to verify the policy is enforcing correctly
- Check that authorized requests pass and unauthorized ones are blocked
-
Add more policies
- Run this skill again to layer additional policies (e.g., rate limiting + OAuth2)
- Policy ordering matters — adjust priority in API Manager if needed
-
Monitor policy activity
- Check API Manager analytics for policy enforcement metrics
- Set up alerts for unusual rejection patterns
-
测试策略
- 发送测试请求,验证策略是否正确执行
- 检查已授权请求是否通过、未授权请求是否被阻止
-
添加更多策略
- 再次运行此 skill,以叠加更多策略(例如速率限制 + OAuth2)
- 策略顺序很重要——如有需要,可在 API Manager 中调整优先级
-
监控策略活动
- 查看 API Manager analytics 中的策略执行指标
- 为异常拒绝模式设置警报
Tips and Best Practices
提示和最佳实践
Policy Selection
策略选择
- Rate Limiting: Use when you need to control traffic volume per client
- OAuth 2.0: Use for token-based authentication and authorization
- IP Allowlist/Blocklist: Use to restrict access by network origin
- Client ID Enforcement: Use to require registered client applications
- 速率限制:用于控制每个客户端的流量
- OAuth 2.0:用于基于 token 的身份验证和授权
- IP Allowlist/Blocklist:用于按网络来源限制访问
- Client ID Enforcement:用于要求注册客户端应用程序
Policy Ordering
策略顺序
- Authentication policies should be applied first (lowest order number)
- Rate limiting should come after authentication
- Transformation policies should be last
- 身份验证策略应最先应用(顺序号最低)
- 速率限制应在身份验证之后
- 转换策略应最后应用
Gateway Compatibility
Gateway 兼容性
- Always use with
getExchangePolicyTemplatesto get gateway-compatible templatesapiInstanceId - Configuration property names and defaults vary by gateway type (Omni Gateway vs. Mule Gateway)
- The Exchange template version may differ from the generic template version
- 始终使用 并传入
getExchangePolicyTemplates以获取 gateway 兼容模板apiInstanceId - 配置属性名和默认值因 gateway 类型而异(Omni Gateway 与 Mule Gateway)
- Exchange 模板版本可能与通用模板版本不同
Troubleshooting
故障排查
Policy Not Enforcing
策略未执行
Symptoms: Requests pass through without policy evaluation
Possible causes:
- API instance is not deployed or is in an error state
- Policy configuration has a permissive default that allows all traffic
- Policy is applied but not yet propagated (wait 1-2 minutes)
Solutions:
- Check API instance status in API Manager
- Review policy configuration for overly permissive settings
- Wait for propagation and retry
症状: 请求未经策略评估便直接通过
可能原因:
- API 实例未部署或处于错误状态
- 策略配置使用了允许所有流量的宽松默认值
- 策略已应用,但尚未完成传播(等待 1–2 分钟)
解决方案:
- 检查 API Manager 中的 API 实例状态
- 检查策略配置中是否存在过于宽松的设置
- 等待传播完成并重试
Policy Blocks All Requests
策略阻止所有请求
Symptoms: All requests return 401 or 403, even legitimate ones
Possible causes:
- Policy configuration is too restrictive
- Required credentials are not being sent correctly
- Policy expects headers or parameters in a specific format
Solutions:
- Review the policy configuration schema for required fields
- Check that client applications are sending credentials in the expected format
- Temporarily disable the policy to isolate the issue
症状: 所有请求都返回 401 或 403,即使是合法请求也是如此
可能原因:
- 策略配置过于严格
- 所需凭据未正确发送
- 策略要求以特定格式提供标头或参数
解决方案:
- 检查策略配置 schema 中的必填字段
- 检查客户端应用程序是否按预期格式发送凭据
- 临时禁用策略以隔离问题
400 Error When Applying Policy
应用策略时出现 400 错误
Symptoms:
"The policy to be created is missing at least one of the following properties related to the policy template: 'groupId', 'assetId', 'assetVersion'."Possible causes:
- Used the generic endpoint which does not return Exchange coordinates
listPolicyTemplates
Solutions:
- Use from
getExchangePolicyTemplatesinstead — this returns the full Exchange coordinates needed by the apply endpointapi-portal-xapi
症状:
"The policy to be created is missing at least one of the following properties related to the policy template: 'groupId', 'assetId', 'assetVersion'."可能原因:
- 使用了通用 端点,该端点不会返回 Exchange 坐标
listPolicyTemplates
解决方案:
- 改用 中的
api-portal-xapi——它会返回应用端点所需的完整 Exchange 坐标getExchangePolicyTemplates
Related Jobs
相关 Jobs
- apply-policy-to-api-instance: Apply a policy when you already have an API instance (simpler flow)
- deploy-api-with-rate-limiting: Deploy an API with pre-configured rate limiting tiers
- apply-policy-to-api-instance:当已有 API 实例时应用策略(更简单的流程)
- deploy-api-with-rate-limiting:部署带有预配置速率限制层级的 API