当前位置:网站首页>Interpretation of new plug-ins | how to enhance authentication capability with forward auth
Interpretation of new plug-ins | how to enhance authentication capability with forward auth
2022-06-26 16:46:00 【Apacheapisik China Community】
Forward Auth Can skillfully transfer authentication and authorization logic to special external services , The gateway will forward the user's request to the authentication service , And in the authentication service response non 20x In the state of , Block the original request and replace the result . In this way , You can realize when the certification fails , Return the custom error message or redirect the user to the authentication page .
This article will introduce Apache APISIX 2.12.0 New plug-ins in version forward-auth How to use , Let's briefly explain how to use this simple authentication model .
principle

About forward-auth Plug in Apache APISIX The operation principle and process of the are shown in the figure above , The specific summary is as follows :
First step : From the client to APISIX Initiate request
The second step : from APISIX Initiate a request to the user configured authentication service
The third step : Authentication service response (2xx Or abnormal state )
Step four :APISIX Will respond according to the authentication service , decision Forward the request upstream or direct **** Send a reject response to the client
How to use
Step one : Set up authentication service
Suppose there is such an authentication service , The user sends it with Authorization Request header request . If the data is verified, it returns 200 The status code and a code named X-User-ID Response header for ; If it fails to pass the verification, the authentication status is considered to be expired , return 302 Status codes and Location The response header redirects the client to the login page .
Step two : Create a route and turn it on forward-auth plug-in unit
Next , We will configure a route and turn on forward-auth plug-in unit , Connect the above authentication services with upstream applications .
curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '{ "plugins": { "forward-auth": { "address": "http://127.0.0.1:9080/auth", "request_headers": ["Authorization"], "upstream_headers": ["X-User-ID"], "client_headers": ["Location"] } }, "uri": "/user"}'Explanation of the above configuration details :
When a request matches the current route , Send a request to
addressAddress in , Which will be attachedrequest_headersRequest header defined inAuthorization( That is, configure the request header that needs to be forwarded by the client to the authentication service , If not set, no request header will be forwarded ), The authentication service can confirm the user's identity based on this .If the certification passes , Status code for 200 And return a
upstream_headersAs defined inX-User-ID( That is, the request header forwarded by the authentication service to the upstream when the authentication passes , If not set, no request header will be forwarded ).If authentication fails , Status code for 302 And return one in
client_headersAs defined inLocation( That is, the response header sent by the authentication service to the client when authentication fails , If not set, no response header will be forwarded ).
Step three : The test request
# Use POST Request and send data curl http://127.0.0.1:9080/user \ --header 'Authorization: true'HTTP/1.1 200 OKContent-Type: application/jsonContent-Length: 28Server: APISIX/2.11.0{"user_id":"i-am-real-user"}# Use GET request curl -i http://127.0.0.1:9080/user \ --header 'Authorization: false'HTTP/1.1 302 FOUNDServer: APISIX/2.11.0Location: https://example.com/authAdd : Close plugins
If used , Just remove... From the routing configuration forward-auth Plug in related configuration and save , You can turn off... On the route Forward Auth plug-in unit . Thanks to the Apache APISIX Dynamic characteristics of , There is no need to restart the process of opening and closing plug-ins Apache APISIX.
summary
Want to learn more about forward-auth Plug in description and complete configuration list , May refer to :https://apisix.apache.org/docs/apisix/next/plugins/forward-auth.
About Apache APISIX
Apache APISIX It's a dynamic 、 real time 、 High-performance open source API gateway , Provide load balancing 、 Dynamic upstream 、 Grayscale Publishing 、 Service failure 、 Identity Authentication 、 Observability and other rich traffic management functions .
Apache APISIX It can help enterprises quickly 、 Handle safely API And microservice traffic , Including gateways 、Kubernetes Ingress And service grid . At present, it has been approved by PwC data security team 、 Tencent blue army 、 Ping An Galaxy lab 、 Iqiyi SRC And Yuanbao technology security team and other professional network security institutions , And highly recognized .
Apache APISIX Landing users ( Only part )

Apache APISIX GitHub:https://github.com/apache/apisix
Apache APISIX Official website :https://apisix.apache.org/
Apache APISIX file :https://apisix.apache.org/zh/docs/apisix/getting-started
边栏推荐
- Research on natural transition dubbing processing scheme based on MATLAB
- Use the array to calculate the average of N numbers, and output the numbers greater than the average
- The student record consists of student number and academic performance. The data of n students have been stored in the a structure array to find out the student record with the lowest performance
- Knowing these commands allows you to master shell's own tools
- I regard it as a dry product with a monthly income of more than 30000 yuan for sidelines and more than 10000 yuan for novices!
- [matlab project practice] prediction of remaining service life of lithium ion battery based on convolutional neural network and bidirectional long short time (cnn-lstm) fusion
- num[i]++
- Arduino UNO + DS1302简单获取时间并串口打印
- 100+ data science interview questions and answers Summary - basic knowledge and data analysis
- 用Attention和微调BERT进行自然语言推断-PyTorch
猜你喜欢

Gui+sqlserver examination system

探讨:下一代稳定币

When a programmer is disturbed 10 times a day, the consequences are amazing!

How to implement interface current limiting?

国内首款开源 MySQL HTAP 数据库即将发布,三大看点提前告知

100+数据科学面试问题和答案总结 - 基础知识和数据分析

JUnit unit test

经典同步问题

The first open source MySQL HTAP database in China will be released soon, and the three highlights will be notified in advance

r329(MAIX-II-A(M2A)资料汇总
随机推荐
Greenplum数据库故障分析——semop(id=2000421076,num=11) failed: invalid argument
[force deduction question] two point search: 4 Find the median of two positive arrays
5G未平6G再启,中国引领无线通信,6G的最大优势在哪里?
Cuckoo filter for Chang'an chain transaction
无需人工先验!港大&同济&LunarAI&旷视提出基于语义分组的自监督视觉表征学习,显著提升目标检测、实例分割和语义分割任务!...
JS tutorial electron JS is a good tool for designing powerful multi platform desktop applications
【MATLAB项目实战】基于卷积神经网络与双向长短时(CNN-LSTM)融合的锂离子电池剩余使用寿命预测
Calculate the average of N numbers in the group indexed by the formal parameter x, move the data less than the average in the group indexed to the front of the array, and move the data greater than or
[Li Kou brush question] monotone stack: 84 The largest rectangle in the histogram
长安链交易防重之布谷鸟过滤器
Teach you to learn dapr - 8 binding
用Attention和微调BERT进行自然语言推断-PyTorch
108. 简易聊天室11:实现客户端群聊
Gui+sqlserver examination system
Calculate the sum of the main diagonals of the array
I regard it as a dry product with a monthly income of more than 30000 yuan for sidelines and more than 10000 yuan for novices!
我把它当副业月入3万多,新手月入过万的干货分享!
Develop operator based on kubebuilder (for getting started)
Make up the weakness - Open Source im project openim about initialization / login / friend interface document introduction
C语言 头哥习题答案截图