ACME: bxp-cli acme¶
bxp-cli acme gets TLS certificates with the ACME protocol. This is the same
protocol that Let's Encrypt uses.
With ACME, nobody needs to create a token, and nobody needs to log in. Instead, the machine proves that the names in the certificate belong to it. It does this by answering a challenge from the CA.
bxp-cli acme works with the BastionXP CA's ACME endpoints. It also works with
any other ACME CA, through --directory.
| Command | What it does |
|---|---|
bxp-cli acme issue |
Gets a certificate. The first run also creates the ACME account. |
bxp-cli acme renew |
Gets a new certificate for the same names, when the current one is due for renewal. |
bxp-cli acme revoke |
Revokes the certificate. |
bxp-cli acme rollover-key |
Replaces the ACME account key. |
bxp-cli acme deactivate |
Closes the ACME account. This cannot be undone. |
Which ACME endpoint¶
On the BastionXP CA, each ACME verifier of an authority is a separate ACME
endpoint. To choose one, give its ID with --acme-id. The ID is the
verifier's Name in the web portal.
bxp-cli then builds the endpoint's address. It uses the server and the
authority that bxp-cli trust saved:
Instead of --acme-id, you can give the full address with --directory.
This can be the ACME server directory URL that the portal shows, or the
address of another CA:
sudo bxp-cli acme issue --directory https://acme-v02.api.letsencrypt.org/directory --name web1.example.com
Get a certificate¶
$ sudo bxp-cli acme issue --acme-id my-acme --name web1.example.com --name www.example.com
Private key: /root/.bxp-cli/acme/data/certs/privkey.pem
Certificate: /root/.bxp-cli/acme/data/certs/fullchain.pem
Valid until: 2027-02-17 14:37 UTC
--name takes a host name or an IP address. To put more names in the
certificate, give --name once for each name.
The challenge¶
The challenge decides how the machine proves that the names belong to it.
Choose it with --challenge:
--challenge |
How the machine answers | What it needs |
|---|---|---|
http-01 (the default) |
bxp-cli answers on port 80. |
Port 80 must be free, and the CA must be able to reach it. Only root can use port 80, so run bxp-cli with sudo. |
tls-alpn-01 |
bxp-cli answers on port 443. |
Port 443 must be free, and the CA must be able to reach it. Only root can use port 443, so run bxp-cli with sudo. |
dns-01 |
bxp-cli creates a TXT record in your DNS. |
An HTTP API that sets DNS records for you. No port and no sudo are needed. |
The DNS API for dns-01¶
For dns-01, bxp-cli does not talk to your DNS provider directly. Instead, it
calls a small HTTP API that you run in front of your DNS provider. Give the
API's address with --dns-api-url. The default is http://localhost:8080.
The API must answer two requests:
| Request | Body | What the API must do |
|---|---|---|
POST /present |
{"fqdn": "_acme-challenge.web1.example.com.", "key_auth": "<value>"} |
Create the TXT record, and answer 200. |
DELETE /cleanup?fqdn=_acme-challenge.web1.example.com. |
none | Remove the TXT record. |
After present, bxp-cli waits 10 seconds, so that the new record can reach
the DNS servers. Then it asks the CA to check the record.
Where the files are kept¶
bxp-cli acme keeps its files in the folder given with --out-dir. The default
is ~/.bxp-cli/acme.
| File | What it is |
|---|---|
account.key |
The ACME account key. Keep it, because renewals and revocations need it. |
data/certs/privkey.pem |
The certificate's private key. |
data/certs/cert.pem |
The certificate. |
data/certs/fullchain.pem |
The certificate, followed by the intermediate CA's certificate. Give this file to web servers. |
External Account Binding (EAB)¶
An ACME verifier can require External Account Binding. Then only a client with an EAB credential can create an ACME account.
A BastionXP administrator creates the credential for you. It has two parts:
a key ID and an HMAC key. Give both to your first issue:
sudo bxp-cli acme issue --acme-id my-acme --name web1.example.com \
--eab-kid "$EAB_KID" --eab-hmac-key "$EAB_HMAC_KEY"
The credential is needed only to create the account, and it works only once.
After that, issue, renew, revoke and the other commands use the
account key in --out-dir. So keep that folder.
| The message says | What it means, and what to do |
|---|---|
externalAccountRequired |
The verifier requires EAB. Give --eab-kid and --eab-hmac-key. |
EAB signature verification failed |
The HMAC key does not belong to the key ID. Check that you copied both correctly. |
invalid or already used eab credential |
The credential was already used, or it has expired. A credential expires after 24 hours by default. Ask your administrator for a new one. |
Renew¶
$ sudo bxp-cli acme renew --acme-id my-acme --exec "systemctl reload nginx"
Not due yet: valid until 2027-02-17 14:37 UTC, renews after 2027-01-18 14:37 UTC.
renew checks whether the certificate is due for renewal. It renews the
certificate only when less than a third of its lifetime is left. Otherwise
it does nothing.
So you can run renew every day from a timer. It then renews the
certificate at the right time by itself. The new certificate has the same
names, and a new private key.
--exec runs a command after a renewal. Use it to make the web server load
the new certificate. --force renews the certificate now, even if it is not
due.
# /etc/systemd/system/bxp-cli-acme-renew.service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/bxp-cli acme renew --acme-id my-acme --exec "systemctl reload nginx"
# /etc/systemd/system/bxp-cli-acme-renew.timer
[Timer]
OnCalendar=daily
RandomizedDelaySec=1h
Persistent=true
[Install]
WantedBy=timers.target
The timer runs as root, and root has its own .bxp-cli folder. So run
sudo bxp-cli trust ... once, to make root trust the CA too.
Revoke, replace the account key, close the account¶
$ sudo bxp-cli acme revoke --acme-id my-acme --reason superseded
Revoked: /root/.bxp-cli/acme/data/certs/fullchain.pem (superseded)
$ sudo bxp-cli acme rollover-key --acme-id my-acme
Account key: /root/.bxp-cli/acme/account.key (replaced)
$ sudo bxp-cli acme deactivate --acme-id my-acme
Account deactivated.
revoke signs the request with the certificate's own private key. After the
revocation, the authority's CRL and OCSP responder report the certificate as
revoked, if they are turned on.
Give the reason for the revocation with --reason. The CA stores the reason.
The CRL and the OCSP answers report it. If you leave out --reason, the
reason is unspecified.
| Reason | When to use it |
|---|---|
unspecified |
No other reason fits. This is the default. |
key-compromise |
The certificate's private key may be known to someone else. |
superseded |
A new certificate replaces this one. |
cessation |
The machine or the service no longer needs a certificate. |
bxp-cli refuses any other value before it contacts the CA.
Flags¶
| Flag | Commands | What it means |
|---|---|---|
--acme-id |
all | The ID of the ACME endpoint on the BastionXP server. |
--directory |
all | The full address of an ACME directory. Use it instead of --acme-id. |
--out-dir |
all | The folder for the account key and the certificate. The default is ~/.bxp-cli/acme. |
--name |
issue |
A host name or IP address for the certificate. Give it once for each name. |
--challenge |
issue, renew |
The challenge: http-01 (the default), tls-alpn-01 or dns-01. |
--dns-api-url |
issue, renew |
The address of your DNS API, for dns-01. |
--email |
issue |
A contact email address for the ACME account. |
--eab-kid, --eab-hmac-key |
issue |
The key ID and the HMAC key of the External Account Binding credential. They are needed only to create the account. |
--force |
issue, renew |
With issue, replace the existing certificate. With renew, renew now. |
--exec |
renew |
A command to run after a renewal. |
Other ACME clients, such as certbot and acme.sh, also work with the BastionXP CA. See ACME Verifier.