Squid als Caching-Proxy

CoMo

Commander
Registriert
Dez. 2015
Beiträge
2.132
Hallo,

ich spiele gerade etwas mit Squid rum. Ich habe den bei mir lokal auf dem Proxmox-Server installiert. In einem Alpine LXC-Container.

Vorerst soll der gar nichts filtern o.ä., sondern einfach nur cachen. Und zwar komplett im RAM.

Ich habe den in Windows als System-Proxy sowie in Firefox konfiguriert. Das funktioniert auch. Aber ich habe das Gefühl, dass da nix wirklich aus dem Cache beantwortet wird.

Meine Config sieht aktuell so aus:

Code:
cat /etc/squid/squid.conf
#
# Recommended minimum configuration:
#

# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl localnet src 0.0.0.1-0.255.255.255  # RFC 1122 "this" network (LAN)
acl localnet src 10.0.0.0/8             # RFC 1918 local private network (LAN)
acl localnet src 100.64.0.0/10          # RFC 6598 shared address space (CGN)
acl localnet src 169.254.0.0/16         # RFC 3927 link-local (directly plugged) machines
acl localnet src 172.16.0.0/12          # RFC 1918 local private network (LAN)
acl localnet src 192.168.0.0/16         # RFC 1918 local private network (LAN)
acl localnet src fc00::/7               # RFC 4193 local private network range
acl localnet src fe80::/10              # RFC 4291 link-local (directly plugged) machines

#acl SSL_ports port 443
acl SSL_ports port 1-65535
acl Safe_ports port 1-65535
#acl Safe_ports port 80         # http
#acl Safe_ports port 21         # ftp
#acl Safe_ports port 443                # https
#acl Safe_ports port 70         # gopher
#acl Safe_ports port 210                # wais
#acl Safe_ports port 1025-65535 # unregistered ports
#acl Safe_ports port 280                # http-mgmt
#acl Safe_ports port 488                # gss-http
#acl Safe_ports port 591                # filemaker
#acl Safe_ports port 777                # multiling http

#
# Recommended minimum Access Permission configuration:
#
# Deny requests to certain unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

# Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager

# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost

#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#

# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet
http_access allow localhost

# And finally deny all other access to this proxy
http_access deny all

# Squid normally listens to port 3128
http_port 3128

# Uncomment and adjust the following to add a disk cache directory.
#cache_dir aufs /dev/shm/squid 10000000 max-size=1000000000
#cache_dir aufs /dev/shm/squid 10000 MB
#cache_dir aufs /dev/shm/squid 10000000 16 256 max-size=15000000
cache_dir ufs /dev/shm/squid 15000 16 256
#cache_mem 15000 MB
cache allow all
maximum_object_size 16 MB

# Leave coredumps in the first cache dir
coredump_dir /var/cache/squid

#
# Add any of your own refresh_pattern entries above these.
#
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern .               0       20%     4320

Ich sehe aber kaum HIT Messages im LOG.

squidclient mgr:info gibt mir folgendes aus:

Code:
HTTP/1.1 200 OK
Server: squid/5.7
Mime-Version: 1.0
Date: Mon, 08 May 2023 14:08:30 GMT
Content-Type: text/plain;charset=utf-8
Expires: Mon, 08 May 2023 14:08:30 GMT
Last-Modified: Mon, 08 May 2023 14:08:30 GMT
X-Cache: MISS from squid
X-Cache-Lookup: MISS from squid:3128
Via: 1.1 squid (squid/5.7)
Connection: close

Squid Object Cache: Version 5.7
Build Info:
Service Name: squid
Start Time:     Mon, 08 May 2023 13:34:13 GMT
Current Time:   Mon, 08 May 2023 14:08:30 GMT
Connection information for squid:
        Number of clients accessing cache:      2
        Number of HTTP requests received:       593
        Number of ICP messages received:        0
        Number of ICP messages sent:    0
        Number of queued ICP replies:   0
        Number of HTCP messages received:       0
        Number of HTCP messages sent:   0
        Request failure ratio:   0.00
        Average HTTP requests per minute since start:   17.3
        Average ICP messages per minute since start:    0.0
        Select loop called: 183275 times, 11.227 ms avg
Cache information for squid:
        Hits as % of all requests:      5min: 0.0%, 60min: 0.0%
        Hits as % of bytes sent:        5min: -0.0%, 60min: 0.0%
        Memory hits as % of hit requests:       5min: 0.0%, 60min: 0.0%
        Disk hits as % of hit requests: 5min: 0.0%, 60min: 0.0%
        Storage Swap size:      22752 KB
        Storage Swap capacity:   0.1% used, 99.9% free
        Storage Mem size:       228 KB
        Storage Mem capacity:    0.1% used, 99.9% free
        Mean Object Size:       361.14 KB
        Requests given to unlinkd:      0
Median Service Times (seconds)  5 min    60 min:
        HTTP Requests (All):  12.00465  5.63745
        Cache Misses:          0.00000  0.00000
        Cache Hits:            0.00000  0.00000
        Near Hits:             0.00000  0.00000
        Not-Modified Replies:  0.00000  0.00000
        DNS Lookups:           0.01609  0.02033
        ICP Queries:           0.00000  0.00000
Resource usage for squid:
        UP Time:        2057.710 seconds
        CPU Time:       2.125 seconds
        CPU Usage:      0.10%
        CPU Usage, 5 minute avg:        0.09%
        CPU Usage, 60 minute avg:       0.10%
        Maximum Resident Size: 83744 KB
        Page faults with physical i/o: 0
Memory accounted for:
        Total accounted:         1855 KB
        memPoolAlloc calls:     56744
        memPoolFree calls:      58941
File descriptor usage for squid:
        Maximum number of file descriptors:   1024
        Largest file desc currently in use:     88
        Number of file desc currently in use:   63
        Files queued for open:                   0
        Available number of file descriptors:  961
        Reserved number of file descriptors:   100
        Store Disk files open:                   0
Internal Data Structures:
           116 StoreEntries
            55 StoreEntries with MemObjects
             2 Hot Object Cache Items
            63 on-disk objects

Ich hab zum Test mehrfach den Edge gestartet. Das äußert sich so:

Code:
tail -f /var/log/squid/access.log
1683554993.509      0 192.168.100.65 NONE_NONE/500 0 CONNECT api.edgeoffer.microsoft.com:443 - HIER_NONE/- -
1683554993.781      0 192.168.100.65 NONE_NONE/500 0 CONNECT sb.scorecardresearch.com:443 - HIER_NONE/- -
1683554993.784      0 192.168.100.65 NONE_NONE/500 0 CONNECT c.msn.com:443 - HIER_NONE/- -
1683554993.784      0 192.168.100.65 NONE_NONE/500 0 CONNECT c.bing.com:443 - HIER_NONE/- -
1683554993.939      0 192.168.100.65 NONE_NONE/500 0 CONNECT c.msn.com:443 - HIER_NONE/- -
1683554993.951      0 192.168.100.65 NONE_NONE/500 0 CONNECT sb.scorecardresearch.com:443 - HIER_NONE/- -
1683554994.017      0 192.168.100.65 NONE_NONE/500 0 CONNECT arc.msn.com:443 - HIER_NONE/- -
1683554994.109      0 192.168.100.65 NONE_NONE/500 0 CONNECT browser.events.data.msn.com:443 - HIER_NONE/- -
1683554994.112      0 192.168.100.65 NONE_NONE/500 0 CONNECT browser.events.data.msn.com:443 - HIER_NONE/- -
1683554994.115      0 192.168.100.65 NONE_NONE/500 0 CONNECT browser.events.data.msn.com:443 - HIER_NONE/- -
1683554994.155      0 192.168.100.65 NONE_NONE/500 0 CONNECT browser.events.data.msn.com:443 - HIER_NONE/- -
1683554994.211      0 192.168.100.65 NONE_NONE/500 0 CONNECT srtb.msn.com:443 - HIER_NONE/- -
1683554994.216      0 192.168.100.65 NONE_NONE/500 0 CONNECT srtb.msn.com:443 - HIER_NONE/- -
1683554994.230      0 192.168.100.65 NONE_NONE/500 0 CONNECT browser.events.data.msn.com:443 - HIER_NONE/- -
1683554994.425      0 192.168.100.65 NONE_NONE/500 0 CONNECT srtb.msn.com:443 - HIER_NONE/- -
1683554994.492      0 192.168.100.65 NONE_NONE/500 0 CONNECT browser.events.data.msn.com:443 - HIER_NONE/- -
1683554994.910      0 192.168.100.65 NONE_NONE/500 0 CONNECT browser.events.data.msn.com:443 - HIER_NONE/- -
1683554995.021      0 192.168.100.65 NONE_NONE/500 0 CONNECT browser.events.data.msn.com:443 - HIER_NONE/- -
1683554995.921      0 192.168.100.65 NONE_NONE/500 0 CONNECT browser.events.data.msn.com:443 - HIER_NONE/- -
1683554996.431      0 192.168.100.65 NONE_NONE/500 0 CONNECT browser.events.data.msn.com:443 - HIER_NONE/- -
1683554997.996      0 192.168.100.65 NONE_NONE/500 0 CONNECT browser.events.data.msn.com:443 - HIER_NONE/- -
1683555000.408      0 192.168.100.65 NONE_NONE/500 0 CONNECT c.msn.com:443 - HIER_NONE/- -
1683555000.409      0 192.168.100.65 NONE_NONE/500 0 CONNECT sb.scorecardresearch.com:443 - HIER_NONE/- -
1683555000.409      0 192.168.100.65 NONE_NONE/500 0 CONNECT c.bing.com:443 - HIER_NONE/- -
1683555000.517      0 192.168.100.65 NONE_NONE/500 0 CONNECT arc.msn.com:443 - HIER_NONE/- -
1683555001.026      0 192.168.100.65 NONE_NONE/500 0 CONNECT browser.events.data.msn.com:443 - HIER_NONE/- -
1683555001.472      0 192.168.100.65 NONE_NONE/500 0 CONNECT srtb.msn.com:443 - HIER_NONE/- -
1683555003.856  10072 192.168.100.65 TCP_TUNNEL/200 3970 CONNECT img-s-msn-com.akamaized.net:443 - HIER_DIRECT/23.53.40.209 -
1683555004.096      0 192.168.100.65 NONE_NONE/500 0 CONNECT browser.events.data.msn.com:443 - HIER_NONE/- -
1683555004.781  10111 192.168.100.65 TCP_TUNNEL/200 6685 CONNECT r.bing.com:443 - HIER_DIRECT/23.53.43.147 -
1683555004.782  10111 192.168.100.65 TCP_TUNNEL/200 6685 CONNECT r.bing.com:443 - HIER_DIRECT/23.53.43.147 -
1683555007.004      0 192.168.100.65 NONE_NONE/500 0 CONNECT browser.events.data.msn.com:443 - HIER_NONE/- -
1683555009.998      0 192.168.100.65 NONE_NONE/500 0 CONNECT browser.events.data.msn.com:443 - HIER_NONE/- -
1683555013.007      0 192.168.100.65 NONE_NONE/500 0 CONNECT browser.events.data.msn.com:443 - HIER_NONE/- -

Das sollte doch längst alles aus dem Cache beantwortet werden?

Warum dann aber immer noch


Code:
Cache information for squid:
        Hits as % of all requests:      5min: 0.0%, 60min: 0.0%
        Hits as % of bytes sent:        5min: -0.0%, 60min: 0.0%
        Memory hits as % of hit requests:       5min: 0.0%, 60min: 0.0%

Was habe ich übersehen oder was stimmt mit meiner Config noch nicht?
 
dank Letsencrypt, ist inzwischen sehr viel Traffic transportverschlüsselt. Wenn du willst, dass dieser aus deine lokalen cache und nicht ueber das Internet kommt: Ja
Ich finde es ist ein relativ hässlicher hack, der dir aus Cert sicht auch recht viel arbeit machen kann.
Antiviren machen das ja auch ganz gerne
 
  • Gefällt mir
Reaktionen: andy_m4, GTrash81 und CoMo
Ach der Squid muss das SSL terminieren und mir dann quasi neu verpackt weiterreichen? Dafür muss ich dann auf dem Squid eine CA bauen und dieser vertrauen, damit HTTPS weiterhin funktioniert?

Also die Technik, mit denen dubiose Schlangenöl-Software PC's unsicher macht.

Ja jetzt wo du das sagst, leuchtet es mir ein. Hab ich gar nicht dran gedacht. Muss ich mir heute Abend mal genauer anschauen.
 
  • Gefällt mir
Reaktionen: GTrash81 und madmax2010
Jo genau, dafür ist ssl-bumping bzw. peek-slice gedacht, es erzeugt dir dynamisch "passende" Zertifikate.
 
  • Gefällt mir
Reaktionen: GTrash81, madmax2010 und CoMo
Ich habe Squid jetzt mal mit den entsprechenden Flags kompiliert. Ich bekomme aber trotzdem noch einen Fehler, mit dem ich nichts anfangen kann:

Code:
2023/05/10 15:28:29 kid1| Set Current Directory to /var/cache/squid
2023/05/10 15:28:29 kid1| Starting Squid Cache version 5.7 for x86_64-pc-linux-gnu...
2023/05/10 15:28:29 kid1| Service Name: squid
2023/05/10 15:28:29 kid1| Process ID 52140
2023/05/10 15:28:29 kid1| Process Roles: worker
2023/05/10 15:28:29 kid1| With 1024 file descriptors available
2023/05/10 15:28:29 kid1| Initializing IP Cache...
2023/05/10 15:28:29 kid1| DNS Socket created at [::], FD 8
2023/05/10 15:28:29 kid1| DNS Socket created at 0.0.0.0, FD 9
2023/05/10 15:28:29 kid1| Adding domain home.arpa from /etc/resolv.conf
2023/05/10 15:28:29 kid1| Adding nameserver 192.168.100.53 from /etc/resolv.conf
2023/05/10 15:28:29 kid1| Adding nameserver fda6:7d51:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX from /etc/resolv.conf
2023/05/10 15:28:29 kid1| helperOpenServers: Starting 5/32 'security_file_certgen' processes
2023/05/10 15:28:29 kid1| Logfile: opening log daemon:/var/log/squid/access.log
2023/05/10 15:28:29 kid1| Logfile Daemon: opening log /var/log/squid/access.log
2023/05/10 15:28:30 kid1| Unlinkd pipe opened on FD 25
2023/05/10 15:28:30 kid1| Local cache digest enabled; rebuild/rewrite every 3600/3600 sec
2023/05/10 15:28:30 kid1| Store logging disabled
2023/05/10 15:28:30 kid1| Swap maxSize 15360000 + 262144 KB, estimated 1201703 objects
2023/05/10 15:28:30 kid1| Target number of buckets: 60085
2023/05/10 15:28:30 kid1| Using 65536 Store buckets
2023/05/10 15:28:30 kid1| Max Mem  size: 262144 KB
2023/05/10 15:28:30 kid1| Max Swap size: 15360000 KB
2023/05/10 15:28:30 kid1| Rebuilding storage in /dev/shm/squid (clean log)
2023/05/10 15:28:30 kid1| Using Least Load store dir selection
2023/05/10 15:28:30 kid1| Set Current Directory to /var/cache/squid
2023/05/10 15:28:30 kid1| Finished loading MIME types and icons.
2023/05/10 15:28:30 kid1| HTCP Disabled.
2023/05/10 15:28:30 kid1| Pinger socket opened on FD 32
2023/05/10 15:28:30 kid1| Squid plugin modules loaded: 0
2023/05/10 15:28:30 kid1| Adaptation support is off.
2023/05/10 15:28:30 kid1| Accepting HTTP Socket connections at conn13 local=[::]:3128 remote=[::] FD 28 flags=9
2023/05/10 15:28:30 kid1| Accepting SSL bumped HTTP Socket connections at conn15 local=[::]:3129 remote=[::] FD 29 flags=9
2023/05/10 15:28:30 kid1| Accepting NAT intercepted SSL bumped HTTP Socket connections at conn17 local=[::]:3130 remote=[::] FD 30 flags=41
2023/05/10 15:28:30 kid1| Done reading /dev/shm/squid swaplog (0 entries)
2023/05/10 15:28:30 kid1| Store rebuilding is 0.00% complete
2023/05/10 15:28:30 kid1| Finished rebuilding storage from disk.
2023/05/10 15:28:30 kid1|         0 Entries scanned
2023/05/10 15:28:30 kid1|         0 Invalid entries.
2023/05/10 15:28:30 kid1|         0 With invalid flags.
2023/05/10 15:28:30 kid1|         0 Objects loaded.
2023/05/10 15:28:30 kid1|         0 Objects expired.
2023/05/10 15:28:30 kid1|         0 Objects cancelled.
2023/05/10 15:28:30 kid1|         0 Duplicate URLs purged.
2023/05/10 15:28:30 kid1|         0 Swapfile clashes avoided.
2023/05/10 15:28:30 kid1|   Took 0.01 seconds (  0.00 objects/sec).
2023/05/10 15:28:30 kid1| Beginning Validation Procedure
2023/05/10 15:28:30 kid1|   Completed Validation Procedure
2023/05/10 15:28:30 kid1|   Validated 0 Entries
2023/05/10 15:28:30 kid1|   store_swap_size = 0.00 KB
2023/05/10 15:28:30| pinger: Initialising ICMP pinger ...
2023/05/10 15:28:30| pinger: ICMP socket opened.
2023/05/10 15:28:30| pinger: ICMPv6 socket opened
2023/05/10 15:28:31 kid1| storeLateRelease: released 0 objects
2023/05/10 15:29:00 kid1| ERROR: NF getsockopt(ORIGINAL_DST) failed on conn30 local=192.168.100.41:3130 remote=192.168.100.65:61891 FD 13 flags=33: (2) No such file or directory
    listening port: 3130
2023/05/10 15:29:00 kid1| ERROR: NAT/TPROXY lookup failed to locate original IPs on conn30 local=192.168.100.41:3130 remote=192.168.100.65:61891 FD 13 flags=33
    listening port: 3130

Ich versteh nicht, warum Squid da irgendwas mit NAT / TPROXY machen will.
Ergänzung ()

Ach, ich glaube ich habs. Das "intercept" in meiner Config hat einen transparenten Proxy-Modus aktiviert:

Code:
http_port 3128
http_port 3129 ssl-bump cert=/etc/squid/ssl_cert.pem key=/etc/squid/squid.pem generate-host-certificates=on dynamic_cert_mem_cache_size=16MB
http_port 3130 intercept ssl-bump cert=/etc/squid/ssl_cert.pem key=/etc/squid/squid.pem generate-host-certificates=on dynamic_cert_mem_cache_size=16MB

Nun geändert auf:

Code:
http_port 3128
http_port 3129 ssl-bump cert=/etc/squid/ssl_cert.pem key=/etc/squid/squid.pem generate-host-certificates=on dynamic_cert_mem_cache_size=16MB

Und jetzt ist die Verbindung zu Computerbase mit meinem selbsterstellten Squid-Zertifikat signiert 🙂
 
Zuletzt bearbeitet:
  • Gefällt mir
Reaktionen: madmax2010
Jo, stimmt 😄
Ergänzung ()

Also grundsätzlich scheint das zu funktionieren. Die RAMDisk füllt sich langsam mit Daten und einige Cache-HITs sind auch schon zu sehen:
Code:
squid /dev/shm # squidclient -h 127.0.0.1 -p 3129 mgr:info
HTTP/1.1 200 OK
Server: squid/5.7
Mime-Version: 1.0
Date: Wed, 10 May 2023 16:20:43 GMT
Content-Type: text/plain;charset=utf-8
Expires: Wed, 10 May 2023 16:20:43 GMT
Last-Modified: Wed, 10 May 2023 16:20:43 GMT
X-Cache: MISS from squid
X-Cache-Lookup: MISS from squid:3128
Via: 1.1 squid (squid/5.7)
Connection: close

Squid Object Cache: Version 5.7
Build Info: Gentoo squid-5.7-r1 (r: NONE)
Service Name: squid
Start Time:     Wed, 10 May 2023 15:38:10 GMT
Current Time:   Wed, 10 May 2023 16:20:43 GMT
Connection information for squid:
        Number of clients accessing cache:      2
        Number of HTTP requests received:       8362
        Number of ICP messages received:        0
        Number of ICP messages sent:    0
        Number of queued ICP replies:   0
        Number of HTCP messages received:       0
        Number of HTCP messages sent:   0
        Request failure ratio:   0.00
        Average HTTP requests per minute since start:   196.5
        Average ICP messages per minute since start:    0.0
        Select loop called: 141675 times, 18.023 ms avg
Cache information for squid:
        Hits as % of all requests:      5min: 16.2%, 60min: 2.0%
        Hits as % of bytes sent:        5min: 12.8%, 60min: 4.5%
        Memory hits as % of hit requests:       5min: 6.2%, 60min: 18.8%
        Disk hits as % of hit requests: 5min: 0.0%, 60min: 0.0%
        Storage Swap size:      38724 KB
        Storage Swap capacity:   0.3% used, 99.7% free
        Storage Mem size:       37192 KB
        Storage Mem capacity:   14.2% used, 85.8% free
        Mean Object Size:       17.99 KB
        Requests given to unlinkd:      132
Median Service Times (seconds)  5 min    60 min:
        HTTP Requests (All):   0.04047  0.02899
        Cache Misses:          0.03829  0.02899
        Cache Hits:            0.00000  0.00000
        Near Hits:             0.24524  0.23230
        Not-Modified Replies:  0.00000  0.00000
        DNS Lookups:           0.00000  0.00094
        ICP Queries:           0.00000  0.00000
Resource usage for squid:
        UP Time:        2553.418 seconds
        CPU Time:       6.250 seconds
        CPU Usage:      0.24%
        CPU Usage, 5 minute avg:        0.19%
        CPU Usage, 60 minute avg:       0.25%
        Maximum Resident Size: 324608 KB
        Page faults with physical i/o: 255
Memory accounted for:
        Total accounted:        52169 KB
        memPoolAlloc calls:   2902662
        memPoolFree calls:    2954395
File descriptor usage for squid:
        Maximum number of file descriptors:   1024
        Largest file desc currently in use:    107
        Number of file desc currently in use:   44
        Files queued for open:                   0
        Available number of file descriptors:  980
        Reserved number of file descriptors:   100
        Store Disk files open:                   0
Internal Data Structures:
          2218 StoreEntries
          2214 StoreEntries with MemObjects
          2149 Hot Object Cache Items
          2153 on-disk objects

Was ich aber nicht ganz verstehe: Squid macht ja jetzt SSL Man-In-The-Middle. Ich habe das selbsterstellte Zertifikat zur Liste der vertrauenswürdigen CA's hinzugefügt. So weit, so gut. Aber. In meiner Config ist folgendes konfiguriert:

Code:
sslproxy_cert_error allow all

Ich hätte erwartet, dass Squid jetzt stumpf alle Zertifikate akzeptiert. Das ist aber nicht der Fall. Wenn ich auf https://badssl.com/ z.B. eine Seite mit abgelaufenem Zertifikat öffne, bekomme ich ganz normal eine Warnung im Browser.

Das ist ja eigentlich super, dürfte aber doch nicht sein? Ist da noch irgendwas falsch konfiguriert?
 
Zuletzt bearbeitet:
Zurück
Oben