Anonymous Access的理解

摘要:
EveryrequestproxiedbyKongmustbeassociatedwithaConsumer.You’llnowcreateaConsumernamedanonymous_users启用认证插件后,如果不配置匿名用户,那么如果客户端不传递凭据,那么就不会通过每个请求必须要和一个消费者关联,匿名消费者的配置,需要如下:$curl-i-XPATCH--urlhttp://localho

Every request proxied by Kong must be associated with a Consumer.

You’ll now create a Consumer named anonymous_users

启用认证插件后,如果不配置匿名用户,那么如果客户 端不传递凭据,那么就不会通过

每个请求必须要和一个消费者关联,匿名消费者的配置,需要如下:

 $ curl -i -X PATCH --url http://localhost:8001/plugins/<your-plugin-id> --data "config.anonymous=<your-consumer-id>"

当客户端不设置apikey的时候,kongm默认取配置的匿名用户转发到后端

我们可以针对匿名用户配置限流策略

PermalinkAnonymous Access

Kong has the ability to configure a given Service to allow both authenticated and anonymous access.

You might use this configuration to grant access to anonymous users with a low rate-limit, and grant access to authenticated users with a higher rate limit.

To configure a Service like this, you first apply your selected authentication plugin, then create a new consumer to represent anonymous users, then configure your authentication plugin to allow anonymous access. Here is an example, which assumes you have already configured a Service named example-service and the corresponding route:

  1. PermalinkCreate an example Service and a Route

    Issue the following cURL request to create example-service pointing to mockbin.org, which will echo the request:

     $ curl -i -X POST --url http://localhost:8001/services/ --data 'name=example-service' --data 'url=http://mockbin.org/request'
    

    Add a route to the Service:

     $ curl -i -X POST --url http://localhost:8001/services/example-service/routes --data 'paths[]=/auth-sample'
    

    The url http://localhost:8000/auth-sample will now echo whatever is being requested.

  2. PermalinkConfigure the key-auth Plugin for your Service

    Issue the following cURL request to add a plugin to a Service:

     $ curl -i -X POST --url http://localhost:8001/services/example-service/plugins/ --data 'name=key-auth'
    

    Be sure to note the created Plugin id - you’ll need it in step 5.

  3. PermalinkVerify that the key-auth plugin is properly configured

    Issue the following cURL request to verify that the key-auth plugin was properly configured on the Service:

     $ curl -i -X GET --url http://localhost:8000/auth-sample
    

    Since you did not specify the required apikey header or parameter, and you have not yet enabled anonymous access, the response should be 403 Forbidden:

    HTTP/1.1 403 Forbidden
    ...
    
     {
       "message": "No API key found in headers or querystring"
     }
    
  4. PermalinkCreate an anonymous Consumer

    Every request proxied by Kong must be associated with a Consumer. You’ll now create a Consumer named anonymous_users (that Kong will utilize when proxying anonymous access) by issuing the following request:

     $ curl -i -X POST --url http://localhost:8001/consumers/ --data "username=anonymous_users"
    

    You should see a response similar to the one below:

    HTTP/1.1 201 Created
    Content-Type: application/json
    Connection: keep-alive
    
     {
       "username": "anonymous_users",
       "created_at": 1428555626000,
       "id": "bbdf1c48-19dc-4ab7-cae0-ff4f59d87dc9"
     }
    

    Be sure to note the Consumer id - you’ll need it in the next step.

  5. PermalinkEnable anonymous access

    You’ll now re-configure the key-auth plugin to permit anonymous access by issuing the following request (replace the sample uuids below by the id values from step 2 and 4):

     $ curl -i -X PATCH --url http://localhost:8001/plugins/<your-plugin-id> --data "config.anonymous=<your-consumer-id>"
    

    The config.anonymous=<your-consumer-id> parameter instructs the key-auth plugin on this Service to permit anonymous access, and to associate such access with the Consumer id we received in the previous step. It is required that you provide a valid and pre-existing Consumer id in this step - validity of the Consumer id is not currently checked when configuring anonymous access, and provisioning of a Consumer id that doesn’t already exist will result in an incorrect configuration.

  6. PermalinkCheck anonymous access

    Confirm that your Service now permits anonymous access by issuing the following request:

     $ curl -i -X GET --url http://localhost:8000/auth-sample
    

    This is the same request you made in step #3, however this time the request should succeed, because you enabled anonymous access in step #5.

    The response (which is the request as Mockbin received it) should have these elements:

    {..."headers":{..."x-consumer-id":"713c592c-38b8-4f5b-976f-1bd2b8069494","x-consumer-username":"anonymous_users","x-anonymous-consumer":"true",...},...}

    It shows the request was successful, but anonymous.

免责声明:文章转载自《Anonymous Access的理解》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇WPF_界面_图片/界面/文字模糊解决之道整理wpf 获取datagrid中模板中控件下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Elastic search 基本使用

1. elasticsearch 命令的基本格式 RESTful接口URL的格式: http://localhost:9200/<index>/<type>/[<id>] 其中index、type是必须提供的。id是可选的,不提供es会自动生成。index、type将信息进行分层,利于管理。index可以理解为数据库;t...

六、对ES增删改查

一、ES的数据结构 ES跟MySQL有很大的区别,现在将MySQL跟ES做对比,这样方便理解。 因为ES数据库是通过API接口进行访问的,访问的方式有如下几种 1、es-head插件 2、kibana控制台 3、curl命令 4、Postman工具 1、ES数据库结构对比 MySQL术语 ES术语 库,databases 索引,index 表...

微信开发-ACCESS TOKEN 过期失效解决方案

微信开发-ACCESS TOKEN 过期失效解决方案 起因:因为access_token的重要性,开发过微信的都知道,但是他有自己的生命周期,官方解释为:"有效期为7200秒",一天调用2000次。流量一高,就over了,没办法,龙哥不帮我们解决问题,我们就要自己解决,不能等死。 解决思路很简单:建立公共access token数据,有效期内不重新创建ac...

Access关键字

为了避免大家犯同样的错误,现将Access的关键字列出来,如果以后在编程中你遇到了同样的错误,请看看是否使用了Access的关键字。 -A    ADD    ALL    Alphanumeric    ALTER    AND    ANY    Application    AS    ASC    Assistant    AUTOINCREME...

关于Linux下面msyql安装后并未设置初始密码,但是登录报错“Access denied for user 'root'@'localhost' (using password: NO)”的解决方案

如上图:首先我安装mysql的时候并没有设置密码,但是就是登不进去,百度了一下,解决方案如下: 解决方案地址:http://zhidao.baidu.com/link?url=7QvuOKtfRdMTyFCsOf_6Bbb6pHGUxzyr5_afFGLiX_WAD6JJ4MCmepriWnzIo-kEAetXCLsRRhIidzxbL6zTnnJl...

php curl 错误 cURL error 60 unable to get local issuer certificate【转】

原因 curl 配置中开启了证书校验,默认,curl 被设为不信任任何CAs,就是说,它不信任任何服务器验证。 解决此报错有2种处理方法 1、curl 关闭证书校验   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 2、php 配置中添加证书路径 curl.cainfo = D:phpStudyphpp...