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

Add tagging support for AWS Keypairs #9533

Merged
merged 3 commits into from
Jul 29, 2020

Conversation

rifelpet
Copy link
Member

@rifelpet rifelpet commented Jul 9, 2020

AWS recently added tagging support for keypairs as well as autogenerated IDs. This adds the usual cloud tags to keypairs as seen in the integration test outputs.

WIP while I figure out how to handle keys that are shared with the cluster rather than created by kops- would we tag it with "shared" like with do VPCs and Subnets or do we not tag it at all?

Also need to double check how kops deletes keypairs during a delete cluster and make sure these tags don't affect that process.

ref: #9640

At this point we could probably drop the cluster name prefix from key names but that's probably not necessary.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 9, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rifelpet

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

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot requested review from hakman and olemarkus July 9, 2020 04:17
@k8s-ci-robot k8s-ci-robot added area/provider/aws Issues or PRs related to aws provider approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jul 9, 2020
@hakman
Copy link
Member

hakman commented Jul 9, 2020

/test pull-kops-e2e-kubernetes-aws

@@ -50,18 +50,25 @@ func (m *MockEC2) ImportKeyPair(request *ec2.ImportKeyPairInput) (*ec2.ImportKey
return nil, err
}

n := len(m.DhcpOptions) + 1
Copy link
Member

Choose a reason for hiding this comment

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

Do you want len(m.KeyPairs) ?

o := m.KeyPairs[id]
if o == nil {
return nil, fmt.Errorf("KeyPairs %q not found", id)
name := aws.StringValue(request.KeyName)
Copy link
Member

Choose a reason for hiding this comment

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

Can we / should we now delete by id?

tags = {
"KubernetesCluster" = "existing-iam.example.com"
"Name" = "existing-iam.example.com"
"kubernetes.io/cluster/existing-iam.example.com" = "owned"
Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think this should be shared, because we don't delete it (we couldn't safely delete it before); so it does behave more like "shared"

Copy link
Member

Choose a reason for hiding this comment

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

Actually, scratch that - I'm wrong! We do delete the keypairs, which is why we have the cluster name in the prefix, so owned is correct.

@justinsb
Copy link
Member

Generally LGTM. I was a little confused as to whether we delete keys or not; because/if we do, it should be 'owned', which is what you've done 👍

At this point we could probably drop the cluster name prefix from key names but that's probably not necessary.

Can we have duplicate SSH key names now? I assume we can't, so I would imagine if we dropped the prefix that we might get collisions if someone used the same SSH key for two clusters in the same region?

@rifelpet
Copy link
Member Author

rifelpet commented Jul 28, 2020

This is ready for review.

I had to make the SSHKey task aware of whether it is Shared or not. The intent is to not add any tags to keys that are specified in the ClusterSpec.sshKeyName. These tags aren't consumed by anything else (unlike shared VPC and Subnet tags) and may collide with tags from other clusters that also use the same sshKeyName, so I thought it was better to just not add the tags at all. In order to do that, we have to specify whether the key is shared or not. Previously we had the same task behavior regardless of whether a key was defined via sshKeyName or via a SSHPublicKey secret.

I tested the following scenarios:

  1. create new cluster with old kops and local ssh key file specified
  2. update cluster with new kops: correctly applies tags
  3. update cluster with new kops: no changes reported

  1. create new cluster with new kops and local ssh key file specified: correctly applies tags
  2. update cluster with new kops: no changes reported

  1. create new cluster with old kops and existing AWS sshKeyName specified in ClusterSpec:
  2. update cluster with new kops: no changes reported (key remains untagged)

  1. create new cluster with new kops and existing AWS sshKeyName specified in ClusterSpec:
  2. update cluster with new kops: no changes reported (key remains untagged)

  1. create new cluster with new kops and existing AWS sshKeyName specified in ClusterSpec
  2. update cluster --target terraform with new kops: no keypair resource defined (LaunchTemplate hardcodes key name)

  1. create new cluster with new kops and local ssh key file specified
  2. update cluster --target terraform with new kops: keypair resource is defined with tags

@rifelpet rifelpet changed the title WIP Add tagging support for AWS Keypairs Add tagging support for AWS Keypairs Jul 28, 2020
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 28, 2020
pkg/model/sshkey.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. area/addons and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 28, 2020
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 28, 2020
@hakman
Copy link
Member

hakman commented Jul 29, 2020

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 29, 2020
@k8s-ci-robot k8s-ci-robot merged commit 31b03c4 into kubernetes:master Jul 29, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.19 milestone Jul 29, 2020
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. area/addons area/provider/aws Issues or PRs related to aws provider 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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants