# 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.
While it's working, you can proceed to the section below.
Generating and importing the admins GPG key
*******************************************
You should import on the bastion one or more **public** GPG keys that'll be used for encryption. If you don't already have a GPG key for this, you can generate one. As this is the admin GPG key, don't generate it on the bastion itself. On the desk of the administrator (you?), you can run for example:
Not enough random bytes available. Please do some other work to give
the OS a chance to collect more entropy! (Need 119 more bytes)
.....+++++
gpg: key D2BDF9B5 marked as ultimately trusted
gpg: done
Of course, adjust the ``myname``, ``email`` and ``bastion`` variables accordingly. Write down the passphrase in a secure vault. All bastions admins will need it if they are to decrypt ttyrec files later for inspection, and also decrypt the backup should a restore be needed. When the key is done being generated, get the public key with ``gpg -a --export D2BDF9B5``, using the proper key ID that you just generated. Copy it to your clipboard, then back to the bastion, paste it at the following prompt:
..code-block:: shell
/opt/bastion/bin/admin/setup-gpg.sh --import
Also export the private admins GPG key to a secure vault (if you want the same key to be shared by the admins):
..code-block:: shell
gpg --export-secret-keys --armor D2BDF9B5
Rotation, encryption & backup of ttyrec files
=============================================
You should already have all the needed GPG keys at the proper places, by following "Setup the encryption & signature GPG keys" section above.
The configuration file is located in ``/etc/bastion/osh-encrypt-rsync.conf``.
You can ignore the ``signing_key``, ``signing_key_passphrase`` and ``recipients`` options, as these have been auto-filled when you generated the GPG keys, by dropping configuration files in the ``/etc/bastion/osh-encrypt-rsync.conf.d`` directory. Any file there takes precedence over the global configuration file.
Once you are done with you configuration, you might want to test it by running:
Everything that is needed to restore a bastion from backup (keys, accounts, groups, etc.) is backed up daily in ``/root/backups`` by default. If you followed the "Setup the encryption & signature GPG keys" section above, these backups will be encrypted automatically.
If you want to push these backups to a remote location, which is warmly advised, you have to specify the remote location to ``scp`` the backup archives to. The configuration file is ``/etc/bastion/osh-backup-acl-keys.conf``, and you should specify the ``PUSH_REMOTE`` and ``PUSH_OPTIONS``.
To verify that the script is correctly able to connect remotely (and also validate the remote hostkey), start the script manually:
It is advised to use syslog for The Bastion application logs. This can be configured in ``/etc/bastion/bastion.conf`` with the parameter ``enableSyslog``.
There is a default ``syslog-ng`` configuration provided, if you happen to use it. The file can be found as ``etc/syslog-ng/conf.d/20-bastion.conf.dist`` in the repository. Please read the comments in the file to know how to integrate it properly in your system.
The bastions can work in a cluster, with N instances. In that case, there is one *master* instance, where any modification command can be used (creating accounts, deleting groups, granting accesses), and N-1 *slave* instances, where only *readonly* actions are permitted. Note that any instance can be used to connect to infrastructures, so in effect all instances can always be used at the same time. You may set up a DNS round-robin hostname, with all the instances IPs declared, so that clients automatically choose a random instance, without having to rely on another external component such as a load-balancer. Note that if you do this, you'll need all the instances to share the same SSH host keys.
Before, setting up the slave bastion, you should have the two bastions up and running (follow the normal installation documentation).
On the slave
------------
The sync of the ``passwd`` and ``group`` files can have adverse effects on a newly installed machine where the packages where not installed in the same order than on the master, hence having different UIDs for the same users. The following commands are known to fix all the problems that could arise in that case, on an classic Debian machine, that has ``puppet``, ``postfix``, ``ossec`` and ``bind`` installed (disregard any *file or directory not found* message):
Then, on the slave, set the ``readOnlySlaveMode`` option in the ``/etc/bastion/bastion.conf`` file to ``1``:
..code-block:: shell
vim /etc/bastion/bastion.conf
This will instruct the bastion to deny any modification plugin, so that changes can only be done through the master instance.
Then, append the master bastion synchronization public SSH keyfile, found in ``~root/.ssh/id_master2slave.pub`` on the master instance, to ``~bastionsync/.ssh/authorized_keys`` on the slave, with the following prefix: ``from="IP.OF.THE.MASTER",restrict``
Note that if you're using an old OpenSSH before version 7.2, the prefix should be instead: ``from="IP.OF.THE.MASTER",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty,no-user-rc``.
On the master
-------------
- Check that the key setup works correctly by launching the following command under the ``root`` account:
- Check that it's not trying to rsync too much stuff (if you have weird things in your ``/home``, you might want to edit ``/etc/bastion/osh-sync-watcher.rsyncfilter`` to exclude that stuff)
- Once you're happy with the output, retry without the ``--dry-run``
- When it's done, run it immediately again to ensure it still work, because ``/etc/passwd`` and ``/etc/group`` will have been overwritten on the slave
- Then, edit the configuration on the master:
..code-block:: shell
vim /etc/bastion/osh-sync-watcher.sh
- Then, configure the script to start on boot and start it manually:
..code-block:: shell
systemctl enable osh-sync-watcher
systemctl start osh-sync-watcher
- You can check the logs (if you configured ``syslog`` instead, which is encouraged, then the logfile depends on your syslog daemon configuration)
..code-block:: shell
tail -F /var/log/bastion/osh-sync-watcher.log
Misc
====
Create SSHFP records
********************
If you want to use ``SSHFP`` (for a bastion, you should), generate the records and publish them in the DNS:
Note that this script doesn't check everything, just a few items. If you want a complete audit of your SSH configuration, there are other tools available. Using our SSH templates is also a good start.
The script also supports generating custom moduli for your installation. The following command will generate moduli of 8192 bits size. Note that it'll take several hours:
The bastion supports TOTP (Time-based One Time Password), to further secure high profile accesses. This section covers the configuration of 2FA root authentication on the bastion itself. TOTP can also be enabled for regular bastion users, but this is covered in another section. To enable 2FA root authentication, run on the bastion:
Of course, you can check the ``--help`` and adjust the options accordingly. The example given above has sane defaults, but you might want to adjust if needed.
Now, flash this QR code with your phone, using a TOTP application. You might want to copy the QR code somewhere safe in case you need to flash it on some other phone, by exporting the ``base64`` version of it:
You have then two configuration adjustments to do.
- First, ensure you have installed the provided ``/etc/pam.d/sshd`` file, or at least the corresponding line to enable the TOTP pam plugin in your configuration.
- Second, ensure that your ``/etc/ssh/sshd_config`` file calls PAM for root authentication. In the provided templates, there is a commented snippet to do it. The uncommented snippet looks like this:
..code-block:: shell
# 2FA has been configured for root, so we force pubkey+PAM for it
Note that first, the usual publickey method will be used, then control will be passed to PAM. This is where the ``/etc/pam.d/sshd`` configuration will apply.
Now, you should be asked for the TOTP the next time you try to login through ssh as root.
In case something goes wrong with the new configuration, be sure to keep your already opened existing connection to be able to fix the problem without falling back to console access.
Once this has been tested, you can (and probably should) also protect the direct root console access to your machine with TOTP, including a snippet similar to this one: