Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: APISIX did not check whether it was referenced when deleting PluginConfig #5917

Closed
tao12345666333 opened this issue Dec 24, 2021 · 3 comments · Fixed by #6092
Closed
Assignees
Labels
enhancement New feature or request

Comments

@tao12345666333
Copy link
Member

Issue description

When a PluginConfig is referenced by multiple Routes, it can still be deleted.

I expect APISIX can handle it the same as Upstream.
If an Upstream is referenced by multiple Routes, an error will be reported when deleting.

Environment

  • apisix version (cmd: apisix version): 2.10.2
  • OS (cmd: uname -a):
  • OpenResty / Nginx version (cmd: nginx -V or openresty -V):
  • etcd version, if have (cmd: run curl http://127.0.0.1:9090/v1/server_info to get the info from server-info API):
  • apisix-dashboard version, if have:
  • the plugin runner version, if the issue is about a plugin runner (cmd: depended on the kind of runner):
  • luarocks version, if the issue is about installation (cmd: luarocks --version):

Steps to reproduce

  • create PluginConfig
bash-5.1# curl http://127.0.0.1:9180/apisix/admin/plugin_configs/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{                                                                                                                                                                                                         
    "desc": "吾乃插件配置1",                                                                                                                                                                              
    "plugins": {                                                                                                                                                                                          
        "limit-count": {                                                                                                                                                                                  
            "count": 2,                                                                                                                                                                                   
            "time_window": 60,                                                                                                                                                                            
            "rejected_code": 503                                                                                                                                                                          
        }                                                                                            
    }                                                                                                                                                                                                     
}'                                                                                                                                                                                                        
HTTP/1.1 201 Created                                                                                                                                                                                      
Date: Fri, 24 Dec 2021 08:16:42 GMT                                                                                                                                                                       
Content-Type: application/json                                                                       
Transfer-Encoding: chunked                                                                                                                                                                                
Connection: keep-alive                                                                                                                                                                                    
Server: APISIX/2.10.2                                                                                                                                                                                     
Access-Control-Allow-Origin: *                                                                                                                                                                            
Access-Control-Allow-Credentials: true                                                               
Access-Control-Expose-Headers: *
Access-Control-Max-Age: 3600                                                                                                                                                                              
                                                  
{"node":{"value":{"desc":"吾乃插件配置1","create_time":1640333802,"id":"1","update_time":1640333802,"plugins":{"limit-count":{"time_window":60,"key_type":"var","rejected_code":503,"policy":"local","allo
w_degradation":false,"show_limit_quota_header":true,"key":"remote_addr","count":2}}},"key":"\/apisix\/plugin_configs\/1"},"action":"set"}

* create Route 1

```bash
bash-5.1# curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{                                            
    "uris": ["/index.html"],
    "plugin_config_id": 1,                                                                           
    "upstream": {                                                                                                                                                                                         
        "type": "roundrobin",                                                                                                                                                                             
        "nodes": {
            "39.97.63.215:80": 1
        }
    }
}'
HTTP/1.1 201 Created
Date: Fri, 24 Dec 2021 08:17:22 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX/2.10.2
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: *
Access-Control-Max-Age: 3600

{"node":{"value":{"plugin_config_id":1,"priority":0,"uris":["\/index.html"],"update_time":1640333842,"create_time":1640333842,"id":"1","status":1,"upstream":{"nodes":{"39.97.63.215:80":1},"scheme":"http
","type":"roundrobin","pass_host":"pass","hash_on":"vars"}},"key":"\/apisix\/routes\/1"},"action":"set"}
  • create Route 2
bash-5.1# curl http://127.0.0.1:9180/apisix/admin/routes/2 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
    "uris": ["/index.html"],
    "plugin_config_id": 1,
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "39.97.63.215:80": 1
        }
    }
}'
HTTP/1.1 201 Created
Date: Fri, 24 Dec 2021 08:17:40 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX/2.10.2
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: *
Access-Control-Max-Age: 3600

{"node":{"value":{"plugin_config_id":1,"priority":0,"uris":["\/index.html"],"update_time":1640333860,"create_time":1640333860,"id":"2","status":1,"upstream":{"nodes":{"39.97.63.215:80":1},"scheme":"http
","type":"roundrobin","pass_host":"pass","hash_on":"vars"}},"key":"\/apisix\/routes\/2"},"action":"set"}
  • delete one route, then delete PluginConfig
bash-5.1# curl -X DELETE http://127.0.0.1:9180/apisix/admin/routes/1  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1'
{"node":{},"key":"\/apisix\/routes\/1","action":"delete","deleted":"1"}
bash-5.1# curl http://127.0.0.1:9180/apisix/admin/routes  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1'
{"action":"get","count":1,"node":{"nodes":[{"value":{"plugin_config_id":1,"priority":0,"uris":["\/index.html"],"upstream":{"nodes":{"39.97.63.215:80":1},"scheme":"http","type":"roundrobin","pass_host":"
pass","hash_on":"vars"},"status":1,"id":"2","create_time":1640333860,"update_time":1640333860},"createdIndex":15,"modifiedIndex":15,"key":"\/apisix\/routes\/2"}],"dir":true,"key":"\/apisix\/routes"}}


bash-5.1# curl -X DELETE http://127.0.0.1:9180/apisix/admin/plugin_configs/1  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1'
{"node":{},"key":"\/apisix\/plugin_configs\/1","action":"delete","deleted":"1"}



bash-5.1# curl http://127.0.0.1:9180/apisix/admin/routes  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1'
{"action":"get","count":1,"node":{"nodes":[{"value":{"plugin_config_id":1,"priority":0,"uris":["\/index.html"],"upstream":{"nodes":{"39.97.63.215:80":1},"scheme":"http","type":"roundrobin","pass_host":"
pass","hash_on":"vars"},"status":1,"id":"2","create_time":1640333860,"update_time":1640333860},"createdIndex":15,"modifiedIndex":15,"key":"\/apisix\/routes\/2"}],"dir":true,"key":"\/apisix\/routes"}}


bash-5.1# curl http://127.0.0.1:9180/apisix/admin/plugin_configs  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1'
{"action":"get","count":0,"node":{"nodes":{},"dir":true,"key":"\/apisix\/plugin_configs"}}

Actual result

Successfully deleted PluginConfig.

Error log

.

Expected result

I hope APISIX can check that it is being referenced and prevent the delete operation. like Upstream.

bash-5.1# curl -X DELETE http://127.0.0.1:9180/apisix/admin/upstreams/1  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1'
{"error_msg":"can not delete this upstream, route [5] is still using it now"} 
@tao12345666333 tao12345666333 changed the title bug: bug: APISIX did not check whether it was referenced when deleting PluginConfig Dec 24, 2021
@tokers tokers added bug Something isn't working and removed bug Something isn't working labels Dec 24, 2021
@tokers
Copy link
Contributor

tokers commented Dec 24, 2021

I don't know whether there are some other objects which also are not checked when the Admin API deletes them, if so, we can list them and decide whether to check the reference before deletion.

@juzhiyuan juzhiyuan added the enhancement New feature or request label Dec 29, 2021
@zaunist
Copy link
Contributor

zaunist commented Jan 12, 2022

I would like to complete this feature, please assign to me. @juzhiyuan

@juzhiyuan
Copy link
Member

Assigned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants