mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-11-05 20:32:15 +00:00
Keep SSH fixture keys under a StrictModes-safe directory
This commit is contained in:
@@ -7,6 +7,7 @@ child processes belong to a temporary fixture; no systemd units are installed.
|
|||||||
import importlib.util
|
import importlib.util
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import pwd
|
||||||
import signal
|
import signal
|
||||||
import socket
|
import socket
|
||||||
import stat
|
import stat
|
||||||
@@ -66,7 +67,11 @@ def main():
|
|||||||
raise AssertionError("Expected the host namespace to be rejected")
|
raise AssertionError("Expected the host namespace to be rejected")
|
||||||
|
|
||||||
processes = []
|
processes = []
|
||||||
with tempfile.TemporaryDirectory(prefix="pmx-usbip-") as directory:
|
# StrictModes checks every ancestor of AuthorizedKeysFile. A private
|
||||||
|
# subdirectory of /tmp still fails because /tmp itself is world writable.
|
||||||
|
# Keep the disposable fixture below root's home without changing its SSH
|
||||||
|
# configuration, account settings or existing authorized_keys.
|
||||||
|
with tempfile.TemporaryDirectory(prefix="pmx-usbip-", dir=pwd.getpwuid(os.geteuid()).pw_dir) as directory:
|
||||||
root = Path(directory)
|
root = Path(directory)
|
||||||
log = root / "transport.log"
|
log = root / "transport.log"
|
||||||
with log.open("w") as log_handle:
|
with log.open("w") as log_handle:
|
||||||
@@ -148,7 +153,7 @@ StrictModes yes
|
|||||||
AllowUsers root
|
AllowUsers root
|
||||||
AllowTcpForwarding local
|
AllowTcpForwarding local
|
||||||
AllowStreamLocalForwarding local
|
AllowStreamLocalForwarding local
|
||||||
LogLevel ERROR
|
LogLevel VERBOSE
|
||||||
""")
|
""")
|
||||||
Path("/run/sshd").mkdir(exist_ok=True, mode=0o755)
|
Path("/run/sshd").mkdir(exist_ok=True, mode=0o755)
|
||||||
sshd = subprocess.Popen(["/usr/sbin/sshd", "-D", "-e", "-f", str(ssh_config)],
|
sshd = subprocess.Popen(["/usr/sbin/sshd", "-D", "-e", "-f", str(ssh_config)],
|
||||||
@@ -171,7 +176,7 @@ LogLevel ERROR
|
|||||||
wrong = check_ssh(remote | {"key": str(root / "wrong-client")})
|
wrong = check_ssh(remote | {"key": str(root / "wrong-client")})
|
||||||
assert wrong.returncode != 0 and "Permission denied" in wrong.stderr, wrong.stderr
|
assert wrong.returncode != 0 and "Permission denied" in wrong.stderr, wrong.stderr
|
||||||
accepted = check_ssh(remote)
|
accepted = check_ssh(remote)
|
||||||
assert accepted.returncode == 0, accepted.stderr
|
assert accepted.returncode == 0, accepted.stderr + "\n" + log.read_text()
|
||||||
manager.REMOTE_SOCKET = str(unix_path)
|
manager.REMOTE_SOCKET = str(unix_path)
|
||||||
args = manager.tunnel_args(remote | {"local_port": local_port})
|
args = manager.tunnel_args(remote | {"local_port": local_port})
|
||||||
args[1:1] = extra
|
args[1:1] = extra
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 8
|
timeout-minutes: 8
|
||||||
strategy:
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
python: ['3.11', '3.13']
|
python: ['3.11', '3.13']
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
Reference in New Issue
Block a user