Skip to content

Commit 2914613

Browse files
author
epriestley
committed
Fix failure to record pullerPHID in repository pull logs
Summary: See PHI305. Ref T13046. The SSH workflows currently extend `PhabricatorManagementWorkflow` to benefit from sharing all the standard argument parsing code. Sharing the parsing code is good, but it also means they inherit a `getViewer()` method which returns the ommnipotent viewer. This is appropriate for everything else which extends `ManagementWorkflow` (like `bin/storage`, `bin/auth`, etc.) but not appropriate for SSH workflows, which have a real user. This caused a bug with the pull logs where `pullerPHID` was not recorded properly. We used `$this->getViewer()->getPHID()` but the correct code was `$this->getUser()->getPHID()`. To harden this against future mistakes: - Don't extend `ManagementWorkflow`. Extend `PhutilArgumentWorkflow` instead. We **only** want the argument parsing code. - Rename `get/setUser()` to `get/setSSHUser()` to make them explicit. Then, fix the pull log bug by calling `getSSHUser()` instead of `getViewer()`. Test Plan: - Pulled and pushed to a repository over SSH. - Grepped all the SSH stuff for the altered symbols. - Saw pulls record a valid `pullerPHID` in the pull log. - Used `echo {} | ssh ... conduit conduit.ping` to test conduit over SSH. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13046 Differential Revision: https://secure.phabricator.com/D18912
1 parent bf2868c commit 2914613

8 files changed

+26
-20
lines changed

scripts/ssh/ssh-exec.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@
245245
}
246246

247247
$workflow = $parsed_args->parseWorkflows($workflows);
248-
$workflow->setUser($user);
248+
$workflow->setSSHUser($user);
249249
$workflow->setOriginalArguments($original_argv);
250250
$workflow->setIsClusterRequest($is_cluster_request);
251251

src/__phutil_library_map__.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9620,7 +9620,7 @@
96209620
'PhabricatorSSHKeysSettingsPanel' => 'PhabricatorSettingsPanel',
96219621
'PhabricatorSSHLog' => 'Phobject',
96229622
'PhabricatorSSHPassthruCommand' => 'Phobject',
9623-
'PhabricatorSSHWorkflow' => 'PhabricatorManagementWorkflow',
9623+
'PhabricatorSSHWorkflow' => 'PhutilArgumentWorkflow',
96249624
'PhabricatorSavedQuery' => array(
96259625
'PhabricatorSearchDAO',
96269626
'PhabricatorPolicyInterface',

src/applications/conduit/ssh/ConduitSSHWorkflow.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function execute(PhutilArgumentParser $args) {
4646

4747
try {
4848
$call = new ConduitCall($method, $params);
49-
$call->setUser($this->getUser());
49+
$call->setUser($this->getSSHUser());
5050

5151
$result = $call->execute();
5252
} catch (ConduitException $ex) {
@@ -77,7 +77,7 @@ public function execute(PhutilArgumentParser $args) {
7777

7878
$connection_id = idx($metadata, 'connectionID');
7979
$log = id(new PhabricatorConduitMethodCallLog())
80-
->setCallerPHID($this->getUser()->getPHID())
80+
->setCallerPHID($this->getSSHUser()->getPHID())
8181
->setConnectionID($connection_id)
8282
->setMethod($method)
8383
->setError((string)$error_code)

src/applications/diffusion/ssh/DiffusionGitReceivePackSSHWorkflow.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protected function didConstruct() {
1515

1616
protected function executeRepositoryOperations() {
1717
$repository = $this->getRepository();
18-
$viewer = $this->getUser();
18+
$viewer = $this->getSSHUser();
1919
$device = AlmanacKeys::getLiveDevice();
2020

2121
// This is a write, and must have write access.

src/applications/diffusion/ssh/DiffusionGitUploadPackSSHWorkflow.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protected function didConstruct() {
1515

1616
protected function executeRepositoryOperations() {
1717
$repository = $this->getRepository();
18-
$viewer = $this->getUser();
18+
$viewer = $this->getSSHUser();
1919
$device = AlmanacKeys::getLiveDevice();
2020

2121
$skip_sync = $this->shouldSkipReadSynchronization();

src/applications/diffusion/ssh/DiffusionSSHWorkflow.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function getArgs() {
2626

2727
public function getEnvironment() {
2828
$env = array(
29-
DiffusionCommitHookEngine::ENV_USER => $this->getUser()->getUsername(),
29+
DiffusionCommitHookEngine::ENV_USER => $this->getSSHUser()->getUsername(),
3030
DiffusionCommitHookEngine::ENV_REMOTE_PROTOCOL => 'ssh',
3131
);
3232

@@ -122,14 +122,14 @@ protected function getProxyCommand() {
122122
$key_path,
123123
$port,
124124
$host,
125-
'@'.$this->getUser()->getUsername(),
125+
'@'.$this->getSSHUser()->getUsername(),
126126
$this->getOriginalArguments());
127127
}
128128

129129
final public function execute(PhutilArgumentParser $args) {
130130
$this->args = $args;
131131

132-
$viewer = $this->getUser();
132+
$viewer = $this->getSSHUser();
133133
$have_diffusion = PhabricatorApplication::isClassInstalledForViewer(
134134
'PhabricatorDiffusionApplication',
135135
$viewer);
@@ -164,7 +164,7 @@ final public function execute(PhutilArgumentParser $args) {
164164
}
165165

166166
protected function loadRepositoryWithPath($path, $vcs) {
167-
$viewer = $this->getUser();
167+
$viewer = $this->getSSHUser();
168168

169169
$info = PhabricatorRepository::parseRepositoryServicePath($path, $vcs);
170170
if ($info === null) {
@@ -214,7 +214,7 @@ protected function requireWriteAccess($protocol_command = null) {
214214
}
215215

216216
$repository = $this->getRepository();
217-
$viewer = $this->getUser();
217+
$viewer = $this->getSSHUser();
218218

219219
if ($viewer->isOmnipotent()) {
220220
throw new Exception(
@@ -252,7 +252,7 @@ protected function requireWriteAccess($protocol_command = null) {
252252
}
253253

254254
protected function shouldSkipReadSynchronization() {
255-
$viewer = $this->getUser();
255+
$viewer = $this->getSSHUser();
256256

257257
// Currently, the only case where devices interact over SSH without
258258
// assuming user credentials is when synchronizing before a read. These
@@ -265,7 +265,7 @@ protected function shouldSkipReadSynchronization() {
265265
}
266266

267267
protected function newPullEvent() {
268-
$viewer = $this->getViewer();
268+
$viewer = $this->getSSHUser();
269269
$repository = $this->getRepository();
270270
$remote_address = $this->getSSHRemoteAddress();
271271

src/applications/diffusion/ssh/DiffusionSubversionServeSSHWorkflow.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ protected function executeRepositoryOperations() {
154154
} else {
155155
$command = csprintf(
156156
'svnserve -t --tunnel-user=%s',
157-
$this->getUser()->getUsername());
157+
$this->getSSHUser()->getUsername());
158158
$cwd = PhabricatorEnv::getEmptyCWD();
159159
}
160160

src/infrastructure/ssh/PhabricatorSSHWorkflow.php

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
<?php
22

3-
abstract class PhabricatorSSHWorkflow extends PhabricatorManagementWorkflow {
3+
abstract class PhabricatorSSHWorkflow
4+
extends PhutilArgumentWorkflow {
45

5-
private $user;
6+
// NOTE: We are explicitly extending "PhutilArgumentWorkflow", not
7+
// "PhabricatorManagementWorkflow". We want to avoid inheriting "getViewer()"
8+
// and other methods which assume workflows are administrative commands
9+
// like `bin/storage`.
10+
11+
private $sshUser;
612
private $iochannel;
713
private $errorChannel;
814
private $isClusterRequest;
@@ -21,13 +27,13 @@ public function getErrorChannel() {
2127
return $this->errorChannel;
2228
}
2329

24-
public function setUser(PhabricatorUser $user) {
25-
$this->user = $user;
30+
public function setSSHUser(PhabricatorUser $ssh_user) {
31+
$this->sshUser = $ssh_user;
2632
return $this;
2733
}
2834

29-
public function getUser() {
30-
return $this->user;
35+
public function getSSHUser() {
36+
return $this->sshUser;
3137
}
3238

3339
public function setIOChannel(PhutilChannel $channel) {

0 commit comments

Comments
 (0)