Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding client authentication with public key fuction. #181

Open
wants to merge 66 commits into
base: master
Choose a base branch
from

Conversation

itouri
Copy link
Contributor

@itouri itouri commented Jun 16, 2017

$ ./openvdc console -h
Connect to an instance.

Usage:
  openvdc console [Instance ID] [options] [--] [commands] [flags]

Examples:

% openvdc console i-000000001
root@i-00000001#

% echo ls | openvdc console i-000000001
% cat test.sh | openvdc console i-000000001


Flags:
  -i, --identity-file string   Selects a file from which the identity (private key) for public key authentication is read
      --show                   Show console information

@Metallion Metallion requested a review from unakatsuo July 4, 2017 05:03


RunCmdWithTimeoutAndReportFail(t, 10, 5, "openvdc", "destroy", instance_id)
WaitInstance(t, 5*time.Minute, instance_id, "TERMINATED", nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this a test for console authentication? It just starts an instance and then terminates it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added code to test the console. And change function name to TestCmdConsole_ShowOptionAuthenticationNone.

@itouri itouri changed the title Console auth Adding attribute of authentication to json schema. Aug 3, 2017
@itouri itouri changed the title Adding attribute of authentication to json schema. Adding client authentication with public key. Aug 10, 2017
@itouri itouri changed the title Adding client authentication with public key. Adding client authentication with public key fuction. Aug 10, 2017
}
}

// Check that the key is in SECSH format.
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to support SECSH format at this version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed that part into a comment.

}

keyStr := string(key[:])
// Check that the key is in OpenSSH format.
Copy link
Contributor

@unakatsuo unakatsuo Aug 22, 2017

Choose a reason for hiding this comment

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

Why do you check same thing that happens in ssh.ParsePublicKey()?

https://github.com/golang/crypto/blob/eb71ad9bd329b5ac0fd0148dd99bd62e8be8e035/ssh/keys.go#L246-L258

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ssh.ParsePublicKey() can parse only RFC4253 format key. Therefore if we want to parse other type public key then we must parse by own.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see.

return handlers.ErrInvalidTemplate(h, "ssh_public_key is not set")
}

isValidate := validatePublicKey([]byte(sshPubKey))
Copy link
Contributor

Choose a reason for hiding this comment

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

Just call ssh.ParsePublicKey() then return the error from the function. This function squash the error details from ssh.ParsePublicKey().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the return type of validatePublicKey([]byte) to error.

Copy link
Contributor

@Metallion Metallion left a comment

Choose a reason for hiding this comment

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

I think this is almost ok but it just needs a test to confirm that openvdc console fails when the wrong private key is provided.

@@ -21,6 +22,23 @@ func runConsoleCmd(instance_id string, t *testing.T) {
RunCmdAndExpectFail(t, "sh", "-c", fmt.Sprintf("openvdc console %s -- false", instance_id))
}

func runConsoleCmdWithPrivatekey(instance_id string, private_key_path string, t *testing.T) {
RunCmdAndReportFail(t, "openvdc", "console", instance_id, "-i", private_key_path)
RunCmdAndReportFail(t, "sh", "-c", fmt.Sprintf("openvdc console %s -i %s ls", instance_id, private_key_path))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use sh here? Why not just do this?

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

Also you should run gofmt on this file and any other files that aren't formatted correctly. It's best to set up your editor to run it on save.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test function integrate to TestLXCCmdConsole_AuthenticationPubkeymethod and modified to doesn't using "sh".

RunCmdAndReportFail(t, "sh", "-c", fmt.Sprintf("openvdc console %s -i %s ls", instance_id, private_key_path))
RunCmdAndReportFail(t, "sh", "-c", fmt.Sprintf("openvdc console %s -i %s -- ls", instance_id, private_key_path))
RunCmdAndExpectFail(t, "sh", "-c", fmt.Sprintf("openvdc console %s -i %s -- false", instance_id, private_key_path))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You should also confirm that the console command fails when you provide the wrong private key.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added TestLXCCmdConsole_AuthenticationPubkeymethod testing worng key.

itouri and others added 3 commits October 13, 2017 18:40
# Conflicts:
#	model/model.pb.go
#	model/resource_templates.go
#	registry/bindata_assetfs.go
Copy link
Contributor

@Metallion Metallion left a comment

Choose a reason for hiding this comment

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

Since the ESXi feature was merged to master, the tests started failing on this one.

# github.com/axsh/openvdc/scheduler
scheduler/mesos.go:174: cannot use esxi (type *model.EsxiTemplate) as type model.InstanceResource in argument to model.IsMatchingNodeGroups:
	*model.EsxiTemplate does not implement model.InstanceResource (missing GetAuthenticationType method)

I know this is annoying since it worked before, but you'll have to update to code to work with the latest master.

RunCmdAndExpectFail(t, "openvdc", "console", instance_id, "-i", private_key_path)
} else {
RunCmdAndReportFail(t, "openvdc", "console", instance_id, "-i", private_key_path)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is only called twice. Once with expect_fail = true and once with expect_fail = false.

Since only one line gets executed for each call, I think it's better to write those lines directly in the test instead of in a separate function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted runConsoleCmdWithPrivatekey and integrated to TestLXCCmdConsole_AuthenticationPubkey.

case model.AuthenticationType_PUB_KEY:
if indentityFile == "" {
log.Fatalf("Required private key but not setted")
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

no need for the else block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted it.

@@ -19,8 +21,11 @@ import (
"google.golang.org/grpc"
)

var indentityFile string
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo and no need to be defined as a global variable. Can be refered as cmd.Flags().GetString("identity-file").

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modified typo and using to GetString()

proto/v1.proto Outdated
@@ -90,6 +90,7 @@ message ConsoleReply {
string instance_id = 1 [json_name="instance_id"];
model.Console.Transport type = 2;
string address = 3;
model.AuthenticationType authType = 4;
Copy link
Contributor

Choose a reason for hiding this comment

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

Breaks the convention.

model.AuthenticationType auth_type = 4 [json_name="auth_type"];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added json_name tag for auth_type.

if err := flags.Parse(args); err != nil {
return err
}
mdst.Vcpu = int32(vcpu)
mdst.MemoryGb = int32(mem)
format := model.AuthenticationType_value[strings.ToUpper(authType)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing the validation if --authtication_type gets unknown value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added validation of authtication_type to lxc.go and qemu.go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants