Commit 135d7556 authored by Kamil Trzciński's avatar Kamil Trzciński

Added IdentityFile support for SSH executor

parent af913976
......@@ -173,10 +173,11 @@ This defines the SSH connection parameters.
| Parameter | Explanation |
| ---------- | ----------- |
| `host` | where to connect (overriden when using `docker-ssh`) |
| `host` | where to connect (overridden when using `docker-ssh`) |
| `port` | specify port, default: 22 |
| `user` | specify user |
| `password` | specify password |
| `identity_file` | specify file path to SSH private key (id_rsa, id_dsa or id_edcsa). The file needs to be stored unencrypted |
Example:
......@@ -186,6 +187,7 @@ Example:
port = "22"
user = "root"
password = "production-server-password"
identity_file = "
```
### Note
......
......@@ -9,6 +9,7 @@ import (
"code.google.com/p/go.crypto/ssh"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers"
"io/ioutil"
)
type Command struct {
......@@ -25,14 +26,31 @@ type Command struct {
client *ssh.Client
}
func (s *Command) getSSHAuthMethods() []ssh.AuthMethod {
func (s *Command) getSSHKey(identityFile string) (key ssh.Signer, err error) {
buf, err := ioutil.ReadFile(identityFile)
if err != nil {
return nil, err
}
key, err = ssh.ParsePrivateKey(buf)
return key, err
}
func (s *Command) getSSHAuthMethods() ([]ssh.AuthMethod, error) {
var methods []ssh.AuthMethod
if s.Password != nil {
methods = append(methods, ssh.Password(*s.Password))
}
return methods
if s.IdentityFile != nil {
key, err := s.getSSHKey(*s.IdentityFile)
if err != nil {
return nil, err
}
methods = append(methods, ssh.PublicKeys(key))
}
return methods, nil
}
func (s *Command) Connect() error {
......@@ -40,9 +58,14 @@ func (s *Command) Connect() error {
user := helpers.StringOrDefault(s.User, "root")
port := helpers.StringOrDefault(s.Port, "22")
methods, err := s.getSSHAuthMethods()
if err != nil {
return err
}
config := &ssh.ClientConfig{
User: user,
Auth: s.getSSHAuthMethods(),
Auth: methods,
}
connectRetries := s.ConnectRetries
......
package ssh
type Config struct {
User *string `toml:"user" json:"user"`
Password *string `toml:"password" json:"password"`
Host *string `toml:"host" json:"host"`
Port *string `toml:"port" json:"port"`
User *string `toml:"user" json:"user"`
Password *string `toml:"password" json:"password"`
Host *string `toml:"host" json:"host"`
Port *string `toml:"port" json:"port"`
IdentityFile *string `toml:"identity_file" json:"identity_file"`
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment