summaryrefslogtreecommitdiff
path: root/src/conf_mode/system-login.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2022-10-12 09:02:37 +0200
committerGitHub <noreply@github.com>2022-10-12 09:02:37 +0200
commit6951fa7ef6ea4a2715b9083d654f6cf3f3b60213 (patch)
tree694540848ff0a3ef4fa1ede3659f68bb459c1787 /src/conf_mode/system-login.py
parentb74f297d8a7426cbdb0b44240bfa4b7666986337 (diff)
parent765f84386b6e94984ff79db2eab36d51f759159b (diff)
downloadvyos-1x-6951fa7ef6ea4a2715b9083d654f6cf3f3b60213.tar.gz
vyos-1x-6951fa7ef6ea4a2715b9083d654f6cf3f3b60213.zip
Merge pull request #1555 from goodNETnick/ssh_otp
system login: T874: add 2FA support for local and ssh authentication
Diffstat (limited to 'src/conf_mode/system-login.py')
-rwxr-xr-xsrc/conf_mode/system-login.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/conf_mode/system-login.py b/src/conf_mode/system-login.py
index dbd346fe4..bd9cc3b89 100755
--- a/src/conf_mode/system-login.py
+++ b/src/conf_mode/system-login.py
@@ -253,7 +253,20 @@ def apply(login):
user_config, permission=0o600,
formater=lambda _: _.replace("&quot;", '"'),
user=user, group='users')
-
+ #OTP 2FA key file generation
+ if dict_search('authentication.otp.key', user_config):
+ user_config['authentication']['otp']['key'] = user_config['authentication']['otp']['key'].upper()
+ user_config['authentication']['otp']['rate_limit'] = login['authentication']['otp']['rate_limit']
+ user_config['authentication']['otp']['rate_time'] = login['authentication']['otp']['rate_time']
+ user_config['authentication']['otp']['window_size'] = login['authentication']['otp']['window_size']
+ render(f'{home_dir}/.google_authenticator', 'login/pam_otp_ga.conf.j2',
+ user_config, permission=0o600,
+ formater=lambda _: _.replace("&quot;", '"'),
+ user=user, group='users')
+ #OTP 2FA key file deletion
+ elif os.path.exists(f'{home_dir}/.google_authenticator'):
+ os.remove(f'{home_dir}/.google_authenticator')
+
except Exception as e:
raise ConfigError(f'Adding user "{user}" raised exception: "{e}"')