Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
20f480b
Adding parameter for authentication method.
itouri Jun 9, 2017
67629e3
Adding CI test code for authentication parameters.
itouri Jun 9, 2017
ba21474
Merge branch 'master' into console_auth
itouri Jun 13, 2017
e9ce98c
Add function that validate ssh_public_key of vm/lxc template parameter
itouri Jun 16, 2017
8329e18
Merge branch 'master' into console_auth
itouri Jul 7, 2017
e56737c
Modify lxc.go to can convert authentication_type and ssh_public_key p…
itouri Jul 24, 2017
a8e918f
Merge branch 'master' into console_auth
itouri Jul 24, 2017
b72ff81
Remove processing read file of ssh public key.
itouri Jul 24, 2017
7398602
Adding lxc_auth_ssh.json
itouri Aug 1, 2017
fd9df89
Merge branch 'master' into console_auth
itouri Aug 1, 2017
7d92ca6
Change MergeJSON to use common function of ParseTemplate.
itouri Aug 1, 2017
dc86ac5
Modify validation process of LxcTemplate.
itouri Aug 3, 2017
8714d18
Divided validation authentication_type functions into common functions.
itouri Aug 3, 2017
11a63f7
Modify that common the validation to the authentication_type and ssh_…
itouri Aug 10, 2017
186568b
Modify Qemu test contents
itouri Aug 10, 2017
da2d781
Made SSH server to can authentication with public key.
itouri Aug 10, 2017
e6e0984
Add authentication_type and ssh_public_key to MergeArgs() as parameters.
itouri Aug 21, 2017
2de4fcc
Changed the return type of validatePublicKey([]byte) to error.
itouri Aug 22, 2017
f7b44e9
Modify the SSH server to authenticate the client.
itouri Aug 22, 2017
eb79945
Delete extra line of code about authentification.
itouri Aug 23, 2017
7519521
Adding parameter of Auth to ClientConfig
itouri Aug 24, 2017
fdc200e
Modify arg that is passed to NewSshConsole
itouri Aug 24, 2017
3171355
Delete if section of parse and set indentifyFile
itouri Aug 24, 2017
187827d
Modify ssh.ClientConfig and PublicKeyCallback
itouri Aug 24, 2017
065295b
Modify authenticate process.
itouri Aug 25, 2017
9d4d667
Removed old comment and extra code.
itouri Aug 28, 2017
088e8f5
Delete extra comment.
itouri Aug 28, 2017
9a565bd
Add console with public key test to cmd_console_test.
itouri Aug 28, 2017
76a563c
Fix deleting variable of info.
itouri Aug 28, 2017
c47e357
Modify test command.
itouri Aug 28, 2017
1329d57
Add if process that using api.ConsoleReply.
itouri Aug 28, 2017
de2b220
Add forggten folder.
itouri Aug 29, 2017
b586669
Add authentication type test.
itouri Aug 29, 2017
8d3282d
Modify args of RunCmd.
itouri Aug 30, 2017
b88f005
Modify test code.
itouri Aug 30, 2017
8fd82e0
Add trimming \n from public_key.
itouri Aug 30, 2017
08c9355
Delete extra code.
itouri Aug 30, 2017
819e639
Modify if process.
itouri Aug 30, 2017
4de652d
Modify logic of authType’s switch.
itouri Aug 30, 2017
a0ba12b
Adding show option test to TestCmdConsole_AuthenticationNone.
itouri Sep 1, 2017
5e76df6
Merge branch 'master' into console_auth
itouri Sep 1, 2017
c68c7c0
Merge branch 'fix-jenkins-local-merge' into console_auth
Sep 7, 2017
fe940a5
Upgrade golang.org/x/crypto/ssh
Sep 15, 2017
3d94237
Merge branch 'master' into console_auth
Sep 15, 2017
d036635
Host key callback became mandate parameter.
Sep 15, 2017
ff7a886
Apply same ssh client host key check to acceptance test binary
Sep 16, 2017
299e1ac
Same ssh host key change with d036635
Sep 16, 2017
1596b50
Adding incorrect private key console test.
itouri Oct 13, 2017
853ffa6
Modify the test of console with public key.
itouri Oct 13, 2017
bb8bca2
Merge branch 'master' into console_auth
Oct 23, 2017
533c3d0
Move console auth methods to new interface
Oct 24, 2017
8456dd5
Cast to ConsoleAuthAttributes type instead InstanceResource type
Oct 24, 2017
6554021
Merge branch 'master' into console_auth
Oct 24, 2017
d386fad
Merge branch 'fix-connection-status' into console_auth
Oct 24, 2017
343c305
Merge branch 'master' into console_auth
itouri Jan 24, 2018
f4782d3
Modified the separated function to two lines
itouri Jan 24, 2018
e4a0ecd
Add AuthenticationType to EsxiTmplate
itouri Jan 24, 2018
bc537e3
Modified TestLXCCmdConsole_AuthenticationPubkey
itouri Jan 26, 2018
733384b
Added HostKeyCallback to needed place
itouri Jan 26, 2018
ee4c4ad
Modified none auth type sshd.go logic
itouri Feb 2, 2018
b78fbdc
Added auth password method to ssh config
itouri Feb 2, 2018
3f9bed5
Added ssh.Password("")
itouri Feb 2, 2018
508f170
Added json_name field of authType
itouri Feb 23, 2018
4155a3c
Modified identify typo and change to local variable from global
itouri Feb 23, 2018
f9112cf
Added validation of authtication_type to lxc.go and qemu.go
itouri Feb 23, 2018
6b769a9
Modified lxc and qemu AuthenticationType validation.
itouri Feb 23, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .idea/libraries/GOPATH__openvdc_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"json.schemas": [
{
"fileMatch": [
"/templates/**/*.json"
"/templates/**/*.json",
"/ci/citest/acceptance-test/tests/fixtures/**/*.json"
],
"url": "./schema/v1.json"
}
Expand Down
14 changes: 12 additions & 2 deletions api/instance_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,21 @@ func (s *InstanceAPI) Console(ctx context.Context, in *ConsoleRequest) (*Console
return nil, err
}

return &ConsoleReply{
res := &ConsoleReply{
InstanceId: instanceID,
Type: node.Console.Type,
Address: node.Console.BindAddr,
}, nil
}

authAttrs, ok := inst.ResourceTemplate().(model.ConsoleAuthAttributes)
if !ok {
// Fallback to NONE auth type
res.AuthType = model.AuthenticationType_NONE
} else {
res.AuthType = authAttrs.GetAuthenticationType()
}

return res, nil
}

func (s *InstanceAPI) sendCommand(ctx context.Context, cmd string, instanceID string) error {
Expand Down
8 changes: 8 additions & 0 deletions api/v1.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion ci/citest/acceptance-test/tests/00_ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ package tests

import (
"bytes"
"golang.org/x/crypto/ssh"
"testing"
"time"

"golang.org/x/crypto/ssh"
)

const zookeeper_ip = "10.0.100.10"
Expand All @@ -27,6 +28,7 @@ func RunSsh(ip string, cmd string) (*bytes.Buffer, *bytes.Buffer, error) {
Auth: []ssh.AuthMethod{
ssh.Password("kemumaki"),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}

connection, err := ssh.Dial("tcp", ip+":22", sshConfig)
Expand Down
44 changes: 44 additions & 0 deletions ci/citest/acceptance-test/tests/cmd_console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package tests

import (
"fmt"
"io/ioutil"
"strings"
"testing"
"time"
Expand All @@ -21,6 +22,16 @@ func runConsoleCmd(instance_id string, t *testing.T) {
RunCmdAndExpectFail(t, "sh", "-c", fmt.Sprintf("openvdc console %s -- false", instance_id))
}

func TestCmdConsole_ShowOptionAuthenticationNone(t *testing.T) {
stdout, _ := RunCmdAndReportFail(t, "openvdc", "run", "centos/7/lxc", `{"authentication_type":"none"}`)
instance_id := strings.TrimSpace(stdout.String())
WaitInstance(t, 5*time.Minute, instance_id, "RUNNING", []string{"QUEUED", "STARTING"})
runConsoleCmd(instance_id, t)
runConsoleCmdPiped(instance_id, t)
RunCmdWithTimeoutAndReportFail(t, 10, 5, "openvdc", "destroy", instance_id)
WaitInstance(t, 5*time.Minute, instance_id, "TERMINATED", nil)
}

func TestLXCCmdConsole_ShowOption(t *testing.T) {
stdout, _ := RunCmdAndReportFail(t, "openvdc", "run", "centos/7/lxc")
instance_id := strings.TrimSpace(stdout.String())
Expand All @@ -31,6 +42,39 @@ func TestLXCCmdConsole_ShowOption(t *testing.T) {
WaitInstance(t, 5*time.Minute, instance_id, "TERMINATED", nil)
}

func TestLXCCmdConsole_AuthenticationPubkey(t *testing.T) {
// Make key pair by ssh-keygen
private_key_path := "./testRsa"
private_key_path_worng := "./testRsaWorng"
_, _, err := RunCmd("ssh-keygen", "-t", "rsa", "-f", private_key_path, "-C", "", "-N", "")
if err != nil {
t.Fatalf("err: %s", err)
}
_, _, err = RunCmd("ssh-keygen", "-t", "rsa", "-f", private_key_path_worng, "-C", "", "-N", "")
if err != nil {
t.Fatalf("err: %s", err)
}

// Read public key
data, err := ioutil.ReadFile(private_key_path + ".pub")
if err != nil {
t.Fatalf("Can not read public key: %s\n", err.Error())
}
public_key := strings.Replace(string(data), "\n", "", -1)
stdout, _ := RunCmdAndReportFail(t, "openvdc", "run", "centos/7/lxc", `{"authentication_type":"pub_key","ssh_public_key":"`+public_key+`"}`)

// runConsole()
instance_id := strings.TrimSpace(stdout.String())
WaitInstance(t, 5*time.Minute, instance_id, "RUNNING", []string{"QUEUED", "STARTING"})

RunCmdAndReportFail(t, "openvdc", "console", instance_id, "-i", private_key_path)
RunCmdAndExpectFail(t, "openvdc", "console", instance_id, "-i", private_key_path_worng)

//vrunConsoleCmdPiped(instance_id, t)
RunCmdWithTimeoutAndReportFail(t, 10, 5, "openvdc", "destroy", instance_id)
WaitInstance(t, 5*time.Minute, instance_id, "TERMINATED", nil)
}

func TestQEMUCmdConsole_ShowOption(t *testing.T) {
stdout, _ := RunCmdAndReportFail(t, "openvdc", "run", "centos/7/qemu_ga")
instance_id := strings.TrimSpace(stdout.String())
Expand Down
14 changes: 14 additions & 0 deletions ci/citest/acceptance-test/tests/fixtures/lxc_auth_ssh.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"title": "CentOS7",
"template": {
"type": "vm/lxc",
"lxc_template": {
"openvdc": {
"distro": "centos",
"release": "7"
}
},
"authentication_type": "none"
}
}

55 changes: 54 additions & 1 deletion cmd/openvdc-executor/sshd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"io/ioutil"
"net"
"strings"

log "github.com/Sirupsen/logrus"
"github.com/axsh/openvdc/hypervisor"
Expand All @@ -22,9 +23,61 @@ type SSHServer struct {
ctx context.Context
}

func getAuthAttrsFromInstance(ctx context.Context, instanceID string) (model.ConsoleAuthAttributes, error) {
inst, err := model.Instances(ctx).FindByID(instanceID)
if err != nil {
log.WithError(err).Errorf("Unknown instance: %s", instanceID)
return nil, err
}
instResource, ok := inst.ResourceTemplate().(model.ConsoleAuthAttributes)
if !ok {
return nil, errors.Errorf("%T does not support model.ConsoleAuthAttributes", inst.ResourceTemplate())
}
return instResource, nil
}

func NewSSHServer(provider hypervisor.HypervisorProvider, ctx context.Context) *SSHServer {
config := &ssh.ServerConfig{
NoClientAuth: true,
PasswordCallback: func(conn ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the password authentication enabled? Just NONE and PUB_KEY are listed in model.proto.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Library of SSH can't call PublickeyCallBack if does not designate public key. Therefore if client don't designate public key then server authenticate client by using PasswordCallback without password.

authAttrs, err := getAuthAttrsFromInstance(ctx, conn.User())
if err != nil {
return nil, err
}
switch authAttrs.GetAuthenticationType() {
case model.AuthenticationType_NONE:
return nil, nil
case model.AuthenticationType_PUB_KEY:
if authAttrs.GetSshPublicKey() != "" {
return nil, fmt.Errorf("%s auth type is public key but client configured to password auth", conn.User())
}
}
return nil, fmt.Errorf("%s is using undefind AuthenticationType", conn.User())
},
PublicKeyCallback: func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
authAttrs, err := getAuthAttrsFromInstance(ctx, conn.User())
if err != nil {
return nil, err
}
switch authAttrs.GetAuthenticationType() {
case model.AuthenticationType_NONE:
return nil, nil
case model.AuthenticationType_PUB_KEY:
zkPubKey := strings.TrimSpace(authAttrs.GetSshPublicKey())
var clientPubkey string
if key != nil {
clientPubkey = strings.TrimSpace(string(ssh.MarshalAuthorizedKey(key)))
}

if zkPubKey == clientPubkey {
return nil, nil
} else {
log.Errorf("Private key mismatch with database public key")
return nil, fmt.Errorf("Private key mismatch with database public key")
}
default:
return nil, fmt.Errorf("Unknown AuthenticationType")
}
},
}

return &SSHServer{
Expand Down
40 changes: 37 additions & 3 deletions cmd/openvdc/cmd/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package cmd
import (
"fmt"
"io"
"io/ioutil"
"net"
"os"
"strings"
"time"

log "github.com/Sirupsen/logrus"
"github.com/axsh/openvdc/cmd/openvdc/cmd/console"
Expand All @@ -21,6 +23,7 @@ import (

func init() {
consoleCmd.Flags().Bool("show", false, "Show console information")
consoleCmd.Flags().StringP("identity-file", "i", "", "Selects a file from which the identity (private key) for public key authentication is read")
}

var consoleCmd = &cobra.Command{
Expand All @@ -46,6 +49,7 @@ var consoleCmd = &cobra.Command{
}

var res *api.ConsoleReply

err := util.RemoteCall(func(conn *grpc.ClientConn) error {
ic := api.NewInstanceClient(conn)
var err error
Expand All @@ -56,7 +60,7 @@ var consoleCmd = &cobra.Command{
log.WithError(err).Fatal("Failed request to Instance.Console API")
}

info, err := cmd.Flags().GetBool("show")
info, _ := cmd.Flags().GetBool("show")
switch res.Type {
case model.Console_SSH:
if info {
Expand All @@ -71,8 +75,38 @@ var consoleCmd = &cobra.Command{
fmt.Println("")
return nil
}
sshcon := console.NewSshConsole(instanceID, nil)
var err error

var config = &ssh.ClientConfig{
Timeout: 5 * time.Second,
Auth: []ssh.AuthMethod{
ssh.Password(""),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}

switch res.AuthType {
case model.AuthenticationType_NONE:
config.Auth = []ssh.AuthMethod{ssh.Password("")}
case model.AuthenticationType_PUB_KEY:
identityFile, _ := cmd.Flags().GetString("identity-file")
if identityFile == "" {
log.Fatalf("Required private key but not setted")
}

// Parse and set indetifyFifle
key, err := ioutil.ReadFile(identityFile)
if err != nil {
log.Fatalf("unable to read private key: %v", err)
}
// Create the Signer for this private key.
signer, err := ssh.ParsePrivateKey(key)
if err != nil {
log.Fatalf("unable to parse private key: %v", err)
}
config.Auth = []ssh.AuthMethod{ssh.PublicKeys(signer)}
}

sshcon := console.NewSshConsole(instanceID, config)
if len(execArgs) > 0 {
err = sshcon.Exec(res.GetAddress(), execArgs)
} else {
Expand Down
4 changes: 4 additions & 0 deletions cmd/openvdc/cmd/console/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func NewSshConsole(instanceID string, config *ssh.ClientConfig) *SshConsole {
if config == nil {
config = &ssh.ClientConfig{
Timeout: 5 * time.Second,
Auth: []ssh.AuthMethod{
ssh.Password(""),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}
}
return &SshConsole{
Expand Down
4 changes: 4 additions & 0 deletions cmd/openvdc/cmd/copy/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func NewClient(cr *api.CopyReply) (*Client, error) {

config := &ssh.ClientConfig{
User: cr.GetInstanceId(),
Auth: []ssh.AuthMethod{
ssh.Password(""),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}

return &Client{
Expand Down
Loading