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

Don't provision SSH key by default on AWS #12011

Merged
merged 1 commit into from
Jul 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 cmd/kops/create_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func NewCmdCreateCluster(f *util.Factory, out io.Writer) *cobra.Command {
return []string{"containerd", "docker"}, cobra.ShellCompDirectiveNoFileComp
})

cmd.Flags().StringVar(&sshPublicKey, "ssh-public-key", sshPublicKey, "SSH public key to use (defaults to ~/.ssh/id_rsa.pub on AWS)")
cmd.Flags().StringVar(&sshPublicKey, "ssh-public-key", sshPublicKey, "SSH public key to use")
cmd.RegisterFlagCompletionFunc("ssh-public-key", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"pub"}, cobra.ShellCompDirectiveFilterFileExt
})
Expand Down Expand Up @@ -700,8 +700,7 @@ func RunCreateCluster(ctx context.Context, f *util.Factory, out io.Writer, c *Cr
if len(c.SSHPublicKeys) == 0 {
autoloadSSHPublicKeys := true
switch c.CloudProvider {
case "gce":
// We don't normally use SSH keys on GCE
case "gce", "aws":
autoloadSSHPublicKeys = false
}

Expand Down
2 changes: 1 addition & 1 deletion docs/cli/kops_create_cluster.md

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

3 changes: 3 additions & 0 deletions docs/releases/1.22-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ spec:

## Other significant changes

* New clusters on AWS will no longer provision an SSH public key by default. To provision
an SSH public key on a new cluster, use the `--ssh-public-key` flag to `kops create cluster`.

* The kOps Terraform support now renders managed files through the Terraform configuration instead
of writing them to S3 directly. This defers changes to these files until the time of `terraform apply`.
This feature may be temporarily disabled by turning off the `TerraformManagedFiles` feature flag
Expand Down
9 changes: 6 additions & 3 deletions pkg/model/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,14 @@ func (b *KopsModelContext) UseEtcdTLS() bool {
return false
}

// UseSSHKey returns true if SSHKeyName from the cluster spec is not set to an empty string (""). Setting SSHKeyName
// to an empty string indicates that an SSH key should not be set on instances.
// UseSSHKey returns true if SSHKeyName from the cluster spec is set to a nonempty string
// or there is an SSH public key provisioned in the key store.
func (b *KopsModelContext) UseSSHKey() bool {
sshKeyName := b.Cluster.Spec.SSHKeyName
return sshKeyName == nil || *sshKeyName != ""
if sshKeyName == nil {
return len(b.SSHPublicKeys) > 0
}
return *sshKeyName != ""
}

// KubernetesVersion parses the semver version of kubernetes, from the cluster spec
Expand Down
4 changes: 0 additions & 4 deletions upup/pkg/fi/cloudup/apply_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,6 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
modelContext.AWSAccountID = accountID
modelContext.AWSPartition = partition

if len(sshPublicKeys) == 0 && c.Cluster.Spec.SSHKeyName == nil {
return fmt.Errorf("SSH public key must be specified when running with AWS (create with `kops create secret --name %s sshpublickey admin -i ~/.ssh/id_rsa.pub`)", cluster.ObjectMeta.Name)
}

if len(sshPublicKeys) > 1 {
return fmt.Errorf("exactly one 'admin' SSH public key can be specified when running with AWS; please delete a key using `kops delete secret`")
}
Expand Down