Skip to content

Commit 6dd0169

Browse files
author
epriestley
committed
Fix various issues with SSH receivers
Summary: - Original command is in SSH_ORIGINAL_COMMAND, not normal argv. - Use PhutilShellLexer to parse it. - Fix a protocol encoding issue with ConduitSSHWorkflow. I think I'm going to make this protocol accept multiple commands anyway because SSH pipes are crazy expensive to build (even locally, they're ~300ms). Test Plan: With other changes, successfully executed "arc list --conduit-uri=ssh://localhost:2222". Reviewers: btrahan, vrana Reviewed By: btrahan CC: aran Maniphest Tasks: T550 Differential Revision: https://secure.phabricator.com/D4232
1 parent e788989 commit 6dd0169

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

scripts/ssh/ssh-auth.php

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,36 @@
66

77
$cert = file_get_contents('php://stdin');
88

9-
$user = null;
10-
if ($cert) {
11-
$user_dao = new PhabricatorUser();
12-
$ssh_dao = new PhabricatorUserSSHKey();
13-
$conn = $user_dao->establishConnection('r');
14-
15-
list($type, $body) = array_merge(
16-
explode(' ', $cert),
17-
array('', ''));
18-
19-
$row = queryfx_one(
20-
$conn,
21-
'SELECT userName FROM %T u JOIN %T ssh ON u.phid = ssh.userPHID
22-
WHERE ssh.keyBody = %s AND ssh.keyType = %s',
23-
$user_dao->getTableName(),
24-
$ssh_dao->getTableName(),
25-
$body,
26-
$type);
27-
if ($row) {
28-
$user = idx($row, 'userName');
29-
}
9+
if (!$cert) {
10+
exit(1);
11+
}
12+
13+
$parts = preg_split('/\s+/', $cert);
14+
if (count($parts) < 2) {
15+
exit(1);
3016
}
3117

18+
list($type, $body) = $parts;
19+
20+
$user_dao = new PhabricatorUser();
21+
$ssh_dao = new PhabricatorUserSSHKey();
22+
$conn_r = $user_dao->establishConnection('r');
23+
24+
$row = queryfx_one(
25+
$conn_r,
26+
'SELECT userName FROM %T u JOIN %T ssh ON u.phid = ssh.userPHID
27+
WHERE ssh.keyType = %s AND ssh.keyBody = %s',
28+
$user_dao->getTableName(),
29+
$ssh_dao->getTableName(),
30+
$type,
31+
$body);
32+
33+
if (!$row) {
34+
exit(1);
35+
}
36+
37+
$user = idx($row, 'userName');
38+
3239
if (!$user) {
3340
exit(1);
3441
}

scripts/ssh/ssh-exec.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
$root = dirname(dirname(dirname(__FILE__)));
55
require_once $root.'/scripts/__init_script__.php';
66

7+
$original_command = getenv('SSH_ORIGINAL_COMMAND');
8+
$original_argv = id(new PhutilShellLexer())->splitArguments($original_command);
9+
$argv = array_merge($argv, $original_argv);
10+
711
$args = new PhutilArgumentParser($argv);
812
$args->setTagline('receive SSH requests');
913
$args->setSynopsis(<<<EOSYNOPSIS
@@ -50,7 +54,7 @@
5054
// concise/relevant exceptions when the client is a remote SSH.
5155
$remain = $args->getUnconsumedArgumentVector();
5256
if (empty($remain)) {
53-
throw new Exception("No command.");
57+
throw new Exception("No interactive logins.");
5458
} else {
5559
$command = head($remain);
5660
$workflow_names = mpull($workflows, 'getName', 'getName');

src/applications/conduit/ssh/ConduitSSHWorkflow.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ public function execute(PhutilArgumentParser $args) {
3131
throw new Exception("Invalid JSON input.");
3232
}
3333

34-
$params = $raw_params;
34+
$params = idx($raw_params, 'params', array());
35+
$params = json_decode($params, true);
36+
$metadata = idx($params, '__conduit__', array());
3537
unset($params['__conduit__']);
36-
$metadata = idx($raw_params, '__conduit__', array());
3738

3839
$call = null;
3940
$error_code = null;

0 commit comments

Comments
 (0)