Skip to content

Commit

Permalink
Disable ssh password auth (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
alvaroaleman authored Apr 29, 2018
1 parent 76e06ef commit 25c35e4
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 3 deletions.
3 changes: 2 additions & 1 deletion examples/machine-digitalocean.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ spec:
backups: false
ipv6: false
private_networking: true
monitoring: true
# Monitoring must be turned off for CoreOS Container Linux
monitoring: false
tags:
- "machine-controller"
# Can be 'ubuntu', 'coreos' or 'centos'
Expand Down
5 changes: 4 additions & 1 deletion pkg/controller/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,9 @@ func (c *Controller) updateMachineError(machine *machinev1alpha1.Machine, reason
// and at the same time terminal error will be returned to the caller
// otherwise it will return formatted error according to errMsg
func (c *Controller) updateMachineErrorIfTerminalError(machine *machinev1alpha1.Machine, stReason machinev1alpha1.MachineStatusError, stMessage string, err error, errMsg string) error {
c.recorder.Eventf(machine, corev1.EventTypeWarning, string(stReason), stMessage)
if ok, _, _ := cloudprovidererrors.IsTerminalError(err); ok {
if _, errNested := c.updateMachineError(machine, machinev1alpha1.DeleteMachineError, stMessage); errNested != nil {
if _, errNested := c.updateMachineError(machine, stReason, stMessage); errNested != nil {
return fmt.Errorf("failed to update machine error after due to %v, terminal error = %v", errNested, stMessage)
}
return err
Expand Down Expand Up @@ -496,11 +497,13 @@ func (c *Controller) ensureInstanceExistsForMachine(prov cloud.Provider, machine

kubeconfig, err := c.createBootstrapKubeconfig(machine.Name)
if err != nil {
c.recorder.Eventf(machine, corev1.EventTypeWarning, "CreateBootstrapKubeconfigFailed", "Creating bootstrap kubeconfig failed: %v", err)
return fmt.Errorf("failed to create bootstrap kubeconfig: %v", err)
}

userdata, err := userdataProvider.UserData(machine.Spec, kubeconfig, prov, c.clusterDNSIPs)
if err != nil {
c.recorder.Eventf(machine, corev1.EventTypeWarning, "UserdataRenderingFailed", "Userdata rendering failed: %v", err)
return fmt.Errorf("failed get userdata: %v", err)
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/userdata/centos/testdata/docker-1.13-aws.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#cloud-config
hostname: node1

ssh_pwauth: no



write_files:
Expand Down
2 changes: 2 additions & 0 deletions pkg/userdata/centos/userdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ package_upgrade: true
package_reboot_if_required: true
{{- end }}
ssh_pwauth: no
{{ if ne (len .ProviderConfig.SSHPublicKeys) 0 }}
ssh_authorized_keys:
{{- range .ProviderConfig.SSHPublicKeys }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@
"verification": {}
},
"mode": 384
},
{
"filesystem": "root",
"group": {
"id": 0
},
"path": "/etc/ssh/sshd_config",
"user": {
"id": 0
},
"contents": {
"source": "data:,%23%20Use%20most%20defaults%20for%20sshd%20configuration.%0ASubsystem%20sftp%20internal-sftp%0AClientAliveInterval%20180%0AUseDNS%20no%0AUsePAM%20yes%0APrintLastLog%20no%20%23%20handled%20by%20PAM%0APrintMotd%20no%20%23%20handled%20by%20PAM%0APasswordAuthentication%20no%0AChallengeResponseAuthentication%20no%0A",
"verification": {}
},
"mode": 384
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@
"verification": {}
},
"mode": 384
},
{
"filesystem": "root",
"group": {
"id": 0
},
"path": "/etc/ssh/sshd_config",
"user": {
"id": 0
},
"contents": {
"source": "data:,%23%20Use%20most%20defaults%20for%20sshd%20configuration.%0ASubsystem%20sftp%20internal-sftp%0AClientAliveInterval%20180%0AUseDNS%20no%0AUsePAM%20yes%0APrintLastLog%20no%20%23%20handled%20by%20PAM%0APrintMotd%20no%20%23%20handled%20by%20PAM%0APasswordAuthentication%20no%0AChallengeResponseAuthentication%20no%0A",
"verification": {}
},
"mode": 384
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@
"verification": {}
},
"mode": 384
},
{
"filesystem": "root",
"group": {
"id": 0
},
"path": "/etc/ssh/sshd_config",
"user": {
"id": 0
},
"contents": {
"source": "data:,%23%20Use%20most%20defaults%20for%20sshd%20configuration.%0ASubsystem%20sftp%20internal-sftp%0AClientAliveInterval%20180%0AUseDNS%20no%0AUsePAM%20yes%0APrintLastLog%20no%20%23%20handled%20by%20PAM%0APrintMotd%20no%20%23%20handled%20by%20PAM%0APasswordAuthentication%20no%0AChallengeResponseAuthentication%20no%0A",
"verification": {}
},
"mode": 384
}
]
},
Expand Down
19 changes: 19 additions & 0 deletions pkg/userdata/coreos/userdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,23 @@ storage:
mode: 0600
contents:
inline: '{{ .MachineSpec.Name }}'
- path: /etc/ssh/sshd_config
filesystem: root
mode: 0600
user:
id: 0
group:
id: 0
contents:
inline: |
# Use most defaults for sshd configuration.
Subsystem sftp internal-sftp
ClientAliveInterval 180
UseDNS no
UsePAM yes
PrintLastLog no # handled by PAM
PrintMotd no # handled by PAM
PasswordAuthentication no
ChallengeResponseAuthentication no
`
2 changes: 1 addition & 1 deletion pkg/userdata/coreos/userdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestProvider_UserData(t *testing.T) {

userdata, err := p.UserData(spec, kubeconfig, test.ccProvider, test.DNSIPs)
if err != nil {
return
t.Fatal(err)
}

golden := filepath.Join("testdata", test.name+".golden")
Expand Down
2 changes: 2 additions & 0 deletions pkg/userdata/ubuntu/testdata/cri-o-1.9-digitalocean.golden
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ hostname: node1

package_update: true

ssh_pwauth: no

ssh_authorized_keys:
- "ssh-rsa AAABBB"
- "ssh-rsa CCCDDD"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package_update: true
package_upgrade: true
package_reboot_if_required: true

ssh_pwauth: no

ssh_authorized_keys:
- "ssh-rsa AAABBB"
- "ssh-rsa CCCDDD"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package_update: true
package_upgrade: true
package_reboot_if_required: true

ssh_pwauth: no

ssh_authorized_keys:
- "ssh-rsa AAABBB"
- "ssh-rsa CCCDDD"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package_update: true
package_upgrade: true
package_reboot_if_required: true

ssh_pwauth: no

ssh_authorized_keys:
- "ssh-rsa AAABBB"
- "ssh-rsa CCCDDD"
Expand Down
2 changes: 2 additions & 0 deletions pkg/userdata/ubuntu/userdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ package_upgrade: true
package_reboot_if_required: true
{{- end }}
ssh_pwauth: no
ssh_authorized_keys:
{{- range .ProviderConfig.SSHPublicKeys }}
- "{{ . }}"
Expand Down

0 comments on commit 25c35e4

Please sign in to comment.