Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Fallback to local authentication #112

Open
mmehra opened this issue Feb 28, 2018 · 5 comments
Open

Fallback to local authentication #112

mmehra opened this issue Feb 28, 2018 · 5 comments

Comments

@mmehra
Copy link

mmehra commented Feb 28, 2018

When TACACS+ server is not reachable, it might be desirable to fall back to local authentication. In order to achieve it, pam_tacplus needs to return PAM_IGNORE return code instead of PAM_ERROR. Following diff provides this support

[~: pam_tacplus]# git diff
diff --git a/pam_tacplus.c b/pam_tacplus.c
index f29f45e..b62093e 100644
--- a/pam_tacplus.c
+++ b/pam_tacplus.c
@@ -291,6 +291,7 @@ int pam_sm_authenticate(pam_handle_t * pamh, int flags, int argc,
                if (tac_fd < 0) {
                        _pam_log(LOG_ERR, "connection failed srv %d: %m", srv_i);
                        active_server.addr = NULL;
+                       status = PAM_IGNORE;
                        continue;
                }
                if (tac_authen_send(tac_fd, user, pass, tty, r_addr,
@@ -587,7 +588,7 @@ int pam_sm_acct_mgmt(pam_handle_t * pamh, int flags, int argc,
         than TACACS+ */
        if (active_server.addr == NULL) {
                _pam_log(LOG_ERR, "user not authenticated by TACACS+");
-               return PAM_AUTH_ERR;
+               return PAM_IGNORE;
        }
        if (ctrl & PAM_TAC_DEBUG)
                syslog(LOG_DEBUG, "%s: active server is [%s]", __FUNCTION__,

We can then configure following in /etc/pam.d/tacacs so that SSHD fallsback to local authentication when TACACS+ server is not reachable. When the server is reachable, SSHD always honours TACACS+ auth response

auth    [success=done default=bad authinfo_unavail=bad ignore=ignore] /lib/security/pam_tacplus.so ...
account [success=done default=bad ignore=ignore] /lib/security/pam_tacplus.so ...
@daveolson53
Copy link

daveolson53 commented Feb 28, 2018 via email

@mmehra
Copy link
Author

mmehra commented Feb 28, 2018

Config knob might not be needed after all. Here is what can be done with PAM constructs

When fallback to local auth is desired:

[root@gotham: ~]# head /etc/pam.d/sshd 
auth     include     tacacs
account  include     tacacs

[root@gotham: ~]# head /etc/pam.d/tacacs
auth    [success=done default=bad authinfo_unavail=bad ignore=ignore] /lib/security/pam_tacplus.so ...
account [success=done default=bad ignore=ignore] /lib/security/pam_tacplus.so ...

When fallback to local auth is not desired:

[root@gotham: ~]# head /etc/pam.d/sshd 
auth     include     tacacs
auth     requisite   pam_deny.so
account  include     tacacs

[root@gotham: ~]# head /etc/pam.d/tacacs
auth  sufficient /lib/security/pam_tacplus.so ...
account sufficient /lib/security/pam_tacplus.so ...

@daveolson53
Copy link

daveolson53 commented Feb 28, 2018 via email

@mmehra
Copy link
Author

mmehra commented Feb 28, 2018

Sure, we can even go with explicit option and depending on the config option return PAM_IGNORE or PAM_FAILURE

@stancufm
Copy link

stancufm commented Dec 5, 2022

Unfortunately, for me it didn't work with authinfo_unavail=bad.
In logs i found that i was keep receiving "pam_sm_authenticate: exit with pam status: 9". After i've changed to
auth [default=bad success=done ignore=ignore authinfo_unavail=ignore] /usr/local/lib/pam_tacplus.so is working.
Tests were made with tacacs server running (where user has password1 set), and for fallback scenario i've stopped the tac_plus service from server and use local password2 defined.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants