Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,17 @@ docstring gives: it is a record, not a claim about now.
[#1691](https://github.com/Gerrrt/HomeLab/issues/1691), and they join
`hardware.md` when they are in hand.

- **`mjolnir`'s card runs boot monitor 2.1.0.3**, read by the owner on its
*About → Network* page. That's the version the 3.6.1.2 package carried, so
the entry above that left it unread is settled.
- **`gen-certs.sh --csr` signs a request made on another device.** The key
stays on the device and no key is written here. The CA sets the subject
and SANs whatever the request asked for, and refuses a request whose own
signature doesn't verify. It's for the APC card, which can make a key and
a request on its command line. `generate-certificates.md` has the card's
steps, which end by switching its probe to `http_2xx_lab_ca`. The card
still serves its factory certificate until those steps are run.

## 2026-11-23

- **NUT's driver on `morpheus` retries for 14 seconds, not 6.** The *data
Expand Down
3 changes: 2 additions & 1 deletion docs/hardware.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ revisions of this repository treated `shiva` as the hypervisor itself.

**`mjolnir`'s card is an AP9641 at `10.0.99.10`, on current firmware; the
UPS's own firmware is well behind APC's.** The card runs AOS 3.6.1.2 with the
Smart-UPS application 3.6.1.2, installed on 2026-11-24 from AOS 2.0.0.6. Schneider's notes put the 3.x line behind a paid
Smart-UPS application 3.6.1.2 and boot monitor 2.1.0.3, installed on
2026-11-24 from AOS 2.0.0.6. Schneider's notes put the 3.x line behind a paid
Secure NMC subscription, but its support said 3.6.1.2 installs without one,
and the card took it by a plain file copy. The card kept its settings, its
SSH host key and its factory TLS certificate. Its SSH offers only
Expand Down
68 changes: 68 additions & 0 deletions docs/runbooks/generate-certificates.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,74 @@ of `ca.pem` ahead of it. The self-signed *GUI default* is still in the
certificate manager, as the rollback: select it under **System → Advanced → Admin Access → SSL/TLS
Certificate**.

### The APC card's leaf

`mjolnir`'s AP9641 card makes its own key and a certificate signing request,
and imports a signed certificate, all from its command line. Its key never
leaves the card: `gen-certs.sh --csr` signs the request and writes only the
certificate. The card's key is ECDSA P-256, made on the card. The leaf is
`mjolnir.matrix.elysium` with an IP SAN for `10.0.99.10`. The name doesn't
resolve, so the address is what the probe and a browser use.

Everything below runs from the main checkout on the monitoring host, as the
card's super user `apc`, whose password you type. The card offers no
curve25519, which `prometheus`'s SSH client is limited to, so each command
names the card's key exchange and host key:

```bash
cd ~/code/Gerrrt/HomeLab
O=(-o KexAlgorithms=ecdh-sha2-nistp256 -o HostKeyAlgorithms=ecdsa-sha2-nistp256)
```

1. **Make the request on the card, and copy it off.** `-q` builds it from the
card's current key and settings. Its subject and SANs don't matter, because
the CA sets its own:

```bash
ssh "${O[@]}" apc@10.0.99.10 ssl csr -q
scp -O "${O[@]}" apc@10.0.99.10:ssl/nmc.csr ./certificates/mjolnir-nmc.csr
```

2. **Sign it.** `--force` only when reissuing:

```bash
make certs ARGS="--host mjolnir.matrix.elysium --ip 10.0.99.10 --csr certificates/mjolnir-nmc.csr"
```

3. **Copy the certificate to the card and import it.** The card serves it at
once; nothing restarts:

```bash
scp -O "${O[@]}" certificates/mjolnir.matrix.elysium.pem apc@10.0.99.10:ssl/nmc.crt
ssh "${O[@]}" apc@10.0.99.10 ssl cert -i ssl/nmc.crt
```

The card refuses a certificate that doesn't match the key its request came
from. If the import fails, it keeps serving the certificate it had.

4. **Check what it serves**, against the CA rather than by eye:

```bash
echo | openssl s_client -connect 10.0.99.10:443 -CAfile certificates/ca.pem \
-verify_return_error -verify_ip 10.0.99.10 2>&1 | grep -E 'Verify return code|subject=|issuer='
```

You want `Verify return code: 0 (ok)`.

5. **Make the probe verify it.** In
[`targets/blackbox.yaml`](../../stacks/observability/prometheus/targets/blackbox.yaml),
change the `ups-ui` target's module from `http_2xx_self_signed` to
`http_2xx_lab_ca`, so a lapsed or factory-reset certificate fails the probe
rather than passing it. `TlsCertificateExpiringSoon` and
`TlsCertificateExpiryImminent` read its expiry either way.

Delete `certificates/mjolnir-nmc.csr` afterwards. It isn't secret, but
`certificates/` is for what this CA issues.

A factory reset of the card, or a downgrade below 2.4, which formats it,
brings back a self-signed certificate. Once step 5 is done, that fails the
probe and `EndpointUnreachable` fires. Re-run steps 1 to 4 to recover.

## If something goes wrong

| Symptom | Cause | Fix |
Expand Down
52 changes: 45 additions & 7 deletions scripts/gen-certs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
# morpheus's, for TLS syslog to Alloy (#1049), whose
# listener pins that exact certificate rather than
# trusting every client leaf this CA signs.
# --csr <file> sign a certificate signing request made ELSEWHERE, so the
# private key never leaves the device that made it. No key
# is written here. The CSR supplies only its public key:
# the subject is /CN=<host>/O=matrix.elysium and the SANs
# are the ones given here, whatever the CSR asked for. The
# first is the APC card on mjolnir, which can make a key and
# a CSR but has nowhere to import a key from this host
# except a Security Wizard .p15.
# --days <n> leaf lifetime, default 825
# --force overwrite an existing CA or leaf
#
Expand Down Expand Up @@ -79,6 +87,7 @@ IPS=()
DNS=()
FORCE=0
CLIENT=0
CSR=""

while (($#)); do
case "$1" in
Expand All @@ -90,6 +99,7 @@ while (($#)); do
--days) LEAF_DAYS="${2:?--days needs a number}"; shift 2 ;;
--force) FORCE=1; shift ;;
--client) CLIENT=1; shift ;;
--csr) CSR="${2:?--csr needs a file}"; shift 2 ;;
# Printed straight from the comment block above rather than kept as a
# second copy that drifts. Bounded by where the comments stop, not by a
# line number: the literal 2,32p this replaced had already slipped and was
Expand All @@ -99,6 +109,7 @@ while (($#)); do
esac
done

[[ -z "${CSR}" || "${MODE}" == "leaf" ]] || die "--csr signs a leaf: give it with --host <fqdn>"
[[ -n "${MODE}" ]] || die "nothing to do — try --ca, --host <fqdn>, or --list (see --help)"
command -v openssl >/dev/null 2>&1 || die "openssl not found"

Expand Down Expand Up @@ -188,8 +199,23 @@ fi
KEY="${CERT_DIR}/${HOST}-key.pem"
CRT="${CERT_DIR}/${HOST}.pem"

if [[ -s "${KEY}" ]] && ((! FORCE)); then
die "${KEY#"${REPO_ROOT}"/} already exists — pass --force to replace it"
if [[ -n "${CSR}" ]]; then
# The key is the device's. Guard the certificate instead, and refuse a CSR
# whose own signature does not verify: that is a request nobody holding the
# matching key made.
[[ -s "${CSR}" ]] || die "no CSR at ${CSR}"
if [[ -s "${CRT}" ]] && ((! FORCE)); then
die "${CRT#"${REPO_ROOT}"/} already exists — pass --force to replace it"
fi
openssl req -in "${CSR}" -noout -verify >/dev/null 2>&1 \
|| die "${CSR} is not a CSR whose signature verifies"
elif ((! FORCE)); then
# The certificate as well as the key: a leaf signed from a device's CSR
# has no key here, and reissuing it without --csr would replace it with
# one for a local key the device cannot import.
for f in "${KEY}" "${CRT}"; do
[[ -s "${f}" ]] && die "${f#"${REPO_ROOT}"/} already exists — pass --force to replace it"
done
fi

# A certificate with no subjectAltName is rejected outright by every current
Expand Down Expand Up @@ -223,11 +249,19 @@ info "SANs: ${SAN}"
TMP="$(mktemp -d)"
trap 'rm -rf "${TMP}"' EXIT INT TERM

openssl req -newkey rsa:2048 -sha256 -nodes \
-keyout "${KEY}" -out "${TMP}/csr.pem" \
-subj "/CN=${HOST}/O=matrix.elysium" 2>/dev/null
if [[ -n "${CSR}" ]]; then
cp "${CSR}" "${TMP}/csr.pem"
else
openssl req -newkey rsa:2048 -sha256 -nodes \
-keyout "${KEY}" -out "${TMP}/csr.pem" \
-subj "/CN=${HOST}/O=matrix.elysium" 2>/dev/null
fi

# -subj overrides the request's subject, and -extfile is the only source of
# extensions: x509 -req copies none from the CSR. So a CSR from a device says
# nothing about the names this CA vouches for.
openssl x509 -req -in "${TMP}/csr.pem" -sha256 \
-subj "/CN=${HOST}/O=matrix.elysium" \
-CA "${CA_CRT}" -CAkey "${CA_KEY}" -CAcreateserial \
-CAserial "${CERT_DIR}/ca.srl" \
-out "${CRT}" -days "${LEAF_DAYS}" \
Expand All @@ -238,7 +272,7 @@ openssl x509 -req -in "${TMP}/csr.pem" -sha256 \
# service is given the operator's gid as a supplementary group instead of the
# key being made world-readable. This costs nothing: certificates/ is 0700, so
# no other local user can traverse to the file whatever its own mode says.
chmod 640 "${KEY}"
[[ -n "${CSR}" ]] || chmod 640 "${KEY}"
chmod 644 "${CRT}"

# Prove it verifies against the CA now, rather than discovering at deploy time
Expand All @@ -247,7 +281,11 @@ openssl verify -CAfile "${CA_CRT}" -purpose "$( ((CLIENT)) && echo sslclient ||
|| die "the issued certificate does not verify against the CA — refusing to report success"

ok "issued ${CRT#"${REPO_ROOT}"/}"
printf ' key %s\n' "${KEY#"${REPO_ROOT}"/}"
if [[ -n "${CSR}" ]]; then
printf ' key on the device that made %s; none here\n' "${CSR}"
else
printf ' key %s\n' "${KEY#"${REPO_ROOT}"/}"
fi
printf ' SANs %s\n' "${SAN}"
printf ' EKU %s\n' "${EKU}"
printf ' verified against %s\n\n' "${CA_CRT#"${REPO_ROOT}"/}"