This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new ec0fc2c docs: add public-api related content (#6218)
ec0fc2c is described below
commit ec0fc2ceaf04a20b0bd0ebdaad67296a1d3f621c
Author: Zeping Bai <[email protected]>
AuthorDate: Tue Feb 8 11:42:29 2022 +0800
docs: add public-api related content (#6218)
---
docs/en/latest/config.json | 7 +-
docs/en/latest/plugin-develop.md | 3 +-
docs/en/latest/plugin-interceptors.md | 55 -------------
docs/en/latest/plugins/batch-requests.md | 2 +-
docs/en/latest/plugins/jwt-auth.md | 2 +-
docs/en/latest/plugins/node-status.md | 2 +-
docs/en/latest/plugins/prometheus.md | 7 +-
docs/en/latest/plugins/public-api.md | 132 +++++++++++++++++++++++++++++++
docs/en/latest/plugins/wolf-rbac.md | 2 +-
docs/zh/latest/config.json | 4 -
docs/zh/latest/plugin-develop.md | 3 +-
docs/zh/latest/plugin-interceptors.md | 50 ------------
docs/zh/latest/plugins/batch-requests.md | 3 +-
docs/zh/latest/plugins/jwt-auth.md | 3 +-
docs/zh/latest/plugins/node-status.md | 2 +-
docs/zh/latest/plugins/prometheus.md | 7 +-
docs/zh/latest/plugins/wolf-rbac.md | 2 +-
17 files changed, 150 insertions(+), 136 deletions(-)
diff --git a/docs/en/latest/config.json b/docs/en/latest/config.json
index f99e528..0977cdc 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"
]
},
{
@@ -244,10 +245,6 @@
"id": "wasm"
},
{
- "type": "doc",
- "id": "plugin-interceptors"
- },
- {
"type": "link",
"label": "CODE_STYLE",
"href": "https://github.com/apache/apisix/blob/master/CODE_STYLE.md"
diff --git a/docs/en/latest/plugin-develop.md b/docs/en/latest/plugin-develop.md
index fdfa8c5..cbcf470 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 1ce36cc..0000000
--- a/docs/en/latest/plugin-interceptors.md
+++ /dev/null
@@ -1,55 +0,0 @@
----
-title: Plugin interceptors
----
-
-<!--
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
--->
-
-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 7e258eb..f397765 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 6c7bf8b..e23653e 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 18cd376..d70f738 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 cf56c2d..36f022c 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 0000000..be614b6
--- /dev/null
+++ b/docs/en/latest/plugins/public-api.md
@@ -0,0 +1,132 @@
+---
+title: public-api
+---
+
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+## 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: <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: <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: <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 96ced3a..eef6e3a 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 22026be..a56d177 100644
--- a/docs/zh/latest/config.json
+++ b/docs/zh/latest/config.json
@@ -227,10 +227,6 @@
},
{
"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 40637f7..d0f0f9a 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 9caad0a..0000000
--- a/docs/zh/latest/plugin-interceptors.md
+++ /dev/null
@@ -1,50 +0,0 @@
----
-title: 插件拦截器
----
-
-<!--
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
--->
-
-有些插件为实现它的功能会注册额外的接口。
-
-由于这些接口不是通过 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 538ac8e..bfb9876 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 68cdecd..2ee3015 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 6973697..1901ac6 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 2f5737b..bf8e4cf 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 46de045..58d07f8 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) 插件来暴露它。
## 依赖项