感谢您提供反馈

这篇文章已经过机器翻译.放弃

使用 API 来管理 API 安全性

您可以访问 API 来创建、配置和部署 API 安全性。

注意:

要了解如何使用 API 安全性 API 来配置该功能,请参阅 Nitro API 文档

步骤 资源 URL
  1 创建 API 定义 https://adm.cloud.com/{customerid}/apisec/nitro/v1/config/apidefs
  2 添加 API 代理 https://adm.cloud.com/apiproxies
  3 使用 API 代理部署 API 实例 https://adm.cloud.com/apiproxies/{customerid}/deployments
  4 添加 API 策略 https://adm.cloud.com/{customerid}/apisec/nitro/v1/config/policies/{id}

每个 API 策略都有不同的 config_spec 对象。它是一个不透明的对象,它包含一个 JSON 字典,用于使用特定值配置 policytype

在此对象中,您可以使用以下选项选择 API 资源及其方法:

  • api-resource-paths - 指定 API 定义中定义的 API 资源路径和方法。

    示例

    { "endpoints": ["/pet", "/pet/findByStatus", "/pet/findByTags"], "get": true, "post": false, "put": false, "delete": false }
  • custom-rules - 指定 API 定义中可能不存在的自定义 API 资源路径和方法。

    示例

    { "endpoints": ["/pet/categories", "/pet/findByName"], "get": true, "post": false, "put": false, "delete": false }

使用此配置,策略会筛选与指定 API 资源路径匹配的传入流量请求。

有关每种策略类型的 config_spec 的信息,请参阅策略类型的 API 示例

策略类型的 API 示例

本节介绍支持的 API 策略类型及其配置:

速率限制

以下是 Ratelimit 策略类型的示例配置。在 config_spec 对象中指定以下配置:

{ "policytype": "Ratelimit", "config_spec": { "api-resource-paths": { "endpoints": ["/pet", "/pet/findByStatus", "/pet/findByTags"], "get": true, "post": false, "put": false, "delete": false }, "custom-rules": {}, "threshold": "10", "timeslice": "20000", "limittype": "BURSTY", "api-respondertype": "DROP", "header_name": "x-api-key", "per_client_ip": true }, "order_index": 1, "policy_name": "ratelimit_policy" }

有关每个属性的更多信息,请参阅 速率限制策略

OAuth

下面是 JWT Auth validation 策略类型的 API 配置示例。在 config_spec 对象中指定以下配置:

{ "policytype": "JWT Auth Validation", "config_spec": { "api-resource-paths": { "endpoints": ["/pet", "/pet/findByStatus", "/pet/findByTags"], "get": true, "post": true, "put": false, "delete": false }, "custom-rules": {}, "jwks-uri": "https://uri.petstore.com", "issuer": "https://issuer.petstore.com", "audience": "petstore", "introspect-uri": "https://introspect.uri.com", "clientid": "client", "clientsecret": "clientsecret", "claims-to-save": ["scope", "scope2"], "allowed-algorithms": { "hs256": true, "rs256": true, "rs512": true } }, "order_index": 2, "policy_name": "Jwt_auth_policy" }

有关每个属性的更多信息,请参阅 OAuth 策略

基本认证

以下是 BasicAuth 策略类型的 API 配置示例:

{ "config_spec": { "api-resource-paths": { "delete": false, "endpoints": ["/pet", "/pet/findByStatus", "/pet/findByTags"], "get": true, "post": true, "put": false }, "custom-rules": {} }, "order_index": 3, "policy_name": "Auth_BaSIC", "policytype": "BasicAuth" }

有关每个属性的更多信息,请参阅 基本身份验证策略

未进行身份验证

以下是 NoAuth 策略类型的 API 配置示例:

{ "config_spec": { "api-resource-paths": { "delete": false, "endpoints": ["/pet", "/pet/findByStatus", "/pet/findByTags"], "get": true, "post": false, "put": false }, "custom-rules": {} }, "order_index": 4, "policy_name": "no_auth_policy", "policytype": "NoAuth" }

机器人

以下是 Bot 策略类型的 API 配置示例:

{ "config_spec": { "api-resource-paths": { "delete": false, "endpoints": ["/pet", "/pet/findByStatus", "/pet/findByTags"], "get": false, "post": false, "put": false }, "bot-prof-name": "apisec_test_profile", "custom-rules": {} }, "order_index": 5, "policy_name": "bot_policy", "policytype": "Bot" }

有关每个属性的更多信息,请参阅机器人策略

WAF

以下是 WAF 策略类型的 API 配置示例:

{ "config_spec": { "api-resource-paths": { "delete": false, "endpoints": ["/pet", "/pet/findByStatus", "/pet/findByTags"], "get": false, "post": false, "put": false }, "waf-prof-name": "apisec_waf_profile", "custom-rules": {} }, "order_index": 6, "policy_name": "waf_policy", "policytype": "WAF" }

有关每个属性的更多信息,请参阅 WAF 策略

标题重写

以下是 Header Rewrite 策略类型的 API 配置示例,请在 config_spec 对象中指定此配置:

{ "policytype": "Header Rewrite", "config_spec": { "api-resource-paths": { "endpoints": ["/pet", "/pet/findByStatus", "/pet/findByTags"], "get": true, "post": true, "put": false, "delete": false }, "custom-rules": {}, "rewrite-policy-header-field-name": "org", "rewrite-policy-header-field-val": "Citrix", "rewrite-policy-header-field-new-val": "Citrite" }, "order_index": 7, "policy_name": "header_rewrite_pol" }

有关每个属性的更多信息,请参阅标题重写策略

URI 路径重写

以下是 URI 路径重写策略类型的 API 配置示例:

{ "config_spec": { "api-resource-paths": { "endpoints": ["/store/order", "/store/inventory"], "delete": false, "get": true, "post": true, "patch": false, "put": false }, "custom-rules": { "delete": false, "endpoints": [], "get": false, "post": false, "patch": false, "put": true }, "path-rewrite-params": [ { "insert-segment-position": "beginning", "new-path-value": "v3", "old-path-value": "v2", "action-type": "replace path segment" }, { "insert-segment-position": "beginning", "new-path-value": "begin", "action-type": "insert path segment" }, { "insert-segment-position": "end", "new-path-value": "end", "action-type": "insert path segment" }, { "insert-segment-position": "before", "new-path-value": "before", "old-path-value": "store", "action-type": "insert path segment" }, { "insert-segment-position": "after", "new-path-value": "after", "old-path-value": "store", "action-type": "insert path segment" } ] }, "order_index": 24, "policy_name": "eats_uripathrewrite", "policytype": "URI Path Rewrite” }

有关每个属性的更多信息,请参阅 URI 路径重写策略

Authorization(授权)

下面是 Authorization 策略类型的 API 配置示例。在 config_spec 对象中指定以下配置:

{ "policytype": "Authorization", "config_spec": { "api-resource-paths": { "endpoints": ["/pet", "/pet/findByStatus", "/pet/findByTags"], "get": true, "post": true, "put": false, "delete": false }, "custom-rules": {}, "claims": [{ "name": "scope", "values": ["value1", "value2"] }] }, "order_index": 8, "policy_name": "authorization" }

有关每个属性的更多信息,请参阅授权策略

拒绝

下面是 Deny 策略类型的 API 配置示例。在 config_spec 对象中指定以下配置:

{ "policytype": "Deny", "config_spec": { "api-resource-paths": { "endpoints": ["/pet", "/pet/findByStatus", "/pet/findByTags"], "get": true, "post": true, "put": false, "delete": false }, "custom-rules": {}, "api-denytype": "RESPONDWITH" }, "order_index": 9, "policy_name": "deny_policy" }

api-denytype 中,您可以指定以下值之一:

  • RESPONDWITH
  • RESET

有关每个属性的更多信息,请参阅 拒绝规则

本内容的正式版本为英文版。部分 Cloud Software Group 文档内容采用了机器翻译,仅供您参考。Cloud Software Group 无法控制机器翻译的内容,这些内容可能包含错误、不准确或不合适的语言。对于从英文原文翻译成任何其他语言的内容的准确性、可靠性、适用性或正确性,或者您的 Cloud Software Group 产品或服务沿用了任何机器翻译的内容,我们均不作任何明示或暗示的保证,并且适用的最终用户许可协议或服务条款或者与 Cloud Software Group 签订的任何其他协议(产品或服务与已进行机器翻译的任何文档保持一致)下的任何保证均不适用。对于因使用机器翻译的内容而引起的任何损害或问题,Cloud Software Group 不承担任何责任。
使用 API 来管理 API 安全性