Skip to content

Commit 690f078

Browse files
committed
If the keystore is removed, clear out the config and http client so we don't use it anymore after it's been deleted.
1 parent 369beef commit 690f078

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

agent/agent.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,14 @@ func PollForConfiguration() (configChanged bool, err error) {
6969
}
7070

7171
if response == nil {
72+
// No changes from the poll response
7273
return false, nil
7374
}
7475

7576
if response.Keystore != nil {
7677
updateKeystoreConfig(response.Keystore)
78+
} else if config.CurrentConfig.Keystore != nil {
79+
removeKeystoreConfig()
7780
}
7881

7982
if response.LockRequested && !isLocked {
@@ -183,6 +186,15 @@ func updateKeystoreConfig(ks *config.KeystoreConfig) {
183186
}
184187
}
185188

189+
func removeKeystoreConfig() {
190+
log.Printf("Keystore configuration removed by server, clearing keystore client")
191+
api.ClearKeystoreClient()
192+
config.CurrentConfig.Keystore = nil
193+
if err := config.SaveConfig(&config.CurrentConfig, config.CurrentPath); err != nil {
194+
log.Printf("Error saving config after keystore removal: %v", err)
195+
}
196+
}
197+
186198
// InitKeystoreFromConfig rebuilds the keystore TLS client from saved config (e.g. on restart).
187199
func InitKeystoreFromConfig() {
188200
ks := config.CurrentConfig.Keystore

api/keystore_client.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ func GetKeystoreClient() *http.Client {
5858
return keystoreClient
5959
}
6060

61+
// ClearKeystoreClient removes the keystore HTTP client and closes its idle connections.
62+
func ClearKeystoreClient() {
63+
keystoreMu.Lock()
64+
defer keystoreMu.Unlock()
65+
if keystoreClient != nil {
66+
keystoreClient.CloseIdleConnections()
67+
}
68+
keystoreClient = nil
69+
keystoreHost = ""
70+
}
71+
6172
// GetKeystoreHost returns the configured keystore host.
6273
func GetKeystoreHost() string {
6374
keystoreMu.RLock()

0 commit comments

Comments
 (0)