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

added certificate authentication for ssh authentication #18017

Closed
wants to merge 2 commits into from

Conversation

sherodtaylor
Copy link
Contributor

This pull request addresses #14413. It adds certificate support for the ssh provisioner. It adds a new parameter certificate which is used to authenticate ssh sessions. I updated the provisioner_test and docs to reflect this.

@sherodtaylor sherodtaylor changed the title added certificate for ssh authentication added certificate authentication for ssh authentication May 9, 2018
@sherodtaylor
Copy link
Contributor Author

@apparentlymart is there anyway we can get this into the next release. We need this to provision our environment. I updated the tests and it works perfectly in our staging environment.

@sherodtaylor
Copy link
Contributor Author

@apparentlymart any update on this? We really need it.

remove debug logs

update err log

add debug logs

logging
@sherodtaylor
Copy link
Contributor Author

@catsby or any other contributor can this get a look. We have a production deployment coming up and this would be really nice to get in the next release :)

Copy link
Contributor

@catsby catsby left a comment

Choose a reason for hiding this comment

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

Question about unit testing the new method.

Additionally, what is the user experience if the user supplies a certificate but does not supply the private key? The documentation says that to use certificate they must also provide the private key, is there a way we can check this in code, rather than just failing during the connection attempt?

@@ -254,6 +269,31 @@ func buildSSHClientConfig(opts sshClientConfigOpts) (*ssh.ClientConfig, error) {
return conf, nil
}

// Create a Cert Signer and return ssh.AuthMethod
func signCertWithPrivateKey(pk string, certificate string) (ssh.AuthMethod, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this something we can add unit tests for? My knowledge of SSH and certificates is fairly shallow, so forgive me if I'm asking a silly question

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don’t know how the unit tests work for this provisioner.

@@ -105,6 +110,7 @@ func TestProvisioner_connInfoHostname(t *testing.T) {
"user": "root",
"password": "supersecret",
"private_key": "someprivatekeycontents",
"certificate": "somecertificate",
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's remove somecertificate from one of these 3 tests, and use that test to verify that conf.Certificate remains an empty string. Because it's optional, I'd like to see at least one test verify the exclusion still works as expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

@sherodtaylor
Copy link
Contributor Author

sherodtaylor commented May 16, 2018

@catsby the fail check is handled in line of provisioner.go 139

@apparentlymart
Copy link
Contributor

Hi @sherodtaylor! Thanks for working on this, and sorry for the slow response on my part.

It looks like you've already been working on some feedback with @catsby here, which is great! I just wanted to let you know that your PR here has a small conflict with a bigger development branch we have in progress for updating the configuration language in the next major release, and so I'd like to hold on merging this until we've merged that branch into master.

At that point we can also give some pointers on ways to test this code... the communicator_test.go file has some tests that use an in-process mock SSH server, but I expect that mock will need some adjustments to also support client certs, and so we can work together to figure out the best way to do that.

Sorry again for the slow response here. The current configuration language project work is taking our attention a lot more than usual due to how many of Terraform's subsystems need small updates to work with it.

@sherodtaylor
Copy link
Contributor Author

@apparentlymart thanks for the response! The bulk of the changes where made in the provisioner.go I was looking at the communicator. Is it better for me to add or move a test from communicator_test.go to provision_test.go? Or I was thinking I could do a unit test on the function signCertWithPrivateKey to test if it returns a valid public key certificate. I don't know which is better.

@sherodtaylor
Copy link
Contributor Author

@apparentlymart how long until the development branch gets merged? Is there any guidance you can give me on the unit testing aspect?

@sherodtaylor
Copy link
Contributor Author

@apparentlymart See the above pr ^^. I've added some better unit tests for communicator_test.go

@ghost
Copy link

ghost commented Mar 29, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants