Skip to content

Commit 1a6bb74

Browse files
authored
fix: Remove the temp cert files only after the docker client is initialized (#1030)
## Description: The temp cert files were removed before the docker client got a chance to read them to build a TLS config. Not sure if this was due to a race condition or a recent change in the docker client. ## Is this change user facing? NO
1 parent cb2918d commit 1a6bb74

File tree

1 file changed

+9
-6
lines changed
  • container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/backend_creator

1 file changed

+9
-6
lines changed

container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/backend_creator/backend_creator.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,30 +86,33 @@ func getRemoteDockerKurtosisBackend(
8686
optionalApiContainerModeArgs *APIContainerModeArgs,
8787
remoteBackendConfig *configs.KurtosisRemoteBackendConfig,
8888
) (backend_interface.KurtosisBackend, error) {
89-
remoteDockerClientOpts, err := buildRemoteDockerClientOpts(remoteBackendConfig)
89+
remoteDockerClientOpts, cleanCertFilesFunc, err := buildRemoteDockerClientOpts(remoteBackendConfig)
9090
if err != nil {
9191
return nil, stacktrace.Propagate(err, "Error building client configuration for Docker remote backend")
9292
}
93+
defer cleanCertFilesFunc()
9394
kurtosisRemoteBackend, err := getDockerKurtosisBackend(remoteDockerClientOpts, optionalApiContainerModeArgs)
9495
if err != nil {
9596
return nil, stacktrace.Propagate(err, "Error building Kurtosis remote Docker backend")
9697
}
9798
return kurtosisRemoteBackend, nil
9899
}
99100

100-
func buildRemoteDockerClientOpts(remoteBackendConfig *configs.KurtosisRemoteBackendConfig) ([]client.Opt, error) {
101+
func buildRemoteDockerClientOpts(remoteBackendConfig *configs.KurtosisRemoteBackendConfig) ([]client.Opt, func(), error) {
101102
var clientOptions []client.Opt
102103

103104
// host and port option
104105
clientOptions = append(clientOptions, client.WithHost(remoteBackendConfig.Endpoint))
105106

106107
// TLS option if config is present
108+
cleanCertFilesFunc := func() {}
107109
if tlsConfig := remoteBackendConfig.Tls; tlsConfig != nil {
108-
tlsFilesDir, cleanCertFilesFunc, err := writeTlsConfigToTempDir(tlsConfig.Ca, tlsConfig.ClientCert, tlsConfig.ClientKey)
110+
var tlsFilesDir string
111+
var err error
112+
tlsFilesDir, cleanCertFilesFunc, err = writeTlsConfigToTempDir(tlsConfig.Ca, tlsConfig.ClientCert, tlsConfig.ClientKey)
109113
if err != nil {
110-
return nil, stacktrace.Propagate(err, "Error building TLS configuration to connect to remote Docker backend")
114+
return nil, nil, stacktrace.Propagate(err, "Error building TLS configuration to connect to remote Docker backend")
111115
}
112-
defer cleanCertFilesFunc()
113116
tlsOpt := client.WithTLSClientConfig(
114117
path.Join(tlsFilesDir, caFileName),
115118
path.Join(tlsFilesDir, certFileName),
@@ -119,7 +122,7 @@ func buildRemoteDockerClientOpts(remoteBackendConfig *configs.KurtosisRemoteBack
119122

120123
// Timeout and API version negotiation option
121124
clientOptions = append(clientOptions, client.WithAPIVersionNegotiation())
122-
return clientOptions, nil
125+
return clientOptions, cleanCertFilesFunc, nil
123126
}
124127

125128
// writeTlsConfigToTempDir writes the different TLS files to a directory, and returns the path to this directory.

0 commit comments

Comments
 (0)