如何通过ACLcache manager指令控制客户端对Squid Web管理接口的访问?

一)在/usr/local/squid/etc/squid.conf(具体位置要看编译时的prefix参数),注意和cache manager相关的行:

 

 
  
  1. #Recommended minimum configuration: 
  2. acl all src 0.0.0.0/0.0.0.0 
  3. acl manager proto cache_object 
  4. acl localhost src 127.0.0.1/255.255.255.255 
  5. acl to_localhost dst 127.0.0.0/8 
  6. acl SSL_ports port 443 
  7. acl Safe_ports port 80 # http 
  8. acl Safe_ports port 21 # ftp 
  9. acl Safe_ports port 443 # https 
  10. acl Safe_ports port 70 # gopher 
  11. acl Safe_ports port 210 # wais 
  12. acl Safe_ports port 1025-65535 # unregistered ports 
  13. acl Safe_ports port 280 # http-mgmt 
  14. acl Safe_ports port 488 # gss-http 
  15. acl Safe_ports port 591 # filemaker 
  16. acl Safe_ports port 777 # multiling http 
  17. acl CONNECT method CONNECT 
  18.  
  19. # 
  20. # Only allow cachemgr access from localhost 
  21. http_access allow manager localhost 
  22. http_access deny manager 
  23. # Deny requests to unknown ports 
  24. http_access deny !Safe_ports 
  25. # Deny CONNECT to other than SSL ports 
  26. http_access deny CONNECT !SSL_ports 
  27.  
  28. # And finally deny all other access to this proxy 
  29. http_access deny all 
  30.  
  31.  
  32. # TAG: cachemgr_passwd 
  33. # Specify passwords for cachemgr operations. 
  34. # 
  35. # Usage: cachemgr_passwd password action action ... 
  36. # 
  37. # Some valid actions are (see cache manager menu for a full list): 
  38. # 5min 
  39. # 60min 
  40. # asndb 
  41. # authenticator 
  42. # cbdata 
  43. # client_list 
  44. # comm_incoming 
  45. # config * 
  46. # counters 
  47. # delay 
  48. # digest_stats 
  49. # dns 
  50. # events 
  51. # filedescriptors 
  52. # fqdncache 
  53. # histograms 
  54. # http_headers 
  55. # info 
  56. # io 
  57. # ipcache 
  58. # mem 
  59. # menu 
  60. # netdb 
  61. # non_peers 
  62. # objects 
  63. # offline_toggle * 
  64. # pconn 
  65. # peer_select 
  66. # redirector 
  67. # refresh 
  68. # server_list 
  69. # shutdown * 
  70. # store_digest 
  71. # storedir 
  72. # utilization 
  73. # via_headers 
  74. # vm_objects 
  75. # 
  76. # * Indicates actions which will not be performed without a 
  77. # valid password, others can be performed if not listed here. 
  78. # 
  79. # To disable an action, set the password to "disable". 
  80. # To allow performing an action without a password, set the 
  81. # password to "none". 
  82. # 
  83. # Use the keyword "all" to set the same password for all actions. 
  84. # 
  85. #Example: 
  86. # cachemgr_passwd secret shutdown 
  87. # cachemgr_passwd lesssssssecret info stats/objects 
  88. # cachemgr_passwd disable all 
  89. # 
  90. #Default: 
  91. # none 

我们需要在acl指令、http_access指令和cachemgr_passwd指令都添加相关的参数。

起作用的是以下的指令:

 

 
  
  1. acl localhost src 127.0.0.1/255.255.255.255 
  2. acl manager proto cache_object 
  3. # 允许本地用户清除缓存 
  4. acl Purge method PURGE 
  5. http_access allow Purge localhost 
  6. http_access deny Purge 
  7. # Only allow cachemgr access from localhost 
  8. http_access allow manager localhost 
  9. http_access deny manager 
  10. # 对于查看配置,关闭Squid等这类重要操作禁用掉 
  11. cachemgr_passwd disable config shutdown authenticator offline_toggle 
  12. # 对于不大查询的操作使用不使用密码 
  13. cachemgr_passwd none info stats/objects 
  14. # 对于其它操作密码保护 
  15. # cachemgr_passwd secretP all 

二)检验我们的配置

访问不需要密码的项:


 
  
  1. squidclient -p80 cache_object://localhost/info 

或者


 
  
  1. squidclient -p80 -h localhost mgr:info 

访问需要密码的项:

 
  
  1. squidclient -p80 cache_object://localhost/menu@secretP 

注:该命令常用来有权限访问的项

或者


 
  
  1. squidclient -p80 -h localhost mgr:menu@secretP 

删除缓存:


 
  
  1. squidclient -m PURGE http://url 

 

下面是默认的权限(未做配置):


 
  
  1. # squidclient -p80 -h localhost mgr:menu@secretP 
  2. HTTP/1.0 200 OK 
  3. ... 此处省略部分内容 
  4. mem Memory Utilization protected 
  5. cbdata Callback Data Registry Contents protected 
  6. events Event Queue protected 
  7. squidaio_counts Async IO Function Counters protected 
  8. config Current Squid Configuration disabled 
  9. ipcache IP Cache Stats and Contents protected 
  10. fqdncache FQDN Cache Stats and Contents protected 
  11. idns Internal DNS Statistics protected 
  12. external_acl External ACL stats protected 
  13. http_headers HTTP Header Statistics protected 
  14. menu This Cachemanager Menu protected 
  15. shutdown Shut Down the Squid Process disabled 
  16. offline_toggle Toggle offline_mode setting disabled 
  17. info General Runtime Information public 
  18. filedescriptors Process Filedescriptor Allocation protected 
  19. objects All Cache Objects protected 
  20. vm_objects In-Memory and In-Transit Objects protected 
  21. openfd_objects Objects with Swapout files open protected 
  22. pending_objects Objects being retreived from the network protected 
  23. client_objects Objects being sent to clients protected 
  24. io Server-side network read() size histograms protected 
  25. counters Traffic and Resource Counters public 
  26. peer_select Peer Selection Algorithms protected 
  27. digest_stats Cache Digest and ICP blob protected 
  28. 5min 5 Minute Average of Counters protected 
  29. 60min 60 Minute Average of Counters protected 
  30. utilization Cache Utilization protected 
  31. histograms Full Histogram Counts protected 
  32. active_requests Client-side Active Requests protected 
  33. store_digest Store Digest protected 
  34. storedir Store Directory Stats protected 
  35. store_check_cachable_stats storeCheckCachable() Stats protected 
  36. store_io Store IO Interface Stats protected 
  37. pconn Persistent Connection Utilization Histograms protected 
  38. refresh Refresh Algorithm Statistics protected 
  39. delay Delay Pool Levels protected 
  40. forward Request Forwarding Statistics protected 
  41. client_list Cache Client List protected 
  42. netdb Network Measurement Database protected 
  43. asndb AS Number Database protected 
  44. server_list Peer Cache Statistics protected 
  45. non_peers List of Unknown sites sending ICP messages protected 

即:

默认设置hidden的项为:

 
  
  1. config shutdown offline_toggle 

它的含意是,如果服务端不配置密码,将不能被访问,默认是隐藏的。

这不同于配置为,这样不允许客户端访问这几个项,访问时状态为disable

 
  
  1. http_access disable config shutdown offline_toggle 

这也不同于被配置为hidden,这样也不允许客户端访问这几个项,不过访问时状态为protected

 
  
  1. http_access protected config shutdown offline_toggle 

三)配置允许以哪些域名和端口访问cache manager

修改/usr/local/squid/etc/squid/etc/cachemgr.conf(文件位置依赖于我们的编译选项)文件

,增加Host:Port的行。

例如我的配置:

# grep ^[^#] /etc/squid/etc/cachemgr.conf

 
  
  1. localhost:80 
  2. 192.168.88.51:80 
  3. squid01.wangxiaoyu.org:80