Squid SslBump配置导致HTTPS连接SSL_ERROR_SYSCALL问题排查
AWS EC2上Squid v3.5透明代理HTTPS流量异常问题
问题描述
HTTP流量正常,但HTTPS流量存在以下异常:
- 访问不在允许列表的网站时,立即报错:
curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to google.com:443 - 访问在允许列表的网站时,连接会在
TLSv1.2 (OUT), TLS handshake, Client hello (1):状态长时间挂起,最终抛出相同错误。
Squid配置信息
Squid版本为3.5.20,通过yum安装,编译时包含--with-openssl,squid -v输出如下:
Squid Cache: Version 3.5.20 Service Name: squid configure options: '--build=x86_64-koji-linux-gnu' '--host=x86_64-koji-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--disable-strict-error-checking' '--exec_prefix=/usr' '--libexecdir=/usr/lib64/squid' '--localstatedir=/var' '--datadir=/usr/share/squid' '--sysconfdir=/etc/squid' '--with-logdir=$(localstatedir)/log/squid' '--with-pidfile=$(localstatedir)/run/squid.pid' '--disable-dependency-tracking' '--enable-eui' '--enable-follow-x-forwarded-for' '--enable-auth' '--enable-auth-basic=DB,LDAP,MSNT-multi-domain,NCSA,NIS,PAM,POP3,RADIUS,SASL,SMB,SMB_LM,getpwnam' '--enable-auth-ntlm=smb_lm,fake' '--enable-auth-digest=file,LDAP,eDirectory' '--enable-auth-negotiate=kerberos' '--enable-external-acl-helpers=file_userip,LDAP_group,time_quota,session,unix_group,wbinfo_group,kerberos_ldap_group' '--enable-cache-digests' '--enable-cachemgr-hostname=localhost' '--enable-delay-pools' '--enable-epoll' '--enable-ident-lookups' '--enable-linux-netfilter' '--enable-removal-policies=heap,lru' '--enable-snmp' '--enable-ssl-crtd' '--enable-storeio=aufs,diskd,rock,ufs' '--enable-wccpv2' '--enable-esi' '--enable-ecap' '--with-aio' '--with-default-user=squid' '--with-dl' '--with-openssl' '--with-pthreads' '--disable-arch-native' 'build_alias=x86_64-koji-linux-gnu' 'host_alias=x86_64-koji-linux-gnu' 'CFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fpie' 'LDFLAGS=-Wl,-z,relro -pie -Wl,-z,relro -Wl,-z,now' 'CXXFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fpie' 'PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig'
squid.conf配置如下:
visible_hostname squid cache deny all # Log format and rotation logformat squid %ts.%03tu %6tr %>a %Ss/%03>Hs %<st %rm %ru %ssl::>sni %Sh/%<a %mt logfile_rotate 10 debug_options rotate=10 # Handle HTTP requests http_port 3128 http_port 3129 intercept # Handle HTTPS requests https_port 3130 cert=/etc/squid/ssl/squid.pem ssl-bump intercept acl SSL_port port 443 http_access allow SSL_port acl step1 at_step SslBump1 acl step2 at_step SslBump2 acl step3 at_step SslBump3 ssl_bump peek step1 all # Deny requests to proxy instance metadata acl instance_metadata dst 169.254.169.254 http_access deny instance_metadata # Filter HTTP requests based on the allowlist acl allowed_http_sites dstdomain "/etc/squid/allowlist.txt" http_access allow allowed_http_sites # Filter HTTPS requests based on the allowlist acl allowed_https_sites ssl::server_name "/etc/squid/allowlist.txt" ssl_bump peek step2 allowed_https_sites ssl_bump splice step3 allowed_https_sites ssl_bump terminate step2 all http_access deny all
iptables配置
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3129 iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 3130
AWS EC2/VPC配置
- Squid代理EC2实例位于公有子网
- Squid代理EC2实例已禁用源/目标检查
- 客户端EC2实例位于另一个公有子网
- 这些EC2实例的安全组允许内部(基于私有IP)所有入站流量,以及所有出站流量。
路由表
- Squid子网路由:默认路由指向Internet网关,无特殊自定义路由
- 客户端子网路由:所有流量(0.0.0.0/0)指向Squid代理EC2实例的弹性网络接口
问题排查与解决方案
1. 验证SSL证书有效性
确保/etc/squid/ssl/squid.pem是包含私钥的完整有效证书,执行以下命令验证:
openssl x509 -in /etc/squid/ssl/squid.pem -text -noout
若证书无效,重新生成自签名证书:
mkdir -p /etc/squid/ssl openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 -keyout /etc/squid/ssl/squid.pem -out /etc/squid/ssl/squid.pem chown squid:squid /etc/squid/ssl/squid.pem
2. 修正SSL Bump配置逻辑
原配置中ssl_bump规则顺序存在逻辑冲突,调整为以下顺序:
# HTTPS处理规则修正 acl step1 at_step SslBump1 acl step2 at_step SslBump2 acl allowed_https_sites ssl::server_name "/etc/squid/allowlist.txt" ssl_bump peek step1 all ssl_bump splice step2 allowed_https_sites ssl_bump terminate step2 all
调整后确保Squid先识别SNI信息,再对允许站点执行连接拼接,终止非允许站点的连接。
3. 开启IP转发
透明代理需要开启系统IP转发功能,检查当前状态:
sysctl net.ipv4.ip_forward
若输出为0,执行以下命令开启并永久生效:
sysctl -w net.ipv4.ip_forward=1 echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
4. 检查网络ACL与安全组
确认Squid实例的安全组允许出站443端口访问Internet;同时VPC网络ACL需要允许双向的443流量(入站和出站)。
5. 启用详细调试日志
修改debug_options开启SSL调试日志:
debug_options ALL,1 33,2 28,9
重启Squid后查看/var/log/squid/cache.log,根据日志中的SSL握手细节定位具体错误点。
内容的提问来源于stack exchange,提问作者Chaos
相关产品推荐
相关产品推荐

