Reformat and lint
This commit is contained in:
@ -54,7 +54,10 @@ def audit_process(
|
||||
data["command"] = cmd
|
||||
data["args"] = " ".join(cmd_args)
|
||||
|
||||
backend.audit(SubSystem.SSHD).write(operation, message, remote_ip, client, secret=None, secret_name=secret, **data)
|
||||
backend.audit(SubSystem.SSHD).write(
|
||||
operation, message, remote_ip, client, secret=None, secret_name=secret, **data
|
||||
)
|
||||
|
||||
|
||||
def audit_event(
|
||||
backend: SshecretBackend,
|
||||
@ -67,7 +70,10 @@ def audit_event(
|
||||
"""Add an audit event."""
|
||||
if not origin:
|
||||
origin = "UNKNOWN"
|
||||
backend.audit(SubSystem.SSHD).write(operation, message, origin, client, secret=None, secret_name=secret)
|
||||
backend.audit(SubSystem.SSHD).write(
|
||||
operation, message, origin, client, secret=None, secret_name=secret
|
||||
)
|
||||
|
||||
|
||||
def verify_key_input(public_key: str) -> str | None:
|
||||
"""Verify key input."""
|
||||
@ -118,14 +124,19 @@ def get_info_remote_ip(process: asyncssh.SSHServerProcess[str]) -> str | None:
|
||||
|
||||
return remote_ip
|
||||
|
||||
def get_info_allowed_registration(process: asyncssh.SSHServerProcess[str]) -> list[IPvAnyNetwork] | None:
|
||||
|
||||
def get_info_allowed_registration(
|
||||
process: asyncssh.SSHServerProcess[str],
|
||||
) -> list[IPvAnyNetwork] | None:
|
||||
"""Get allowed networks to allow registration from."""
|
||||
|
||||
allowed_registration = cast(list[IPvAnyNetwork] | None, process.get_extra_info("allow_registration_from", None))
|
||||
allowed_registration = cast(
|
||||
list[IPvAnyNetwork] | None,
|
||||
process.get_extra_info("allow_registration_from", None),
|
||||
)
|
||||
return allowed_registration
|
||||
|
||||
|
||||
|
||||
def get_optional_commands(process: asyncssh.SSHServerProcess[str]) -> dict[str, bool]:
|
||||
"""Get optional command state."""
|
||||
with_registration = cast(
|
||||
@ -236,7 +247,12 @@ async def dispatch_cmd_register(process: asyncssh.SSHServerProcess[str]) -> None
|
||||
allowed_networks = get_info_allowed_registration(process)
|
||||
if not allowed_networks:
|
||||
process.stdout.write("Unauthorized.\n")
|
||||
audit_process(backend, process, Operation.DENY, "Received registration command, but no subnets are allowed.")
|
||||
audit_process(
|
||||
backend,
|
||||
process,
|
||||
Operation.DENY,
|
||||
"Received registration command, but no subnets are allowed.",
|
||||
)
|
||||
return
|
||||
|
||||
remote_ip = get_info_remote_ip(process)
|
||||
@ -250,7 +266,12 @@ async def dispatch_cmd_register(process: asyncssh.SSHServerProcess[str]) -> None
|
||||
if client_address in network:
|
||||
break
|
||||
else:
|
||||
audit_process(backend, process, Operation.DENY, "Received registration command from unauthorized subnet.")
|
||||
audit_process(
|
||||
backend,
|
||||
process,
|
||||
Operation.DENY,
|
||||
"Received registration command from unauthorized subnet.",
|
||||
)
|
||||
process.stdout.write("Unauthorized.\n")
|
||||
return
|
||||
|
||||
@ -369,7 +390,6 @@ class AsshyncServer(asyncssh.SSHServer):
|
||||
self._conn.set_extra_info(client=client)
|
||||
self._conn.set_authorized_keys(key)
|
||||
else:
|
||||
|
||||
audit_event(
|
||||
self.backend,
|
||||
"Client denied due to policy",
|
||||
@ -380,8 +400,12 @@ class AsshyncServer(asyncssh.SSHServer):
|
||||
LOG.warning("Client connection denied due to policy.")
|
||||
elif self.registration_enabled:
|
||||
self._conn.set_extra_info(provided_username=username)
|
||||
self._conn.set_extra_info(allow_registration_from=self.allow_registration_from)
|
||||
LOG.warning("Registration enabled, and client is not recognized. Bypassing authentication.")
|
||||
self._conn.set_extra_info(
|
||||
allow_registration_from=self.allow_registration_from
|
||||
)
|
||||
LOG.warning(
|
||||
"Registration enabled, and client is not recognized. Bypassing authentication."
|
||||
)
|
||||
return False
|
||||
|
||||
LOG.debug("Continuing to regular authentication")
|
||||
|
||||
Reference in New Issue
Block a user