### Run integration tests on Debian 12 Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/development/setup.rst Example invocation using debian12 as the target OS, a good default if no preference. Full tests typically take 25 to 50 minutes. ```none tests/functional/docker/docker_build_and_run_tests.sh debian12 ``` -------------------------------- ### Bastion connection output example Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx-plugins-override/info.rst Example output shown when connecting to the bastion, displaying user alias, MFA status, bastion details, policy settings, and a BOFH excuse. ```text ~ You are user1 ~ ~ Your alias to connect to this bastion is: ~ alias bastion='ssh user1@testbastion.example.org -p 22 -t -- ' ~ Your alias to connect to this bastion with MOSH is: ~ alias bastionm='mosh --ssh="ssh -p 22 -t" user1@testbastion.example.org -- ' ~ ~ Multi-Factor Authentication (MFA) on your account: ~ - Additional password authentication is not required ~ - Additional password authentication bypass is disabled ~ - Additional password authentication is enabled and active ~ - Additional TOTP authentication is not required ~ - Additional TOTP authentication bypass is disabled ~ - Additional TOTP authentication is disabled ~ ~ I am testbastion-a.example.org, aka bastion ~ I have 42 registered accounts and 46 groups ~ I am a MASTER, which means I accept modifications ~ The networks I'm able to connect you to on the egress side are: all ~ The networks that are explicitly forbidden on the egress side are: none ~ My egress connection IP to remote servers is 192.0.2.45/32 ~ ...don't forget to whitelist me in your firewalls! ~ ~ The following policy applies on this bastion: ~ - The interactive mode (-i) is ENABLED ~ - The support of mosh is ENABLED ~ - Account expiration is DISABLED ~ - Keyboard input idle time for session locking is DISABLED ~ - Keyboard input idle time for session killing is DISABLED ~ - The forced "from" prepend on ingress keys is DISABLED ~ - The following algorithms are allowed for ingress SSH keys: rsa, ecdsa, ed25519 ~ - The RSA key size for ingress SSH keys must be between 2048 and 8192 bits ~ - The following algorithms are allowed for egress SSH keys: rsa, ecdsa, ed25519 ~ - The RSA key size for egress SSH keys must be between 2048 and 8192 bits ~ - The Multi-Factor Authentication (MFA) policy is ENABLED ~ ~ Here is your excuse for anything not working today: ~ BOFH excuse #444: ~ overflow error in /dev/null ``` -------------------------------- ### Review fine-grained install options with --help Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/basic.rst Shows all fine-grained options for the installation script, allowing control over what is managed by the script versus manually. ```shell /opt/bastion/bin/admin/install --help ``` -------------------------------- ### info command output example Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/plugins/open/info.rst Example output of the info command, showing user details, bastion information, and policy settings. ```shell ~ You are user1 ~ ~ Your alias to connect to this bastion is: ~ alias bastion='ssh user1@testbastion.example.org -p 22 -t -- ' ~ Your alias to connect to this bastion with MOSH is: ~ alias bastionm='mosh --ssh="ssh -p 22 -t" user1@testbastion.example.org -- ' ~ ~ Multi-Factor Authentication (MFA) on your account: ~ - Additional password authentication is not required ~ - Additional password authentication bypass is disabled ~ - Additional password authentication is enabled and active ~ - Additional TOTP authentication is not required ~ - Additional TOTP authentication bypass is disabled ~ - Additional TOTP authentication is disabled ~ ~ I am testbastion-a.example.org, aka bastion ~ I have 42 registered accounts and 46 groups ~ I am a MASTER, which means I accept modifications ~ The networks I'm able to connect you to on the egress side are: all ~ The networks that are explicitly forbidden on the egress side are: none ~ My egress connection IP to remote servers is 192.0.2.45/32 ~ ...don't forget to whitelist me in your firewalls! ~ ~ The following policy applies on this bastion: ~ - The interactive mode (-i) is ENABLED ~ - The support of mosh is ENABLED ~ - Account expiration is DISABLED ~ - Keyboard input idle time for session locking is DISABLED ~ - Keyboard input idle time for session killing is DISABLED ~ - The forced "from" prepend on ingress keys is DISABLED ~ - The following algorithms are allowed for ingress SSH keys: rsa, ecdsa, ed25519 ~ - The RSA key size for ingress SSH keys must be between 2048 and 8192 bits ~ - The following algorithms are allowed for egress SSH keys: rsa, ecdsa, ed25519 ~ - The RSA key size for egress SSH keys must be between 2048 and 8192 bits ~ - The Multi-Factor Authentication (MFA) policy is ENABLED ~ ~ Here is your excuse for anything not working today: ~ BOFH excuse #444: ~ overflow error in /dev/null ``` -------------------------------- ### Enable and start osh-sync-watcher on first setup Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/advanced.rst If the synchronization daemon was not already enabled and started (first slave instance for this master), configure it to start on boot and start it manually. ```shell systemctl enable osh-sync-watcher systemctl start osh-sync-watcher ``` -------------------------------- ### Enable MFA for a plugin (adminSudo example) Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/administration/mfa.rst Add the mfa_required option to a plugin configuration file (e.g., /etc/bastion/plugin.adminSudo.conf) to require MFA for that plugin. The file must be readable by the bastion-users group. Requires proper /etc/pam.d/ssh setup. ```shell { "mfa_required": "any" } ``` -------------------------------- ### Install yubico-piv-checker and mkhash-helper Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/basic.rst Install the yubico-piv-checker helper for PIV functionalities and the-bastion-mkhash-helper for generating type 8 and type 9 password hashes. ```shell /opt/bastion/bin/admin/install-yubico-piv-checker.sh -a /opt/bastion/bin/admin/install-mkhash-helper.sh -a ``` -------------------------------- ### Plugin configuration example (JSON) Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/plugins/restricted/accountAddPersonalAccess.rst Configuration file for the accountAddPersonalAccess plugin, located at /etc/bastion/plugin.accountAddPersonalAccess.conf. The example sets widest_v4_prefix to 24 and self_remote_user_only to true. ```json { "widest_v4_prefix": 24, "self_remote_user_only": true } ``` -------------------------------- ### Output of running the example test Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/development/tests.rst Expected output when running the example test, showing the test steps and their results. ```none 00m04 [--] *** [0010/0021] 320-base::help2 (timeout --foreground 30 ssh -F /tmp/bastiontest.pgoA5h/ssh_config -i /tmp/bastiontest.pgoA5h/account0key1file user.5000@bastion_debian10_target -p 22 -- --json-greppable --osh help) 00m05 [--] [ OK ] RETURN VALUE (0) 00m05 [--] [ OK ] MUST CONTAIN (OSH help) 00m05 [--] [ OK ] JSON VALUE (.error_code => OK) [ ] 00m05 [--] [ OK ] JSON VALUE (.command => help) [ ] 00m05 [--] [ OK ] JSON VALUE (.value => null) [ ] ``` -------------------------------- ### Show help for launch_tests_on_instance.sh Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/development/setup.rst Displays usage and all supported options for the underlying test script. The output shown may not be up to date; run the command yourself for current information. ```none tests/functional/launch_tests_on_instance.sh --help Usage: /home/user/bastion/tests/functional/launch_tests_on_instance.sh [OPTIONS] Test Options: --consistency-check Check system consistency between every test --no-pause-on-fail Don't pause when a test fails --log-prefix=X Prefix all logs by this name --module=X Only test this module (specify a filename found in `functional/tests.d/`), can be specified multiple times Remote OS directory locations: --remote-etc-bastion=X Override the default remote bastion configuration directory (default: /etc/bastion) --remote-basedir=X Override the default remote basedir location (default: /home/user/bastion) Specifying features support of the underlying OS of the tested bastion: --has-ed25519=[0|1] Ed25519 keys are supported (default: 1) --has-mfa=[0|1] PAM is usable to check passwords and TOTP (default: 1) --has-mfa-password=[0|1] PAM is usable to check passwords (default: 0) --has-pamtester=[0|1] The `pamtester` binary is available, and PAM is usable (default: 1) --has-piv=[0|1] The `yubico-piv-tool` binary is available (default: 1) --has-sk=[0|1] The openssh-server supports Secure Keys (FIDO2) (default: 0) ``` -------------------------------- ### Install required packages with packages-check.sh -i Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/basic.rst Run this command to install the required packages for supported Linux distros. Add -s to install syslog-ng (advised) or -d for development packages (useless in production). ```shell /opt/bastion/bin/admin/packages-check.sh -i ``` -------------------------------- ### Run setup-encryption.sh helper script Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/basic.rst Guides through encrypting /home. When prompted, enter the passphrase chosen earlier. If a cryptsetup error occurs, you may need to add --type luks1 to the cryptsetup luksFormat command in the script. ```shell /opt/bastion/bin/admin/setup-encryption.sh ``` -------------------------------- ### Clone the repository Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/development/setup.rst Clone the the-bastion repository from GitHub. ```none git clone https://github.com/ovh/the-bastion ``` -------------------------------- ### Install bastion with --new-install Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/basic.rst For a new machine, regenerates host keys and hardens SSH configuration without side effects. ```shell /opt/bastion/bin/admin/install --new-install ``` -------------------------------- ### Install ovh-ttyrec with install-ttyrec.sh -a Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/basic.rst Detects your distro, downloads, and installs the precompiled .deb or .rpm package for ovh-ttyrec. Falls back to static binaries if the package type isn't handled. ```shell /opt/bastion/bin/admin/install-ttyrec.sh -a ``` -------------------------------- ### List plugins with bssh --osh help Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/using/basics/first_steps.rst Get a list of all available plugins. The list depends on your access level; some commands are restricted. ```shell bssh --osh help ``` -------------------------------- ### Configure first administrator account Source: https://github.com/ovh/the-bastion/blob/master/README.md Executes the setup script inside the running container to create the first admin account. Requires your public SSH key to be available. ```bash docker exec -it bastiontest /opt/bastion/bin/admin/setup-first-admin-account.sh poweruser auto ``` -------------------------------- ### Show plugin help with bssh --osh selfAddIngressKey --help Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/using/basics/first_steps.rst Get more information about a specific plugin command by using '--help' with it. ```shell bssh --osh selfAddIngressKey --help ``` -------------------------------- ### ingressToEgressRules example configuration Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/administration/configuration/bastion_conf.rst Example of the ingressToEgressRules configuration option, a JSON array of rules. Each rule is a 3-uple of [ingress networks, egress networks, policy]. The policy can be ALLOW, DENY, or ALLOW-EXCLUSIVE. Rules are processed in order; the first match applies. ```shell [ [["10.19.0.0/16","10.15.15.0/24"], ["10.20.0.0/16"], "ALLOW-EXCLUSIVE"], [["192.168.42.0/24"], ["192.168.42.0/24"], "ALLOW"], [["192.168.0.0/16"], ["192.168.0.0/16"], "DENY"] ] ``` -------------------------------- ### Example of open log entry Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/administration/logs.rst Shows a sample log line produced when a user establishes a session with the bastion. The log includes fields such as uniqid, version, user, account, cmdtype, allowed, IPs, ports, hostnames, plugin, globalsql, accountsql, comment, and params. ```shell Dec 28 11:12:26 myhostname bastion: open uniqid="e9e4baf6873b" version="3.01.03" pid="18721" ppid="18720" sysuser="gthreepw" sudo_user="" uid="99998" gid="99998" account="gthreepw" cmdtype="ssh" allowed="true" ip_from="172.17.0.1" port_from="39696" host_from="172.17.0.1" ip_bastion="172.17.0.2" port_bastion="22" host_bastion="myhostname.example.org" user="foo" ip_to="172.17.0.123" port_to="22" host_to="srv123.example.org" plugin="" globalsql="ok" accountsql="ok" comment="" params="ttyrec -f /home/gthreepw/ttyrec/172.17.0.123/2020-12-28.11-12-26.074894.e9e4baf6873b.gthreepw.foo.172.17.0.123.22.ttyrec -F /home/gthreepw/ttyrec/172.17.0.123/%Y--%d.%H-%M-%S.#usec#.e9e4baf6873b.gthreepw.foo.172.17.0.123.22.ttyrec -- /usr/bin/ssh 172.17.0.123 -l foo -p 22 -i /home/gthreepw/.ssh/id_rsa4096_private.1594384739 -i /home/keykeeper/keyagroup/id_ed25519_agroup.1607524914 -o PreferredAuthentications=publickey" ``` -------------------------------- ### Install mkhash helper for type 8/9 password hashes Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/upgrading.rst Run as root to install the optional helper supporting type 8 and type 9 password hash types. Detects OS and installs .deb, .rpm, or static binary. ```shell /opt/bastion/bin/admin/install-mkhash-helper.sh -a ``` -------------------------------- ### Test the pre-commit hook with dummy files Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/development/setup.rst Create a test branch, add dummy shell and Perl files, and commit to verify the hook runs. The output shows expected failures from shellcheck and perltidy, aborting the commit. ```none git checkout -B mybranch printf "%b" "#! /usr/bin/env bash\n# vim: set filetype=sh\nunused=1\n" > bin/shell/dummy.sh printf "%b" "#! /usr/bin/env perl\n# vim: set filetype=perl\nsub dummy { 1; };\n" > lib/perl/dummy.pm git add bin/shell/dummy.sh lib/perl/dummy.pm git commit -m dummy ``` ```none *** Checking shell files syntax using system shellcheck `-> bin/shell/dummy.sh In bin/shell/dummy.sh line 3: unused=1 ^----^ SC2034: unused appears unused. Verify use (or export if used externally). `-> [ERR.] Got 1 errors ERROR: shell-check failed on bin/shell/dummy.sh *** Checking perl tidiness `-> lib/perl/dummy.pm ./lib/perl/dummy.pm ./lib/perl/dummy.pm.tdy differ: char 63, line 3 --- ./lib/perl/dummy.pm 2023-10-03 08:19:55.605950307 +0000 +++ ./lib/perl/dummy.pm.tdy 2023-10-03 08:20:43.618577295 +0000 @@ -1,3 +1,3 @@ #! /usr/bin/env perl # vim: set filetype=perl -sub dummy { 1; }; +sub dummy { 1; } ERROR: perl tidy failed on lib/perl/dummy.pm !!! COMMIT ABORTED !!! If you want to commit nevertheless, use -n. ``` -------------------------------- ### Install ttyrec package with install-ttyrec.sh -a Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/upgrading.rst For v3.00.01, the deprecated build-and-install-ttyrec.sh script is replaced by install-ttyrec.sh, which downloads and installs prebuilt rpm or deb packages. Use -a to download and install the proper package. ```bash install-ttyrec.sh -a ``` -------------------------------- ### Check required modules with perl-check.sh Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/basic.rst Run this script to verify that all required modules are installed. If installing to restore a backup, you may stop here and resume the standard restoring from backup procedure. ```shell /opt/bastion/bin/dev/perl-check.sh ``` -------------------------------- ### Output example of accountInfo Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/plugins/restricted/accountInfo.rst Example output from the accountInfo command showing account roles, group memberships, activity status, MFA settings, and password information. ```shell │ user1 is a bastion admin │ user1 is a bastion superowner │ user1 is a bastion auditor │ │ user1 has access to the following restricted commands: │ - accountCreate │ - accountDelete │ - groupCreate │ - groupDelete │ │ This account is part of the following groups: │ testgroup1 Owner GateKeeper ACLKeeper Member - │ gatekeeper-grp2 Owner GateKeeper - - - │ │ This account is active │ This account has no TTL set │ This account is not frozen │ This account has seen recent-enough activity to not be activity-expired │ As a consequence, this account can connect to this bastion │ │ Last seen on Thu 2023-03-16 07:51:49 UTC (00:00:00 ago) │ Created on Fri 2022-06-17 09:52:50 UTC (271d+21:58:59 ago) │ Created by jdoe │ Created using The Bastion v3.08.01 │ │ Account egress SSH config: │ - (default) │ │ PIV-enforced policy for ingress keys on this account is enabled │ │ Account Multi-Factor Authentication status: │ - Additional password authentication is not required for this account │ - Additional password authentication bypass is disabled for this account │ - Additional password authentication is enabled and active │ - Additional TOTP authentication is not required for this account │ - Additional TOTP authentication bypass is disabled for this account │ - Additional TOTP authentication is disabled │ - PAM authentication bypass is disabled │ - Optional public key authentication is disabled │ - MFA policy on personal accesses (using personal keys) on egress side is: password │ │ - Account is immune to idle counter-measures: no │ - Maximum number of days of inactivity before account is disabled: (default) │ │ Account PAM UNIX password information (used for password MFA): │ - Password is set │ - Password was last changed on 2023-01-27 │ - Password must be changed every 90 days at least │ - A warning is displayed 75 days before expiration │ - Account will not be disabled after password expiration ``` -------------------------------- ### Example osh-sync-watcher log output Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/advanced.rst Sample output from the synchronization daemon log showing successful sync steps and watching for changes. ```text Apr 12 18:11:25 bastion1.example.org osh-sync-watcher.sh[3346532]: Starting sync! Apr 12 18:11:25 bastion1.example.org osh-sync-watcher.sh[3346532]: 192.0.2.42: [Server 1/1 - Step 1/3] syncing needed data... Apr 12 18:11:27 bastion1.example.org osh-sync-watcher.sh[3346532]: 192.0.2.42: [Server 1/1 - Step 1/3] sync ended with return value 0 Apr 12 18:11:27 bastion1.example.org osh-sync-watcher.sh[3346532]: 192.0.2.42: [Server 1/1 - Step 2/3] syncing lastlog files from master to slave, only if master version is newer... Apr 12 18:11:28 bastion1.example.org osh-sync-watcher.sh[3346532]: 192.0.2.42: [Server 1/1 - Step 2/3] sync ended with return value 0 Apr 12 18:11:28 bastion1.example.org osh-sync-watcher.sh[3346532]: 192.0.2.42: [Server 1/1 - Step 3/3] syncing lastlog files from slave to master, only if slave version is newer... Apr 12 18:11:30 bastion1.example.org osh-sync-watcher.sh[3346532]: 192.0.2.42: [Server 1/1 - Step 3/3] sync ended with return value 0 Apr 12 18:11:39 bastion1.example.org osh-sync-watcher.sh[3346532]: All secondaries have been synchronized successfully Apr 12 18:11:39 bastion1.example.org osh-sync-watcher.sh[3346532]: Watching for changes (timeout: 120)... ``` -------------------------------- ### Copy pre-commit script to .git/hooks Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/development/setup.rst Copy the provided pre-commit script into the local .git/hooks directory to enable local lint checks. ```none cp contrib/git/pre-commit .git/hooks/pre-commit ``` -------------------------------- ### Run a subset of integration tests with --module Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/development/setup.rst Launches only the specified test module (e.g., 320-base.sh) instead of the full suite. Additional options are passed through as-is to the underlying test script. ```none tests/functional/docker/docker_build_and_run_tests.sh debian12 --module=320-base.sh ``` -------------------------------- ### Example of valid lines to be fed through STDIN Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/plugins/group-aclkeeper/groupSetServers.rst Provides example lines that can be passed via STDIN to the groupSetServers command. Each line follows the format [USER@]HOST[:PORT][ COMMENT], where USER and PORT are optional, HOST can be a hostname, IP, or CIDR block, and COMMENT is optional and may contain spaces. ```shell server12.example.org logs@server 192.0.2.21 host1.example.net:2222 host1 on secondary sshd with alternate port root@192.0.2.0/24 production database cluster ``` -------------------------------- ### run-tool.sh usage Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/development/setup.rst Shows the supported commands for the devenv tool script. Run `lint` before submitting a pull request. ```none Usage: ./docker/devenv/run-tool.sh COMMAND [OPTIONS] COMMAND may be one of the following: tidy [FILES..] runs perltidy on several or all the Perl source files, modifying them if needed checktidy [FILES..] runs perltidy in dry-run mode, and returns an error if files are not tidy perlcritic runs perlcritic on all the Perl source files shellcheck [FILES..] runs shellcheck on all the shell source files lint runs tidy, perlcritic and shellcheck on all files in one command doc generates the documentation sphinx-view-objects shows the named objects of the Sphinx documentation that can be referenced doc-serve starts a local HTTP python server on PORT to view generated documentation bash spawns an interactive shell to run any arbitrary command in the devenv docker run runs an arbitrary command in the devenv docker rebuild forces the rebuild of the devenv docker image that is needed to run all the above commands ``` -------------------------------- ### Example output of groupInfo Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx-plugins-override/groupInfo.rst Shows the output format for a group, listing roles and the public egress key. The key line must be copied entirely for use in remote authorized_keys files. ```text | Group mygroup's Owners are: user1 | Group mygroup's GateKeepers (managing the members/guests list) are: user2 | Group mygroup's ACLKeepers (managing the group servers list) are: user3 | Group mygroup's Members (with access to ALL the group servers) are: user4 | Group mygroup's Guests (with access to SOME of the group servers) are: user5 | | The public key of this group is: | | fingerprint: SHA256:r/PQS4wLdSWqjYsDca8ReKjhq0l9EX+zQgiUR5qKdlc (ED25519-256) [2018/04/16] | keyline follows, please copy the *whole* line: from="203.0.113.4/32,192.0.2.0/26" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILdD60bA3NgaOpRLgcACWfKcAMRQQRyFMppwp5GpHLTB mygroup@testbastion:1523886640 ``` -------------------------------- ### Test mkhash helper installation Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/upgrading.rst Call the helper manually to verify it works; outputs JSON with Type8, Type9, and PasswordLen fields. ```shell echo test | the-bastion-mkhash-helper ``` ```json {"Type8":"$8$EpvF1cVVzoEQFE$L3ZBWzfH9MTPo4WLX29Jd8LTM5sKlfEjtRZ//XMys2U","Type9":"$9$yRlXzt0T7WBs3E$YdKk8WMvLvAVcbglx.bMZoRlwBa6l5EhwLhBh1o0u4g","PasswordLen":4} ``` -------------------------------- ### Using --json with groupListServers Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/using/api.rst Same anchors as --json-pretty but compact JSON output. The parsing logic is identical to the --json-pretty example. ```shell ssh robot-group@bastion1.example.org -- --osh groupListServers --group mygroup --json ---ac777d06bec9-------------------------------------------the-bastion-3.12.00--- => list of servers pertaining to the group -------------------------------------------------------------------------------- ~ IP PORT USER ACCESS-BY ADDED-BY ADDED-AT ~ --------- ---- ----- ------------------ -------- ---------- ~ 127.1.2.3 22 (any) mygroup(group) johndoe 2023-07-31 ~ ~ 1 accesses listed JSON_START {"error_code":"OK","error_message":"OK","value":[{"forcePassword":null,"expiry":null,"port":"22","addedBy":"johndoe","ip":"127.1.2.3","userComment":null,"addedDate":"2023-07-31 08:56:05","user":null,"reverseDns":null,"comment":null,"forceKey":null}],"command":"groupListServers"} JSON_END ``` -------------------------------- ### Enter interactive mode Source: https://github.com/ovh/the-bastion/blob/master/README.md Starts the bastion interactive shell to call multiple --osh plugins in sequence. ```bash bastion -i ``` -------------------------------- ### Send GET request through proxy Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/using/http_proxy.rst Sends a GET /info request to router12.example.org on port 443 using remote account monitoring through the bastion. The proxy denies access because the account lacks permission for the requested host. ```none curl -u robot-mon@monitoring@router12.example.org https://bastion1.example.org:8443/info Enter host password for user 'robot-mon@monitoring@router12.example.org': This account doesn't have access to this user@host tuple (Access denied for robot-mon to monitoring@router12.example.org:443) ``` -------------------------------- ### info plugin configuration example Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/plugins/open/info.rst JSON configuration for the info plugin, stored in /etc/bastion/plugin.info.conf. Disables admin_show_system_info and show_fortune. ```json { "admin_show_system_info": false, "show_fortune": false } ``` -------------------------------- ### Run The Bastion Docker sandbox container Source: https://github.com/ovh/the-bastion/blob/master/README.md Starts a disposable sandbox container for testing The Bastion. The image supports multiple architectures. The container runs in detached mode and maps port 22 to a random host port. ```bash docker run -d -p 22 --name bastiontest ovhcom/the-bastion:sandbox ``` -------------------------------- ### Build and run integration tests with Docker Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/development/setup.rst Runs docker build and launches the functional tests against a Docker environment. Requires a target OS as argument; currently only Linux targets are supported. Calling without argument lists supported targets. ```none tests/functional/docker/docker_build_and_run_tests.sh ``` -------------------------------- ### Example test from 320-base.sh Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/development/tests.rst A simple integration test that runs the '--osh help' command, expects success, checks output contains 'OSH help', and validates JSON fields. ```none success help2 $a0 --osh help contain "OSH help" json .error_code OK .command help .value null ``` -------------------------------- ### Parsing --json output with awk and jq Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/using/api.rst Uses the same awk/jq pipeline as the --json-pretty example to extract and pretty-print the JSON output. ```shell ssh robot-group@bastion1.example.org -- --osh groupListServers --group mygroup --json --quiet | \ awk '/^JSON_END\r?$/ {if(P==1){exit}} { if(P==1){print} } /^JSON_START\r?$/ {P=1}' | jq . { "error_code": "OK", "error_message": "OK", "value": [ { "userComment": null, "reverseDns": null, "expiry": null, "user": null, "forceKey": null, "addedDate": "2023-07-31 08:56:05", "port": "22", "addedBy": "johndoe", "ip": "127.1.2.3", "forcePassword": null, "comment": null } ], "command": "groupListServers" } ``` -------------------------------- ### run function examples Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/development/tests.rst The run function executes a test command on the tester docker. Preconfigured accounts provide ssh command-lines ($a0, $a1, etc.) and account names ($account0, etc.) for use in commands. The function does not check exit status; use other functions for verification. ```none run test1 $a0 --osh info ``` ```none run test2 $a0 --osh accountInfo --account $account1 ``` ```none run test3 $a1 --osh accountDelete --account $account2 ``` -------------------------------- ### Enter bssh interactive mode Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/using/basics/first_steps.rst Starts the interactive mode of bssh, which provides auto-completion and a prompt. The session disconnects after 60 seconds of inactivity. ```shell bssh -i Enter PIN for 'PIV Card Holder pin (PIV_II)': Welcome to bssh interactive mode, type `help' for available commands. You can use and for autocompletion. You'll be disconnected after 60 seconds of inactivity. Loading... 88 commands and 341 autocompletion rules loaded. bssh(master)> ``` -------------------------------- ### Direct SSH connection using bssh alias Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/using/basics/first_steps.rst Shows the direct command to connect to a server using the bssh alias, bypassing interactive mode. This is the non-interactive equivalent of the previous SSH example. ```shell bssh root@198.51.100.42 ``` -------------------------------- ### Clone the bastion code with git Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/basic.rst Use git clone to fetch the bastion code into /opt/bastion and check out the latest release tag. Requires root access and SSH public key authentication before proceeding, as SSH password authentication will be disabled during installation. ```shell git clone https://github.com/ovh/the-bastion /opt/bastion git -C /opt/bastion checkout $(git -C /opt/bastion tag | tail -1) ``` -------------------------------- ### Enter interactive mode with bssh -i Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/using/basics/first_steps.rst Start the interactive mode to enter commands directly and use auto-completion with the TAB key. Typing 'help' is equivalent to 'bssh --osh help'. The session disconnects after idle time for security. ```shell bssh -i ``` -------------------------------- ### Test rsync of passwd and group files to slave Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/advanced.rst Run this command under the `root` account to verify the key setup and push the master's `/etc/passwd` and `/etc/group` files to the slave's `/root` directory. The output shows the transferred files and statistics. ```shell rsync -v --rsh "ssh -i /root/.ssh/id_master2slave" /etc/passwd /etc/group bastionsync@IP.OF.THE.SLAVE:/root/ group passwd sent 105,512 bytes received 8,046 bytes 75,705.33 bytes/sec total size is 1,071,566 speedup is 9.44 ``` -------------------------------- ### Run integration tests without Docker Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/development/setup.rst Runs the test script against a remote bastion installed on a BSD or other OS. This method is discouraged; prefer the Docker method. Do NOT run on a production bastion. ```none test/functional/launch_tests_on_instance.sh [outdir] ``` -------------------------------- ### Show help for all plugins Source: https://github.com/ovh/the-bastion/blob/master/README.md Displays the list of available plugins inside the interactive bastion shell. ```bash $> help ``` -------------------------------- ### Create first admin account with setup-first-admin-account.sh Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/basic.rst Run this script, replacing USERNAME with the desired username. You'll need to specify the public SSH key; the account is created as a bastion admin with all restricted commands granted. This also provides a bastion alias for routine connections. ```shell /opt/bastion/bin/admin/setup-first-admin-account.sh USERNAME auto ``` -------------------------------- ### Import GPG key interactively Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/restoring_from_backup.rst Run this command on the new server to import the private GPG key used to encrypt the backup. You will be prompted to paste the key. ```shell gpg --import ``` -------------------------------- ### Set up bastion alias and test info command Source: https://github.com/ovh/the-bastion/blob/master/README.md Retrieves the mapped port, creates a shell alias for the bastion, and runs the info command to verify admin access. ```bash PORT=$(docker port bastiontest | cut -d: -f2) alias bastion="ssh poweruser@127.0.0.1 -tp $PORT -- " bastion --osh info ``` -------------------------------- ### Review main configuration with vim Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/basic.rst Open the main configuration file to review and modify it to your needs after base configuration files have been copied. ```shell vim /etc/bastion/bastion.conf ``` -------------------------------- ### Install SELinux module with --no-install-selinux-module option Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/upgrading.rst When upgrading The Bastion to v3.01.00, an SELinux module is automatically installed if SELinux is detected. To skip this module, specify --no-install-selinux-module on the /opt/bastion/bin/admin/install upgrade call. ```bash /opt/bastion/bin/admin/install --no-install-selinux-module ``` -------------------------------- ### Set up bastion alias bssh Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/using/basics/first_steps.rst Define a shell alias to connect to the bastion. Replace 'myname' and 'the-bastion.example.org' with your account details. You can customize the alias, e.g., add '-i' for a private key. ```shell alias bssh='ssh -t myname@the-bastion.example.org --' ``` -------------------------------- ### Dry-run osh-encrypt-rsync.pl Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/advanced.rst Start the encryption and rsync script in dry-run mode to simulate the process without making changes. Use after a successful config-test. ```shell /opt/bastion/bin/cron/osh-encrypt-rsync.pl --dry-run ``` -------------------------------- ### Connect with bssh using -J jump host Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/using/proxyjump.rst Use the -J option with the familiar [user@]host[:port] syntax. The user and port parts are optional, defaulting to your remote user and port 22. The jump host must match the one granted in the access; otherwise, the connection is denied. ```none bssh -J relay@jump.example.org admin@server.example.org ``` -------------------------------- ### Run info plugin with bssh --osh info Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/using/basics/first_steps.rst Verify bastion access by running the 'info' plugin. The output shows a banner, PIN prompt, and account details. The alias shown in the output is for your account. ```shell bssh --osh info *------------------------------------------------------------------------------* |THIS IS A PRIVATE COMPUTER SYSTEM, UNAUTHORIZED ACCESS IS STRICTLY PROHIBITED.| |ALL CONNECTIONS ARE LOGGED. IF YOU ARE NOT AUTHORIZED, DISCONNECT NOW. | *------------------------------------------------------------------------------* Enter PIN for 'PIV Card Holder pin (PIV_II)': ---the-bastion.example.org----------------------------the-bastion-2.99.99-rc9--- => information -------------------------------------------------------------------------------- ~ You are johndoe ~ You are a bastion auditor! ~ Look at you, you are a bastion superowner! ~ Woosh, you are even a bastion admin! ~ ~ Your alias to connect to this bastion is: ~ alias bssh='ssh johndoe@the-bastion.example.org -p 22 -t -- ' ~ Your alias to connect to this bastion with MOSH is: ~ alias bsshm='mosh --ssh="ssh -p 22 -t" johndoe@the-bastion.example.org -- ' ~ ~ [...] ~ ~ Here is your excuse for anything not working today: ~ BOFH excuse #46: ~ waste water tank overflowed onto computer ------------------------------------------------------------------------- Connection to the-bastion.example.org closed. ``` -------------------------------- ### Show scp-via-bastion usage Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/plugins/open/scp.rst Run the script with no options to display the list of supported scp options. ```shell Usage: ./scp-via-bastion [-p] [-q] [-r] [-T] [-v] [-l limit] [-i identity_file] [-P port] [-o ssh_option] source target ``` -------------------------------- ### Enable 2FA root authentication with google-authenticator Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/advanced.rst Run this command on the bastion to configure TOTP for root. It generates a QR code saved to /root/qrcode. The options set sane defaults; adjust with --help if needed. ```shell script -c "google-authenticator -t -Q UTF8 -r 3 -R 15 -s /var/otp/root -w 2 -e 4 -D" /root/qrcode ``` -------------------------------- ### Retrieve the egress public key of the group on ACME's bastion Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/using/realms.rst Gets the public part of the group's egress key, which ACME will communicate to you along with their egress IPs. ```shell acmebssh --osh groupInfo --group example-partner ``` -------------------------------- ### Import admin public GPG key on bastion Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/advanced.rst Paste the exported public key at this prompt to import it into the bastion's GPG keyring. ```shell /opt/bastion/bin/admin/setup-gpg.sh --import ``` -------------------------------- ### SSH command with --json-greppable and output Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/using/api.rst Shows the --json-greppable option in action, producing JSON output on one line starting with the JSON_OUTPUT= anchor. The output includes the JSON payload after the anchor. ```shell ssh robot-group@bastion1.example.org -- --osh groupListServers --group mygroup --json--greppable ---ac777d06bec9-------------------------------------------the-bastion-3.12.00--- => list of servers pertaining to the group -------------------------------------------------------------------------------- ~ IP PORT USER ACCESS-BY ADDED-BY ADDED-AT ~ --------- ---- ----- ------------------ ---------- ---------- ~ 127.1.2.3 22 (any) mygroup(group) johndoe 2023-07-31 ~ ~ 1 accesses listed JSON_OUTPUT={"error_code":"OK","command":"groupListServers","error_message":"OK","value":[{"reverseDns":null,"userComment":null,"user":null,"forceKey":null,"port":"22","addedDate":"2023-07-31 08:56:05","expiry":null,"addedBy":"johndoe","ip":"127.1.2.3","comment":null,"forcePassword":null}]} ------------------------------------------------------------- ``` -------------------------------- ### Create a realm on the local bastion Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/using/realms.rst Declares a realm on your bastion, registering ACME's egress group public key and the IPs their bastion connects from. The --from option uses the same syntax as the from= directive of SSH keys. If --public-key is omitted, you'll be prompted to paste it interactively. ```shell bssh --osh realmCreate --realm acme --from 203.0.113.0/24 --public-key "ssh-ed25519 AAAAC3Nza... acme_egress_key" ``` -------------------------------- ### Generate bastion GPG key with setup-gpg.sh --generate Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/advanced.rst Generates a GPG key for the bastion to sign ttyrec files. May take time and require entropy. Updates /etc/bastion/osh-encrypt-rsync.conf.d/50-gpg-bastion-key.conf with the signing key. ```shell /opt/bastion/bin/admin/setup-gpg.sh --generate gpg: directory `/root/.gnupg' created gpg: Generating GPG key, it'll take some time. Not enough random bytes available. Please do some other work to give the OS a chance to collect more entropy! (Need 39 more bytes) ..........+++++ gpg: /root/.gnupg/trustdb.gpg: trustdb created gpg: key A4480F26 marked as ultimately trusted gpg: done gpg: checking the trustdb gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u Configuration file /etc/bastion/osh-encrypt-rsync.conf.d/50-gpg-bastion-key.conf updated: 8<---8<---8<---8<---8<---8<-- # autogenerated with /opt/bastion/bin/admin/setup-gpg.sh at Wed Mar 21 10:03:08 CET 2018 { "signing_key_passphrase": "************", "signing_key": "5D3CFDFFA4480F26" } --->8--->8--->8--->8--->8--->8 Done. ``` -------------------------------- ### Force pubkey+PAM for root (commented) Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/administration/mfa.rst Commented by default, this section forces publickey and keyboard-interactive PAM authentication for the root user to protect The Bastion's own system. Uncomment the two lines if you need 2FA root authentication. ```shell # If 2FA has been configured for root, we force pubkey+PAM for it. If this is the case # on your system, uncomment the next two lines (see # https://ovh.github.io/the-bastion/installation/advanced.html#fa-root-authentication) #Match User root # AuthenticationMethods publickey,keyboard-interactive:pam ``` -------------------------------- ### Import GPG key from file Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/restoring_from_backup.rst Alternative to interactive import: imports the private GPG key from a temporary file, e.g., /tmp/backupkey.asc. ```shell gpg --import < /tmp/backupkey.asc ``` -------------------------------- ### Skip PAM for bastion-nopam group Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/administration/mfa.rst Tells the SSH server to not rely on PAM (hence disable MFA) for accounts in the bastion-nopam group. This internal group is used for accounts whose MFA setup has been set to bypass PAM authentication. ```shell # Unconditionally skip PAM auth for members of the bastion-nopam group Match Group bastion-nopam AuthenticationMethods publickey ``` -------------------------------- ### Import new admin key with setup-gpg.sh Source: https://github.com/ovh/the-bastion/blob/master/doc/sphinx/installation/upgrading.rst After generating the Ed25519 key, import a new admin key using the --overwrite parameter. ```shell /opt/bastion/bin/admin/setup-gpg.sh import --overwrite ```