Skip to content

Commit 437ece9

Browse files
committed
Update host keys config so it can be fully overridden if necessary
1 parent eec7f99 commit 437ece9

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

config-defaults.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,16 @@ api:
288288
# The timeout in seconds for a "git push" command. Set to null for no timeout.
289289
git_push_timeout: 3600
290290

291+
ssh:
291292
# A file containing SSH host keys to install for the user.
292-
# If a relative path is given, it is considered relative to the CLI source
293-
# code root. Note this will need to be built into the Phar.
294-
ssh_host_keys_file: resources/ssh/host-keys
293+
# The filename is relative to the CLI root. Note it would need to be built
294+
# into the Phar.
295+
host_keys_file: resources/ssh/host-keys
296+
297+
# A list of SSH host keys to install for the user.
298+
# They should be set as a string (one per line).
299+
# If a "host_keys_file" is also specified, both will be used.
300+
host_keys: ''
295301

296302
# How the CLI detects and configures Git repositories as projects.
297303
detection:

src/Service/SshConfig.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,21 @@ public function __construct(Config $config, Filesystem $fs, OutputInterface $out
3535
*/
3636
public function configureHostKeys()
3737
{
38-
$keysSourceFile = (string) $this->config->getWithDefault('api.ssh_host_keys_file', '');
39-
if (!$keysSourceFile) {
40-
return null;
41-
}
42-
if (!(new \Symfony\Component\Filesystem\Filesystem())->isAbsolutePath($keysSourceFile)) {
43-
$keysSourceFile = CLI_ROOT . DIRECTORY_SEPARATOR . $keysSourceFile;
44-
}
4538
$hostKeys = '';
46-
if (file_exists($keysSourceFile)) {
47-
$hostKeys = file_get_contents($keysSourceFile);
39+
if ($hostKeysFile = $this->config->getWithDefault('ssh.host_keys_file', '')) {
40+
$hostKeysFile = CLI_ROOT . DIRECTORY_SEPARATOR . $hostKeysFile;
41+
$hostKeys = file_get_contents($hostKeysFile);
42+
if ($hostKeys === false) {
43+
trigger_error('Failed to load host keys file: ' . $hostKeysFile, E_USER_WARNING);
44+
return null;
45+
}
4846
}
49-
if (!$hostKeys) {
50-
return null;
47+
if ($additionalKeys = $this->config->getWithDefault('ssh.host_keys', '')) {
48+
if (!is_string($additionalKeys)) {
49+
trigger_error('Invalid value for ssh.host_keys config (it must be a string)', E_USER_WARNING);
50+
return null;
51+
}
52+
$hostKeys = rtrim($hostKeys, "\n") . "\n" . $additionalKeys;
5153
}
5254

5355
// Write the keys.

0 commit comments

Comments
 (0)