NAME

Langertha::Holmgang::Sim::Linux::SshAccess - Whether a user can log in over SSH: port, firewall, Match, account, authorized_keys, StrictModes

VERSION

version 0.001

SYNOPSIS

use Langertha::Holmgang::Sim::Linux::SshAccess ();

my ( $ok, $client, @log ) = Langertha::Holmgang::Sim::Linux::SshAccess::check( $dev, {
    user => 'anna', from => '10.1.0.77', key => 'ssh-ed25519 AAAAC3Nz…',
    iif  => 'eth1', daddr => '10.1.0.20',          # for the firewall (optional)
    port => 22, auth => 'publickey',                 # defaults
}, 'srv1' );
# ( 1, 'Welcome …' ) or ( 0, 'anna@srv1: Permission denied (publickey).', 'Authentication refused: …' )

DESCRIPTION

A user's login to the OpenSSH server of a simulated Linux device (cai-platform docs/entwurf-evals.md §3.3.1), built on Langertha::Holmgang::Sim::Linux::Sshd. Checked in the order in which sshd sees it:

1. Service ssh is running, Port of the loaded configuration matches (otherwise "Connection refused"); the nftables firewall lets the connection through (Langertha::Holmgang::Sim::Linux::Nft, otherwise "Connection timed out").
2. The configuration for this connection: global (first value wins) and on top the matching Match sections (User, Group, Address, LocalPort, all; patterns with *, ?, ! and CIDR), within a matching section again the first value.
3. Account (present, not expired, valid shell), PermitRootLogin (no; prohibit-password denies root the password; forced-commands-only admits only keys with command=), DenyUsers/AllowUsers/DenyGroups/AllowGroups.
4. Key: PubkeyAuthentication, the files from AuthorizedKeysFile (%h, %u, %%, relative to the home directory), with StrictModes (default yes) the permissions: the file and every directory up to the home directory belong to the user or root and are not writable by group and others; options from="…" of the key line. Password (auth: password): PasswordAuthentication and a password on the account, not locked.

What sshd has loaded is in services.ssh._loaded (texts of the configuration files at the time of start, restart or reload); if it is missing, the files of the initial state apply ("remember"). A change to /etc/ssh/sshd_config thus takes effect only after reload/restart — as with sshd. Users in the state:

users:
  anna: { uid: 1001, groups: [anna, devs], home: /home/anna, shell: /bin/bash, password: true }
dirs:  { /home/anna: { owner: anna, group: anna, mode: "0755" }, /home/anna/.ssh: { owner: anna, mode: "0700" } }
files: { /home/anna/.ssh/authorized_keys: { owner: anna, mode: "0600", content: "ssh-ed25519 AAAA… anna@laptop\n" } }
ssh_tries: [ { user: anna, from: 10.1.0.77, key: "ssh-ed25519 AAAA…", iif: eth1, daddr: 10.1.0.20 } ]

ssh_tries are login attempts by others (e.g. the colleague from the incident report); the journal of ssh shows for each the lines sshd would write ("journal").

remember

remember($dev);

Records which sshd configuration is loaded (texts under /etc/ssh), if that has not happened yet — before the first command of a case and after every successful load of the service ("loaded").

loaded

loaded($dev);   # after start/restart/reload of ssh

config_for

my $eff = config_for( $dev, { user, from, groups => [...], port } );

The settings of the loaded configuration for this connection (keys lower case, lists as lists).

match_overrides

my $set = match_overrides( $dev, { user, from, groups, port }, 1 );

Only the values that matching Match sections set; with a true third argument from the files (like sshd -T -C), otherwise from the loaded configuration.

check

my ( $ok, $client, @log ) = check( $dev, \%attempt, $host );

$ok 1/0, $client the ssh client's message, @log the lines of sshd (without timestamp).

journal

my @lines = journal( $dev, $host );

Lines of sshd for the login attempts ssh_tries (with timestamp), checked against the current state.

SUPPORT

Issues

Please report bugs and feature requests at https://github.com/Getty/langertha-holmgang/issues.

IRC

Join #langertha on irc.perl.org or message Getty directly.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <torsten@raudssus.de>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> https://raudssus.de/.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.