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

Allow specifying a SSH key name for AWS #3215

Merged

Conversation

johnzeringue
Copy link
Contributor

Related to #2309, this allows naming an existing key pair using the
cluster spec field sshKeyName.

In our use case, kops can now be used without providing the ability to
create EC2 key pairs.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 16, 2017
@k8s-ci-robot
Copy link
Contributor

Hi @johnzeringue. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 16, 2017
@johnzeringue
Copy link
Contributor Author

/assign @zmerlynn

Copy link
Contributor

@chrislovecnm chrislovecnm left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Question for you and we will need documentation as well, please.

@@ -116,14 +116,21 @@ func (b *KopsModelContext) LinkToIAMInstanceProfile(ig *kops.InstanceGroup) *aws
return &awstasks.IAMInstanceProfile{Name: &name}
}

// SSHKeyName computes a unique SSH key name, combining the cluster name and the SSH public key fingerprint
// SSHKeyName computes a unique SSH key name, combining the cluster name and the SSH public key fingerprint.
// If an SSH key name is provided in the cluster configuration, it will use that instead.
func (c *KopsModelContext) SSHKeyName() (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Dumb questions, but when we do a delete a cluster do we delete the key? We have an approach of having shared items, such as https://github.com/kubernetes/kops/blob/master/upup/pkg/fi/cloudup/awstasks/vpc.go#L43. We would probably want that as well, and it may help with delete.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

when we do a delete a cluster do we delete the key?

I don't think we should. I'm not sure what's been done in the past, but I think that things created by kops should be deleted by kops and things not created by kops should not be deleted by kops.

I don't fully understand the current behavior on deletion (the task lifecycle is hard to follow in my IDE), but my intention is not to delete.

Copy link
Contributor

Choose a reason for hiding this comment

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

@johnzeringue yes we should not delete a shared pre-existing ssh key. Does kops try with your changes?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, this is just re-using the aws key, not the ssh public key that is installed on the users' machine? Correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@johnzeringue yes we should not delete a shared pre-existing ssh key. Does kops try with your changes?

In our testing, it seems not.

Also, this is just re-using the aws key, not the ssh public key that is installed on the users' machine? Correct?

Yes

@chrislovecnm
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 18, 2017
@chrislovecnm
Copy link
Contributor

/assign

@justinsb
Copy link
Member

Code looks good - thanks @johnzeringue

I had to check, but looking at the existing code we do compute the AWS-style-fingerprint and thus don't rely on the name. We currently embed the fingerprint in the name to avoid collisions and because we can't change a public key - and nor can we tag SSH public keys. And that means we don't delete the key as part of cluster deletion.

But ... I'm wondering about the use case here. I never thought of the ability to create an SSH key as something particularly powerful (but do LMK!) We have the lifecycle work going on, which will separate out IAM & SSH permissions, and I know some people have wanted to split those further. But if the motivation here is to minimize the amount of permissions needed, it seems like the IAM permissions are the big one, not the permission to register an AWS public key!

That said I don't think these are blocking issues to the PR, I would just like to better understand the use case. I was pondering the name - whether we should put this into an SSH section, but we don't have any other SSH fields (other than SSHAccess, which would logically better fit into a networking section anyway) - so I think the schema change is fine.

@justinsb justinsb assigned justinsb and unassigned zmerlynn Aug 20, 2017
@johnzeringue
Copy link
Contributor Author

@justinsb the use case is separating the ability to provision EC2 instances with the ability to access those instances. There are other ways to do it, but preventing key creation is an easy way to create a strong access barrier.

@johnzeringue
Copy link
Contributor Author

Documentation added

@johnzeringue
Copy link
Contributor Author

@justinsb any more feedback on this? I'm happy to hop on Slack if you want to talk about use case more in depth

@chrislovecnm
Copy link
Contributor

You may need a rebase to get e2e passing.

Related to kubernetes#2309, this allows naming an existing key pair using the
cluster spec field `sshKeyName`.

In our use case, kops can now be used without providing the ability to
create EC2 key pairs.
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 7, 2017
@johnzeringue
Copy link
Contributor Author

@chrislovecnm I tried rebasing, but e2e is still failing. Not quite sure what's wrong from the logs. Any tips?

@chrislovecnm
Copy link
Contributor

@johnzeringue we have been having problems with e2e. Most likely flakey testing not your code. How have you tested?

/retest

@johnzeringue
Copy link
Contributor Author

@chrislovecnm we created a new cluster in AWS with a preexisting SSH key. We verified that we could SSH into instances using the preexisting key. We destroyed the cluster and saw that it did not delete or attempt to delete the preexisting key.

@ApsOps
Copy link
Contributor

ApsOps commented Sep 18, 2017

I've felt the need for this use-case too. Is this ready to be merged?

@chrislovecnm I think you mentioned someone else instead of @justinsb by mistake 😅

@chrislovecnm
Copy link
Contributor

@justinsb we good with this PR? I may need this as well.

@chrislovecnm
Copy link
Contributor

Thanks @ApsOps

@chrislovecnm
Copy link
Contributor

I know certain parties are super busy, merging this in, we can iterate if needs be

@chrislovecnm
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 21, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chrislovecnm

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 21, 2017
@chrislovecnm
Copy link
Contributor

@johnzeringue you mind filing an issue to add validation that this is aws only? I think, may be wrong, that GCE does not have this feature

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue. .

@k8s-github-robot k8s-github-robot merged commit 66b9838 into kubernetes:master Sep 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants