Skip to content

Run with systemd

The repository ships a hardened unit, packaging/systemd/bastionxp-ca.service. It runs the server as its own user, with write access to its data directory only and most of the system out of reach.

Install

# 1. A system user for the CA.
sudo useradd --system --home-dir /var/lib/bastionxp-ca --shell /usr/sbin/nologin bastionxp-ca

# 2. The binary.
sudo install -m 755 bxp /usr/local/bin/bxp

# 3. The configuration, readable by the CA's group only.
sudo install -d -m 750 -o root -g bastionxp-ca /etc/bastionxp-ca
sudo install -m 640 -o root -g bastionxp-ca bastionxp-ca.yaml /etc/bastionxp-ca/bastionxp-ca.yaml   # with data_dir: /var/lib/bastionxp-ca

# 4. The data directory, private to the CA's user.
sudo install -d -m 700 -o bastionxp-ca -g bastionxp-ca /var/lib/bastionxp-ca

# 5. Create the CA, as the CA's user, with the root key on removable storage.
sudo -u bastionxp-ca bxp init --config /etc/bastionxp-ca/bastionxp-ca.yaml --root-key-out /media/usb/root.key

# 6. The unit.
sudo cp packaging/systemd/bastionxp-ca.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now bastionxp-ca

Check it:

systemctl status bastionxp-ca
journalctl -u bastionxp-ca -o cat
sudo -u bastionxp-ca bxp doctor --config /etc/bastionxp-ca/bastionxp-ca.yaml

The unit

/etc/systemd/system/bastionxp-ca.service
[Unit]
Description=BastionXP CA certificate authority
Documentation=https://github.com/bastionxp/bastionxp-ca
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=bastionxp-ca
Group=bastionxp-ca
ExecStart=/usr/local/bin/bxp serve --config /etc/bastionxp-ca/bastionxp-ca.yaml
# "systemctl reload bastionxp-ca" re-reads the access rules and the ACME domains.
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=5s

# If the server's keys are encrypted: the passphrase, sealed to this
# machine's TPM.
#LoadCredentialEncrypted=bastionxp-ca-key-passphrase

# No capabilities. To listen on a port below 1024, e.g.
# server.address: ":443", replace the first line with the two after it.
CapabilityBoundingSet=
#AmbientCapabilities=CAP_NET_BIND_SERVICE
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE

# The server writes only to its data directory.
StateDirectory=bastionxp-ca
StateDirectoryMode=0700
UMask=0077

# Hardening.
NoNewPrivileges=yes
ProtectSystem=strict
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectKernelLogs=yes
ProtectControlGroups=yes
ProtectClock=yes
ProtectHostname=yes
ProtectProc=invisible
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
RestrictNamespaces=yes
RestrictRealtime=yes
RestrictSUIDSGID=yes
LockPersonality=yes
MemoryDenyWriteExecute=yes
SystemCallArchitectures=native
SystemCallFilter=@system-service
# A call outside the filter fails instead of killing the server.
SystemCallErrorNumber=EPERM

[Install]
WantedBy=multi-user.target

Common changes

Seal the passphrase to the machine's TPM (see Protect the CA keys), then uncomment:

LoadCredentialEncrypted=bastionxp-ca-key-passphrase

BastionXP CA finds the credential by itself; systemd looks for the file /etc/credstore.encrypted/bastionxp-ca-key-passphrase.

#CapabilityBoundingSet=
AmbientCapabilities=CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_NET_BIND_SERVICE

and server.address: ":443" in the configuration.

Environment=BXP_LOG_FORMAT=json

Edit with sudo systemctl edit bastionxp-ca to keep your changes in a drop-in file, apart from the shipped unit.

Reload and restart

Command Effect
systemctl reload bastionxp-ca Sends SIGHUP: re-reads the access rules and the ACME settings, without dropping connections. See Reload.
systemctl restart bastionxp-ca Everything else: addresses, names, OIDC/LDAP settings, profiles, switching ACME or SCEP on or off.

Renewal timers for clients

The same folder has bastionxp-ca-renew.service and bastionxp-ca-renew.timer, for machines that renew their certificates daily. See Renew certificates.