Skip to content

Commit c526c6e

Browse files
Mossakaclaude
andcommitted
fix: resolve SSL Bump initialization and config ordering issues
- Fix SSL database initialization: security_file_certgen requires the directory to NOT exist, but Docker volume mounts create it. Now initSslDb() creates the complete DB structure (certs/, index.txt, size) directly on the host. - Simplify entrypoint.sh: Since DB is pre-initialized on host, the entrypoint only needs to fix permissions for the proxy user. - Fix Squid config ordering: ACL definitions must appear before ssl_bump rules that reference them. Moved ${aclSection} before ${sslBumpSection} in the config template. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent fe19008 commit c526c6e

3 files changed

Lines changed: 38 additions & 21 deletions

File tree

containers/squid/entrypoint.sh

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,17 @@ set -e
66
chown -R proxy:proxy /var/log/squid
77
chmod -R 755 /var/log/squid
88

9-
# Initialize SSL certificate database if SSL Bump is enabled
10-
# Check if ssl_db directory is mounted (indicates SSL Bump mode)
9+
# Fix permissions on SSL certificate database if SSL Bump is enabled
10+
# The database is initialized on the host side by awf, but the permissions
11+
# need to be fixed for the proxy user inside the container.
1112
if [ -d "/var/spool/squid_ssl_db" ]; then
12-
echo "[squid-entrypoint] SSL Bump mode detected - initializing SSL certificate database..."
13-
14-
# Initialize the SSL database if it's empty or not yet initialized
15-
if [ ! -f "/var/spool/squid_ssl_db/index.txt" ]; then
16-
echo "[squid-entrypoint] Creating SSL certificate database..."
17-
# Use Squid's security_file_certgen to initialize the database
18-
# Using 16MB for the certificate cache (sufficient for typical AI agent sessions)
19-
/usr/lib/squid/security_file_certgen -c -s /var/spool/squid_ssl_db -M 16MB
20-
chown -R proxy:proxy /var/spool/squid_ssl_db
21-
echo "[squid-entrypoint] SSL certificate database initialized"
22-
else
23-
echo "[squid-entrypoint] SSL certificate database already exists"
24-
fi
25-
26-
# Fix permissions on SSL database
13+
echo "[squid-entrypoint] SSL Bump mode detected - fixing SSL database permissions..."
14+
15+
# Fix ownership for Squid (runs as proxy user)
2716
chown -R proxy:proxy /var/spool/squid_ssl_db
2817
chmod -R 700 /var/spool/squid_ssl_db
18+
19+
echo "[squid-entrypoint] SSL certificate database ready"
2920
fi
3021

3122
# Start Squid

src/squid-config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,12 @@ access_log /var/log/squid/access.log firewall_detailed
399399
cache_log /var/log/squid/cache.log
400400
cache deny all
401401
402+
${aclSection}
403+
402404
# Port configuration
403405
${portConfig}
404406
${sslBumpSection}
405407
406-
${aclSection}
407-
408408
# Network ACLs
409409
acl localnet src 10.0.0.0/8
410410
acl localnet src 172.16.0.0/12

src/ssl-bump.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,45 @@ export async function generateSessionCa(config: SslBumpConfig): Promise<CaFiles>
110110
* Initializes Squid's SSL certificate database
111111
*
112112
* Squid requires a certificate database to store dynamically generated
113-
* certificates for SSL Bump mode.
113+
* certificates for SSL Bump mode. The database structure expected by Squid is:
114+
* - ssl_db/certs/ - Directory for storing generated certificates
115+
* - ssl_db/index.txt - Index file for certificate lookups
116+
* - ssl_db/size - File tracking current database size
117+
*
118+
* NOTE: We create this structure on the host because security_file_certgen
119+
* (Squid's DB initialization tool) requires the directory to NOT exist when
120+
* it runs. Since Docker volume mounts create the directory, we need to
121+
* pre-populate the structure ourselves.
114122
*
115123
* @param workDir - Working directory
116124
* @returns Path to the SSL database directory
117125
*/
118126
export async function initSslDb(workDir: string): Promise<string> {
119127
const sslDbPath = path.join(workDir, 'ssl_db');
128+
const certsPath = path.join(sslDbPath, 'certs');
129+
const indexPath = path.join(sslDbPath, 'index.txt');
130+
const sizePath = path.join(sslDbPath, 'size');
120131

121-
// Create directory if it doesn't exist
132+
// Create the database structure
122133
if (!fs.existsSync(sslDbPath)) {
123134
fs.mkdirSync(sslDbPath, { recursive: true, mode: 0o700 });
124135
}
125136

137+
// Create certs subdirectory
138+
if (!fs.existsSync(certsPath)) {
139+
fs.mkdirSync(certsPath, { mode: 0o700 });
140+
}
141+
142+
// Create index.txt (empty file for certificate index)
143+
if (!fs.existsSync(indexPath)) {
144+
fs.writeFileSync(indexPath, '', { mode: 0o600 });
145+
}
146+
147+
// Create size file (tracks current DB size, starts at 0)
148+
if (!fs.existsSync(sizePath)) {
149+
fs.writeFileSync(sizePath, '0\n', { mode: 0o600 });
150+
}
151+
126152
logger.debug(`SSL certificate database initialized at: ${sslDbPath}`);
127153
return sslDbPath;
128154
}

0 commit comments

Comments
 (0)