diff --git a/docs/en/latest/config.json b/docs/en/latest/config.json index f99e528e..0977cdc9 100644 --- a/docs/en/latest/config.json +++ b/docs/en/latest/config.json @@ -82,7 +82,8 @@ "plugins/ua-restriction", "plugins/referer-restriction", "plugins/consumer-restriction", - "plugins/csrf" + "plugins/csrf", + "plugins/public-api" ] }, { @@ -243,10 +244,6 @@ "type": "doc", "id": "wasm" }, - { - "type": "doc", - "id": "plugin-interceptors" - }, { "type": "link", "label": "CODE_STYLE", diff --git a/docs/en/latest/plugin-develop.md b/docs/en/latest/plugin-develop.md index fdfa8c52..cbcf470d 100644 --- a/docs/en/latest/plugin-develop.md +++ b/docs/en/latest/plugin-develop.md @@ -409,8 +409,7 @@ function _M.api() end ``` -Note that the public API is exposed to the public. -You may need to use [interceptors](plugin-interceptors.md) to protect it. +Note that the public API will not be exposed by default, you will need to use the [public-api plugin](plugins/public-api.md) to expose it. ## register control API diff --git a/docs/en/latest/plugin-interceptors.md b/docs/en/latest/plugin-interceptors.md deleted file mode 100644 index 1ce36ccc..00000000 --- a/docs/en/latest/plugin-interceptors.md +++ /dev/null @@ -1,55 +0,0 @@ ---- -title: Plugin interceptors ---- - - - -Some plugins will register API to serve their purposes. - -Since these API are not added as regular [Route](admin-api.md), we can't add -plugins to protect them. To solve the problem, we add a new concept called 'interceptors' -to run rules to protect them. - -Here is an example to limit the access of `/apisix/prometheus/metrics` (a route introduced via plugin prometheus) -to clients in `10.0.0.0/24`: - -```shell -$ curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/prometheus -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -i -X PUT -d ' -{ - "interceptors": [ - { - "name": "ip-restriction", - "conf": { - "whitelist": ["10.0.0.0/24"] - } - } - ] -}' -``` - -You can see that the interceptors are configured like the plugins. The `name` is -the name of plugin which you want to run and the `conf` is the configuration of the -plugin. - -Currently we only support a subset of plugins which can be run as interceptors. - -Supported interceptors: - -* [ip-restriction](./plugins/ip-restriction.md) diff --git a/docs/en/latest/plugins/batch-requests.md b/docs/en/latest/plugins/batch-requests.md index 7e258eb2..f397765a 100644 --- a/docs/en/latest/plugins/batch-requests.md +++ b/docs/en/latest/plugins/batch-requests.md @@ -47,7 +47,7 @@ None ## API This plugin will add `/apisix/batch-requests` as the endpoint. -You may need to use [interceptors](../plugin-interceptors.md) to protect it. +You may need to use [public-api](public-api.md) plugin to expose it. ## How To Enable diff --git a/docs/en/latest/plugins/jwt-auth.md b/docs/en/latest/plugins/jwt-auth.md index 6c7bf8b6..e23653e8 100644 --- a/docs/en/latest/plugins/jwt-auth.md +++ b/docs/en/latest/plugins/jwt-auth.md @@ -62,7 +62,7 @@ For more information on JWT, refer to [JWT](https://jwt.io/) for more informatio ## API This plugin will add `/apisix/plugin/jwt/sign` to sign. -You may need to use [interceptors](../plugin-interceptors.md) to protect it. +You may need to use [public-api](public-api.md) plugin to expose it. ## How To Enable diff --git a/docs/en/latest/plugins/node-status.md b/docs/en/latest/plugins/node-status.md index 18cd3761..d70f7389 100644 --- a/docs/en/latest/plugins/node-status.md +++ b/docs/en/latest/plugins/node-status.md @@ -41,7 +41,7 @@ None ## API This plugin will add `/apisix/status` to get status information. -You may need to use [interceptors](../plugin-interceptors.md) to protect it. +You may need to use [public-api](public-api.md) plugin to expose it. ## How To Enable diff --git a/docs/en/latest/plugins/prometheus.md b/docs/en/latest/plugins/prometheus.md index cf56c2dc..36f022c0 100644 --- a/docs/en/latest/plugins/prometheus.md +++ b/docs/en/latest/plugins/prometheus.md @@ -46,10 +46,7 @@ plugin_attr: Assume environment variable `INTRANET_IP` is `172.1.1.1`, now APISIX will export the metrics via `172.1.1.1:9092`. -**Before version `2.6`, the metrics are exposed via the data plane port, -you may need to use [interceptors](../plugin-interceptors.md) to protect it.** - -If you still want this behavior, you can configure it like this: +If you still want to expose the metrics via the data plane port (default: 9080), you can configure it like this: ``` plugin_attr: @@ -57,6 +54,8 @@ plugin_attr: enable_export_server: false ``` +You may need to use [public-api](public-api.md) plugin to expose it. + ## How to enable it `prometheus` plugin could be enable with empty table. diff --git a/docs/en/latest/plugins/public-api.md b/docs/en/latest/plugins/public-api.md new file mode 100644 index 00000000..be614b64 --- /dev/null +++ b/docs/en/latest/plugins/public-api.md @@ -0,0 +1,132 @@ +--- +title: public-api +--- + + + +## Summary + +- [**Description**](#description) +- [**Attributes**](#attributes) +- [**Example**](#example) + +## Description + +The `public-api` plugin is used to enhance the plugin public API access control. +When current users develop custom plugins, they can register some public APIs for fixed functionality, such as the `/apisix/plugin/jwt/sign` API in `jwt-auth`. These APIs can only apply limited plugins for access control (currently only `ip-restriction`) by way of plugin interceptors. + +With the `public-api` plugin, we put all public APIs into the general HTTP API router, which is consistent with the normal Route registered by the user and can apply any plugin. The public API added in the user plugin is no longer expose by default by APISIX, and the user has to manually configure the Route for it, the user can configure any uri and plugin. + +## Attributes + +| Name | Type | Requirement | Default | Valid | Description | +| -- | -- | -- | -- | -- | -- | +| uri | string | optional | "" | | The uri of the public API. When you set up the route, you can use this to configure the original API uri if it is used in a way that is inconsistent with the original public API uri. | + +## Example + +We take the `jwt-auth` token sign API as an example to show how to configure the `public-api` plugin. Also, the `key-auth` will be used to show how to configure the protection plugin for the public API. + +### Prerequisites + +The use of key-auth and jwt-auth requires the configuration of a consumer that contains the configuration of these plugins, and you need to create one in advance, the process will be omitted here. + +### Basic Use Case + +First we will setup a route. + +```shell +$ curl -X PUT 'http://127.0.0.1:9080/apisix/admin/routes/r1' \ + -H 'X-API-KEY: ' \ + -H 'Content-Type: application/json' \ + -d '{ + "uri": "/apisix/plugin/jwt/sign", + "plugins": { + "public-api": {} + } +}' +``` + +Let's test it. + +```shell +$ curl 'http://127.0.0.1:9080/apisix/plugin/jwt/sign?key=user-key' +``` + +It will respond to a text JWT. + +### Customize URI + +Let's setup another route. + +```shell +$ curl -X PUT 'http://127.0.0.1:9080/apisix/admin/routes/r2' \ + -H 'X-API-KEY: ' \ + -H 'Content-Type: application/json' \ + -d '{ + "uri": "/gen_token", + "plugins": { + "public-api": { + "uri": "/apisix/plugin/jwt/sign" + } + } +}' +``` + +Let's test it. + +```shell +$ curl 'http://127.0.0.1:9080/gen_token?key=user-key' +``` + +It will still respond to a text JWT. We can see that users are free to configure URI for the public API to match. + +### Protect Route + +Let's modify the last route and add `key-auth` authentication to it. + +```shell +$ curl -X PUT 'http://127.0.0.1:9080/apisix/admin/routes/r2' \ + -H 'X-API-KEY: ' \ + -H 'Content-Type: application/json' \ + -d '{ + "uri": "/gen_token", + "plugins": { + "public-api": { + "uri": "/apisix/plugin/jwt/sign" + }, + "key-auth": {} + } +}' +``` + +Let's test it. + +```shell +$ curl -i 'http://127.0.0.1:9080/gen_token?key=user-key' + -H "apikey: test-apikey" +HTTP/1.1 200 OK + +# Failed request +$ curl -i 'http://127.0.0.1:9080/gen_token?key=user-key' +HTTP/1.1 401 UNAUTHORIZED +``` + +It will still respond to a text JWT. If we don't add `apikey` to the request header, it will respond with a 401 block request. In this way, we have implemented a plugin approach to protect the public API. diff --git a/docs/en/latest/plugins/wolf-rbac.md b/docs/en/latest/plugins/wolf-rbac.md index 96ced3a3..eef6e3af 100644 --- a/docs/en/latest/plugins/wolf-rbac.md +++ b/docs/en/latest/plugins/wolf-rbac.md @@ -51,7 +51,7 @@ This plugin will add several API: * /apisix/plugin/wolf-rbac/change_pwd * /apisix/plugin/wolf-rbac/user_info -You may need to use [interceptors](../plugin-interceptors.md) to protect it. +You may need to use [public-api](public-api.md) plugin to expose it. ## Dependencies diff --git a/docs/zh/latest/config.json b/docs/zh/latest/config.json index 22026bed..a56d1777 100644 --- a/docs/zh/latest/config.json +++ b/docs/zh/latest/config.json @@ -225,10 +225,6 @@ "type": "doc", "id": "plugin-develop" }, - { - "type": "doc", - "id": "plugin-interceptors" - }, { "type": "doc", "id": "CODE_STYLE" diff --git a/docs/zh/latest/plugin-develop.md b/docs/zh/latest/plugin-develop.md index 40637f77..d0f0f9a3 100644 --- a/docs/zh/latest/plugin-develop.md +++ b/docs/zh/latest/plugin-develop.md @@ -326,8 +326,7 @@ function _M.api() end ``` -注意注册的接口会暴露到外网。 -你可能需要使用 [interceptors](plugin-interceptors.md) 来保护它。 +注意,注册的接口将不会默认暴露,需要使用[public-api 插件](../../en/latest/plugins/public-api.md)来暴露它。 ## 注册控制接口 diff --git a/docs/zh/latest/plugin-interceptors.md b/docs/zh/latest/plugin-interceptors.md deleted file mode 100644 index 9caad0a8..00000000 --- a/docs/zh/latest/plugin-interceptors.md +++ /dev/null @@ -1,50 +0,0 @@ ---- -title: 插件拦截器 ---- - - - -有些插件为实现它的功能会注册额外的接口。 - -由于这些接口不是通过 admin API 添加的,所以没办法像管理 Route 那样管理它们。为了能够保护这些接口不被利用,我们引入了 interceptors 的概念。 - -下面是通过 interceptors 来保护由 prometheus 插件引入的 `/apisix/prometheus/metrics` 接口,限定只能由 `10.0.0.0/24` 网段的用户访问: - -```shell -$ curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/prometheus -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -i -X PUT -d ' -{ - "interceptors": [ - { - "name": "ip-restriction", - "conf": { - "whitelist": ["10.0.0.0/24"] - } - } - ] -}' -``` - -我们能看到配置 interceptors 就像配置 plugin 一样:name 是 interceptor 的名称,而 conf 是它的配置。 - -当前我们只支持一部分插件作为 interceptor 运行。 - -支持的 interceptor: - -* [ip-restriction](./plugins/ip-restriction.md) diff --git a/docs/zh/latest/plugins/batch-requests.md b/docs/zh/latest/plugins/batch-requests.md index 538ac8e7..bfb9876e 100644 --- a/docs/zh/latest/plugins/batch-requests.md +++ b/docs/zh/latest/plugins/batch-requests.md @@ -52,8 +52,7 @@ title: batch-requests ## 接口 -插件会增加 `/apisix/batch-requests` 这个接口,你可能需要通过 [interceptors](../plugin-interceptors.md) -来保护它。 +插件会增加 `/apisix/batch-requests` 这个接口,需要通过 [public-api](../../../en/latest/plugins/public-api.md) 插件来暴露它。 ## 如何启用 diff --git a/docs/zh/latest/plugins/jwt-auth.md b/docs/zh/latest/plugins/jwt-auth.md index 68cdecdc..2ee30151 100644 --- a/docs/zh/latest/plugins/jwt-auth.md +++ b/docs/zh/latest/plugins/jwt-auth.md @@ -51,8 +51,7 @@ title: jwt-auth ## 接口 -插件会增加 `/apisix/plugin/jwt/sign` 这个接口,你可能需要通过 [interceptors](../plugin-interceptors.md) -来保护它。 +插件会增加 `/apisix/plugin/jwt/sign` 这个接口,需要通过 [public-api](../../../en/latest/plugins/public-api.md) 插件来暴露它。 ## 如何启用 diff --git a/docs/zh/latest/plugins/node-status.md b/docs/zh/latest/plugins/node-status.md index 69736971..1901ac6b 100644 --- a/docs/zh/latest/plugins/node-status.md +++ b/docs/zh/latest/plugins/node-status.md @@ -40,7 +40,7 @@ title: node-status ## 插件接口 -插件增加接口 `/apisix/status`,可通过 [interceptors](../plugin-interceptors.md) 保护该接口。 +插件增加接口 `/apisix/status`,需要通过 [public-api](../../../en/latest/plugins/public-api.md) 插件来暴露它。 ## 启用插件 diff --git a/docs/zh/latest/plugins/prometheus.md b/docs/zh/latest/plugins/prometheus.md index 2f5737b6..bf8e4cfc 100644 --- a/docs/zh/latest/plugins/prometheus.md +++ b/docs/zh/latest/plugins/prometheus.md @@ -46,10 +46,7 @@ plugin_attr: 假设环境变量 `INTRANET_IP` 是 `172.1.1.1`,现在 APISIX 会在 `172.1.1.1:9092` 上暴露指标。 -**在 2.6 版本之前,指标会直接暴露到数据面的端口上,你可能需要通过 [interceptors](../plugin-interceptors.md) -来保护它。** - -如果你依然想要这样的行为,你可以这么配置: +如果你依然想要让指标暴露在数据面的端口(默认:9080)上,你可以这么配置: ``` plugin_attr: @@ -57,6 +54,8 @@ plugin_attr: enable_export_server: false ``` +同时,您还需要使用 [public-api](../../../en/latest/plugins/public-api.md) 插件来暴露它。 + ## 如何开启插件 `prometheus` 插件可以使用空 {} 开启。 diff --git a/docs/zh/latest/plugins/wolf-rbac.md b/docs/zh/latest/plugins/wolf-rbac.md index 46de0453..58d07f8a 100644 --- a/docs/zh/latest/plugins/wolf-rbac.md +++ b/docs/zh/latest/plugins/wolf-rbac.md @@ -51,7 +51,7 @@ rbac 功能由 [wolf](https://github.com/iGeeky/wolf) 提供, 有关 `wolf` 的 * /apisix/plugin/wolf-rbac/change_pwd * /apisix/plugin/wolf-rbac/user_info -你可能需要通过 [interceptors](../plugin-interceptors.md) 来保护它们。 +需要通过 [public-api](../../../en/latest/plugins/public-api.md) 插件来暴露它。 ## 依赖项