lxz999 commented on issue #12279:
URL: https://github.com/apache/apisix/issues/12279#issuecomment-2934472868

   <!-- Failed to upload "image.png" -->
   
   > [@moonming](https://github.com/moonming) 
[@lxz999](https://github.com/lxz999)
   > 
   > Not sure if that's related, but I've noticed something curious: when 
setting the API key explicitly as a **string**, it works fine. But if the 
API-key is a **number**, setting it without quoting, makes calls to Admin API 
return 401.
   > 
   > Appearently not the same issue, since it's 401, not 403, but maybe gives 
an insight.
   > 
   > Maybe this can be tracked in a different issue, if that's unexpected 
behaviour 🙂
   > 
   > ## Minimal Reproducible Example
   > File `compose.yaml`:
   > 
   > services:
   >   etcd:
   >     image: bitnami/etcd:latest
   >     environment:
   >       ALLOW_NONE_AUTHENTICATION: yes
   >       ETCD_ADVERTISE_CLIENT_URLS: http://etcd:2379
   >       ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379
   >     ports:
   >       - "2379:2379"
   >     healthcheck:
   >       test: "etcdctl endpoint health"
   >       interval: 5s
   >       timeout: 30s
   >       retries: 5
   >     networks:
   >       apisix:
   > 
   >   apisix:
   >     image: apache/apisix:latest
   >     depends_on:
   >       etcd:
   >         condition: service_healthy
   >     volumes:
   >       - ./conf/config.yaml:/usr/local/apisix/conf/config.yaml:ro
   >     ports:
   >       - "9080:9080/tcp"
   >       - "9443:9443/tcp"
   >       - "9180:9180/tcp"
   >     networks:
   >       apisix:
   > 
   > networks:
   >   apisix:
   >     driver: bridge
   > File `conf/config.yaml`:
   > 
   >  
   > deployment:
   >   admin:
   >     admin_key_required: true
   >     admin_key:
   >       - name: admin
   >         key: 123455678
   >         role: admin
   > 
   >     allow_admin:
   >       - 127.0.0.0/24
   >       - 0.0.0.0/0
   > 
   >     admin_listen:
   >       ip: 0.0.0.0
   >       port: 9180
   > 
   >   etcd:
   >     host:
   >       - http://etcd:2379
   >     prefix: "/apisix"
   >     timeout: 30
   > 
   > #END
   > Run with:
   > 
   > docker compose up
   > ### API Key Number
   > Using the following API key:
   > 
   > deployment:
   >   admin:
   >     admin_key_required: true
   >     admin_key:
   >       - name: admin
   >         key: 123455678
   >         role: admin
   > Test the request:
   > 
   > curl -i -H "x-api-key: 123455678" "localhost:9180/apisix/admin/upstreams"
   > Result:
   > 
   > ```
   > HTTP/1.1 401 Unauthorized
   > ...
   > Server: APISIX/3.12.0
   > 
   > {"error_msg":"failed to check token","description":"wrong apikey"}
   > ```
   > 
   > Warning
   > 
   > Is this expected?
   > 
   > Logs:
   > 
   > ```
   > [warn] 224#224: *24432 [lua] init.lua:120: set_ctx_and_check_token(): 
failed to check token: wrong apikey, client: 10.89.1.3, server: , request: "GET 
/apisix/admin/upstreams HTTP/1.1", host: "localhost:9180"
   > ```
   > 
   > ### API Key String
   > Using the following API key:
   > 
   > deployment:
   >   admin:
   >     admin_key_required: true
   >     admin_key:
   >       - name: admin
   >         key: "123455678"
   >         role: admin
   > Test the request:
   > 
   > curl -i -H "x-api-key: 123455678" "localhost:9180/apisix/admin/upstreams"
   > Result:
   > 
   > ```
   > HTTP/1.1 200 OK
   > ...
   > Server: APISIX/3.12.0
   > 
   > {"total":0,"list":[]}
   > ```
   
   I set it as a string, but it still returns 403. 
   
   <!-- Failed to upload "image.png" -->


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

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

Reply via email to