Почему этим пользователям не нужна двухфакторная аутентификация PAM для входа в систему?

Почему этим пользователям не нужна двухфакторная аутентификация PAM для входа в систему?

Я унаследовал систему от ушедшего коллеги. Он установил в системе двухфакторную аутентификацию, за исключением пользователя rootи ftpupload.

Однако есть этот конкретный пользователь, который имеет доступ по SSH, но не нуждается в двухфакторной аутентификации. Этот пользователь может просто войти в систему с помощью имени пользователя и пароля!

Я заметил, что он установил, что всем пользователям в группе disable2faтребуется двухфакторная аутентификация. Я вижу только следующих пользователей в этой группе:

$ getent group disable2fa
disable2fa:x:2003:root,publicftpupload

Я проверил файл PAM ( sudo nano /etc/pam.d/sshd) и вижу следующее:

# PAM configuration for the Secure Shell service

# Standard Un*x authentication.
@include common-auth

# Disallow non-root logins when /etc/nologin exists.
account    required     pam_nologin.so

# Uncomment and edit /etc/security/access.conf if you need to set complex
# access limits that are hard to express in sshd_config.
# account  required     pam_access.so

# Standard Un*x authorization.
@include common-account

# SELinux needs to be the first session rule.  This ensures that any
# lingering context has been cleared.  Without this it is possible that a
# module could execute code in the wrong domain.
session [success=ok ignore=ignore module_unknown=ignore default=bad]        pam_selinux.so close

# Set the loginuid process attribute.
session    required     pam_loginuid.so

# Create a new session keyring.
session    optional     pam_keyinit.so force revoke

# Standard Un*x session setup and teardown.
@include common-session

# Print the message of the day upon successful login.
# This includes a dynamically generated part from /run/motd.dynamic
# and a static (admin-editable) part from /etc/motd.
session    optional     pam_motd.so  motd=/run/motd.dynamic
session    optional     pam_motd.so noupdate

# Print the status of the user's mailbox upon successful login.
session    optional     pam_mail.so standard noenv # [1]

# Set up user limits from /etc/security/limits.conf.
session    required     pam_limits.so

# Read environment variables from /etc/environment and
# /etc/security/pam_env.conf.
session    required     pam_env.so # [1]
# In Debian 4.0 (etch), locale-related environment variables were moved to
# /etc/default/locale, so read that as well.
session    required     pam_env.so user_readenv=1 envfile=/etc/default/locale

# SELinux needs to intervene at login time to ensure that the process starts
# in the proper default security context.  Only sessions which are intended
# to run in the user's context should be run after this.
session [success=ok ignore=ignore module_unknown=ignore default=bad]        pam_selinux.so open

# Standard Un*x password updating.
@include common-password
auth [success=done default=ignore] pam_succeed_if.so user ingroup disable2fa
auth required pam_google_authenticator.so nullok

Есть ли еще что-то, что мне нужно проверить? Кто-нибудь может помочь? Спасибо!

решение1

Вот что делает эта строка:

auth [success=done default=ignore] pam_succeed_if.so user ingroup disable2fa

Отman pam.d:

ok
   this tells PAM that the administrator thinks this return code should contribute
   directly to the return code of the full stack of modules. In other words, if the
   former state of the stack would lead to a return of PAM_SUCCESS, the module's return
   code will override this value. Note, if the former state of the stack holds some value
   that is indicative of a modules failure, this 'ok' value will not be used to override
   that value.

done
   equivalent to ok with the side effect of terminating the module stack and PAM
   immediately returning to the application.

По сути, success=doneэто означает, что если этот модуль завершается успешно, то больше ничего проверять не нужно, поэтому последующий модуль pam_google_authenticator.soпропускается, если этот модуль завершается успешно, а этот модуль просто проверяет,пользователь — это группаdisable2fa:

user ingroup group
   User is in given group.

решение2

Вероятно, вы можете деконфигурировать строки «user ingroup disable2fa» в файлах конфигурации PAM и заменить их настройкой, описанной в:

https://codeberg.org/kpiq/Tech-Space/wiki/2FA-Authenticator-app-%28any-compatible-with-Google-Authenticator%29-setup-for-Ubuntu-Jammy

Таким образом, только пользователи, которые настроили свои токены Google Authenticator (файл ~/.google_authenticator), получат запрос на код подтверждения. Настройка "user ingroup" была для меня вопросительным знаком, пока я не нашел аргумент nullok в документации.

Отлично работает!

Связанный контент