Skip to content

Renew a server certificate: bxp-cli renew

bxp-cli renew renews a TLS server certificate, or an SSH host certificate, before it expires. It does not need a token and it does not need a login. The current certificate and its private key are the proof that the server is allowed to renew.

Use bxp-cli renew on servers that got their certificate with bxp-cli tls or bxp-cli ssh. It replaces the manual steps of creating a new token in the portal each time.

Before you start

bxp-cli renew needs to know your BastionXP server and the CA's root certificate. If you ran bxp-cli trust on this machine, as the same user, bxp-cli renew uses what bxp-cli trust saved. Otherwise, give them with the options --ca-url, --authority and --root.

Which certificates can bxp-cli renew renew?

Certificate Can bxp-cli renew renew it?
A TLS server certificate from bxp-cli tls --token ... --name ... Yes.
An SSH host certificate from bxp-cli ssh with a host token Yes.
A certificate for a person (a user certificate) No. The person signs in again.
A certificate from ACME No. Renew it with bxp-cli acme renew or your ACME client.
A certificate from SCEP No. Renew it with bxp-cli scep renew.
A certificate that has already expired, or that was revoked No. Get a new one with a token.

Renew a certificate before it expires. An expired certificate cannot prove anything.

Renew a TLS certificate

bxp-cli renew --cert web.example.com.crt --key web.example.com.key \
    --exec "systemctl reload nginx"

bxp-cli renew does the following:

  1. It checks how much of the certificate's life is left. If more than a third of its lifetime is left, it does nothing and says so. This lets you run the command often, for example once a day. It renews at the right moment by itself.
  2. It makes a new private key.
  3. It gets a new certificate from the CA. The new certificate has the same names as the old one.
  4. It replaces the key file and the certificate file, in one step. The files keep their owner, group and permissions.
  5. It runs the command that you gave with --exec, so that your service loads the new certificate.

Renew an SSH host certificate

bxp-cli renew --cert /etc/ssh/ssh_host_ed25519_key-cert.pub \
    --key /etc/ssh/ssh_host_ed25519_key \
    --exec "systemctl reload sshd"

For an SSH certificate, the host key does not change. Only the certificate file is replaced.

Renew at once with --force

Normally, bxp-cli renew waits until two thirds of the certificate's lifetime have passed. Use --force to renew at once:

bxp-cli renew --force --cert web.example.com.crt --key web.example.com.key \
    --exec "systemctl reload nginx"

Use --force after an intermediate CA was revoked, for example because its key may have been stolen. Run it once on every server, with your configuration tool, such as Ansible, Puppet or Chef. The servers then get certificates from the new CA within minutes. See Revoke a CA.

A server can still renew with a certificate from a revoked intermediate CA, if BastionXP issued that exact certificate and it was not revoked itself. This is how your servers move to the new CA.

Renew automatically with a timer

Run bxp-cli renew from a timer. It does nothing most of the time, and it renews when the time comes. This example uses a systemd timer.

The service below gives the options explicitly, because a system service does not use the files that bxp-cli trust saved in your own home folder. --root is the CA's root certificate, which bxp-cli trust saved as ~/.bxp-cli/tls_root_ca.crt. Copy it to the path that you use.

Create /etc/systemd/system/bxp-cli-renew.service:

[Unit]
Description=Renew the server certificate with BastionXP

[Service]
Type=oneshot
ExecStart=/usr/local/bin/bxp-cli renew \
    --cert /etc/ssl/web.example.com.crt \
    --key /etc/ssl/web.example.com.key \
    --ca-url https://ca.example.com \
    --authority my-ca \
    --root /etc/ssl/certs/bastionxp-root-ca.crt \
    --exec "systemctl reload nginx"

Create /etc/systemd/system/bxp-cli-renew.timer:

[Unit]
Description=Check the server certificate every day

[Timer]
OnCalendar=daily
RandomizedDelaySec=1h
Persistent=true

[Install]
WantedBy=timers.target

Turn it on:

sudo systemctl daemon-reload
sudo systemctl enable --now bxp-cli-renew.timer

The random delay spreads the load, when you have many servers.

Options

Option What it means
--cert The certificate to renew. A TLS .crt file, or an SSH ...-cert.pub file.
--key The private key of the certificate.
--exec A command to run after a renewal, for example systemctl reload nginx.
--force Renew now, even if more than a third of the lifetime is left.
--ca-url The address of your BastionXP server. Or set BXP_CLI_CA_URL. The default is the address that bxp-cli trust saved.
--authority The ID of the certificate authority. Or set BXP_CLI_AUTHORITY. The default is the one that bxp-cli trust saved.
--root The path of the CA's root certificate. Or set BXP_CLI_ROOT. The default is the one that bxp-cli trust saved.

See the bxp-cli renew reference for the complete list.

If it does not work

Message or problem What to check
It says that nothing was done The certificate still has more than a third of its life. This is normal. Use --force to renew anyway.
It cannot connect to the server Check --ca-url, and that the server's certificate is trusted on this machine. See Trust the CA.
The server refuses the renewal The certificate has expired or was revoked, or it was not issued by this BastionXP. Get a new one with a token.
The service still shows the old certificate The --exec command did not run or did not reload the service. Run it by hand, and check its output.