kayx23 opened a new issue, #12431:
URL: https://github.com/apache/apisix/issues/12431

   ### Description
   
   From this test case, it looks like the use of env var in `key` is supported 
in the `key-auth` plugin: 
https://github.com/apache/apisix/blob/master/t/plugin/key-auth.t#L558-L594
   
   However during testing, the behaviour was unexpected.
   
   ## Reproduction
   
   Start the latest APISIX in Docker (3.13.0).
   
   Save the value of the key to an environment variable:
   
   ```shell
   export JACK_AUTH_KEY=jack-key
   ```
   
   Create a consumer jack:
   
   ```shell
   curl "http://127.0.0.1:9180/apisix/admin/consumers"; -X PUT \
     -H "X-API-KEY: ${ADMIN_API_KEY}" \
     -d '{
       "username": "jack"
     }'
   ```
   
   Configure the `key-auth` credential for jack:
   
   ```shell
   curl "http://127.0.0.1:9180/apisix/admin/consumers/jack/credentials"; -X PUT \
     -H "X-API-KEY: ${ADMIN_API_KEY}" \
     -d '{
       "id": "cred-jack-key-auth",
       "plugins": {
         "key-auth": {
           "key": "$env://JACK_AUTH_KEY"
         }
       }
     }'
   ```
   
   Create a route and enable `key-auth`:
   
   ```shell
   curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
     -H "X-API-KEY: ${ADMIN_API_KEY}" \
     -d '{
       "id": "key-auth-route",
       "uri": "/anything",
       "plugins": {
         "key-auth": {}
       },
       "upstream" : {
         "nodes": {
           "httpbin.org": 1
         }
       }
     }'
   ```
   
   Send a request to the route with jack's key:
   
   ```shell
   curl "http://127.0.0.1:9080/anything"; -H 'apikey: jack-key'
   ```
   
   Here the expectation is to receive an `HTTP/1.1 200 OK` response, but I 
received an `HTTP/1.1 401 Unauthorized` response:
   
   ```
   {"message":"Invalid API key in request"}
   ```
   
   ### Environment
   
   - APISIX version (run `apisix version`): 3.13.0 (in Docker)
   


-- 
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-unsubscr...@apisix.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to