You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "KID-G (via GitHub)" <gi...@apache.org> on 2023/01/30 07:55:55 UTC
[GitHub] [apisix-website] KID-G opened a new pull request, #1488: docs:add something about api gateway policy blog
KID-G opened a new pull request, #1488:
URL: https://github.com/apache/apisix-website/pull/1488
Changes:
Add something about api gateway policy blog
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-website] SkyeYoung commented on a diff in pull request #1488: docs:add something about api gateway policy blog
Posted by "SkyeYoung (via GitHub)" <gi...@apache.org>.
SkyeYoung commented on code in PR #1488:
URL: https://github.com/apache/apisix-website/pull/1488#discussion_r1090404831
##########
blog/zh/blog/2023/01/30/something-about-api-gateway-policy.md:
##########
@@ -0,0 +1,226 @@
+---
+title: "API 网关策略的二三事"
+authors:
+ - name: "暴渊"
+ title: "Author"
+ url: "https://github.com/Baoyuantop"
+ image_url: "https://github.com/Baoyuantop.png"
+keywords:
+- API Gateway
+- 网关策略
+- APISIX
+- Gateway Policy
+description: 这篇文章介绍了什么是 API 网关策略,并针对认证授权、安全、流量处理与可观测性这四类 API 网关中常用的策略进行描述。
+tags: [Ecosystem]
+---
+
+> 这篇文章介绍了什么是 API 网关策略,并针对认证授权、安全、流量处理与可观测性这四类 API 网关中常用的策略进行描述。
+
+<!--truncate-->
+
+>作者[暴渊](https://github.com/Baoyuantop),API7.ai 技术工程师,Apache APISIX Committer。
Review Comment:
```suggestion
> 作者[暴渊](https://github.com/Baoyuantop),API7.ai 技术工程师,Apache APISIX Committer。
```
##########
blog/zh/blog/2023/01/30/something-about-api-gateway-policy.md:
##########
@@ -0,0 +1,226 @@
+---
+title: "API 网关策略的二三事"
+authors:
+ - name: "暴渊"
+ title: "Author"
+ url: "https://github.com/Baoyuantop"
+ image_url: "https://github.com/Baoyuantop.png"
+keywords:
+- API Gateway
+- 网关策略
+- APISIX
+- Gateway Policy
+description: 这篇文章介绍了什么是 API 网关策略,并针对认证授权、安全、流量处理与可观测性这四类 API 网关中常用的策略进行描述。
+tags: [Ecosystem]
+---
+
+> 这篇文章介绍了什么是 API 网关策略,并针对认证授权、安全、流量处理与可观测性这四类 API 网关中常用的策略进行描述。
+
+<!--truncate-->
+
+>作者[暴渊](https://github.com/Baoyuantop),API7.ai 技术工程师,Apache APISIX Committer。
+
+近些年随着云原生和微服务架构的日趋发展,API 网关以流量入口的角色在技术架构中扮演着越来越重要的作用。**API 网关主要负责接收所有请求的流量并进行处理转发至上游服务,API 网关的策略决定了 API 网关处理这些流量的逻辑与规则,直接决定了实际的业务流量行为。**
+
+## 什么是 API 网关策略?
+
+API 网关一般位于所有的上游服务之前,当用户向服务发送请求后请求会先到 API 网关,API 网关接收到请求之后一般会判断几件事情:
+
+1. **请求是否合法,比如是否来自被禁止访问的用户列表中;**
+2. **这个请求是否通过认证,访问的内容是否是经过授权的;**
+3. **请求是否触发了某些限制规则,比如限流限速等;**
+4. **请求应该转发给哪个上游服务。**
+
+经过这一系列步骤,这个请求要么不符合预设的规则被拒绝,要么经过了层层处理正确到达指定的上游服务中。我们将这些处理规则称之为 API 网关的策略。这些规则由网关的管理员在网关运行时不断添加至网关中,网关接受这些规则并根据这些规则作出正确的流量处理行为。
+
+以 API 网关 [Apache APISIX](https://apisix.apache.org/) 为例,APISIX 的配置信息有两种:网关启动用的配置文件,比如 `config.yaml`,这个文件决定了网关正常启动所必须的一些配置。另外在运行时管理员可以通过 [Admin API](https://apisix.apache.org/docs/apisix/admin-api/) 动态创建各种规则与配置,比如 Route、Consumer、Plugin 等等。API 网关的策略就是管理员通过 Admin API 动态创建的各种规则与配置。
+
+本文不再额外描述基本常用场景,而是针对认证授权、安全、流量处理与可观测性这四类 API 网关中重要的场景进行阐述,介绍每种场景下包含的一些 API 网关策略的作用以及使用方法。
+
+## 认证和授权策略
+
+认证可以确认 API 调用者的身份,授权主要限制调用者仅能访问权限内的资源。
+
+
+
+比如说一位乘客前往车站出行,进入车站之前会使用身份证进行“认证”确认身份,在进入车站后出示车票,经工作人员确认后被“授权”进入某班列车。
+
+认证授权类策略主要目的是保证网关转发到上游服务的所有请求都是经过认证和授权的,不会出现非法请求。并且访问的都是权限范围内的资源。比较常用的策略有下面几种:
+
+### Basic Auth
+
+[基本访问认证](https://en.wikipedia.org/wiki/Basic_access_authentication)策略,这是一种最简单的访问控制技术。一般由用户的 HTTP 代理在发出请求时携带用于认证的请求头,一般为:`Authorization: Basic <credentials>`,credentials 中即包含了用户认证需要的用户 ID 和密码,使用 `:` 隔离。这种方式不需要登陆页面、cookie 等繁杂的设置,仅仅基于请求头中的简单凭据信息进行认证,一般为用户名和密码,配置使用起来较为简单。
+
+携带基本认证的 `cURL` 请求的示例如下,用户名为 `username`,密码为 `password`:
+
+```shell
+curl -i -u 'username:password' http://127.0.0.1:8080/hello
+```
+
+需要注意的是 `credentials` 中的信息在传输过程中并不会被加密,仅仅做 Base64 编码,所以通常需要和 HTTPS 一起使用来保证密码的安全性。
+
+在网关中实施这一策略后,未携带凭据的请求将无法正常通过网关转发,除非在请求中携带了正确的认证信息,实现了最小成本下为 API 添加了访问验证。
+
+### Key Auth
+
+Key Auth 策略通过在 API 中添加 Key 来限制 API 调用,并识别请求携带的 Key 来进行访问资源的控制。只有携带了正确的 Key 之后的请求才能正常访问,可以在请求头中或 Query 中携带。通常还可以通过这个 Key 来区分不同的 API 调用方,从而可以针对不同的调用方实施不同的其他策略或资源控制。同样的 Key 在 HTTP 中是明文传输的,确保请求使用了 HTTPS 以保证安全。
+
+以 APISIX 的 [key-auth](https://apisix.apache.org/docs/apisix/plugins/key-auth/) 插件为例,插件需要通过 Admin API 创建一个具有唯一 key 值的 Consumer:
+
+```shell
+curl http://127.0.0.1:9180/apisix/admin/consumers \
+-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+ "username": "jack",
+ "plugins": {
+ "key-auth": {
+ "key": "jack-key"
+ }
+ }
+}'
+```
+
+这一请求创建了一个名字为 `jack` 的 Consumer,它的 key 值为 `jack-key`。在路由中启用插件时需要配置网关从请求中读取 Key 值的位置和字段名称。默认的配置位置为 `header` ,字段名称为 `apikey`, 那么正确的请求这个路由的示例为:
+
+```shell
+curl -i http://127.0.0.1:8080/hello -H 'apikey: jack-key'
+```
+
+APISIX 在收到这一请求后会从请求中解析出 Key,然后从配置的所有 Key 中找到和这个请求匹配的 Consumer `jack`,这样网关就清楚这个请求是 `jack` 发出的。如果没有找到匹配的 Key 即可判定为非法请求。
+
+### JSON Web Token
Review Comment:
```suggestion
### JSON Web Token (JWT)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-website] netlify[bot] commented on pull request #1488: docs:add something about api gateway policy blog
Posted by netlify.
netlify[bot] commented on PR #1488:
URL: https://github.com/apache/apisix-website/pull/1488#issuecomment-1408139440
### <span aria-hidden="true">👷</span> Deploy Preview for *apache-apisix* processing.
| Name | Link |
|---------------------------------|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | 6241abec89074d732b122f37d5c2e1f20c3a2f88 |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/sites/apache-apisix/deploys/63d7780b3455e60009757149 |
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-website] SylviaBABY merged pull request #1488: docs:add something about api gateway policy blog
Posted by "SylviaBABY (via GitHub)" <gi...@apache.org>.
SylviaBABY merged PR #1488:
URL: https://github.com/apache/apisix-website/pull/1488
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org