Skip to content

Commit

Permalink
docs: Add doc for ApisixConsumer (#2074)
Browse files Browse the repository at this point in the history
  • Loading branch information
Revolyssup authored Dec 4, 2023
1 parent 9b3b605 commit 8bd4cd0
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 0 deletions.
108 changes: 108 additions & 0 deletions docs/en/latest/concepts/apisix_consumer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
title: ApisixConsumer
keywords:
- APISIX ingress
- Apache APISIX
- ApisixConsumer
description: Guide to using ApisixConsumer custom Kubernetes resource.
---

<!--
#
# 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.
#
-->

`ApisixConsumer` is a Kubernetes CRD object that provides a spec to create an APISIX consumer and uniquely identify using any of the available authentication plugins.

:::note

Currently only authentication plugins are supported with `ApisixConsumer` CRD.

:::

## Usage

The example below shows how you can configure an `ApisixConsumer` resource with `keyAuth` plugin:

```yaml
apiVersion: apisix.apache.org/v2
kind: ApisixConsumer
metadata:
name: jack
spec:
authParameter:
keyAuth:
value:
key: "auth-one"
```
You can then enable `key-auth` plugin on a route and use this consumer.

```yaml
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
name: httpbin-route
spec:
http:
- name: route-1
match:
hosts:
- httpbin.org
paths:
- /*
backends:
- serviceName: httpbin
servicePort: 80
authentication:
enable: true
type: keyAuth
```

Now if you send a request without the API key, you will get a response with 401 Unauthorized.

```shell
curl http://127.0.0.1:9080/headers -H 'Host: httpbin.org'
```

It should output:

```shell
{"message":"Missing API key found in request"}
```

But if you pass the key as configured in the ApisixConsumer resource, the request passes.

```shell
curl -H "Host: httpbin.org" -H "apiKey: auth-one" http://127.0.0.1:9080/headers
```

It should output:

```json
{
"headers": {
"Accept": "*/*",
"Apikey": "auth-one",
"Host": "httpbin.org",
"User-Agent": "curl/8.1.2",
"X-Forwarded-Host": "httpbin.org"
}
}
```

Similarly you can use other authentication plugins with `ApisixConsumer`. See [reference](../references/apisix_consumer_v2.md) for the full API documentation.
46 changes: 46 additions & 0 deletions docs/en/latest/references/apisix_consumer_v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: ApisixConsumer/v2
keywords:
- APISIX ingress
- Apache APISIX
- ApisixConsumer
description: Reference for ApisixConsumer/v2 custom Kubernetes resource.
---
<!--
#
# 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.
#
-->

## Spec

See the [definition](../../../../samples/deploy/crd/v1/ApisixConsumer.yaml) on GitHub.

| Field | Type | Description |
|------------------|---------|------------------------------------------------------------------------------------------------------------------------------------------------|
| authParameter | object | Configuration of one of the available authentication plugins. |
| authParameter.basicAuth.value | object | Plugin configuration for [`basic-auth` plugin](https://apisix.apache.org/docs/apisix/plugins/basic-auth/) |
| authParameter.basicAuth.secretRef.name | string | You can store plugin configuration in Kubernetes secret and reference here with the secret name |
| authParameter.keyAuth.value | object | Plugin configuration for [`key-auth` plugin](https://apisix.apache.org/docs/apisix/plugins/key-auth/)
| authParameter.keyAuth.secretRef.name | string | You can store plugin configuration in Kubernetes secret and reference here with the secret name. |
| authParameter.jwtAuth.value | object | Plugin configuration for [`jwt-auth` plugin](https://apisix.apache.org/docs/apisix/plugins/jwt-auth/)
| authParameter.jwtAuth.secretRef.name | string | You can store plugin configuration in Kubernetes secret and reference here with the secret name. |
| authParameter.wolfRBAC.value | object | Plugin configuration for [`wolf-rbac` plugin](https://apisix.apache.org/docs/apisix/plugins/wolf-rbac/)
| authParameter.wolfRBAC.secretRef.name | string | You can store plugin configuration in Kubernetes secret and reference here with the secret name. |
| authParameter.hmacAuth.value | object | Plugin configuration for [`hmac-auth` plugin](https://apisix.apache.org/docs/apisix/plugins/hmac-auth/)
| authParameter.hmacAuth.secretRef.name | string | You can store plugin configuration in Kubernetes secret and reference here with the secret name. |
| authParameter.ldapAuth.value | object | Plugin configuration for [`ldap-auth` plugin](https://apisix.apache.org/docs/apisix/plugins/ldap-auth/)
| authParameter.ldapAuth.secretRef.name | string | You can store plugin configuration in Kubernetes secret and reference here with the secret name. |

0 comments on commit 8bd4cd0

Please sign in to comment.