skills/a6-plugin-key-auth/SKILL.md
Skill for configuring the Apache APISIX key-auth plugin via the a6 CLI. Covers API key authentication setup on routes, consumer credential binding, key lookup from header/query/cookie, hide_credentials, anonymous consumer fallback, and common operational patterns.
npx skillsauth add moonming/a6 a6-plugin-key-authInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
The key-auth plugin authenticates requests using API keys. Clients include a
key in a header, query parameter, or cookie. APISIX looks up the key against
consumer credentials and, on match, forwards the request with consumer identity
headers. On failure it returns 401 Unauthorized.
| Field | Type | Required | Default | Description |
|-------|------|----------|---------|-------------|
| header | string | No | "apikey" | Header name to extract API key from |
| query | string | No | "apikey" | Query parameter name (lower priority than header) |
| hide_credentials | boolean | No | false | Remove key from request before forwarding upstream |
| anonymous_consumer | string | No | — | Consumer username for unauthenticated requests |
| realm | string | No | "key" | Realm in WWW-Authenticate response header on 401 |
| Field | Type | Required | Description |
|-------|------|----------|-------------|
| key | string | Yes | Unique API key for the consumer. Auto-encrypted in etcd. |
apikey) — checked firstapikey) — checked if header absent401 Unauthorized with "Missing API key in request"a6 consumer create -f - <<'EOF'
{
"username": "alice"
}
EOF
Use the Admin API (credentials are sub-resources of consumers):
curl "$(a6 context current -o json | jq -r .server)/apisix/admin/consumers/alice/credentials" \
-X PUT \
-H "X-API-KEY: $(a6 context current -o json | jq -r .api_key)" \
-d '{
"id": "cred-alice-key-auth",
"plugins": {
"key-auth": {
"key": "alice-secret-key-001"
}
}
}'
a6 route create -f - <<'EOF'
{
"id": "protected-api",
"uri": "/api/*",
"plugins": {
"key-auth": {}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"backend:8080": 1
}
}
}
EOF
# Should succeed (200)
curl -i http://127.0.0.1:9080/api/users -H "apikey: alice-secret-key-001"
# Should fail (401)
curl -i http://127.0.0.1:9080/api/users
{
"plugins": {
"key-auth": {
"header": "X-API-Token"
}
}
}
Client sends: curl -H "X-API-Token: alice-secret-key-001" ...
{
"plugins": {
"key-auth": {
"query": "token"
}
}
}
Client sends: curl "http://127.0.0.1:9080/api/users?token=alice-secret-key-001"
{
"plugins": {
"key-auth": {
"hide_credentials": true
}
}
}
The apikey header or query param is stripped before reaching the backend.
Always enable this in production.
# Create anonymous consumer with strict limits
a6 consumer create -f - <<'EOF'
{
"username": "anonymous",
"plugins": {
"limit-count": {
"count": 10,
"time_window": 60,
"rejected_code": 429
}
}
}
EOF
{
"plugins": {
"key-auth": {
"anonymous_consumer": "anonymous"
}
}
}
Requests with valid keys → authenticated consumer. Requests without keys → anonymous consumer with rate limits.
On successful authentication, APISIX adds:
| Header | Value |
|--------|-------|
| X-Consumer-Username | Consumer's username |
| X-Credential-Identifier | Credential ID |
| X-Consumer-Custom-Id | Consumer's labels.custom_id (if set) |
| Symptom | Cause | Fix |
|---------|-------|-----|
| 401 "Missing API key in request" | No key in header or query | Add apikey header or query param |
| 401 "Invalid API key in request" | Key does not match any consumer | Verify the key value in consumer credentials |
| Key visible in upstream logs | hide_credentials is false | Set hide_credentials: true |
| Anonymous users not working | anonymous_consumer not set or consumer missing | Create the consumer and set the field |
version: "1"
consumers:
- username: alice
routes:
- id: protected-api
uri: /api/*
plugins:
key-auth: {}
upstream_id: my-upstream
upstreams:
- id: my-upstream
type: roundrobin
nodes:
"backend:8080": 1
Note: Consumer credentials must be created separately via the Admin API;
a6 config syncmanages the consumer resource but credentials are sub-resources.
tools
Core skill for working with the a6 CLI — the Apache APISIX command-line tool. Provides project conventions, command patterns, architecture overview, and development workflow. Load this skill when working on a6 source code, adding new commands, writing tests, or modifying any a6 component.
tools
Recipe skill for implementing multi-tenant API gateway patterns using the a6 CLI. Covers tenant isolation via Consumer Groups, host/path/header-based routing, per-tenant rate limiting, context forwarding with proxy-rewrite, and declarative config sync workflows for multi-tenant management.
tools
Recipe skill for configuring mutual TLS (mTLS) using the a6 CLI. Covers SSL certificate management, upstream mTLS to backend services, client certificate verification, and end-to-end mTLS setup from client through APISIX to upstream.
tools
Recipe skill for configuring upstream health checks using the a6 CLI. Covers active health checks (HTTP probing), passive health checks (response analysis), combining both, configuring healthy/unhealthy thresholds, and monitoring upstream node status.