Skip to content

Commit 24f771c

Browse files
author
epriestley
committed
Add an optional "--sshd-key" argument to "bin/ssh-auth" for reading "%k" from modern sshd
Summary: Depends on D20873. Ref T13436. Allow callers to configure "bin/ssh-auth --sshd-key %k" as an "AuthorizedKeysCommand"; if they do, and we recognize the key, emit just that key in the output. Test Plan: - Used `git pull` locally, still worked fine. - Instrumented things, saw the public key lookup actually work and emit a single key. - Ran without "--sshd-key", got a full key list as before. Maniphest Tasks: T13436 Differential Revision: https://secure.phabricator.com/D20874
1 parent 02f85f0 commit 24f771c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

scripts/ssh/ssh-auth.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@
44
$root = dirname(dirname(dirname(__FILE__)));
55
require_once $root.'/scripts/init/init-script.php';
66

7+
// TODO: For now, this is using "parseParital()", not "parse()". This allows
8+
// the script to accept (and ignore) additional arguments. This preserves
9+
// backward compatibility until installs have time to migrate to the new
10+
// syntax.
11+
12+
$args = id(new PhutilArgumentParser($argv))
13+
->parsePartial(
14+
array(
15+
array(
16+
'name' => 'sshd-key',
17+
'param' => 'k',
18+
'help' => pht(
19+
'Accepts the "%%k" parameter from "AuthorizedKeysCommand".'),
20+
),
21+
));
22+
23+
$sshd_key = $args->getArg('sshd-key');
24+
725
// NOTE: We are caching a datastructure rather than the flat key file because
826
// the path on disk to "ssh-exec" is arbitrarily mutable at runtime. See T12397.
927

@@ -85,6 +103,22 @@
85103
$cache->setKey($authstruct_key, $authstruct_raw, $ttl);
86104
}
87105

106+
// If we've received an "--sshd-key" argument and it matches some known key,
107+
// only emit that key. (For now, if the key doesn't match, we'll fall back to
108+
// emitting all keys.)
109+
if ($sshd_key !== null) {
110+
$matches = array();
111+
foreach ($authstruct['keys'] as $key => $key_struct) {
112+
if (phutil_hashes_are_identical($key_struct['key'], $sshd_key)) {
113+
$matches[$key] = $key_struct;
114+
}
115+
}
116+
117+
if ($matches) {
118+
$authstruct['keys'] = $matches;
119+
}
120+
}
121+
88122
$bin = $root.'/bin/ssh-exec';
89123
$instance = PhabricatorEnv::getEnvConfig('cluster.instance');
90124

0 commit comments

Comments
 (0)