Skip to content

Commit

Permalink
Merge pull request #7096 from austinmoore-/no-ssh-key
Browse files Browse the repository at this point in the history
Configuration to specify no SSH key
  • Loading branch information
k8s-ci-robot committed Jan 15, 2020
2 parents 8c6b74d + 4a88f7b commit dbfd7f1
Show file tree
Hide file tree
Showing 22 changed files with 2,302 additions and 85 deletions.
128 changes: 69 additions & 59 deletions cmd/kops/integration_test.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions docs/cluster_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,13 @@ spec:
sshKeyName: myexistingkey
```

If you want to create your instance without any SSH keys you can set this to an empty string:
```yaml
spec:
sshKeyName: ""
```


### useHostCertificates

Self-signed certificates towards Cloud APIs. In some cases Cloud APIs do have self-signed certificates.
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/kops/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type ClusterSpec struct {
// HTTPProxy defines connection information to support use of a private cluster behind an forward HTTP Proxy
EgressProxy *EgressProxySpec `json:"egressProxy,omitempty"`
// SSHKeyName specifies a preexisting SSH key to use
SSHKeyName string `json:"sshKeyName,omitempty"`
SSHKeyName *string `json:"sshKeyName,omitempty"`
// KubernetesAPIAccess is a list of the CIDRs that can access the Kubernetes API endpoint (master HTTPS)
KubernetesAPIAccess []string `json:"kubernetesApiAccess,omitempty"`
// IsolateMasters determines whether we should lock down masters so that they are not on the pod network.
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/kops/v1alpha1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ type ClusterSpec struct {
// HTTPProxy defines connection information to support use of a private cluster behind an forward HTTP Proxy
EgressProxy *EgressProxySpec `json:"egressProxy,omitempty"`
// SSHKeyName specifies a preexisting SSH key to use
SSHKeyName string `json:"sshKeyName,omitempty"`
SSHKeyName *string `json:"sshKeyName,omitempty"`
// EtcdClusters stores the configuration for each cluster
EtcdClusters []*EtcdClusterSpec `json:"etcdClusters,omitempty"`
// Component configurations
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/kops/v1alpha1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion pkg/apis/kops/v1alpha2/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ type ClusterSpec struct {
// HTTPProxy defines connection information to support use of a private cluster behind an forward HTTP Proxy
EgressProxy *EgressProxySpec `json:"egressProxy,omitempty"`
// SSHKeyName specifies a preexisting SSH key to use
SSHKeyName string `json:"sshKeyName,omitempty"`
SSHKeyName *string `json:"sshKeyName,omitempty"`
// KubernetesAPIAccess determines the permitted access to the API endpoints (master HTTPS)
// Currently only a single CIDR is supported (though a richer grammar could be added in future)
KubernetesAPIAccess []string `json:"kubernetesApiAccess,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/kops/v1alpha2/zz_generated.deepcopy.go

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

5 changes: 5 additions & 0 deletions pkg/apis/kops/zz_generated.deepcopy.go

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

7 changes: 4 additions & 3 deletions pkg/model/awsmodel/autoscalinggroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,10 @@ func (b *AutoscalingGroupModelBuilder) buildLaunchConfigurationTask(c *fi.ModelB
})
}

// @step: attach the ssh key to the instancegroup
if t.SSHKey, err = b.LinkToSSHKey(); err != nil {
return nil, err
if b.AWSModelContext.UseSSHKey() {
if t.SSHKey, err = b.LinkToSSHKey(); err != nil {
return nil, err
}
}

// @step: add the instancegroup userdata
Expand Down
7 changes: 7 additions & 0 deletions pkg/model/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,13 @@ func (m *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.
func (m *KopsModelContext) UseSSHKey() bool {
sshKeyName := m.Cluster.Spec.SSHKeyName
return sshKeyName == nil || *sshKeyName != ""
}

// KubernetesVersion parses the semver version of kubernetes, from the cluster spec
func (m *KopsModelContext) KubernetesVersion() semver.Version {
// TODO: Remove copy-pasting c.f. https://github.com/kubernetes/kops/blob/master/pkg/model/components/context.go#L32
Expand Down
8 changes: 4 additions & 4 deletions pkg/model/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,17 @@ func (b *KopsModelContext) LinkToIAMInstanceProfile(ig *kops.InstanceGroup) (*aw
// If an SSH key name is provided in the cluster configuration, it will use that instead.
func (c *KopsModelContext) SSHKeyName() (string, error) {
// use configured SSH key name if present
name := c.Cluster.Spec.SSHKeyName
if name != "" {
return name, nil
sshKeyName := c.Cluster.Spec.SSHKeyName
if sshKeyName != nil && *sshKeyName != "" {
return *sshKeyName, nil
}

fingerprint, err := pki.ComputeOpenSSHKeyFingerprint(string(c.SSHPublicKeys[0]))
if err != nil {
return "", err
}

name = "kubernetes." + c.Cluster.ObjectMeta.Name + "-" + fingerprint
name := "kubernetes." + c.Cluster.ObjectMeta.Name + "-" + fingerprint
return name, nil
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/model/sshkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ type SSHKeyModelBuilder struct {
var _ fi.ModelBuilder = &SSHKeyModelBuilder{}

func (b *SSHKeyModelBuilder) Build(c *fi.ModelBuilderContext) error {
if !b.UseSSHKey() {
return nil
}

name, err := b.SSHKeyName()
if err != nil {
return err
Expand Down
17 changes: 5 additions & 12 deletions protokube/pkg/gossip/mesh/mesh.pb.go

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

Loading

0 comments on commit dbfd7f1

Please sign in to comment.