mirror of
https://github.com/deployphp/deployer.git
synced 2025-02-24 09:12:51 +01:00
Implement SSH Agent Forwarding Feature
This commit is contained in:
parent
ef209e2ba0
commit
9f05d7c94b
@ -80,6 +80,17 @@ class Builder
|
|||||||
$this->config->setPemFile($pemFile);
|
$this->config->setPemFile($pemFile);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Using forward agent to authentication
|
||||||
|
*
|
||||||
|
* @return \Deployer\Server\Builder
|
||||||
|
*/
|
||||||
|
public function forwardAgent()
|
||||||
|
{
|
||||||
|
$this->config->setAuthenticationMethod(Configuration::AUTH_BY_AGENT);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
|
@ -16,6 +16,8 @@ class Configuration
|
|||||||
const AUTH_BY_PUBLIC_KEY = 2;
|
const AUTH_BY_PUBLIC_KEY = 2;
|
||||||
|
|
||||||
const AUTH_BY_PEM_FILE = 3;
|
const AUTH_BY_PEM_FILE = 3;
|
||||||
|
|
||||||
|
const AUTH_BY_AGENT = 4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type of authentication.
|
* Type of authentication.
|
||||||
|
@ -11,6 +11,7 @@ use Deployer\Server\Configuration;
|
|||||||
use Deployer\Server\ServerInterface;
|
use Deployer\Server\ServerInterface;
|
||||||
use phpseclib\Crypt\RSA;
|
use phpseclib\Crypt\RSA;
|
||||||
use phpseclib\Net\SFTP;
|
use phpseclib\Net\SFTP;
|
||||||
|
use \phpseclib\System\SSH\Agent;
|
||||||
|
|
||||||
class PhpSecLib implements ServerInterface
|
class PhpSecLib implements ServerInterface
|
||||||
{
|
{
|
||||||
@ -71,6 +72,13 @@ class PhpSecLib implements ServerInterface
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Configuration::AUTH_BY_AGENT:
|
||||||
|
|
||||||
|
$key = new Agent();
|
||||||
|
$this->sftp->login($serverConfig->getUser(), $key);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new \RuntimeException('You need to specify authentication method.');
|
throw new \RuntimeException('You need to specify authentication method.');
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,10 @@ class SshExtension implements ServerInterface
|
|||||||
case Configuration::AUTH_BY_PEM_FILE:
|
case Configuration::AUTH_BY_PEM_FILE:
|
||||||
|
|
||||||
throw new \RuntimeException('If you want to use pem file, switch to using PhpSecLib.');
|
throw new \RuntimeException('If you want to use pem file, switch to using PhpSecLib.');
|
||||||
|
|
||||||
|
case Configuration::AUTH_BY_AGENT:
|
||||||
|
|
||||||
|
throw new \RuntimeException('If you want to use forward agent function, switch to using PhpSecLib.');
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new \RuntimeException('You need to specify authentication method.');
|
throw new \RuntimeException('You need to specify authentication method.');
|
||||||
|
@ -101,4 +101,17 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$b = new Builder($config, $env);
|
$b = new Builder($config, $env);
|
||||||
$b->env('name', 'value');
|
$b->env('name', 'value');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testForwardAgent()
|
||||||
|
{
|
||||||
|
$config = $this->getMockBuilder('Deployer\Server\Configuration')->disableOriginalConstructor()->getMock();
|
||||||
|
$config->expects($this->once())
|
||||||
|
->method('setAuthenticationMethod')
|
||||||
|
->with(Configuration::AUTH_BY_AGENT)
|
||||||
|
->will($this->returnSelf());
|
||||||
|
$env = $this->getMock('Deployer\Server\Environment');
|
||||||
|
|
||||||
|
$b = new Builder($config, $env);
|
||||||
|
$b->forwardAgent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user