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

Remove automatic cloud-init option allowing PasswordAuthentication #124

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions tasks/ssh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
line: "X11Forwarding {{ security_ssh_x11_forwarding }}"
notify: restart ssh

- name: Ensure cloud-init conf does not still allow passwords anyway.
lineinfile:
dest: "{{ security_ssh_cloudinit_config_path }}"
regexp: "^PasswordAuthentication"
state: absent
Copy link
Owner

Choose a reason for hiding this comment

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

The way this is set up, it would still remove this option even if Password Auth is allowed, and it might also break on non-Ubuntu systems...

Copy link

Choose a reason for hiding this comment

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

- name: Apply same SSH configuration to Ubuntu cloud-init SSH configuration
  lineinfile:
    dest: "{{ security_ssh_cloud_init_config_path }}"
    regexp: "^PasswordAuthentication"
    line: "PasswordAuthentication {{ security_ssh_password_authentication }}"
    state: present
    validate: 'sshd -T -f %s'
    mode: 0600
  notify: restart ssh
  when: ansible_distribution == 'Ubuntu'

Would that be a better approach?

Copy link

Choose a reason for hiding this comment

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

I changed the Debian.yml to

---
security_ssh_config_path: /etc/ssh/sshd_config
security_ssh_config_dir_path: /etc/ssh/sshd_config.d
security_ssh_cloud_init_config_path: "{{ security_ssh_config_dir_path }}/50-cloud-init.conf"
security_sshd_name: ssh

validate: 'sshd -T -f %s'
mode: 0600
notify: restart ssh

- name: Add configured users allowed to connect over ssh
lineinfile:
dest: "{{ security_ssh_config_path }}"
Expand Down
1 change: 1 addition & 0 deletions vars/Debian.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
security_ssh_config_path: /etc/ssh/sshd_config
security_ssh_cloudinit_config_path: /etc/ssh/sshd_config.d/50-cloud-init.conf
security_sshd_name: ssh