Skip to content

Commit 7750ae4

Browse files
committed
Allow key authentication for SSH proxy users
1 parent 4a14d94 commit 7750ae4

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎roles/ssh_proxy/tasks/main.yml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@
3737
append: false
3838
create_home: false
3939
shell: /usr/sbin/nologin
40-
password: "{{ item.authentication.password_hash | default('!') }}"
41-
password_lock: "{{ item.authentication.type != 'password' }}"
40+
# A leading ! or * marks the whole account as locked, so OpenSSH rejects public keys too.
41+
# "x" is not a usable crypt hash but leaves key-only accounts eligible for public-key auth.
42+
password: "{{ item.authentication.password_hash if item.authentication.type == 'password' else 'x' }}"
43+
password_lock: false
4244
update_password: always
4345
loop: "{{ megaproxy_services.ssh.users }}"
4446
when: not ansible_check_mode or megaproxy_group_current.rc == 0

‎tests/test_ssh_proxy_role.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from pathlib import Path
2+
3+
4+
ROOT = Path(__file__).resolve().parents[1]
5+
6+
7+
def test_key_only_account_is_not_locked_before_public_key_authentication() -> None:
8+
tasks = (ROOT / "roles" / "ssh_proxy" / "tasks" / "main.yml").read_text(encoding="utf-8")
9+
user_task = tasks.split("- name: Create restricted SSH proxy users", 1)[1].split(
10+
"- name: Explain deferred SSH user planning", 1
11+
)[0]
12+
13+
assert "else 'x'" in user_task
14+
assert "password_lock: false" in user_task

0 commit comments

Comments
 (0)