Skip to content
This repository was archived by the owner on Dec 26, 2020. It is now read-only.

Conversation

@lazzurs
Copy link
Contributor

@lazzurs lazzurs commented Jul 10, 2017

Adding Google Authenticator second factor auth to SSH.

This requires password auth to be disabled and SSH key based auth to be used along side the 2FA support.

If this is acceptable I would be happy to replicate the work in the Puppet and Chef modules that you do too.

lazzurs added 7 commits June 27, 2017 19:43
This adds the PAM module package, changes the SSHd configuration and the
PAM configuration on RedHat and Debian systems to allow TOTP based
second factor auth to work with SSH keys.
This will remove password auth from RedHat distros to ensure that only
key based auth and 2FA codes can be used to authenticate users over SSH.
I had accidently placed this under an SELinux block rather than at the
end of it as I had planned. Now placed before the SELinux block to be
clear.
This will allow the current tests to run as they are failing because
this is not defined. A better step would be to add some tests.
@rndmh3ro
Copy link
Member

I am on vacation right now and will have a look afterwards.
From first look it seems really good!

@rndmh3ro rndmh3ro self-assigned this Jul 13, 2017
@rndmh3ro rndmh3ro self-requested a review July 16, 2017 19:35
lineinfile: "dest=/etc/pam.d/sshd state=present insertbefore=BOF regexp='pam_google_authenticator.so$' line='auth required pam_google_authenticator.so'"
notify: restart sshd

- name: Remove password auth from PAM
Copy link
Member

Choose a reason for hiding this comment

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

I haven't tested it yet, but is it possible to use the pamd module instead of replace and lineinfile?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting. I will go and have a look at the module and see if it would work. I was trying to ensure I was not bringing in any additional external dependencies but using a module for this would be nicer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mostly done, I could not see how to remove the include with the Ansible PAM support.

# Enable PAM to enforce system wide rules
UsePAM {{ 'yes' if ssh_use_pam else 'no' }}
{% if ssh_google_auth %}
AuthenticationMethods publickey,keyboard-interactive
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment before this line indicating that it's here because of 2fa?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to, will get this pushed up later today.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Using the Ansible PAM support rather than regex based line editing for
two out of the three PAM changes required for 2FA support.

The last change does not appear to be supported by the Ansible PAM
support unless I have missed something from the documentation.
This makes it clear why the ordering is public key then keyboard
interactive.
@lazzurs
Copy link
Contributor Author

lazzurs commented Aug 11, 2017

I have made the requested changes. Let me know if there is anything else I can do to improve this.

Thanks for the help.

Copy link
Contributor Author

@lazzurs lazzurs left a comment

Choose a reason for hiding this comment

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

Changes as requested.

@rndmh3ro
Copy link
Member

rndmh3ro commented Nov 9, 2017

Thanks for rebasing, sorry that I did not react sooner. :(

Could you remove this line: https://github.com/dev-sec/ansible-ssh-hardening/pull/123/files#diff-2444ad0870f91f17ca6c2a5e96b26823R66

Then I'll merge!

@rndmh3ro rndmh3ro merged commit 8a4046b into dev-sec:master Dec 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants