mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-20 13:52:40 +01:00
Correct private key permissions before extracting public key in bin/almanac register
Summary: `ssh-keygen` declines to run on a too-public key. Write the correctly-restricted key a little earlier in the workflow. Test Plan: ``` epriestley@orbital ~/dev/phabricator $ chmod 644 ~/dev/core/conf/keys/daemon.key epriestley@orbital ~/dev/phabricator $ ./bin/almanac register --private-key ~/dev/core/conf/keys/daemon.key --identify-as local.phacility.net --device daemon.phacility.net --force --allow-key-reuse Installing public key... Installing private key... Installing device ID... HOST REGISTERED This host has been registered as "local.phacility.net" and a trusted keypair has been installed. epriestley@orbital ~/dev/phabricator $ ``` Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D11700
This commit is contained in:
parent
74ea59235a
commit
57f1ab705e
1 changed files with 10 additions and 6 deletions
|
@ -115,7 +115,16 @@ final class AlmanacManagementRegisterWorkflow
|
|||
}
|
||||
}
|
||||
|
||||
list($raw_public_key) = execx('ssh-keygen -y -f %s', $private_key_path);
|
||||
// NOTE: We're writing the private key here so we can change permissions
|
||||
// on it without causing weird side effects to the file specified with
|
||||
// the `--private-key` flag. The file needs to have restrictive permissions
|
||||
// before `ssh-keygen` will willingly operate on it.
|
||||
$tmp_private = new TempFile();
|
||||
Filesystem::changePermissions($tmp_private, 0600);
|
||||
execx('chown %s %s', $phd_user, $tmp_private);
|
||||
Filesystem::writeFile($tmp_private, $raw_private_key);
|
||||
|
||||
list($raw_public_key) = execx('ssh-keygen -y -f %s', $tmp_private);
|
||||
|
||||
$key_object = PhabricatorAuthSSHPublicKey::newFromRawKey($raw_public_key);
|
||||
|
||||
|
@ -173,11 +182,6 @@ final class AlmanacManagementRegisterWorkflow
|
|||
$console->writeOut(
|
||||
"%s\n",
|
||||
pht('Installing private key...'));
|
||||
|
||||
$tmp_private = new TempFile();
|
||||
Filesystem::changePermissions($tmp_private, 0600);
|
||||
execx('chown %s %s', $phd_user, $tmp_private);
|
||||
Filesystem::writeFile($tmp_private, $raw_private_key);
|
||||
execx('mv -f %s %s', $tmp_private, $stored_private_path);
|
||||
|
||||
$raw_device = $device_name;
|
||||
|
|
Loading…
Reference in a new issue