executor: fail early on reattach if listener is not executor (#24538)

This commit is contained in:
Michael Smithhisler
2024-12-02 09:56:00 -05:00
committed by GitHub
parent b293e6a82a
commit 4e2d9675e7
2 changed files with 16 additions and 2 deletions

3
.changelog/24538.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:bug
executor: validate executor on reattach to avoid possibility of killing non-Nomad processes
```

View File

@@ -75,7 +75,11 @@ func CreateExecutor(
return newExecutorClient(config, logger)
}
// ReattachToExecutor launches a plugin with a given plugin config
// ReattachToExecutor launches a plugin with a given plugin config and validates it can call the executor.
// Note: On Windows, go-plugin listens on a localhost port. It is possible on a reboot that another process
// is listening on that port, and a process is running with the previous executors PID, leading the Nomad
// TaskRunner to kill the PID after it errors calling the Wait RPC. So, fail early via the Version RPC if
// we detect the listener isn't actually an Executor.
func ReattachToExecutor(reattachConfig *plugin.ReattachConfig, logger hclog.Logger, compute cpustats.Compute) (Executor, *plugin.Client, error) {
config := &plugin.ClientConfig{
HandshakeConfig: base.Handshake,
@@ -84,7 +88,14 @@ func ReattachToExecutor(reattachConfig *plugin.ReattachConfig, logger hclog.Logg
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
Logger: logger.Named("executor"),
}
return newExecutorClient(config, logger)
exec, pluginClient, err := newExecutorClient(config, logger)
if err != nil {
return nil, nil, err
}
if _, err := exec.Version(); err != nil {
return nil, nil, err
}
return exec, pluginClient, nil
}
func newExecutorClient(config *plugin.ClientConfig, logger hclog.Logger) (Executor, *plugin.Client, error) {