Changeset View
Changeset View
Standalone View
Standalone View
scripts/ssh/ssh-connect.php
Show All 28 Lines | |||||
$pattern[] = '-o'; | $pattern[] = '-o'; | ||||
$pattern[] = 'StrictHostKeyChecking=no'; | $pattern[] = 'StrictHostKeyChecking=no'; | ||||
// This prevents "known host" failures, and covers for issues where HOME is set | // This prevents "known host" failures, and covers for issues where HOME is set | ||||
// to something unusual. | // to something unusual. | ||||
$pattern[] = '-o'; | $pattern[] = '-o'; | ||||
$pattern[] = 'UserKnownHostsFile=/dev/null'; | $pattern[] = 'UserKnownHostsFile=/dev/null'; | ||||
$as_device = getenv('PHABRICATOR_AS_DEVICE'); | |||||
$credential_phid = getenv('PHABRICATOR_CREDENTIAL'); | $credential_phid = getenv('PHABRICATOR_CREDENTIAL'); | ||||
if ($as_device) { | |||||
$device = AlmanacKeys::getLiveDevice(); | |||||
if (!$device) { | |||||
throw new Exception( | |||||
pht( | |||||
'Attempting to create an SSH connection that authenticates with '. | |||||
'the current device, but this host is not configured as a cluster '. | |||||
'device.')); | |||||
} | |||||
if ($credential_phid) { | |||||
throw new Exception( | |||||
pht( | |||||
'Attempting to proxy an SSH connection that authenticates with '. | |||||
'both the current device and a specific credential. These options '. | |||||
'are mutually exclusive.')); | |||||
} | |||||
} | |||||
if ($credential_phid) { | if ($credential_phid) { | ||||
$viewer = PhabricatorUser::getOmnipotentUser(); | $viewer = PhabricatorUser::getOmnipotentUser(); | ||||
$key = PassphraseSSHKey::loadFromPHID($credential_phid, $viewer); | $key = PassphraseSSHKey::loadFromPHID($credential_phid, $viewer); | ||||
$pattern[] = '-l %P'; | $pattern[] = '-l %P'; | ||||
$arguments[] = $key->getUsernameEnvelope(); | $arguments[] = $key->getUsernameEnvelope(); | ||||
$pattern[] = '-i %P'; | $pattern[] = '-i %P'; | ||||
$arguments[] = $key->getKeyfileEnvelope(); | $arguments[] = $key->getKeyfileEnvelope(); | ||||
} | } | ||||
if ($as_device) { | |||||
$pattern[] = '-l %R'; | |||||
$arguments[] = AlmanacKeys::getClusterSSHUser(); | |||||
$pattern[] = '-i %R'; | |||||
$arguments[] = AlmanacKeys::getKeyPath('device.key'); | |||||
} | |||||
$port = $args->getArg('port'); | $port = $args->getArg('port'); | ||||
if ($port) { | if ($port) { | ||||
$pattern[] = '-p %d'; | $pattern[] = '-p %d'; | ||||
$arguments[] = $port; | $arguments[] = $port; | ||||
} | } | ||||
$pattern[] = '--'; | $pattern[] = '--'; | ||||
Show All 13 Lines |