Difference between revisions of "Google Authenticator"

From Michael's Information Zone
Jump to navigation Jump to search
 
(32 intermediate revisions by the same user not shown)
Line 1: Line 1:
==CentOS 7==
+
==Docker==
https://www.linuxsysadmintutorials.com/setup-sudo-with-google-authenticator-for-2-factor-authentication-on-centos-7.html
+
<ref>https://github.com/rharmonson/richtech/wiki/Two-Factor-Authentication-using-FreeRADIUS-with-SSSD-(FreeIPA-or-Active-Directory)-and-Google-Authenticator-on-CentOS-7</ref>
 
+
The purpose of this container is to run freeradius with google authenticator pam modules loaded. Taken from a production system that runs freeradius and apache for a full featured solution allowing users to request new codes without bothering IT.
yum install -y git autoconf automake make libtool pam-devel
+
===Host Prep===
git clone https://github.com/google/google-authenticator
+
This is not a fully contained solution. I ran into problems with SSS and kerberose authentication into AD. The problem stems from two sides
cd google-authenticator/libpam
+
<br>
./bootstrap.sh
+
<br>
./configure
+
1. The kerberos works out of the secure kernel. Which causes unprivileged containers the inability to access this. <ref>https://blog.tomecek.net/post/kerberos-in-a-container/</ref>
./make
+
<br>
./make install
+
2. Kerberos likes a stable network. Containers tend to jump around and this causes problems.
ln -s /usr/local/lib/security/pam_google_authenticator.so /usr/lib64/security/pam_google_authenticator.so
+
<br>
yum install freeradius
+
<br>
ln -s /etc/raddb/mods-enabled/pam /etc/raddb/mods-available/pam
+
So I settled on enrolling the host into AD as those are more stable, and because I will be using EC2 instances until I learn the orchastrator in AWS.
sed -i 's/user = freerad/user = root/' /etc/raddb/radiusd.conf
+
*Make sure your DNS solution is configured to resolve the domain you want to authenticate to.
sed -i 's/group = freerad/group - root/' /etc/raddb/radiusd.conf
 
nano /etc/raddb/users
 
 
<pre>
 
<pre>
DEFAULT Group == “GG_S_GOOGLE_AUTH_DISABLED”, Auth-Type := Reject
+
sudo yum -y upgrade
Reply-Message = “Your account has been disabled.”
+
sudo yum -y install yum-cron oddjob oddjob-mkhomedir sssd samba-common-tools realmd docker
DEFAULT Auth-Type := PAM
+
sudo realm join -U <username> <domain>
 
</pre>
 
</pre>
sed -i 's/^#\ \ \ \ \ \ \ pam/\ \ \ \ \ \ \ \ pam/' /etc/raddb/sites-enabled/default
+
===Container build===
Comment out all lines in /etc/pam.d/radiusd then add the following
+
I normally work with CentOS while the FreeRadius containers are based on Debian/Ubuntu. So for this we want to build our own image using the following template. This could be made smaller if I would compile the pam module outside the container and simply add it in, but I wanted to compile it the container just for the fun of it. This makes a number of packages unnecessary.<ref>https://axdlog.com/2016/using-google-authenticator-to-set-up-multi-factor-authentication-on-gnu-linux/</ref><ref>https://github.com/Elemental-IRCd/elemental-ircd/issues/100</ref>
echo auth requisite pam_google_authenticator.so forward_pass >> /etc/pam.d/radiusd
+
<br>
echo auth required pam_lsass.so use_first_pass >> /etc/pam.d/radiusd
+
<br>
==Ubuntu 16.04 LTS==
 
sudo wget http://download.beyondtrust.com/PBISO/8.0.1/linux.deb.x64/pbis-open-8.0.1.2029.linux.x86_64.deb.sh
 
git clone https://github.com/google/google-authenticator
 
cd google-authenticator/libpam/
 
sudo apt install dh-autoreconf
 
sudo ./bootstrap.sh
 
./configure
 
sudo make
 
sudo make install
 
sudo apt install freeradius
 
sudo sed -i 's/^user\ =\ freerad/user\ =\ root/' /etc/freeradius/radiusd.conf
 
sudo sed -i 's/^group\ =\ freerad/user\ =\ root/' /etc/freeradius/radiusd.conf
 
sudo nano /etc/freeradius/users
 
 
<pre>
 
<pre>
#
+
FROM centos:7.6.1810
# Deny access for a group of users.
+
RUN yum -y upgrade
#
+
RUN yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# Note that there is NO 'Fall-Through' attribute, so the user will not
+
##Google Auth Steps
# be given any additional resources.
+
RUN yum install -y google-authenticator \
#
+
        git \
#DEFAULT        Group == "disabled", Auth-Type := Reject
+
        autoconf \
#              Reply-Message = "Your account has been disabled."
+
        dh-autoreconf \
#
+
        cmake \
DEFAULT Group == “CSP-VMWare.GoogleAuth”, Auth-Type := Reject
+
        automake \
Reply-Message = “Your account has been disabled.
+
        libtool.x86_64 \
DEFAULT Auth-Type := PAM
+
        pam-devel mailx
 +
RUN git clone https://github.com/google/google-authenticator-libpam.git
 +
RUN cd /google-authenticator-libpam; ./bootstrap.sh
 +
RUN cd /google-authenticator-libpam; ./configure && make; make install
  
#
+
##Freeradius steps
</pre>
+
RUN yum -y install freeradius \
sudo sed -i 's/^#\ \ \ \ \ \ \ pam/\ \ \ \ \ \ \ \ pam/' /etc/freeradius/sites-enabled/default
+
        freeradius-utils
sudo nano /etc/pam.d/radiusd
+
RUN sed -i 's/user\ =\ radiusd/user\ =\ root/; s/group\ =\ radiusd/group\ =\ root/' /etc/raddb/radiusd.conf
<pre>
+
RUN sed -i "s/^#\\tpam/\\tpam/" /etc/raddb/sites-enabled/default
#
+
RUN ln -s /etc/raddb/mods-available/pam /etc/raddb/mods-enabled/pam
# /etc/pam.d/radiusd - PAM configuration for FreeRADIUS
+
RUN echo -e " \n\
#
+
client vcs-vdi-01 { \n\
 +
        secret          = your_secret_here\n\
 +
        shortname      = vcs01 \n\
 +
        ipaddr          = 10.xxx.xxx.0 \n\
 +
        netmask        = 23 \n\
 +
} \n\
 +
" >> /etc/raddb/clients.conf
 +
RUN echo "DEFAULT Auth-Type := PAM" >> /etc/raddb/users
 +
RUN rm -f /etc/pam.d/radiusd; echo -e "auth      required    pam_google_authenticator.so\n\
 +
account    required    pam_nologin.so\n\
 +
account    include      password-auth\n\
 +
session    include      password-auth\n\
 +
" >> /etc/pam.d/radiusd
  
# We fall back to the system default in /etc/pam.d/common-*
+
##Kerberos config
#
+
RUN yum -y install krb5-workstation \
 +
        openldap-clients \
 +
        mysql \
 +
        realmd \
 +
        oddjob \
 +
        oddjob-mkhomedir \
 +
        sssd \
 +
        samba-common-tools && yum clean all
  
#@include common-auth
+
COPY run.sh /run.sh
#@include common-account
+
RUN chmod +x /run.sh
#@include common-password
+
#CMD /run.sh
#@include common-session
 
auth requisite pam_google_authenticator.so forward_pass
 
auth required pam_lsass.so use_first_pass
 
 
</pre>
 
</pre>
sudo systemctl start freeradius
+
Build the image
sudo nano /etc/freeradius/clients.conf
 
*Modify the following to match your environment
 
 
<pre>
 
<pre>
#client some.host.org {
+
sudo docker build -t googleauth -f Dockerfile .
#      secret          = testing123
 
#      shortname      = localhost
 
#}
 
 
</pre>
 
</pre>
ie
+
 
 +
===Start Container===
 +
This is old style of binding host kerberos config to container, this is no longer needed but still works.
 
<pre>
 
<pre>
client vcs-vdi-my.domain.com {
+
sudo docker run --name radtest -dit -v /var/lib/sss:/var/lib/sss -v /home/ec2-user/ga_codes/home:/home -v /home/ec2-user/ga_scripts:/ga_scripts -v /home/ec2-user/ga_web:/ga_web -p 1812:1812  googleauth2
      secret          = Imadeasecret!
 
      shortname      = vcs
 
}
 
 
</pre>
 
</pre>

Latest revision as of 16:08, 30 March 2022

Docker

[1] The purpose of this container is to run freeradius with google authenticator pam modules loaded. Taken from a production system that runs freeradius and apache for a full featured solution allowing users to request new codes without bothering IT.

Host Prep

This is not a fully contained solution. I ran into problems with SSS and kerberose authentication into AD. The problem stems from two sides

1. The kerberos works out of the secure kernel. Which causes unprivileged containers the inability to access this. [2]
2. Kerberos likes a stable network. Containers tend to jump around and this causes problems.

So I settled on enrolling the host into AD as those are more stable, and because I will be using EC2 instances until I learn the orchastrator in AWS.

  • Make sure your DNS solution is configured to resolve the domain you want to authenticate to.
sudo yum -y upgrade
sudo yum -y install yum-cron oddjob oddjob-mkhomedir sssd samba-common-tools realmd docker
sudo realm join -U <username> <domain>

Container build

I normally work with CentOS while the FreeRadius containers are based on Debian/Ubuntu. So for this we want to build our own image using the following template. This could be made smaller if I would compile the pam module outside the container and simply add it in, but I wanted to compile it the container just for the fun of it. This makes a number of packages unnecessary.[3][4]

FROM centos:7.6.1810
RUN yum -y upgrade
RUN yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
##Google Auth Steps
RUN yum install -y google-authenticator \
        git \
        autoconf \
        dh-autoreconf \
        cmake \
        automake \
        libtool.x86_64 \
        pam-devel mailx
RUN git clone https://github.com/google/google-authenticator-libpam.git
RUN cd /google-authenticator-libpam; ./bootstrap.sh
RUN cd /google-authenticator-libpam; ./configure && make; make install

##Freeradius steps
RUN yum -y install freeradius \
        freeradius-utils
RUN sed -i 's/user\ =\ radiusd/user\ =\ root/; s/group\ =\ radiusd/group\ =\ root/' /etc/raddb/radiusd.conf
RUN sed -i "s/^#\\tpam/\\tpam/" /etc/raddb/sites-enabled/default
RUN ln -s /etc/raddb/mods-available/pam /etc/raddb/mods-enabled/pam
RUN echo -e " \n\
client vcs-vdi-01 { \n\
        secret          = your_secret_here\n\
        shortname       = vcs01 \n\
        ipaddr          = 10.xxx.xxx.0 \n\
        netmask         = 23 \n\
} \n\
" >> /etc/raddb/clients.conf
RUN echo "DEFAULT Auth-Type := PAM" >> /etc/raddb/users
RUN rm -f /etc/pam.d/radiusd; echo -e "auth       required     pam_google_authenticator.so\n\
account    required     pam_nologin.so\n\
account    include      password-auth\n\
session    include      password-auth\n\
" >> /etc/pam.d/radiusd

##Kerberos config
RUN yum -y install krb5-workstation \
        openldap-clients \
        mysql \
        realmd \
        oddjob \
        oddjob-mkhomedir \
        sssd \
        samba-common-tools && yum clean all

COPY run.sh /run.sh
RUN chmod +x /run.sh
#CMD /run.sh

Build the image

sudo docker build -t googleauth -f Dockerfile .

Start Container

This is old style of binding host kerberos config to container, this is no longer needed but still works.

sudo docker run --name radtest -dit -v /var/lib/sss:/var/lib/sss -v /home/ec2-user/ga_codes/home:/home -v /home/ec2-user/ga_scripts:/ga_scripts -v /home/ec2-user/ga_web:/ga_web -p 1812:1812  googleauth2