@@ -134,6 +134,19 @@ func Run(config Config, args []string) error {
134
134
return fmt .Errorf ("failed to get config directory: %v" , err )
135
135
}
136
136
137
+ // Create network namespace configuration
138
+ nsConfig := namespace.Config {
139
+ HTTPPort : 8040 ,
140
+ HTTPSPort : 8043 ,
141
+ }
142
+
143
+ // Create network namespace instance
144
+ networkInstance , err := namespace .New (nsConfig , logger )
145
+ if err != nil {
146
+ logger .Error ("Failed to create network namespace" , "error" , err )
147
+ return fmt .Errorf ("failed to create network namespace: %v" , err )
148
+ }
149
+
137
150
// Create certificate manager (if TLS interception is enabled)
138
151
var certManager * tls.CertificateManager
139
152
var tlsConfig * cryptotls.Config
@@ -145,19 +158,31 @@ func Run(config Config, args []string) error {
145
158
return fmt .Errorf ("failed to create certificate manager: %v" , err )
146
159
}
147
160
tlsConfig = certManager .GetTLSConfig ()
148
- }
149
161
150
- // Create network namespace configuration
151
- nsConfig := namespace.Config {
152
- HTTPPort : 8040 ,
153
- HTTPSPort : 8043 ,
154
- }
162
+ // Get CA certificate for environment
163
+ caCertPEM , err := certManager .GetCACertPEM ()
164
+ if err != nil {
165
+ logger .Error ("Failed to get CA certificate" , "error" , err )
166
+ return fmt .Errorf ("failed to get CA certificate: %v" , err )
167
+ }
155
168
156
- // Create network namespace instance
157
- networkInstance , err := namespace .New (nsConfig , logger )
158
- if err != nil {
159
- logger .Error ("Failed to create network namespace" , "error" , err )
160
- return fmt .Errorf ("failed to create network namespace: %v" , err )
169
+ // Write CA certificate to a temporary file for tools that need a file path
170
+ caCertPath := filepath .Join (configDir , "ca-cert.pem" )
171
+ err = os .WriteFile (caCertPath , caCertPEM , 0644 )
172
+ if err != nil {
173
+ logger .Error ("Failed to write CA certificate file" , "error" , err )
174
+ return fmt .Errorf ("failed to write CA certificate file: %v" , err )
175
+ }
176
+
177
+ // Set standard CA certificate environment variables for common tools
178
+ // This makes tools like curl, git, etc. trust our dynamically generated CA
179
+ networkInstance .SetEnv ("SSL_CERT_FILE" , caCertPath ) // OpenSSL/LibreSSL-based tools
180
+ networkInstance .SetEnv ("SSL_CERT_DIR" , configDir ) // OpenSSL certificate directory
181
+ networkInstance .SetEnv ("CURL_CA_BUNDLE" , caCertPath ) // curl
182
+ networkInstance .SetEnv ("GIT_SSL_CAINFO" , caCertPath ) // Git
183
+ networkInstance .SetEnv ("REQUESTS_CA_BUNDLE" , caCertPath ) // Python requests
184
+ networkInstance .SetEnv ("NODE_EXTRA_CA_CERTS" , caCertPath ) // Node.js
185
+ networkInstance .SetEnv ("JAIL_CA_CERT" , string (caCertPEM )) // Keep for backward compatibility
161
186
}
162
187
163
188
// Create proxy server
@@ -215,34 +240,6 @@ func Run(config Config, args []string) error {
215
240
return fmt .Errorf ("failed to open jail: %v" , err )
216
241
}
217
242
218
- // Setup CA certificate environment variables if TLS interception is enabled
219
- if ! config .NoTLSIntercept && certManager != nil {
220
- // Get CA certificate for environment
221
- caCertPEM , err := certManager .GetCACertPEM ()
222
- if err != nil {
223
- logger .Error ("Failed to get CA certificate" , "error" , err )
224
- return fmt .Errorf ("failed to get CA certificate: %v" , err )
225
- }
226
-
227
- // Write CA certificate to a temporary file for tools that need a file path
228
- caCertPath := filepath .Join (configDir , "ca-cert.pem" )
229
- err = os .WriteFile (caCertPath , caCertPEM , 0644 )
230
- if err != nil {
231
- logger .Error ("Failed to write CA certificate file" , "error" , err )
232
- return fmt .Errorf ("failed to write CA certificate file: %v" , err )
233
- }
234
-
235
- // Set standard CA certificate environment variables for common tools
236
- // This makes tools like curl, git, etc. trust our dynamically generated CA
237
- jailInstance .CommandExecutor ().SetEnv ("SSL_CERT_FILE" , caCertPath ) // OpenSSL/LibreSSL-based tools
238
- jailInstance .CommandExecutor ().SetEnv ("SSL_CERT_DIR" , configDir ) // OpenSSL certificate directory
239
- jailInstance .CommandExecutor ().SetEnv ("CURL_CA_BUNDLE" , caCertPath ) // curl
240
- jailInstance .CommandExecutor ().SetEnv ("GIT_SSL_CAINFO" , caCertPath ) // Git
241
- jailInstance .CommandExecutor ().SetEnv ("REQUESTS_CA_BUNDLE" , caCertPath ) // Python requests
242
- jailInstance .CommandExecutor ().SetEnv ("NODE_EXTRA_CA_CERTS" , caCertPath ) // Node.js
243
- jailInstance .CommandExecutor ().SetEnv ("JAIL_CA_CERT" , string (caCertPEM )) // Keep for backward compatibility
244
- }
245
-
246
243
// Create context for graceful shutdown
247
244
ctx , cancel := context .WithCancel (context .Background ())
248
245
defer cancel ()
@@ -267,4 +264,4 @@ func Run(config Config, args []string) error {
267
264
}
268
265
269
266
return nil
270
- }
267
+ }
0 commit comments