Skip to content

Commit 2726ad6

Browse files
authored
Support connection reset when changes detected in TLS cert files (#1004)
* add command.tls paths to credential watcher if present * Add unit tests for tls cert paths * update tests
1 parent 0c9d46b commit 2726ad6

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

internal/watcher/credentials/credential_watcher_service.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,6 @@ func (cws *CredentialWatcherService) addWatcher(ctx context.Context, filePath st
107107

108108
if err := cws.watcher.Add(filePath); err != nil {
109109
slog.ErrorContext(ctx, "Failed to add credential watcher", "path", filePath, "error", err)
110-
removeError := cws.watcher.Remove(filePath)
111-
if removeError != nil {
112-
slog.ErrorContext(
113-
ctx, "Failed to remove credential watcher", "path", filePath, "error", removeError)
114-
}
115110

116111
return
117112
}
@@ -183,6 +178,19 @@ func credentialPaths(agentConfig *config.Config) []string {
183178
}
184179
}
185180

181+
// agent's tls certs
182+
if agentConfig.Command.TLS != nil {
183+
if agentConfig.Command.TLS.Ca != "" {
184+
paths = append(paths, agentConfig.Command.TLS.Ca)
185+
}
186+
if agentConfig.Command.TLS.Cert != "" {
187+
paths = append(paths, agentConfig.Command.TLS.Cert)
188+
}
189+
if agentConfig.Command.TLS.Key != "" {
190+
paths = append(paths, agentConfig.Command.TLS.Key)
191+
}
192+
}
193+
186194
return paths
187195
}
188196

internal/watcher/credentials/credential_watcher_service_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ func Test_credentialPaths(t *testing.T) {
211211
agentConfig: types.AgentConfig(),
212212
want: []string{
213213
"/tmp/token",
214+
"ca.pem",
215+
"cert.pem",
216+
"key.pem",
214217
},
215218
},
216219
{
@@ -224,6 +227,27 @@ func Test_credentialPaths(t *testing.T) {
224227
},
225228
want: nil,
226229
},
230+
{
231+
name: "Test 3: Add TLS paths if Command TLS is set",
232+
agentConfig: &config.Config{
233+
Command: &config.Command{
234+
Server: nil,
235+
Auth: nil,
236+
TLS: &config.TLSConfig{
237+
Cert: "/tmp-ca",
238+
Key: "/tmp-token",
239+
Ca: "/tmp-key",
240+
ServerName: "my-server",
241+
SkipVerify: false,
242+
},
243+
},
244+
},
245+
want: []string{
246+
"/tmp-key",
247+
"/tmp-ca",
248+
"/tmp-token",
249+
},
250+
},
227251
}
228252
for _, tt := range tests {
229253
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)