You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/04/19 08:40:49 UTC

[GitHub] [apisix-ingress-controller] AlinsRan opened a new pull request, #972: add 'enable authentication and restriction' document

AlinsRan opened a new pull request, #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972

   <!-- Please answer these questions before submitting a pull request -->
   
   ### Type of change:
   
   <!-- Please delete options that are not relevant. -->
   
   - [ ] Bugfix
   - [ ] New feature provided
   - [ ] Improve performance
   - [ ] Backport patches
   
   ### What this PR does / why we need it:
   <!--- Why is this change required? What problem does it solve? -->
   <!--- If it fixes an open issue, please link to the issue here. -->
   
   ### Pre-submission checklist:
   
   <!--
   Please follow the requirements:
   1. Use Draft if the PR is not ready to be reviewed
   2. Test is required for the feat/fix PR, unless you have a good reason
   3. Doc is required for the feat PR
   4. Use a new commit to resolve review instead of `push -f`
   5. Use "request review" to notify the reviewer once you have resolved the review
   -->
   
   * [ ] Did you explain what problem does this PR solve? Or what new features have been added?
   * [ ] Have you added corresponding test cases?
   * [ ] Have you modified the corresponding document?
   * [ ] Is this PR backward compatible? **If it is not backward compatible, please discuss on the [mailing list](https://github.com/apache/apisix-ingress-controller#community) first**
   


-- 
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-ingress-controller] tao12345666333 commented on pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#issuecomment-1121988665

   The guide is correct. 
   
   I have approved it before


-- 
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-ingress-controller] navendu-pottekkat commented on a diff in pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
navendu-pottekkat commented on code in PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#discussion_r867917269


##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,404 @@
+---
+title: Enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are used for the authentication method controlled by Apache APISIX, if users want to use their own auth system or 3rd party systems, use OIDC.  
+
+## Attributes
+
+### Authentication
+
+#### `keyAuth`
+
+Consumers add their key either in a header `apikey` to authenticate their requests.
+
+```yaml
+keyAuth:
+  value:
+    key: ${key}
+```
+
+#### `basicAuth`
+
+Consumers add their key either in a header `Authentication` to authenticate their requests.
+
+```yaml
+basicAuth:
+  value:
+    username: ${username}
+    password: ${password}
+```
+
+### Restriction
+
+#### `whitelist` or `blacklist`
+
+`whitelist`: Grant full access to all users specified in the provided list, **has the priority over `allowed_by_methods`**  
+`blacklist`: Reject connection to all users specified in the provided list, **has the priority over `whitelist`**
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    blacklist:
+    - "${consumer_name}"
+    - "${consumer_name}"
+```
+
+#### `allowed_by_methods`
+
+HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    allowed_by_methods:
+    - user: "${consumer_name}"
+      methods:
+      - "POST"
+      - "GET"
+    - user: "${consumer_name}"
+      methods:
+      - "GET"
+```
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+
+```shell
+#Now, try to deploy it to your Kubernetes cluster:
+kubectl run httpbin --image kennethreitz/httpbin --port 80
+kubectl expose pod httpbin --port 80
+```
+
+### How to enable `Authentication`
+
+The following is an example. The `keyAuth` is enabled on the specified route to restrict user access.  
+
+Create ApisixConsumer foo:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: foo
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: foo-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+  name: httpserver-route
+spec:
+  http:
+  - name: rule1
+    match:
+      hosts:
+      - local.httpbin.org
+      paths:
+      - /*
+    backends:
+    - serviceName: httpbin
+      servicePort: 80
+    authentication:
+      enable: true
+      type: keyAuth
+EOF
+```
+
+Requests from foo:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:foo-key' -i
+```
+
+```shell
+HTTP/1.1 200 OK
+...
+```
+
+### How to enable `Restriction`
+
+We can also use the `consumer-restriction` Plugin to restrict our user from accessing the API.
+
+#### How to restrict `consumer_name`
+
+The following is an example. The `consumer-restriction` plugin is enabled on the specified route to restrict `consumer_name` access.
+
+* **consumer_name**: Add the `username` of `consumer` to a whitelist or blacklist (supporting single or multiple consumers) to restrict access to services or routes.
+
+Create ApisixConsumer jack1:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack1
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack1-key
+EOF
+```
+
+Create ApisixConsumer jack2:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack2
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack2-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpserver-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - local.httpbin.org
+     paths:
+       - /*
+   backends:
+   - serviceName: httpbin
+     servicePort: 80
+   authentication:
+     enable: true
+     type: keyAuth
+   plugins:
+   - name: consumer-restriction
+     enable: true
+     config:
+       whitelist:
+       - "default_jack1"
+EOF
+```
+
+How to get `default_jack1`:
+
+> view ApisixConsumer resource object from this namespace `default`
+>
+> ```shell
+> $ kubectl get apisixconsumers.apisix.apache.org -n default
+> NAME    AGE
+> foo     14h
+> jack1   14h
+> jack2   14h
+> ```
+>
+> `${consumer_name}` = `${namespace}_${ApisixConsumer_name}` --> `default_foo`  
+> `${consumer_name}` = `${namespace}_${ApisixConsumer_name}` --> `default_jack1`  

Review Comment:
   The apisix-website repo supports admonitions. It should work. In this repo, preview is not available as it cannot be built.



-- 
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-ingress-controller] AlinsRan commented on a diff in pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
AlinsRan commented on code in PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#discussion_r861490305


##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,404 @@
+---
+title: Enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are used for the authentication method controlled by Apache APISIX, if users want to use their own auth system or 3rd party systems, use OIDC.  
+
+## Attributes
+
+### Authentication
+
+#### `keyAuth`
+
+Consumers add their key either in a header `apikey` to authenticate their requests.
+
+```yaml
+keyAuth:
+  value:
+    key: ${key}
+```
+
+#### `basicAuth`
+
+Consumers add their key either in a header `Authentication` to authenticate their requests.
+
+```yaml
+basicAuth:
+  value:
+    username: ${username}
+    password: ${password}
+```
+
+### Restriction
+
+#### `whitelist` or `blacklist`
+
+`whitelist`: Grant full access to all users specified in the provided list, **has the priority over `allowed_by_methods`**  
+`blacklist`: Reject connection to all users specified in the provided list, **has the priority over `whitelist`**
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    blacklist:
+    - "${consumer_name}"
+    - "${consumer_name}"
+```
+
+#### `allowed_by_methods`
+
+HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    allowed_by_methods:
+    - user: "${consumer_name}"
+      methods:
+      - "POST"
+      - "GET"
+    - user: "${consumer_name}"
+      methods:
+      - "GET"
+```
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+
+```shell
+#Now, try to deploy it to your Kubernetes cluster:
+kubectl run httpbin --image kennethreitz/httpbin --port 80
+kubectl expose pod httpbin --port 80
+```
+
+### How to enable `Authentication`
+
+The following is an example. The `keyAuth` is enabled on the specified route to restrict user access.  
+
+Create ApisixConsumer foo:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: foo
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: foo-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f -<<EOF

Review Comment:
   > 
   
   It means that there after be anonymous files ending with EOF later.
   Here, it is mainly used to shorten the length of the article.



-- 
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-ingress-controller] AlinsRan commented on a diff in pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
AlinsRan commented on code in PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#discussion_r855780762


##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,376 @@
+---
+title: Enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are useful when you have different consumers requesting the same API and you need to execute different Plugin and Upstream configurations based on the consumer. These need to be used in conjunction with the user authentication system.  
+
+## Attributes
+
+### Authentication
+
+#### `keyAuth`
+
+Consumers add their key either in a header `apikey` to authenticate their requests.
+
+```yaml
+keyAuth:
+  value:
+    key: ${key}
+```
+
+#### `basicAuth`
+
+Consumers add their key either in a header `Authentication` to authenticate their requests.
+
+```yaml
+basicAuth:
+  value:
+    username: ${username}
+    password: ${password}
+```
+
+### Restriction
+
+#### `whitelist` or `blacklist`
+
+`whitelist`: Grant full access to all users specified in the provided list, **has the priority over `allowed_by_methods`**
+`blacklist`: Reject connection to all users specified in the provided list, **has the priority over `whitelist`**
+
+```yaml
+name: consumer-restriction
+enable: true
+config:
+  blacklist:
+  - "${consumer_name}"
+  - "${consumer_name}"
+```
+
+#### `allowed_by_methods`
+
+HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`
+
+```yaml
+name: consumer-restriction
+enable: true
+config:
+  allowed_by_methods:
+  - user: "${consumer_name}"
+    methods:
+    - "POST"
+    - "GET"
+  - user: "${consumer_name}"
+    methods:
+    - "GET"
+```
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+
+```shell
+#Now, try to deploy it to your Kubernetes cluster:
+kubectl run httpbin --image kennethreitz/httpbin --port 80
+kubectl expose pod httpbin --port 80
+```
+
+### How to enable `Authentication`
+
+The following is an example. The `keyAuth` is enabled on the specified route to restrict user access.  
+
+Create ApisixConsumer foo:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: foo
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: foo-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f -<<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+  name: httpserver-route
+spec:
+  http:
+  - name: rule1
+    match:
+      hosts:
+      - local.httpbin.org
+      paths:
+      - /*
+    backends:
+    - serviceName: httpbin
+      servicePort: 80
+    authentication:
+      enable: true
+      type: keyAuth
+EOF
+```
+
+Requests from foo:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:foo-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+### How to enable `Restriction`
+
+We can also use the `consumer-restriction` Plugin to restrict our user from accessing the API.
+
+#### How to restrict `consumer_name`
+
+The following is an example. The `consumer-restriction` plugin is enabled on the specified route to restrict `consumer_name` access.
+
+* **consumer_name**: Add the `username` of `consumer` to a whitelist or blacklist (supporting single or multiple consumers) to restrict access to services or routes.
+
+Create ApisixConsumer jack1:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack1
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack1-key
+EOF
+```
+
+Create ApisixConsumer jack2:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack2
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack2-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpserver-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - local.httpbin.org
+     paths:
+       - /*
+   backends:
+   - serviceName: httpbin
+     servicePort: 80
+   authentication:
+     enable: true
+     type: keyAuth
+   plugins:
+   - name: consumer-restriction
+     enable: true
+     config:
+       whitelist:
+       - "default_jack1"
+EOF
+```
+
+How to get `default_jack1`:
+
+> view ApisixConsumer resource object from this namespace `default`
+>
+> ```shell
+> $ kubectl get apisixconsumers.apisix.apache.org -n default
+> NAME    AGE
+> foo     14h
+> jack1   14h
+> jack2   14h
+> ```
+>
+> `${consumer_name}` = `${namespace}_${ApisixConsumer_name}` --> `default_foo`
+> `${consumer_name}` = `${namespace}_${ApisixConsumer_name}` --> `default_jack1`
+> `${consumer_name}` = `${namespace}_${ApisixConsumer_name}` --> `default_jack2`
+
+**Example usage**
+
+Requests from jack1:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack1-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+Requests from jack2:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX} -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack2-key'
+HTTP/1.1 403 Forbidden
+...
+{"message":"The consumer_name is forbidden."}
+```
+
+#### How to restrict `allowed_by_methods`
+
+This example restrict the user `jack2` to only `GET` on the resource.
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpserver-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - local.httpbin.org
+     paths:
+       - /*
+   backends:
+   - serviceName: httpbin
+     servicePort: 80
+   authentication:
+     enable: true
+     type: keyAuth
+   plugins:
+   - name: consumer-restriction
+     enable: true
+     config:
+       allowed_by_methods:
+       - user: "default_jack1"
+         methods:
+         - "POST"
+         - "GET"
+       - user: "default_jack2"
+         methods:
+         - "GET"
+EOF
+```
+
+**Example usage**
+
+Requests from jack1:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack1-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack1-key' -d '' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+Requests from jack2:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack2-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack2-key' -d '' -v
+
+HTTP/1.1 403 Forbidden
+...
+```
+
+### Disable authentication and restriction
+
+To disable the `consumer-restriction` Plugin, you can set the `enable: false` from the `plugins` configuration.  
+Also, disable the `keyAuth`, you can set the `enable: false` from the `authentication` configuration.
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpserver-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - local.httpbin.org
+     paths:
+       - /*
+   backends:
+   - serviceName: httpbin
+     servicePort: 80
+   authentication:
+     enable: false
+     type: keyAuth
+   plugins:
+   - name: consumer-restriction
+     enable: false
+     config:
+       allowed_by_methods:
+       - user: "default_jack1"
+         methods:
+         - "POST"
+         - "GET"
+       - user: "default_jack2"
+         methods:
+         - "GET"
+EOF
+```

Review Comment:
   Sure.



-- 
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-ingress-controller] tao12345666333 commented on pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#issuecomment-1120914204

   a kind reminder @navendu-pottekkat @tokers @juzhiyuan @hf400159 


-- 
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-ingress-controller] navendu-pottekkat commented on a diff in pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
navendu-pottekkat commented on code in PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#discussion_r853733195


##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,362 @@
+---
+title: enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are useful when you have different consumers requesting the same API and you need to execute different Plugin and Upstream configurations based on the consumer. These need to be used in conjunction with the user authentication system.  
+
+## Attributes
+
+### Authentication
+
+| Name      | Type   | Requirement | Value                                                   |  Description                                                                                |

Review Comment:
   Could you change the table structure similar to this?
   
   https://github.com/apache/apisix/pull/6877/files



##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,362 @@
+---
+title: enable authentication and restriction

Review Comment:
   Use sentence case.
   
   ```suggestion
   title: Enable authentication and restriction
   
   ```



##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,362 @@
+---
+title: enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are useful when you have different consumers requesting the same API and you need to execute different Plugin and Upstream configurations based on the consumer. These need to be used in conjunction with the user authentication system.  
+
+## Attributes
+
+### Authentication
+
+| Name      | Type   | Requirement | Value                                                   |  Description                                                                                |
+|-----------|--------|-------------|---------------------------------------------------------|---------------------------------------------------------------------------------------------|
+| keyAuth   | object |  required   | `value:{ key: ${key} }`                                 | Consumers add their key either in a header `apikey` to authenticate their requests.         |
+| basicAuth | object |  required   | `value:{ username: ${username}, password: ${password}}` | Consumers add their key either in a header `Authentication` to authenticate their requests. |
+
+### Restriction
+
+|Name                |   Type        | Requirement |  Value  | Description                                                                                                    |
+|--------------------|---------------|-------------|-------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
+| whitelist          | array[string] | required    | `"${namespace}_${name}"`                                    |Grant full access to all users specified in the provided list , **has the priority over `allowed_by_methods`** |
+| blacklist          | array[string] | required    | `"${namespace}_${name}"`                                    | Reject connection to all users specified in the provided list , **has the priority over `whitelist`**          |
+| allowed_by_methods | array[object] | optional    | `{user: "${namespace}_${name}", methods:["GET", "POST"...]}`| HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`              |
+
+* **consumer_name**: Add the `username` of `consumer` to a whitelist or blacklist (supporting single or multiple consumers) to restrict access to services or routes.
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+
+```shell
+#Now, try to deploy it to your Kubernetes cluster:
+kubectl run httpbin --image kennethreitz/httpbin --port 80
+kubectl expose pod httpbin --port 80
+```
+
+### How to enable `Authentication`
+
+The following is an example. The `keyAuth` is enabled on the specified route to restrict user access.  
+
+Create ApisixConsumer foo:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: foo
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: foo-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f -<<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+  name: httpserver-route
+spec:
+  http:
+  - name: rule1
+    match:
+      hosts:
+      - local.httpbin.org
+      paths:
+      - /*
+    backends:
+    - serviceName: httpbin
+      servicePort: 80
+    authentication:
+      enable: true
+      type: keyAuth
+EOF
+```
+
+Requests from foo:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:foo-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+### How to enable `Restriction`
+
+We can also use the `consumer-restriction` Plugin to restrict our user from accessing the API.
+
+The configure:
+
+> Use `whitelist` or `blacklist` restrict `consumer_name`
+>
+> ```yaml
+> config:
+>   whitelist:
+>   - "${namespace}_${name:1}"
+>     "${namespace}_${name:...}"
+> ```
+>
+> Restrict `allowed_by_methods`
+>
+> ```yaml
+>config:
+>  allowed_by_methods:
+>  - user: "${namespace}_${name:1}"
+>    methods:
+>    - "$(method)["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE"]"
+>  - user: "${namespace}_${name:...}"
+>    methods:
+>    - "$(method)["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE"]"
+> ```
+>
+
+#### How to restrict `consumer_name`
+
+The following is an example. The `consumer-restriction` plugin is enabled on the specified route to restrict consumer access.
+
+Create ApisixConsumer jack1:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack1
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack1-key
+EOF
+```
+
+Create ApisixConsumer jack2:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack2
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack2-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpserver-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - local.httpbin.org
+     paths:
+       - /*
+   backends:
+   - serviceName: httpbin
+     servicePort: 80
+   authentication:
+     enable: true
+     type: keyAuth
+   plugins:
+   - name: consumer-restriction
+     enable: true
+     config:
+       whitelist:
+       - "default_jack1"
+EOF
+```
+
+How to get `default_jack1`:
+
+> view ApisixConsumer resource object from this namespace `default`
+>
+> ```shell
+> $ kubectl get apisixconsumers.apisix.apache.org -n default
+> NAME    AGE
+> foo     14h
+> jack1   14h
+> jack2   14h
+> ```
+>
+> `${namespace}_${name}` --> `default_foo`
+> `${namespace}_${name}` --> `default_jack1`
+> `${namespace}_${name}` --> `default_jack2`
+
+**Test Plugin**
+
+Requests from jack1:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack1-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+Requests from jack2:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX} -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack2-key'
+HTTP/1.1 403 Forbidden
+...
+{"message":"The consumer_name is forbidden."}
+```
+
+#### How to restrict `allowed_by_methods`
+
+This example restrict the user `jack2` to only `GET` on the resource.
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpserver-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - local.httpbin.org
+     paths:
+       - /*
+   backends:
+   - serviceName: httpbin
+     servicePort: 80
+   authentication:
+     enable: true
+     type: keyAuth
+   plugins:
+   - name: consumer-restriction
+     enable: true
+     config:
+       allowed_by_methods:
+       - user: "default_jack1"
+         methods:
+         - "POST"
+         - "GET"
+       - user: "default_jack2"
+         methods:
+         - "GET"
+EOF
+```
+
+**Test Plugin**
+
+Requests from jack1:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack1-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack1-key' -d '' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+Requests from jack2:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack2-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack2-key' -d '' -v
+
+HTTP/1.1 403 Forbidden
+...
+```
+
+### Disable Plugin
+
+When you want to disable the `consumer-restriction` plugin, it is very simple,

Review Comment:
   Could you change this line to the disable plugin line in this PR? https://github.com/apache/apisix/pull/6877/files



-- 
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-ingress-controller] tokers commented on a diff in pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
tokers commented on code in PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#discussion_r852794028


##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,342 @@
+---
+title: enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are useful when you have different consumers requesting the same API and you need to execute different Plugin and Upstream configurations based on the consumer. These need to be used in conjunction with the user authentication system.  

Review Comment:
   Consumers are used for the authentication method controlled by Apache APISIX, if users want to use their own auth system or 3rd party systems, use OIDC.



-- 
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-ingress-controller] tao12345666333 commented on pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#issuecomment-1111651660

   ping @tokers  @navendu-pottekkat for review, thanks


-- 
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-ingress-controller] juzhiyuan commented on a diff in pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on code in PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#discussion_r861476710


##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,404 @@
+---
+title: Enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are used for the authentication method controlled by Apache APISIX, if users want to use their own auth system or 3rd party systems, use OIDC.  
+
+## Attributes
+
+### Authentication
+
+#### `keyAuth`
+
+Consumers add their key either in a header `apikey` to authenticate their requests.
+
+```yaml
+keyAuth:
+  value:
+    key: ${key}
+```
+
+#### `basicAuth`
+
+Consumers add their key either in a header `Authentication` to authenticate their requests.
+
+```yaml
+basicAuth:
+  value:
+    username: ${username}
+    password: ${password}
+```
+
+### Restriction
+
+#### `whitelist` or `blacklist`
+
+`whitelist`: Grant full access to all users specified in the provided list, **has the priority over `allowed_by_methods`**  
+`blacklist`: Reject connection to all users specified in the provided list, **has the priority over `whitelist`**
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    blacklist:
+    - "${consumer_name}"
+    - "${consumer_name}"
+```
+
+#### `allowed_by_methods`
+
+HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    allowed_by_methods:
+    - user: "${consumer_name}"
+      methods:
+      - "POST"
+      - "GET"
+    - user: "${consumer_name}"
+      methods:
+      - "GET"
+```
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+
+```shell
+#Now, try to deploy it to your Kubernetes cluster:
+kubectl run httpbin --image kennethreitz/httpbin --port 80
+kubectl expose pod httpbin --port 80
+```
+
+### How to enable `Authentication`
+
+The following is an example. The `keyAuth` is enabled on the specified route to restrict user access.  
+
+Create ApisixConsumer foo:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: foo
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: foo-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f -<<EOF

Review Comment:
   Hi, may I know why we have `EOF` here?
   
   Also, cc @navendu-pottekkat @kwanhur to help review. ๐Ÿ˜‰



-- 
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-ingress-controller] navendu-pottekkat commented on a diff in pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
navendu-pottekkat commented on code in PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#discussion_r861848460


##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,404 @@
+---
+title: Enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are used for the authentication method controlled by Apache APISIX, if users want to use their own auth system or 3rd party systems, use OIDC.  
+
+## Attributes
+
+### Authentication
+
+#### `keyAuth`
+
+Consumers add their key either in a header `apikey` to authenticate their requests.
+
+```yaml
+keyAuth:
+  value:
+    key: ${key}
+```
+
+#### `basicAuth`
+
+Consumers add their key either in a header `Authentication` to authenticate their requests.
+
+```yaml
+basicAuth:
+  value:
+    username: ${username}
+    password: ${password}
+```
+
+### Restriction
+
+#### `whitelist` or `blacklist`
+
+`whitelist`: Grant full access to all users specified in the provided list, **has the priority over `allowed_by_methods`**  
+`blacklist`: Reject connection to all users specified in the provided list, **has the priority over `whitelist`**
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    blacklist:
+    - "${consumer_name}"
+    - "${consumer_name}"
+```
+
+#### `allowed_by_methods`
+
+HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    allowed_by_methods:
+    - user: "${consumer_name}"
+      methods:
+      - "POST"
+      - "GET"
+    - user: "${consumer_name}"
+      methods:
+      - "GET"
+```
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+

Review Comment:
   Could you make this clearer that we want readers to setup APISIX ingress and install HTTPBin on their cluster?



##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,404 @@
+---
+title: Enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are used for the authentication method controlled by Apache APISIX, if users want to use their own auth system or 3rd party systems, use OIDC.  
+
+## Attributes
+
+### Authentication
+
+#### `keyAuth`
+
+Consumers add their key either in a header `apikey` to authenticate their requests.
+
+```yaml
+keyAuth:
+  value:
+    key: ${key}
+```
+
+#### `basicAuth`
+
+Consumers add their key either in a header `Authentication` to authenticate their requests.
+
+```yaml
+basicAuth:
+  value:
+    username: ${username}
+    password: ${password}
+```
+
+### Restriction
+
+#### `whitelist` or `blacklist`
+
+`whitelist`: Grant full access to all users specified in the provided list, **has the priority over `allowed_by_methods`**  
+`blacklist`: Reject connection to all users specified in the provided list, **has the priority over `whitelist`**
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    blacklist:
+    - "${consumer_name}"
+    - "${consumer_name}"
+```
+
+#### `allowed_by_methods`
+
+HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    allowed_by_methods:
+    - user: "${consumer_name}"
+      methods:
+      - "POST"
+      - "GET"
+    - user: "${consumer_name}"
+      methods:
+      - "GET"
+```
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+
+```shell
+#Now, try to deploy it to your Kubernetes cluster:
+kubectl run httpbin --image kennethreitz/httpbin --port 80
+kubectl expose pod httpbin --port 80
+```
+
+### How to enable `Authentication`
+
+The following is an example. The `keyAuth` is enabled on the specified route to restrict user access.  
+
+Create ApisixConsumer foo:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: foo
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: foo-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+  name: httpserver-route
+spec:
+  http:
+  - name: rule1
+    match:
+      hosts:
+      - local.httpbin.org
+      paths:
+      - /*
+    backends:
+    - serviceName: httpbin
+      servicePort: 80
+    authentication:
+      enable: true
+      type: keyAuth
+EOF
+```
+
+Requests from foo:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:foo-key' -i
+```
+
+```shell
+HTTP/1.1 200 OK
+...
+```
+
+### How to enable `Restriction`
+
+We can also use the `consumer-restriction` Plugin to restrict our user from accessing the API.
+
+#### How to restrict `consumer_name`
+
+The following is an example. The `consumer-restriction` plugin is enabled on the specified route to restrict `consumer_name` access.
+
+* **consumer_name**: Add the `username` of `consumer` to a whitelist or blacklist (supporting single or multiple consumers) to restrict access to services or routes.
+
+Create ApisixConsumer jack1:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack1
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack1-key
+EOF
+```
+
+Create ApisixConsumer jack2:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack2
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack2-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpserver-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - local.httpbin.org
+     paths:
+       - /*
+   backends:
+   - serviceName: httpbin
+     servicePort: 80
+   authentication:
+     enable: true
+     type: keyAuth
+   plugins:
+   - name: consumer-restriction
+     enable: true
+     config:
+       whitelist:
+       - "default_jack1"
+EOF
+```
+
+How to get `default_jack1`:
+
+> view ApisixConsumer resource object from this namespace `default`
+>
+> ```shell
+> $ kubectl get apisixconsumers.apisix.apache.org -n default
+> NAME    AGE
+> foo     14h
+> jack1   14h
+> jack2   14h
+> ```
+>
+> `${consumer_name}` = `${namespace}_${ApisixConsumer_name}` --> `default_foo`  
+> `${consumer_name}` = `${namespace}_${ApisixConsumer_name}` --> `default_jack1`  

Review Comment:
   Do we follow this style elsewhere? Would Admonitions be good here? https://docusaurus.io/docs/next/markdown-features/admonitions



-- 
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-ingress-controller] AlinsRan commented on a diff in pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
AlinsRan commented on code in PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#discussion_r866920374


##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,404 @@
+---
+title: Enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are used for the authentication method controlled by Apache APISIX, if users want to use their own auth system or 3rd party systems, use OIDC.  
+
+## Attributes
+
+### Authentication
+
+#### `keyAuth`
+
+Consumers add their key either in a header `apikey` to authenticate their requests.
+
+```yaml
+keyAuth:
+  value:
+    key: ${key}
+```
+
+#### `basicAuth`
+
+Consumers add their key either in a header `Authentication` to authenticate their requests.
+
+```yaml
+basicAuth:
+  value:
+    username: ${username}
+    password: ${password}
+```
+
+### Restriction
+
+#### `whitelist` or `blacklist`
+
+`whitelist`: Grant full access to all users specified in the provided list, **has the priority over `allowed_by_methods`**  
+`blacklist`: Reject connection to all users specified in the provided list, **has the priority over `whitelist`**
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    blacklist:
+    - "${consumer_name}"
+    - "${consumer_name}"
+```
+
+#### `allowed_by_methods`
+
+HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    allowed_by_methods:
+    - user: "${consumer_name}"
+      methods:
+      - "POST"
+      - "GET"
+    - user: "${consumer_name}"
+      methods:
+      - "GET"
+```
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+
+```shell
+#Now, try to deploy it to your Kubernetes cluster:
+kubectl run httpbin --image kennethreitz/httpbin --port 80
+kubectl expose pod httpbin --port 80
+```
+
+### How to enable `Authentication`
+
+The following is an example. The `keyAuth` is enabled on the specified route to restrict user access.  
+
+Create ApisixConsumer foo:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: foo
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: foo-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+  name: httpserver-route
+spec:
+  http:
+  - name: rule1
+    match:
+      hosts:
+      - local.httpbin.org
+      paths:
+      - /*
+    backends:
+    - serviceName: httpbin
+      servicePort: 80
+    authentication:
+      enable: true
+      type: keyAuth
+EOF
+```
+
+Requests from foo:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:foo-key' -i
+```
+
+```shell
+HTTP/1.1 200 OK
+...
+```
+
+### How to enable `Restriction`
+
+We can also use the `consumer-restriction` Plugin to restrict our user from accessing the API.
+
+#### How to restrict `consumer_name`
+
+The following is an example. The `consumer-restriction` plugin is enabled on the specified route to restrict `consumer_name` access.
+
+* **consumer_name**: Add the `username` of `consumer` to a whitelist or blacklist (supporting single or multiple consumers) to restrict access to services or routes.
+
+Create ApisixConsumer jack1:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack1
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack1-key
+EOF
+```
+
+Create ApisixConsumer jack2:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack2
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack2-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpserver-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - local.httpbin.org
+     paths:
+       - /*
+   backends:
+   - serviceName: httpbin
+     servicePort: 80
+   authentication:
+     enable: true
+     type: keyAuth
+   plugins:
+   - name: consumer-restriction
+     enable: true
+     config:
+       whitelist:
+       - "default_jack1"
+EOF
+```
+
+How to get `default_jack1`:
+
+> view ApisixConsumer resource object from this namespace `default`
+>
+> ```shell
+> $ kubectl get apisixconsumers.apisix.apache.org -n default
+> NAME    AGE
+> foo     14h
+> jack1   14h
+> jack2   14h
+> ```
+>
+> `${consumer_name}` = `${namespace}_${ApisixConsumer_name}` --> `default_foo`  
+> `${consumer_name}` = `${namespace}_${ApisixConsumer_name}` --> `default_jack1`  

Review Comment:
   I tried. Doesn't support `Admonitions`.
   How to change it?



-- 
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-ingress-controller] navendu-pottekkat commented on a diff in pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
navendu-pottekkat commented on code in PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#discussion_r867919099


##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,404 @@
+---
+title: Enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are used for the authentication method controlled by Apache APISIX, if users want to use their own auth system or 3rd party systems, use OIDC.  
+
+## Attributes
+
+### Authentication
+
+#### `keyAuth`
+
+Consumers add their key either in a header `apikey` to authenticate their requests.
+
+```yaml
+keyAuth:
+  value:
+    key: ${key}
+```
+
+#### `basicAuth`
+
+Consumers add their key either in a header `Authentication` to authenticate their requests.
+
+```yaml
+basicAuth:
+  value:
+    username: ${username}
+    password: ${password}
+```
+
+### Restriction
+
+#### `whitelist` or `blacklist`
+
+`whitelist`: Grant full access to all users specified in the provided list, **has the priority over `allowed_by_methods`**  
+`blacklist`: Reject connection to all users specified in the provided list, **has the priority over `whitelist`**
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    blacklist:
+    - "${consumer_name}"
+    - "${consumer_name}"
+```
+
+#### `allowed_by_methods`
+
+HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    allowed_by_methods:
+    - user: "${consumer_name}"
+      methods:
+      - "POST"
+      - "GET"
+    - user: "${consumer_name}"
+      methods:
+      - "GET"
+```
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+

Review Comment:
   Yes. I agree that we shouldn't talk about how to install but I think we should make it clear that the **user have to install ingress controller and HTTPbin for the rest of the tutorial to work. Point to other documents on how to do that.



-- 
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-ingress-controller] codecov-commenter commented on pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#issuecomment-1104810395

   # [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/972?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#972](https://codecov.io/gh/apache/apisix-ingress-controller/pull/972?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (51d2a7d) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/0f4391a87a38ae9a2c61a0cea717cb831fc55506?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (0f4391a) will **decrease** coverage by `0.02%`.
   > The diff coverage is `0.00%`.
   
   ```diff
   @@            Coverage Diff             @@
   ##           master     #972      +/-   ##
   ==========================================
   - Coverage   31.91%   31.89%   -0.03%     
   ==========================================
     Files          73       73              
     Lines        7953     7958       +5     
   ==========================================
     Hits         2538     2538              
   - Misses       5139     5144       +5     
     Partials      276      276              
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/972?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage ฮ” | |
   |---|---|---|
   | [pkg/kube/translation/annotations/redirect.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/972/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vYW5ub3RhdGlvbnMvcmVkaXJlY3QuZ28=) | `0.00% <0.00%> (รธ)` | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/972?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `ฮ” = absolute <relative> (impact)`, `รธ = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/972?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [0f4391a...51d2a7d](https://codecov.io/gh/apache/apisix-ingress-controller/pull/972?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
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-ingress-controller] tao12345666333 commented on a diff in pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on code in PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#discussion_r855737117


##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,376 @@
+---
+title: Enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are useful when you have different consumers requesting the same API and you need to execute different Plugin and Upstream configurations based on the consumer. These need to be used in conjunction with the user authentication system.  
+
+## Attributes
+
+### Authentication
+
+#### `keyAuth`
+
+Consumers add their key either in a header `apikey` to authenticate their requests.
+
+```yaml
+keyAuth:
+  value:
+    key: ${key}
+```
+
+#### `basicAuth`
+
+Consumers add their key either in a header `Authentication` to authenticate their requests.
+
+```yaml
+basicAuth:
+  value:
+    username: ${username}
+    password: ${password}
+```
+
+### Restriction
+
+#### `whitelist` or `blacklist`
+
+`whitelist`: Grant full access to all users specified in the provided list, **has the priority over `allowed_by_methods`**
+`blacklist`: Reject connection to all users specified in the provided list, **has the priority over `whitelist`**
+
+```yaml
+name: consumer-restriction
+enable: true
+config:
+  blacklist:
+  - "${consumer_name}"
+  - "${consumer_name}"
+```
+
+#### `allowed_by_methods`
+
+HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`
+
+```yaml
+name: consumer-restriction
+enable: true
+config:
+  allowed_by_methods:
+  - user: "${consumer_name}"
+    methods:
+    - "POST"
+    - "GET"
+  - user: "${consumer_name}"
+    methods:
+    - "GET"
+```
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+
+```shell
+#Now, try to deploy it to your Kubernetes cluster:
+kubectl run httpbin --image kennethreitz/httpbin --port 80
+kubectl expose pod httpbin --port 80
+```
+
+### How to enable `Authentication`
+
+The following is an example. The `keyAuth` is enabled on the specified route to restrict user access.  
+
+Create ApisixConsumer foo:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: foo
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: foo-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f -<<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+  name: httpserver-route
+spec:
+  http:
+  - name: rule1
+    match:
+      hosts:
+      - local.httpbin.org
+      paths:
+      - /*
+    backends:
+    - serviceName: httpbin
+      servicePort: 80
+    authentication:
+      enable: true
+      type: keyAuth
+EOF
+```
+
+Requests from foo:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:foo-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+### How to enable `Restriction`
+
+We can also use the `consumer-restriction` Plugin to restrict our user from accessing the API.
+
+#### How to restrict `consumer_name`
+
+The following is an example. The `consumer-restriction` plugin is enabled on the specified route to restrict `consumer_name` access.
+
+* **consumer_name**: Add the `username` of `consumer` to a whitelist or blacklist (supporting single or multiple consumers) to restrict access to services or routes.
+
+Create ApisixConsumer jack1:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack1
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack1-key
+EOF
+```
+
+Create ApisixConsumer jack2:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack2
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack2-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpserver-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - local.httpbin.org
+     paths:
+       - /*
+   backends:
+   - serviceName: httpbin
+     servicePort: 80
+   authentication:
+     enable: true
+     type: keyAuth
+   plugins:
+   - name: consumer-restriction
+     enable: true
+     config:
+       whitelist:
+       - "default_jack1"
+EOF
+```
+
+How to get `default_jack1`:
+
+> view ApisixConsumer resource object from this namespace `default`
+>
+> ```shell
+> $ kubectl get apisixconsumers.apisix.apache.org -n default
+> NAME    AGE
+> foo     14h
+> jack1   14h
+> jack2   14h
+> ```
+>
+> `${consumer_name}` = `${namespace}_${ApisixConsumer_name}` --> `default_foo`
+> `${consumer_name}` = `${namespace}_${ApisixConsumer_name}` --> `default_jack1`
+> `${consumer_name}` = `${namespace}_${ApisixConsumer_name}` --> `default_jack2`
+
+**Example usage**
+
+Requests from jack1:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack1-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+Requests from jack2:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX} -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack2-key'
+HTTP/1.1 403 Forbidden
+...
+{"message":"The consumer_name is forbidden."}
+```
+
+#### How to restrict `allowed_by_methods`
+
+This example restrict the user `jack2` to only `GET` on the resource.
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpserver-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - local.httpbin.org
+     paths:
+       - /*
+   backends:
+   - serviceName: httpbin
+     servicePort: 80
+   authentication:
+     enable: true
+     type: keyAuth
+   plugins:
+   - name: consumer-restriction
+     enable: true
+     config:
+       allowed_by_methods:
+       - user: "default_jack1"
+         methods:
+         - "POST"
+         - "GET"
+       - user: "default_jack2"
+         methods:
+         - "GET"
+EOF
+```
+
+**Example usage**
+
+Requests from jack1:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack1-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack1-key' -d '' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+Requests from jack2:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack2-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack2-key' -d '' -v
+
+HTTP/1.1 403 Forbidden
+...
+```
+
+### Disable authentication and restriction
+
+To disable the `consumer-restriction` Plugin, you can set the `enable: false` from the `plugins` configuration.  
+Also, disable the `keyAuth`, you can set the `enable: false` from the `authentication` configuration.
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpserver-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - local.httpbin.org
+     paths:
+       - /*
+   backends:
+   - serviceName: httpbin
+     servicePort: 80
+   authentication:
+     enable: false
+     type: keyAuth
+   plugins:
+   - name: consumer-restriction
+     enable: false
+     config:
+       allowed_by_methods:
+       - user: "default_jack1"
+         methods:
+         - "POST"
+         - "GET"
+       - user: "default_jack2"
+         methods:
+         - "GET"
+EOF
+```

Review Comment:
   Can you add an example below to verify that this plugin is indeed disabled?



-- 
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-ingress-controller] tao12345666333 merged pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
tao12345666333 merged PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972


-- 
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-ingress-controller] juzhiyuan commented on pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#issuecomment-1121986378

   > a kind reminder @navendu-pottekkat @tokers @juzhiyuan @hf400159
   
   @tao12345666333 Please help to check if the guide is correct except for Style. @navendu-pottekkat and I are discussing Doc Maintainers Program, and for this PR, if the contents are correct we could merge first.


-- 
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-ingress-controller] tao12345666333 commented on pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#issuecomment-1104966638

   @AlinsRan plz check the line error.


-- 
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-ingress-controller] AlinsRan commented on a diff in pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
AlinsRan commented on code in PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#discussion_r868152637


##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,404 @@
+---
+title: Enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are used for the authentication method controlled by Apache APISIX, if users want to use their own auth system or 3rd party systems, use OIDC.  
+
+## Attributes
+
+### Authentication
+
+#### `keyAuth`
+
+Consumers add their key either in a header `apikey` to authenticate their requests.
+
+```yaml
+keyAuth:
+  value:
+    key: ${key}
+```
+
+#### `basicAuth`
+
+Consumers add their key either in a header `Authentication` to authenticate their requests.
+
+```yaml
+basicAuth:
+  value:
+    username: ${username}
+    password: ${password}
+```
+
+### Restriction
+
+#### `whitelist` or `blacklist`
+
+`whitelist`: Grant full access to all users specified in the provided list, **has the priority over `allowed_by_methods`**  
+`blacklist`: Reject connection to all users specified in the provided list, **has the priority over `whitelist`**
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    blacklist:
+    - "${consumer_name}"
+    - "${consumer_name}"
+```
+
+#### `allowed_by_methods`
+
+HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    allowed_by_methods:
+    - user: "${consumer_name}"
+      methods:
+      - "POST"
+      - "GET"
+    - user: "${consumer_name}"
+      methods:
+      - "GET"
+```
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+
+```shell
+#Now, try to deploy it to your Kubernetes cluster:
+kubectl run httpbin --image kennethreitz/httpbin --port 80
+kubectl expose pod httpbin --port 80
+```
+
+### How to enable `Authentication`
+
+The following is an example. The `keyAuth` is enabled on the specified route to restrict user access.  
+
+Create ApisixConsumer foo:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: foo
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: foo-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+  name: httpserver-route
+spec:
+  http:
+  - name: rule1
+    match:
+      hosts:
+      - local.httpbin.org
+      paths:
+      - /*
+    backends:
+    - serviceName: httpbin
+      servicePort: 80
+    authentication:
+      enable: true
+      type: keyAuth
+EOF
+```
+
+Requests from foo:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:foo-key' -i
+```
+
+```shell
+HTTP/1.1 200 OK
+...
+```
+
+### How to enable `Restriction`
+
+We can also use the `consumer-restriction` Plugin to restrict our user from accessing the API.
+
+#### How to restrict `consumer_name`
+
+The following is an example. The `consumer-restriction` plugin is enabled on the specified route to restrict `consumer_name` access.
+
+* **consumer_name**: Add the `username` of `consumer` to a whitelist or blacklist (supporting single or multiple consumers) to restrict access to services or routes.
+
+Create ApisixConsumer jack1:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack1
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack1-key
+EOF
+```
+
+Create ApisixConsumer jack2:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack2
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack2-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpserver-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - local.httpbin.org
+     paths:
+       - /*
+   backends:
+   - serviceName: httpbin
+     servicePort: 80
+   authentication:
+     enable: true
+     type: keyAuth
+   plugins:
+   - name: consumer-restriction
+     enable: true
+     config:
+       whitelist:
+       - "default_jack1"
+EOF
+```
+
+How to get `default_jack1`:
+
+> view ApisixConsumer resource object from this namespace `default`
+>
+> ```shell
+> $ kubectl get apisixconsumers.apisix.apache.org -n default
+> NAME    AGE
+> foo     14h
+> jack1   14h
+> jack2   14h
+> ```
+>
+> `${consumer_name}` = `${namespace}_${ApisixConsumer_name}` --> `default_foo`  
+> `${consumer_name}` = `${namespace}_${ApisixConsumer_name}` --> `default_jack1`  

Review Comment:
   Solved!



##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,404 @@
+---
+title: Enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are used for the authentication method controlled by Apache APISIX, if users want to use their own auth system or 3rd party systems, use OIDC.  
+
+## Attributes
+
+### Authentication
+
+#### `keyAuth`
+
+Consumers add their key either in a header `apikey` to authenticate their requests.
+
+```yaml
+keyAuth:
+  value:
+    key: ${key}
+```
+
+#### `basicAuth`
+
+Consumers add their key either in a header `Authentication` to authenticate their requests.
+
+```yaml
+basicAuth:
+  value:
+    username: ${username}
+    password: ${password}
+```
+
+### Restriction
+
+#### `whitelist` or `blacklist`
+
+`whitelist`: Grant full access to all users specified in the provided list, **has the priority over `allowed_by_methods`**  
+`blacklist`: Reject connection to all users specified in the provided list, **has the priority over `whitelist`**
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    blacklist:
+    - "${consumer_name}"
+    - "${consumer_name}"
+```
+
+#### `allowed_by_methods`
+
+HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    allowed_by_methods:
+    - user: "${consumer_name}"
+      methods:
+      - "POST"
+      - "GET"
+    - user: "${consumer_name}"
+      methods:
+      - "GET"
+```
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+

Review Comment:
   Solved!



-- 
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-ingress-controller] juzhiyuan commented on pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#issuecomment-1122217232

   Just checked, and LGTM.


-- 
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-ingress-controller] juzhiyuan commented on pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#issuecomment-1106282580

   And @navendu-pottekkat, also this one. 


-- 
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-ingress-controller] tao12345666333 commented on a diff in pull request #972: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on code in PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#discussion_r852821602


##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,342 @@
+---
+title: enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are useful when you have different consumers requesting the same API and you need to execute different Plugin and Upstream configurations based on the consumer. These need to be used in conjunction with the user authentication system.  
+
+## Attributes
+
+### Authentication
+
+| Name      | Type   | Requirement | Value                                                   |  Description                                                                                |
+|-----------|--------|-------------|---------------------------------------------------------|---------------------------------------------------------------------------------------------|
+| keyAuth   | object |  required   | `value:{ key: ${key} }`                                 | Consumers add their key either in a header `apikey` to authenticate their requests.         |
+| basicAuth | object |  required   | `value:{ username: ${username}, password: ${password}}` | Consumers add their key either in a header `Authentication` to authenticate their requests. |
+
+### Restriction
+
+|Name                |   Type        | Requirement |  Value  | Description                                                                                                    |
+|--------------------|---------------|-------------|-------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
+| whitelist          | array[string] | required    | `"${namespace}_${name}"`                                    |Grant full access to all users specified in the provided list , **has the priority over `allowed_by_methods`** |
+| blacklist          | array[string] | required    | `"${namespace}_${name}"`                                    | Reject connection to all users specified in the provided list , **has the priority over `whitelist`**          |
+| allowed_by_methods | array[object] | optional    | `{user: "${namespace}_${name}", methods:["GET", "POST"...]}`| HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`              |
+
+For the `type` field is an enumerated type, it can be `consumer_name` or `service_id`. They stand for the following meanings:
+
+* **consumer_name**: Add the `username` of `consumer` to a whitelist or blacklist (supporting single or multiple consumers) to restrict access to services or routes.
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+
+```shell
+#Now, try to deploy it to your Kubernetes cluster:
+kubectl run httpbin --image kennethreitz/httpbin --port 80
+kubectl expose pod httpbin --port 80
+```
+
+### How to enable `Authentication`
+
+The following is an example. The `keyAuth` is enabled on the specified route to restrict user access.  
+
+Create ApisixConsumer foo:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: foo
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: foo-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f -<<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+  name: httpserver-route
+spec:
+  http:
+  - name: rule1
+    match:
+      hosts:
+      - local.httpbin.org
+      paths:
+      - /*
+    backends:
+    - serviceName: httpbin
+      servicePort: 80
+    authentication:
+      enable: true
+      type: keyAuth
+EOF
+```
+
+**Test keyAuth**

Review Comment:
   I think an example without headers can be added here.



##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,342 @@
+---
+title: enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are useful when you have different consumers requesting the same API and you need to execute different Plugin and Upstream configurations based on the consumer. These need to be used in conjunction with the user authentication system.  
+
+## Attributes
+
+### Authentication
+
+| Name      | Type   | Requirement | Value                                                   |  Description                                                                                |
+|-----------|--------|-------------|---------------------------------------------------------|---------------------------------------------------------------------------------------------|
+| keyAuth   | object |  required   | `value:{ key: ${key} }`                                 | Consumers add their key either in a header `apikey` to authenticate their requests.         |
+| basicAuth | object |  required   | `value:{ username: ${username}, password: ${password}}` | Consumers add their key either in a header `Authentication` to authenticate their requests. |
+
+### Restriction
+
+|Name                |   Type        | Requirement |  Value  | Description                                                                                                    |
+|--------------------|---------------|-------------|-------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
+| whitelist          | array[string] | required    | `"${namespace}_${name}"`                                    |Grant full access to all users specified in the provided list , **has the priority over `allowed_by_methods`** |
+| blacklist          | array[string] | required    | `"${namespace}_${name}"`                                    | Reject connection to all users specified in the provided list , **has the priority over `whitelist`**          |
+| allowed_by_methods | array[object] | optional    | `{user: "${namespace}_${name}", methods:["GET", "POST"...]}`| HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`              |
+
+For the `type` field is an enumerated type, it can be `consumer_name` or `service_id`. They stand for the following meanings:
+
+* **consumer_name**: Add the `username` of `consumer` to a whitelist or blacklist (supporting single or multiple consumers) to restrict access to services or routes.
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+
+```shell
+#Now, try to deploy it to your Kubernetes cluster:
+kubectl run httpbin --image kennethreitz/httpbin --port 80
+kubectl expose pod httpbin --port 80
+```
+
+### How to enable `Authentication`
+
+The following is an example. The `keyAuth` is enabled on the specified route to restrict user access.  
+
+Create ApisixConsumer foo:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: foo
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: foo-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f -<<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+  name: httpserver-route
+spec:
+  http:
+  - name: rule1
+    match:
+      hosts:
+      - local.httpbin.org
+      paths:
+      - /*
+    backends:
+    - serviceName: httpbin
+      servicePort: 80
+    authentication:
+      enable: true
+      type: keyAuth
+EOF
+```
+
+**Test keyAuth**
+
+Requests from foo:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:foo-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+### How to enable `Restriction`
+
+We can also use the `consumer-restriction` Plugin to restrict our user from accessing the API.
+
+The configure:
+
+> Use `whitelist` or `blacklist` restrict `consumer_name`
+>
+> ```yaml
+> config:
+>   whitelist:
+>   - "${namespace}_${name:1}"
+>     "${namespace}_${name:...}"
+> ```
+>
+> Restrict `allowed_by_methods`
+>
+> ```yaml
+>config:
+>  allowed_by_methods:
+>  - user: "${namespace}_${name:1}"
+>    methods:
+>    - "$(method)["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE"]"
+>  - user: "${namespace}_${name:...}"
+>    methods:
+>    - "$(method)["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE"]"
+> ```
+>
+
+#### How to restrict `consumer_name`
+
+The following is an example. The `consumer-restriction` plugin is enabled on the specified route to restrict consumer access.
+
+Create ApisixConsumer jack1:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack1
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack1-key
+EOF
+```
+
+Create ApisixConsumer jack2:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack2
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack2-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpserver-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - local.httpbin.org
+     paths:
+       - /*
+   backends:
+   - serviceName: httpbin
+     servicePort: 80
+   authentication:
+     enable: true
+     type: keyAuth
+   plugins:
+   - name: consumer-restriction
+     enable: true
+     config:
+       whitelist:
+       - "default_jack1"
+EOF
+```
+
+**Test Plugin**
+
+Requests from jack1:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack1-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+Requests from jack2:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX} -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack2-key'
+HTTP/1.1 403 Forbidden
+...
+{"message":"The consumer_name is forbidden."}
+```
+
+#### How to restrict `allowed_by_methods`
+
+This example restrict the user `jack2` to only `GET` on the resource.
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpserver-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - local.httpbin.org
+     paths:
+       - /*
+   backends:
+   - serviceName: httpbin
+     servicePort: 80
+   authentication:
+     enable: true
+     type: keyAuth
+   plugins:
+   - name: consumer-restriction
+     enable: true
+     config:
+       allowed_by_methods:
+       - user: "default_jack1"
+         methods:
+         - "POST"
+         - "GET"
+       - user: "default_jack2"
+         methods:
+         - "GET"
+EOF
+```
+
+**Test Plugin**
+
+Requests from jack1:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack1-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack1-key' -d '' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+Requests from jack2:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack2-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack2-key' -d '' -v
+
+HTTP/1.1 403 Forbidden
+...
+```
+
+### Disable Plugin
+
+When you want to disable the `consumer-restriction` plugin, it is very simple,
+you can delete the corresponding json configuration in the plugin configuration,
+no need to restart the service, it will take effect immediately:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpserver-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - local.httpbin.org
+     paths:
+       - /*
+   backends:
+   - serviceName: httpbin
+     servicePort: 80
+   authentication:
+     enable: true
+     type: keyAuth
+   plugins:
+   - name: consumer-restriction
+     enable: false
+     config:

Review Comment:
   The content in the original config field does not need to be deleted, just modify `enable: false`



##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,342 @@
+---
+title: enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are useful when you have different consumers requesting the same API and you need to execute different Plugin and Upstream configurations based on the consumer. These need to be used in conjunction with the user authentication system.  
+
+## Attributes
+
+### Authentication
+
+| Name      | Type   | Requirement | Value                                                   |  Description                                                                                |
+|-----------|--------|-------------|---------------------------------------------------------|---------------------------------------------------------------------------------------------|
+| keyAuth   | object |  required   | `value:{ key: ${key} }`                                 | Consumers add their key either in a header `apikey` to authenticate their requests.         |
+| basicAuth | object |  required   | `value:{ username: ${username}, password: ${password}}` | Consumers add their key either in a header `Authentication` to authenticate their requests. |
+
+### Restriction
+
+|Name                |   Type        | Requirement |  Value  | Description                                                                                                    |
+|--------------------|---------------|-------------|-------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
+| whitelist          | array[string] | required    | `"${namespace}_${name}"`                                    |Grant full access to all users specified in the provided list , **has the priority over `allowed_by_methods`** |
+| blacklist          | array[string] | required    | `"${namespace}_${name}"`                                    | Reject connection to all users specified in the provided list , **has the priority over `whitelist`**          |
+| allowed_by_methods | array[object] | optional    | `{user: "${namespace}_${name}", methods:["GET", "POST"...]}`| HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`              |
+
+For the `type` field is an enumerated type, it can be `consumer_name` or `service_id`. They stand for the following meanings:
+
+* **consumer_name**: Add the `username` of `consumer` to a whitelist or blacklist (supporting single or multiple consumers) to restrict access to services or routes.
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+
+```shell
+#Now, try to deploy it to your Kubernetes cluster:
+kubectl run httpbin --image kennethreitz/httpbin --port 80
+kubectl expose pod httpbin --port 80
+```
+
+### How to enable `Authentication`
+
+The following is an example. The `keyAuth` is enabled on the specified route to restrict user access.  
+
+Create ApisixConsumer foo:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: foo
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: foo-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f -<<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+  name: httpserver-route
+spec:
+  http:
+  - name: rule1
+    match:
+      hosts:
+      - local.httpbin.org
+      paths:
+      - /*
+    backends:
+    - serviceName: httpbin
+      servicePort: 80
+    authentication:
+      enable: true
+      type: keyAuth
+EOF
+```
+
+**Test keyAuth**
+
+Requests from foo:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:foo-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+### How to enable `Restriction`
+
+We can also use the `consumer-restriction` Plugin to restrict our user from accessing the API.
+
+The configure:
+
+> Use `whitelist` or `blacklist` restrict `consumer_name`
+>
+> ```yaml
+> config:
+>   whitelist:
+>   - "${namespace}_${name:1}"
+>     "${namespace}_${name:...}"
+> ```
+>
+> Restrict `allowed_by_methods`
+>
+> ```yaml
+>config:
+>  allowed_by_methods:
+>  - user: "${namespace}_${name:1}"
+>    methods:
+>    - "$(method)["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE"]"
+>  - user: "${namespace}_${name:...}"
+>    methods:
+>    - "$(method)["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE"]"
+> ```
+>
+
+#### How to restrict `consumer_name`
+
+The following is an example. The `consumer-restriction` plugin is enabled on the specified route to restrict consumer access.
+
+Create ApisixConsumer jack1:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack1
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack1-key
+EOF
+```
+
+Create ApisixConsumer jack2:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack2
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack2-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpserver-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - local.httpbin.org
+     paths:
+       - /*
+   backends:
+   - serviceName: httpbin
+     servicePort: 80
+   authentication:
+     enable: true
+     type: keyAuth
+   plugins:
+   - name: consumer-restriction
+     enable: true
+     config:
+       whitelist:
+       - "default_jack1"

Review Comment:
   Here you can add its generated rules



-- 
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-ingress-controller] AlinsRan commented on a diff in pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
AlinsRan commented on code in PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#discussion_r855826449


##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,385 @@
+---
+title: Enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are useful when you have different consumers requesting the same API and you need to execute different Plugin and Upstream configurations based on the consumer. These need to be used in conjunction with the user authentication system.  
+
+## Attributes
+
+### Authentication
+
+#### `keyAuth`
+
+Consumers add their key either in a header `apikey` to authenticate their requests.
+
+```yaml
+keyAuth:
+  value:
+    key: ${key}
+```
+
+#### `basicAuth`
+
+Consumers add their key either in a header `Authentication` to authenticate their requests.
+
+```yaml
+basicAuth:
+  value:
+    username: ${username}
+    password: ${password}
+```
+
+### Restriction
+
+#### `whitelist` or `blacklist`
+
+`whitelist`: Grant full access to all users specified in the provided list, **has the priority over `allowed_by_methods`**
+`blacklist`: Reject connection to all users specified in the provided list, **has the priority over `whitelist`**
+
+```yaml
+name: consumer-restriction
+enable: true
+config:
+  blacklist:
+  - "${consumer_name}"
+  - "${consumer_name}"
+```
+
+#### `allowed_by_methods`
+
+HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`
+
+```yaml
+name: consumer-restriction
+enable: true
+config:
+  allowed_by_methods:
+  - user: "${consumer_name}"
+    methods:
+    - "POST"
+    - "GET"
+  - user: "${consumer_name}"
+    methods:
+    - "GET"
+```
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+
+```shell
+#Now, try to deploy it to your Kubernetes cluster:
+kubectl run httpbin --image kennethreitz/httpbin --port 80
+kubectl expose pod httpbin --port 80
+```
+
+### How to enable `Authentication`
+
+The following is an example. The `keyAuth` is enabled on the specified route to restrict user access.  
+
+Create ApisixConsumer foo:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: foo
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: foo-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f -<<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+  name: httpserver-route
+spec:
+  http:
+  - name: rule1
+    match:
+      hosts:
+      - local.httpbin.org
+      paths:
+      - /*
+    backends:
+    - serviceName: httpbin
+      servicePort: 80
+    authentication:
+      enable: true
+      type: keyAuth
+EOF
+```
+
+Requests from foo:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:foo-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+### How to enable `Restriction`
+
+We can also use the `consumer-restriction` Plugin to restrict our user from accessing the API.
+
+#### How to restrict `consumer_name`
+
+The following is an example. The `consumer-restriction` plugin is enabled on the specified route to restrict `consumer_name` access.
+
+* **consumer_name**: Add the `username` of `consumer` to a whitelist or blacklist (supporting single or multiple consumers) to restrict access to services or routes.
+
+Create ApisixConsumer jack1:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack1
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack1-key
+EOF
+```
+
+Create ApisixConsumer jack2:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack2
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack2-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpserver-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - local.httpbin.org
+     paths:
+       - /*
+   backends:
+   - serviceName: httpbin
+     servicePort: 80
+   authentication:
+     enable: true
+     type: keyAuth
+   plugins:
+   - name: consumer-restriction
+     enable: true
+     config:
+       whitelist:
+       - "default_jack1"
+EOF
+```
+
+How to get `default_jack1`:
+
+> view ApisixConsumer resource object from this namespace `default`
+>
+> ```shell
+> $ kubectl get apisixconsumers.apisix.apache.org -n default
+> NAME    AGE
+> foo     14h
+> jack1   14h
+> jack2   14h
+> ```
+>
+> `${consumer_name}` = `${namespace}_${ApisixConsumer_name}` --> `default_foo`
+> `${consumer_name}` = `${namespace}_${ApisixConsumer_name}` --> `default_jack1`
+> `${consumer_name}` = `${namespace}_${ApisixConsumer_name}` --> `default_jack2`
+
+**Example usage**
+
+Requests from jack1:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack1-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+Requests from jack2:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX} -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack2-key'
+HTTP/1.1 403 Forbidden
+...
+{"message":"The consumer_name is forbidden."}
+```
+
+#### How to restrict `allowed_by_methods`
+
+This example restrict the user `jack2` to only `GET` on the resource.
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpserver-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - local.httpbin.org
+     paths:
+       - /*
+   backends:
+   - serviceName: httpbin
+     servicePort: 80
+   authentication:
+     enable: true
+     type: keyAuth
+   plugins:
+   - name: consumer-restriction
+     enable: true
+     config:
+       allowed_by_methods:
+       - user: "default_jack1"
+         methods:
+         - "POST"
+         - "GET"
+       - user: "default_jack2"
+         methods:
+         - "GET"
+EOF
+```
+
+**Example usage**
+
+Requests from jack1:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack1-key' -v

Review Comment:
   ok



-- 
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-ingress-controller] AlinsRan commented on pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
AlinsRan commented on PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#issuecomment-1105937778

   > @AlinsRan plz check the lint error.
   The lint of my repository is OK.
   This error is `minikube.md`. 


-- 
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-ingress-controller] AlinsRan commented on pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
AlinsRan commented on PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#issuecomment-1105938259

   > @AlinsRan plz check the lint error.
   
   The lint of my repository is OK.  
   This error is minikube.md.


-- 
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-ingress-controller] tao12345666333 commented on pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#issuecomment-1121990048

   One of our current problems is that we don't have enough approvers.
   
   So I need your help. 


-- 
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-ingress-controller] tao12345666333 commented on pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#issuecomment-1119513922

   ping @AlinsRan any update๏ผŸ


-- 
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-ingress-controller] juzhiyuan commented on pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#issuecomment-1103276962

   Hi, @AlinsRan, please help to update your PR's checklist.
   
   Also cc @navendu-pottekkat to have a review.


-- 
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-ingress-controller] AlinsRan commented on pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
AlinsRan commented on PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#issuecomment-1103372968

   Hi @navendu-pottekkat, Please help review.


-- 
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-ingress-controller] AlinsRan commented on a diff in pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
AlinsRan commented on code in PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#discussion_r861490479


##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,404 @@
+---
+title: Enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are used for the authentication method controlled by Apache APISIX, if users want to use their own auth system or 3rd party systems, use OIDC.  
+
+## Attributes
+
+### Authentication
+
+#### `keyAuth`
+
+Consumers add their key either in a header `apikey` to authenticate their requests.
+
+```yaml
+keyAuth:
+  value:
+    key: ${key}
+```
+
+#### `basicAuth`
+
+Consumers add their key either in a header `Authentication` to authenticate their requests.
+
+```yaml
+basicAuth:
+  value:
+    username: ${username}
+    password: ${password}
+```
+
+### Restriction
+
+#### `whitelist` or `blacklist`
+
+`whitelist`: Grant full access to all users specified in the provided list, **has the priority over `allowed_by_methods`**  
+`blacklist`: Reject connection to all users specified in the provided list, **has the priority over `whitelist`**
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    blacklist:
+    - "${consumer_name}"
+    - "${consumer_name}"
+```
+
+#### `allowed_by_methods`
+
+HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    allowed_by_methods:
+    - user: "${consumer_name}"
+      methods:
+      - "POST"
+      - "GET"
+    - user: "${consumer_name}"
+      methods:
+      - "GET"
+```
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+
+```shell
+#Now, try to deploy it to your Kubernetes cluster:
+kubectl run httpbin --image kennethreitz/httpbin --port 80
+kubectl expose pod httpbin --port 80
+```
+
+### How to enable `Authentication`
+
+The following is an example. The `keyAuth` is enabled on the specified route to restrict user access.  
+
+Create ApisixConsumer foo:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: foo
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: foo-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f -<<EOF

Review Comment:
   > Hi, may I know why we have `EOF` here?
   > 
   > Also, cc @navendu-pottekkat @kwanhur to help review. ๐Ÿ˜‰
   
   It means that there after be anonymous files ending with EOF later.
   Here, it is mainly used to shorten the length of the article.
   



-- 
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-ingress-controller] AlinsRan commented on a diff in pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
AlinsRan commented on code in PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#discussion_r861490479


##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,404 @@
+---
+title: Enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are used for the authentication method controlled by Apache APISIX, if users want to use their own auth system or 3rd party systems, use OIDC.  
+
+## Attributes
+
+### Authentication
+
+#### `keyAuth`
+
+Consumers add their key either in a header `apikey` to authenticate their requests.
+
+```yaml
+keyAuth:
+  value:
+    key: ${key}
+```
+
+#### `basicAuth`
+
+Consumers add their key either in a header `Authentication` to authenticate their requests.
+
+```yaml
+basicAuth:
+  value:
+    username: ${username}
+    password: ${password}
+```
+
+### Restriction
+
+#### `whitelist` or `blacklist`
+
+`whitelist`: Grant full access to all users specified in the provided list, **has the priority over `allowed_by_methods`**  
+`blacklist`: Reject connection to all users specified in the provided list, **has the priority over `whitelist`**
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    blacklist:
+    - "${consumer_name}"
+    - "${consumer_name}"
+```
+
+#### `allowed_by_methods`
+
+HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    allowed_by_methods:
+    - user: "${consumer_name}"
+      methods:
+      - "POST"
+      - "GET"
+    - user: "${consumer_name}"
+      methods:
+      - "GET"
+```
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+
+```shell
+#Now, try to deploy it to your Kubernetes cluster:
+kubectl run httpbin --image kennethreitz/httpbin --port 80
+kubectl expose pod httpbin --port 80
+```
+
+### How to enable `Authentication`
+
+The following is an example. The `keyAuth` is enabled on the specified route to restrict user access.  
+
+Create ApisixConsumer foo:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: foo
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: foo-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f -<<EOF

Review Comment:
   > Hi, may I know why we have `EOF` here?
   > 
   > Also, cc @navendu-pottekkat @kwanhur to help review. ๐Ÿ˜‰
   It means that there after be anonymous files ending with EOF later.
   Here, it is mainly used to shorten the length of the article.
   



-- 
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-ingress-controller] kwanhur commented on a diff in pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
kwanhur commented on code in PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#discussion_r861547570


##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,404 @@
+---
+title: Enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are used for the authentication method controlled by Apache APISIX, if users want to use their own auth system or 3rd party systems, use OIDC.  
+
+## Attributes
+
+### Authentication
+
+#### `keyAuth`
+
+Consumers add their key either in a header `apikey` to authenticate their requests.
+
+```yaml
+keyAuth:
+  value:
+    key: ${key}
+```
+
+#### `basicAuth`
+
+Consumers add their key either in a header `Authentication` to authenticate their requests.
+
+```yaml
+basicAuth:
+  value:
+    username: ${username}
+    password: ${password}
+```
+
+### Restriction
+
+#### `whitelist` or `blacklist`
+
+`whitelist`: Grant full access to all users specified in the provided list, **has the priority over `allowed_by_methods`**  
+`blacklist`: Reject connection to all users specified in the provided list, **has the priority over `whitelist`**
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    blacklist:
+    - "${consumer_name}"
+    - "${consumer_name}"
+```
+
+#### `allowed_by_methods`
+
+HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    allowed_by_methods:
+    - user: "${consumer_name}"
+      methods:
+      - "POST"
+      - "GET"
+    - user: "${consumer_name}"
+      methods:
+      - "GET"
+```
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+
+```shell
+#Now, try to deploy it to your Kubernetes cluster:
+kubectl run httpbin --image kennethreitz/httpbin --port 80
+kubectl expose pod httpbin --port 80
+```
+
+### How to enable `Authentication`
+
+The following is an example. The `keyAuth` is enabled on the specified route to restrict user access.  
+
+Create ApisixConsumer foo:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: foo
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: foo-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f -<<EOF

Review Comment:
   Right, please make it align with the below, like `#173` `#189`.



-- 
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-ingress-controller] AlinsRan commented on a diff in pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
AlinsRan commented on code in PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#discussion_r866949430


##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,404 @@
+---
+title: Enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are used for the authentication method controlled by Apache APISIX, if users want to use their own auth system or 3rd party systems, use OIDC.  
+
+## Attributes
+
+### Authentication
+
+#### `keyAuth`
+
+Consumers add their key either in a header `apikey` to authenticate their requests.
+
+```yaml
+keyAuth:
+  value:
+    key: ${key}
+```
+
+#### `basicAuth`
+
+Consumers add their key either in a header `Authentication` to authenticate their requests.
+
+```yaml
+basicAuth:
+  value:
+    username: ${username}
+    password: ${password}
+```
+
+### Restriction
+
+#### `whitelist` or `blacklist`
+
+`whitelist`: Grant full access to all users specified in the provided list, **has the priority over `allowed_by_methods`**  
+`blacklist`: Reject connection to all users specified in the provided list, **has the priority over `whitelist`**
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    blacklist:
+    - "${consumer_name}"
+    - "${consumer_name}"
+```
+
+#### `allowed_by_methods`
+
+HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`
+
+```yaml
+plugins:
+- name: consumer-restriction
+  enable: true
+  config:
+    allowed_by_methods:
+    - user: "${consumer_name}"
+      methods:
+      - "POST"
+      - "GET"
+    - user: "${consumer_name}"
+      methods:
+      - "GET"
+```
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+

Review Comment:
   I don't think it's necessary.
   1. This article mainly demonstrates the use of `ApisixConsumer`.
   2. The focus is not on the installation of the environment.
   3. This is based on the fact that the user can already use `APISIX Ingress` and `Kubernetes`.



-- 
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-ingress-controller] hf400159 commented on a diff in pull request #972: Doc: add 'enable authentication and restriction' document

Posted by GitBox <gi...@apache.org>.
hf400159 commented on code in PR #972:
URL: https://github.com/apache/apisix-ingress-controller/pull/972#discussion_r855817078


##########
docs/en/latest/practices/enable-authentication-and-restriction.md:
##########
@@ -0,0 +1,385 @@
+---
+title: Enable authentication and restriction
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+Consumers are useful when you have different consumers requesting the same API and you need to execute different Plugin and Upstream configurations based on the consumer. These need to be used in conjunction with the user authentication system.  
+
+## Attributes
+
+### Authentication
+
+#### `keyAuth`
+
+Consumers add their key either in a header `apikey` to authenticate their requests.
+
+```yaml
+keyAuth:
+  value:
+    key: ${key}
+```
+
+#### `basicAuth`
+
+Consumers add their key either in a header `Authentication` to authenticate their requests.
+
+```yaml
+basicAuth:
+  value:
+    username: ${username}
+    password: ${password}
+```
+
+### Restriction
+
+#### `whitelist` or `blacklist`
+
+`whitelist`: Grant full access to all users specified in the provided list, **has the priority over `allowed_by_methods`**
+`blacklist`: Reject connection to all users specified in the provided list, **has the priority over `whitelist`**
+
+```yaml
+name: consumer-restriction
+enable: true
+config:
+  blacklist:
+  - "${consumer_name}"
+  - "${consumer_name}"
+```
+
+#### `allowed_by_methods`
+
+HTTP methods can be `methods:["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]`
+
+```yaml
+name: consumer-restriction
+enable: true
+config:
+  allowed_by_methods:
+  - user: "${consumer_name}"
+    methods:
+    - "POST"
+    - "GET"
+  - user: "${consumer_name}"
+    methods:
+    - "GET"
+```
+
+## Example
+
+### Prepare env
+
+Kubernetes cluster:
+
+1. [apisix-ingress-controller](../deployments/minikube.md).
+2. httpbin.
+
+```shell
+#Now, try to deploy it to your Kubernetes cluster:
+kubectl run httpbin --image kennethreitz/httpbin --port 80
+kubectl expose pod httpbin --port 80
+```
+
+### How to enable `Authentication`
+
+The following is an example. The `keyAuth` is enabled on the specified route to restrict user access.  
+
+Create ApisixConsumer foo:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: foo
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: foo-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f -<<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+  name: httpserver-route
+spec:
+  http:
+  - name: rule1
+    match:
+      hosts:
+      - local.httpbin.org
+      paths:
+      - /*
+    backends:
+    - serviceName: httpbin
+      servicePort: 80
+    authentication:
+      enable: true
+      type: keyAuth
+EOF
+```
+
+Requests from foo:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:foo-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+### How to enable `Restriction`
+
+We can also use the `consumer-restriction` Plugin to restrict our user from accessing the API.
+
+#### How to restrict `consumer_name`
+
+The following is an example. The `consumer-restriction` plugin is enabled on the specified route to restrict `consumer_name` access.
+
+* **consumer_name**: Add the `username` of `consumer` to a whitelist or blacklist (supporting single or multiple consumers) to restrict access to services or routes.
+
+Create ApisixConsumer jack1:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack1
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack1-key
+EOF
+```
+
+Create ApisixConsumer jack2:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixConsumer
+metadata:
+  name: jack2
+spec:
+  authParameter:
+    keyAuth:
+      value:
+        key: jack2-key
+EOF
+```
+
+ApisixRoute:
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpserver-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - local.httpbin.org
+     paths:
+       - /*
+   backends:
+   - serviceName: httpbin
+     servicePort: 80
+   authentication:
+     enable: true
+     type: keyAuth
+   plugins:
+   - name: consumer-restriction
+     enable: true
+     config:
+       whitelist:
+       - "default_jack1"
+EOF
+```
+
+How to get `default_jack1`:
+
+> view ApisixConsumer resource object from this namespace `default`
+>
+> ```shell
+> $ kubectl get apisixconsumers.apisix.apache.org -n default
+> NAME    AGE
+> foo     14h
+> jack1   14h
+> jack2   14h
+> ```
+>
+> `${consumer_name}` = `${namespace}_${ApisixConsumer_name}` --> `default_foo`
+> `${consumer_name}` = `${namespace}_${ApisixConsumer_name}` --> `default_jack1`
+> `${consumer_name}` = `${namespace}_${ApisixConsumer_name}` --> `default_jack2`
+
+**Example usage**
+
+Requests from jack1:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack1-key' -v
+
+HTTP/1.1 200 OK
+...
+```
+
+Requests from jack2:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX} -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack2-key'
+HTTP/1.1 403 Forbidden
+...
+{"message":"The consumer_name is forbidden."}
+```
+
+#### How to restrict `allowed_by_methods`
+
+This example restrict the user `jack2` to only `GET` on the resource.
+
+```shell
+kubectl apply -f - <<EOF
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpserver-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - local.httpbin.org
+     paths:
+       - /*
+   backends:
+   - serviceName: httpbin
+     servicePort: 80
+   authentication:
+     enable: true
+     type: keyAuth
+   plugins:
+   - name: consumer-restriction
+     enable: true
+     config:
+       allowed_by_methods:
+       - user: "default_jack1"
+         methods:
+         - "POST"
+         - "GET"
+       - user: "default_jack2"
+         methods:
+         - "GET"
+EOF
+```
+
+**Example usage**
+
+Requests from jack1:
+
+```shell
+kubectl  exec -it -n ${namespace of Apache APISIX} ${pod of Apache APISIX}  -- curl http://127.0.0.1:9080/anything -H 'Host: local.httpbin.org' -H 'apikey:jack1-key' -v

Review Comment:
   Usually, the command and return result need to be separated. And for long commands, we need to format them. Please check the full text. 



-- 
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