Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2 factor authentication (2 step verification) with Google compute engine

Is there a possibility to enable 2 factor authentication (or 2 step verification a-la Google terminology) for Google compute engine? I'm interested in protecting my VMs, cloud storage and the developers console.

I've tried using the Google Authenticator (libapm) referring to this article Securing SSH with two factor authentication using Google Authenticator on a VM but it didn't succeed (I managed to login with the gcloud compute shell with no additional code).

[Jan 12th] Some updates: Google developer console works perfectly. Thanks.

For 2-step verification with the compute-engine SSH access, I retried everything all over again. Followed the instructions mentioned in the links provided, and did the following:

  • I created a new Google-Cloud project.
  • I used 2 different OS instances - Debian 8.2 and Ubuntu 15.10.

All of these tests failed - there was no prompt for a verification code. I looked around in the Google compute-engine documentation, and they mention explicitly they support only certificate authentication (rather than username/password), so I cannot verify whether this is the root cause.

Is there anyone using 2-step verification with Google compute-engine?

Thanks

like image 670
Homer Avatar asked Dec 24 '15 09:12

Homer


1 Answers

At last - a solution (thanks for Google cloud support).

A couple of updates on top of the document I have referred to:

Apart of adding a line to /etc/pam.d/sshd, one should also comment out the @include common-auth line. So it should be something like:

auth       required     pam_google_authenticator.so # from the original instructions
# @include common-auth # commenting out is new...

Apart of changing the ChallengeResponseAuthentication property in /etc/ssh/sshd_config, one should also add AuthenticationMethods publickey,keyboard-interactive in the following line:

ChallengeResponseAuthentication yes # from the original instructions
AuthenticationMethods publickey,keyboard-interactive # this is new... 

Of course, this is on top of the regular instructions of installing libpam-google-authenticator, changing the sshd and sshd_config (as mentioned above), restarting the ssh/sshd service, and setting up the google-authenticator for the account.

Finally, a few more points:

  1. Consider this carefully - from restarting the ssh/sshd account, no one can login without proper 2FA. So make sure anyone who should have ssh access - configured it properly.
  2. I'm contemplating whether this is the proper solution for us, as it requires setup the VMs (each VM separately), and manual setting up the authenticator per each account and each VM manually. Not sure how scalable is this alternative. I would appreciate your thoughts...
  3. Last but not least - the setup of libpam-google-authenticator may be simplified by using apt-get, no need for manually installing all dependencies and building it. Worked for me by running:

    sudo apt-get install libpam-google-authenticator

Good Luck!

like image 120
Homer Avatar answered Sep 18 '22 23:09

Homer