Search and contents

A certificate that fails: renewed, refused, lost and replaced

A Node is only as trusted as its certificate. This page works through four things on a three-Node practice site: a Node's certificate renewed in place with no restart, clients that a Node refuses and the reasons it logs, the copy of a lost certificate that is still let in, and the site's own certificate authority replaced with one Node left out of the middle step. The last one ends by taking the site away.

Every value on this page is invented. The site, its Nodes and its certificates are made by the script in a throwaway directory. Nothing here is a real certificate authority, and nothing says how a site's own should be run.

This is test tooling, not part of the public API. The site script, and the way it stands in for copying files to a Node, may change in any release, and the stability policy (public-api-stability.md) does not cover them. The certificate scripts it calls are described in site-pki.md. The test that proves the behaviour in process, over certificates made by the same scripts, is tests/test_drill_trust_failure.py.

Practice only: deliver stands in for copying files to a Node. On a real site you copy a Node's three files to it and run install_node_certificate.sh there. deployment/practice_site.sh deliver NODE prints, and then runs, exactly that install, for the Node's own directory, and it runs the install's reload hook, so a running Node uses the new files in place. The site's certificate authority key sits on the same host as its Nodes, which a real site does not do.

What you need

  • A running practice site, as in A Node stopped and started, with every peer link reachable. No model is asked by anything on this page.
  • Two places hold a Node's certificate, as on a real site. The workstation, $SITE/pki/practice/, is where the scripts write and where the authority's key lives. A Node reads only $SITE/node-pki/NODE/, which holds what was delivered to it. A renewal that is not delivered changes nothing for the Node.
  • openssl and curl, which the site needs already.

Run the commands from the repository root, in one shell, after this once:

SITE="${KINDRED_PRACTICE_DIR:-$HOME/.kindred-practice-site}"
export KINDRED_PRACTICE_DIR="$SITE"
export KINDRED_PKI_DIR="$SITE/pki"
ORDER=MD-2027-0301
PS=deployment/practice_site.sh
api() { # the asking Node's Management API, with its token
  KINDRED_MANAGEMENT_URL=http://127.0.0.1:18470 \
  KINDRED_MANAGEMENT_TOKEN_FILE="$SITE/asking-node.token" \
    deployment/kindred_management.sh "$@"
}
show() { # print the named fields of a JSON answer
  python3 -c 'import json, sys; d = json.load(sys.stdin); print({k: d.get(k) for k in sys.argv[1:]})' "$@"
}
links() { # the four peer links, each as the Node's own certificate sees it
  $PS status | grep -- '->'
}
serial() { openssl x509 -in "$SITE/node-pki/$1/node.crt" -noout -serial; }

Case 1: renew a Node's certificate, with no restart

Step 1: read the baseline. Every link is reachable, and the trail is whole. Note ERP's serial and its process file: the file holds the process id and the time that process started.

links
serial erp
cat "$SITE/run/erp.pid"
api trail "$ORDER" | show complete not_contributed
  mes  -> erp          reachable
  mes  -> scheduling   reachable
  erp  -> mes          reachable
  erp  -> scheduling   reachable
serial=B597181F8E259C93FE8DBF944C27C8
1023128 271995908
{'complete': True, 'not_contributed': []}

Step 2: renew on the workstation, and do not deliver yet.

deployment/renew_node_certificate.sh practice erp --now
serial erp
Certificate request self-signature ok
subject=CN = erp
Issued urn:kindred:practice:erp in /home/user/.kindred-practice-site/pki/practice/nodes/erp (valid 365 days).
subject=CN = erp
notAfter=Nov 21 01:30:16 2027 GMT
Renewed. Copy node.crt, node.key and trust-bundle.pem from /home/user/.kindred-practice-site/pki/practice/nodes/erp/ to the Node and run install_node_certificate.sh there.
serial=B597181F8E259C93FE8DBF944C27C8

--now renews whatever the expiry: a new key, and the same identity, names and addresses. ERP's serial has not changed, because ERP still holds what it held, and its peers still see the old certificate.

Step 3: deliver.

$PS deliver erp
cat "$SITE/run/erp.pid"
serial erp
links
grep "certificate reloaded" "$SITE/log/erp.log" | tail -1
Delivering to erp (the install script and its reload hook run as the Node would):
  KINDRED_NODE_PKI_DIR=/home/user/.kindred-practice-site/node-pki/erp KINDRED_ENV_FILE=/home/user/.kindred-practice-site/node-pki/production.env \
    deployment/install_node_certificate.sh practice erp \
    --cert /home/user/.kindred-practice-site/pki/practice/nodes/erp/node.crt --key /home/user/.kindred-practice-site/pki/practice/nodes/erp/node.key \
    --ca-bundle /home/user/.kindred-practice-site/pki/practice/trust-bundle.pem
OK urn:kindred:practice:erp
Installed the certificate files for urn:kindred:practice:erp in /home/user/.kindred-practice-site/node-pki/erp.
Sent SIGHUP to the Node (pid 1023128); it validates the new certificate files before using them.
Reload hook ran: 20-node-tls
1023128 271995908
serial=7F7F647E9BF1BCD13A6B6BEAEFE9BA
  mes  -> erp          reachable
  mes  -> scheduling   reachable
  erp  -> mes          reachable
  erp  -> scheduling   reachable
INFO: certificate reloaded: urn:kindred:practice:erp (generation 2)

The serial changed and the process file is the same, so it is the same process: nothing was restarted. A Node checks the new files before it uses them and keeps the old ones if they are wrong, logging why. The install script cannot see that outcome, which is why the last command reads ERP's log. (The output above is trimmed to the lines that matter; the install prints the command it runs first.)

Case 2: what a Node refuses, and where the reason is written

Every Node answers over mutual TLS: it checks that a caller's certificate chains to its own trust bundle and names an identity in its own site. A refusal is written to the standard log of the side that refused, with the caller's address and the reason, and never to the Activity Log, so unauthenticated traffic cannot fill it. Three callers, each asking the MES for its health:

CA="$SITE/pki/practice/ca.crt"
OP="$SITE/pki/practice/nodes/operator"
OTHER=$(mktemp -d)
KINDRED_PKI_DIR="$OTHER" deployment/create_site_ca.sh other > /dev/null 2>&1
KINDRED_PKI_DIR="$OTHER" deployment/issue_node_certificate.sh other operator --ip 127.0.0.1 > /dev/null 2>&1
echo "--- a client with a certificate from the site's authority"
curl -s -o /dev/null -w "http %{http_code}\n" --cacert "$CA" --cert "$OP/node.crt" --key "$OP/node.key" https://127.0.0.1:18420/health
echo "--- a client with a certificate from another authority"
curl -s -o /dev/null -w "http %{http_code}\n" --cacert "$CA" --cert "$OTHER/other/nodes/operator/node.crt" --key "$OTHER/other/nodes/operator/node.key" https://127.0.0.1:18420/health
echo "--- a client with no certificate"
curl -s -o /dev/null -w "http %{http_code}\n" --cacert "$CA" https://127.0.0.1:18420/health
rm -rf "$OTHER"
grep "refused a connection" "$SITE/log/mes.log" | tail -2 | cut -c1-200
--- a client with a certificate from the site's authority
http 200
--- a client with a certificate from another authority
http 000
--- a client with no certificate
http 000
WARNING: peer listener refused a connection from 127.0.0.1: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)
WARNING: peer listener refused a connection from 127.0.0.1: [SSL: PEER_DID_NOT_RETURN_A_CERTIFICATE] peer did not return a certificate (_ssl.c:1000)

The client sees only a closed connection (curl exits 56); the reason is in the log of the Node that refused, and holds no key or certificate text. The other reasons a Node logs are pinned by the test and not run here: a certificate that has expired (certificate has expired), one with no identity, a valid certificate of the site that names another Node (an asking Node checks that the answerer is the Node it declared), and an identity of another site. A trail names a refused Node unreachable with the route's fixed reason, never the error text.

An expired certificate was not run. The scripts cannot make one, so the test signs one with the authority's key. A Node whose own certificate has expired does not start, and says so with the date of its notAfter; one that is running when its certificate expires keeps running, and its peers refuse it (test_a_node_whose_own_certificate_has_expired_does_not_start_and_says_so).

Case 3: a lost certificate is still let in

Take ERP as the Node whose files were lost, keep a copy of what it holds, and do the renewal of Case 1 again:

rm -rf "$SITE/lost-erp"
cp -rL "$SITE/node-pki/erp" "$SITE/lost-erp"
deployment/renew_node_certificate.sh practice erp --now > /dev/null 2>&1
$PS deliver erp > /dev/null
curl -s -o /dev/null -w "http %{http_code}\n" --cacert "$SITE/pki/practice/ca.crt" --cert "$SITE/lost-erp/node.crt" --key "$SITE/lost-erp/node.key" https://127.0.0.1:18420/health
http 200

The old files are still accepted after the renewal. There is no revocation list and no online check: a certificate stays valid until it expires, and a Node's listener checks that a caller is of its own site, not which Node of the site it is. So whoever holds a lost Node's files is let in as that Node by every other Node until they expire (365 days by default, a shorter life shrinks that and nothing else does). Renewing the Node ends nothing. The only action that stops every certificate an authority signed is replacing the authority, which is the next case.

Case 4: replace the site's authority, with one Node left out

This case ends by taking the site away. After it the MES cannot verify its target system's database server (see the end of the case), and reset fails. Do it last.

The authority is replaced in three steps, with a delivery to every Node between them. At every point each Node's certificate validates against the bundle that Node holds. This case leaves ERP out of the middle delivery on purpose, to show what the guards do and do not catch.

 begin                    promote                     retire
 -----                    -------                     ------
 new authority made       new authority signs         old authority dropped,
 bundle = old + new       bundle still old + new      old key DELETED
   |                        |                           |
   v deliver the BUNDLE     v REISSUE every leaf,       v deliver the new
     to every Node            deliver all three files     single-authority bundle
     (leaf still old)         to every Node               to every Node

Step 1: begin, and deliver the two-authority bundle to every Node.

deployment/replace_site_ca.sh practice begin
for n in mes erp scheduling; do $PS deliver "$n" --bundle-only > /dev/null; done
links

Every link is reachable: the Nodes still present their old certificates, which the two-authority bundle trusts.

Step 2: promote, reissue every certificate, and deliver to two Nodes of three. The certificates to reissue are the three Nodes', the operator identity that status probes with, and the target system's database server's (standin-db): retire refuses while any certificate it issued still depends on the old authority.

deployment/replace_site_ca.sh practice promote
for n in mes erp scheduling operator standin-db; do
  deployment/issue_node_certificate.sh practice "$n" --ip 127.0.0.1 --force > /dev/null 2>&1
done
$PS deliver mes > /dev/null
$PS deliver scheduling > /dev/null   # not erp
links

Every link is still reachable. ERP is presenting its old certificate, and the two-authority bundle every Node holds still trusts it, so a Node left out here is not yet visible.

Step 3: retire.

deployment/replace_site_ca.sh practice retire
ls "$SITE/pki/practice"
Retired the old CA: the bundle holds only the new CA and the old key is deleted.
Next: deliver /home/user/.kindred-practice-site/pki/practice/trust-bundle.pem to every Node.
ca.crt
ca.key
nodes
trust-bundle.pem

retire succeeded although ERP was never delivered its new certificate. It looks at the certificates issued on the workstation, not at what a Node holds. Had a certificate not been reissued, it would have refused, named the file, and kept the old key: the first time this case was run, retire refused on the database server's certificate, which had not been reissued.

Step 4: try to deliver the one-authority bundle to ERP, which still holds its old certificate.

$PS deliver erp --bundle-only
echo "exit $?"
Delivering to erp (the install script and its reload hook run as the Node would):
  KINDRED_NODE_PKI_DIR=/home/user/.kindred-practice-site/node-pki/erp KINDRED_ENV_FILE=/home/user/.kindred-practice-site/node-pki/production.env \
    deployment/install_node_certificate.sh practice erp \
    --ca-bundle /home/user/.kindred-practice-site/pki/practice/trust-bundle.pem
error: ChainNotTrustedError: certificate 'CN=erp' does not chain to the trust bundle: validation failed: candidates exhausted: all candidates exhausted with no interior errors
practice_site.sh: the install refused; erp still holds what it held
exit 1

This is the net under the guard above: the install checks a Node's own certificate against the bundle it is about to hold, and refuses, leaving the Node as it was.

Step 5: deliver the one-authority bundle to the other two, and look.

$PS deliver mes --bundle-only > /dev/null
$PS deliver scheduling --bundle-only > /dev/null
$PS status > /dev/null
echo "status exit $?"
links
api trail "$ORDER" | show complete not_contributed
grep "refused a connection" "$SITE/log/mes.log" | tail -1 | cut -c1-200
status exit 1
  mes  -> erp          unreachable
  mes  -> scheduling   reachable
  erp  -> mes          unreachable
  erp  -> scheduling   unreachable
{'complete': False, 'not_contributed': [{'node_type': 'ERP', 'address': '127.0.0.1:18421', 'outcome': 'unreachable', 'reason': 'unreachable at the last rescan'}]}
WARNING: peer listener refused a connection from 127.0.0.1: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1000)

The Node that was left out falls out in both directions. status shows ERP down, because its process is running but the operator probe now trusts only the new authority and cannot verify ERP's old certificate. The trail names it. ERP cannot reach the others either: their listeners refuse its old certificate, and say so in their logs. The two Nodes that were delivered stay reachable with each other.

Step 6: deliver to ERP.

cat "$SITE/run/erp.pid"
$PS deliver erp > /dev/null
cat "$SITE/run/erp.pid"
links
api trail "$ORDER" | show complete not_contributed
1023128 271995908
1023128 271995908
  mes  -> erp          reachable
  mes  -> scheduling   reachable
  erp  -> mes          reachable
  erp  -> scheduling   reachable
{'complete': True, 'not_contributed': []}

Every link is reachable again, and ERP is the same process.

The target system's database server was not given its new certificate. deliver takes only the three Nodes, and nothing here delivers the database server's reissued files. After the bundle holds only the new authority, the MES cannot verify that server, and reset fails when it reaches it (on the run shown here: dropping the target database failed ... certificate verify failed), leaving the Nodes stopped. Take the site away and make it again:

$PS down

Then up makes a new site with a new authority.

What this does not show

  • A Node that detects a bad peer's content. A Node checks who a peer is, never what a peer says.
  • An expired certificate by hand. The scripts cannot make one: it is in the test only.
  • An external authority, a request-based issuance, or a certificate with intermediates.
  • The revocation of a person's token. A token is not a certificate, and its cascade is not run by hand on this site. That is a different page's question.
  • A real appliance, a network or a clock. Every address is on one host, and the authority's key sits beside the Nodes it signs for.
  • Whether a Node left out is noticed before retire. It is not: the two-authority bundle trusts the old certificate, so nothing shows until the one-authority bundle reaches the others.

Limits

  • Renewing does not revoke. A lost certificate stays valid until it expires. The only way to end it sooner is to replace the authority.
  • retire does not look at the Nodes. Its refusal covers certificates issued on the workstation that the new authority did not sign. A Node that was never delivered its new certificate passes the check and falls out when the one-authority bundle reaches the others.
  • A refusal's reason is only on the refusing side. The asking side sees a closed connection or a TLS alert.
  • The practice site's deliver is a stand-in, and it does not reach the target system's database server, so an authority replacement cannot be finished on this site. See the end of Case 4.
  • A certificate's lifetime is the only bound on a lost one. The default is 365 days.

What the test checks

tests/test_drill_trust_failure.py runs the three Nodes over certificates made and delivered by the site's own scripts, each Node on a database of its own and a real mutual-TLS listener, with a Node holding only what the install script put in its directory. It pins:

  • a renewed certificate reaches the running Node by the reload hook with no restart (test_a_renewed_certificate_reaches_the_running_node_by_the_reload_hook_with_no_restart), and a Node that was not delivered the renewed files stays named (test_a_node_that_was_not_delivered_the_renewed_files_stays_named);
  • a peer that presents a bad certificate is refused, named, and asked nothing (test_a_peer_presenting_a_bad_certificate_is_refused_named_and_asked_nothing), and a caller that does so is refused by the listener with the reason logged (test_a_caller_presenting_a_bad_certificate_is_refused_by_the_listener_and_the_reason_is_logged);
  • a certificate of the site with another Node's identity receives no request (test_a_certificate_of_the_site_with_another_nodes_identity_receives_no_request);
  • a lost Node's stolen certificate stays accepted after renewal (test_a_lost_nodes_stolen_certificate_stays_accepted_after_renewal);
  • a replacement in three steps on three Nodes, with the Node left out falling out in both directions (test_a_ca_replacement_in_three_steps_on_three_nodes), retire refusing while a certificate still depends on the old authority (test_retire_is_refused_while_a_certificate_still_depends_on_the_old_ca);
  • a Node whose own certificate has expired does not start (test_a_node_whose_own_certificate_has_expired_does_not_start_and_says_so).

tests/test_break_it_pages.py runs this page's setup, checks that every script, flag, route and test file the page names exists, and that the page says what it does not show. It does not run a block that needs a running site.

Release: v0.11.0