Skip to content

Certificates and TLS

A chapter for the gateway administrator: what TLS material a node holds, where to check its state, and how to replace the HTTPS certificate and the PKI trust anchor. Replacement happens on the gateway node — on the station only what the station trusts changes.

TLS material on the node

The files live in /etc/amfa/tls/ on the node and are visible inside the gateway containers under the same path.

File Role
gateway.crt Certificate of the gateway vhosts: administration panel, engine API, SSO. The file may carry a chain — the server certificate and its issuer.
gateway.key Private key for gateway.crt.
ca.crt Issuer of the gateway certificate.
pi-ca.crt Issuer of the authentication engine.
postgresql-vip.crt, postgresql-ca.crt Client certificate of the cluster database and its issuer.
root-ca.pem PKI trust anchor. The edge verifies its connection to SSO with it, and the engine client verifies the engine server certificate with it.

Which files enter the inventory is decided by the gateway configuration (/etc/amfa/gateway.json, block tls, field inventory: path and role). Without that field the deployment default applies — the set in the table above. The paths must match what the vhosts use (/etc/amfa/openresty-tls.conf): the panel and API certificate is always gateway.crt with gateway.key.

Checking the state: System → Certificates and TLS

The screen shows the inventory of the node selected at the top; the node list comes from the configuration (tls, peers), so in a cluster you check each node separately. A row is one certificate from a file — a file with a chain gives several rows.

Column Meaning
File and role Path and role from the configuration. When a file cannot be read, the row gives the reason (unreadable: …) instead of certificate data.
Subject, Issuer Who issued the certificate and to whom.
Valid to Expiry date and the number of days left (expired N days ago, expires today).
Key Type and size of the public key: RSA 3072, ECDSA P-256, Ed25519.
Chain Whether the links in the file match each other — the issuer of one certificate is the subject of the next. Name matching, not signature verification; when the links do not match, the column shows chain incomplete: … instead of a confirmation.
Names The certificate names (SAN) that stations use to reach the gateway.
SHA-256 fingerprint Certificate digest — use it to compare the material on the node with the material at the issuer.

Rows are ordered by days to expiry, and a certificate close to its date (30-day threshold) gets a warning tag. The "Read again" button re-reads the files — after replacing material the new date shows immediately, even before the edge is reloaded.

Warning before the date

The same inventory feeds the gateway telemetry: the Days to certificate expiry (minimum) and Unreadable certificate files metrics. The Days before certificate expiry threshold (System → Notification channels) turns a breach into the Certificate close to expiry event, and the message in System → Messages gives the file, the subject and the number of days.

Replacing the HTTPS certificate

  1. Check in the panel which node holds the file and in which role.
  2. Issue a new certificate in your PKI. The name must match the name under which stations and browsers reach the gateway (the panel, API and SSO vhosts). Put the chain — server certificate and issuer — into gateway.crt, and the key into gateway.key.
  3. Replace the files on that node in place (cp, not install or mv) and keep the permissions of the current files — the edge reads them as a user without root (see the notes under the command list). The edge mounts individual files, and a mount holds the inode: install and mv create a new file and the container keeps reading the old one. The gateway mounts the whole directory, so a plain copy is enough for it.
  4. Restart the edge layer so it loads the new material: systemctl restart amfa-gateway-vm<N>.service (the API container starts in the same run). The unit stops and starts the existing containers, so after replacing with install remove the edge container before the restart: sudo podman rm -f amfa-openresty. Copying the files alone does not change the certificate served on port 443.
  5. Check the new date and fingerprint in the panel (the "Read again" button re-reads the files without a restart), then the connection: the panel in a browser without a certificate warning, and a sign-in on a station.
  6. Stations with pinning enabled (require_pinned_cert, in the panel "Additionally pin the certificate") require the server certificate or its issuer in the Windows LocalMachine/TrustedPeople store. Changing the certificate or its issuer requires distributing the new material to the stations (for example by Group Policy) — otherwise the station refuses the connection. Without pinning, standard HTTPS validation applies: trusted issuer, matching name and validity.
  7. In a cluster, repeat on every node and check each node's inventory.

Commands (Ubuntu node)

# 1. Copy the current material — to roll the change back
sudo cp -a /etc/amfa/tls /root/tls-backup-$(date +%F)

# 2. Put the new material in place — `cp` overwrites the file in place (inode unchanged),
#    `install` and `mv` create a new file the edge container no longer sees
sudo cp --preserve=mode,ownership new-gateway.crt /etc/amfa/tls/gateway.crt
sudo cp --preserve=mode,ownership new-gateway.key /etc/amfa/tls/gateway.key
sudo stat -c '%i %n' /etc/amfa/tls/gateway.crt   # same inode as before the replacement

# 3. Does the key match the certificate? Same public-key digest = it matches
diff <(openssl x509 -in /etc/amfa/tls/gateway.crt -noout -pubkey | openssl pkey -pubin -outform der | sha256sum) \
     <(openssl pkey -in /etc/amfa/tls/gateway.key -pubout -outform der | sha256sum) && echo MATCH

# 4. Is the chain complete and do the names match the gateway name
sudo openssl verify -CAfile /etc/amfa/tls/root-ca.pem /etc/amfa/tls/gateway.crt
sudo openssl x509 -in /etc/amfa/tls/gateway.crt -noout -subject -issuer -dates -ext subjectAltName

# 5. The edge loads the new material (N = node number, e.g. 141)
sudo systemctl restart amfa-gateway-vm<N>.service

# 5a. Variant after replacing with install/mv (new inode): recreate the edge container
sudo podman rm -f amfa-openresty && sudo systemctl restart amfa-gateway-vm<N>.service

# 6. What the edge serves on port 443 — the serial number must match the file
NAME=webui.<domain>
echo | openssl s_client -connect $NAME:443 -servername $NAME 2>/dev/null \
  | openssl x509 -noout -subject -issuer -dates -serial
sudo openssl x509 -in /etc/amfa/tls/gateway.crt -noout -serial

# 7. Rolling the change back when something fails
sudo cp -a /root/tls-backup-<date>/. /etc/amfa/tls/ && sudo systemctl restart amfa-gateway-vm<N>.service

Notes on the commands:

  • Permissions: keep the ones the current files have (sudo ls -l /etc/amfa/tls/). The edge starts inside the container as a user without root, so it must be able to read the vhost key; the database key (postgresql-vip.key) belongs to the postgres group and is 0640.
  • Step 5 interrupts the panel and API for a few seconds (the container stop limit is 10 s). Do it outside working hours, and in a cluster node by node, checking the panel after each one.
  • If you also replace the database material (postgresql-vip.crt), the gateway unit restart covers the API container as well.
  • In step 6 use the vhost name you call the panel with (webui.<domain>), not the IP address — servername decides which certificate the edge serves.
  • Reloading the configuration inside the edge container is not the way to replace material. The process in the container may not signal the master process (nginx -s reload ends with kill(1, 1) failed (13: Permission denied)), and an attempt with root permissions stops at reading the included resolver file (open() "/tmp/amfa_gateway_resolver.conf" failed (13: Permission denied)). The restart of the gateway unit completes the replacement.
  • Rolling back (step 7) also overwrites the files in place, so it needs no container recreation.

Issuing new material (CSR requests)

Material is ordered with a request (CSR) and a key generated on the node — the private key never leaves the node, only the request goes to the CA. Names and addresses come from the configuration, not from memory: the vhost names (server_name in /etc/amfa/openresty-tls.conf), the virtual addresses (vrrp_instance in /etc/keepalived/keepalived.conf and amfa-db.conf), the database name from the DSN, and the nodes (tls.nodeName, tls.peers in /etc/amfa/gateway.json).

The set is two shared roles plus one request per node (a pair of nodes = four requests, three nodes = five):

Role CN and names in SAN Target files on the node
vip-web webui.<domain>, amfa-auth.<domain>, sso.<domain> and the VIP address /etc/amfa/tls/gateway.crt + gateway.key
vip-db the database name from the DSN (amfa-db.<domain>) and the database VIP address /etc/amfa/tls/postgresql-vip.crt + .key
wezel-<name> the node name, its address, 127.0.0.1 and localhost the node certificate (telemetry, probes between nodes)
# Request for the vip-web role — names and address from this node's configuration
sudo openssl req -new -newkey rsa:3072 -nodes -sha256 \
  -keyout vip-web.key -out vip-web.req \
  -subj "/CN=webui.<domain>" \
  -addext "subjectAltName=DNS:webui.<domain>,DNS:amfa-auth.<domain>,DNS:sso.<domain>,IP:<panel VIP>"

# Request for the vip-db role
sudo openssl req -new -newkey rsa:3072 -nodes -sha256 \
  -keyout vip-db.key -out vip-db.req \
  -subj "/CN=amfa-db.<domain>" \
  -addext "subjectAltName=DNS:amfa-db.<domain>,IP:<database VIP>"

# Request for a node
sudo openssl req -new -newkey rsa:3072 -nodes -sha256 \
  -keyout wezel-<name>.key -out wezel-<name>.req \
  -subj "/CN=<node name>" \
  -addext "subjectAltName=DNS:<node name>,IP:<node address>,IP:127.0.0.1,DNS:localhost"

The knowledge base repository carries a script that does the same from the node configuration and prints ready-made CA commands: scripts/zadania-certyfikatow.sh (sudo bash … --katalog /root/certyfikaty --szablon <template name>; --wypisz only shows what it collected, and --rozdziel-sso splits SSO into a separate request).

The requests are submitted from a machine with access to the CA console — in a Windows PKI with certreq. Without -config the tool asks which certification authority to use:

certreq -submit -Template <template name> vip-web.req vip-web.cer
certreq -submit -Template <template name> vip-db.req vip-db.cer
certreq -submit -Template <template name> wezel-<name>.req wezel-<name>.cer

The returned file comes back to the node, gets the issuer appended (so it carries a chain), and only then replaces the material — following the in-place rule:

cat vip-web.cer /etc/amfa/tls/ca.crt > /root/gateway.crt      # certificate + issuer = chain
sudo cp --preserve=mode,ownership /root/gateway.crt /etc/amfa/tls/gateway.crt
sudo cp --preserve=mode,ownership vip-web.key /etc/amfa/tls/gateway.key
sudo openssl verify -CAfile /etc/amfa/tls/root-ca.pem /etc/amfa/tls/gateway.crt
sudo systemctl restart amfa-gateway-vm<N>.service

The file with the chain takes the issuer from the same PKI; the anchor (root-ca.pem) is the file stations and services use to check trust — without a chain that reaches it the panel shows chain incomplete: ….

Replacing the trust anchor (root CA and issuer)

The gateway certificate is issued by an issuer from the customer's PKI, and the root CA is the trust anchor of the whole installation. Both the station (machine store) and internal services — the authentication engine, the database and SSO — trust that anchor. Replacing the anchor is therefore a new PKI for the installation, not a single file swap:

  • the new chain must be complete in gateway.crt (the panel shows whether the links match),
  • the new anchor and issuer must first be distributed where trust is checked: to the stations and to the services,
  • only then are the certificates on the nodes replaced.

The anchor lives in /etc/amfa/tls/root-ca.pem and follows the same rule as the vhost certificate: the file is overwritten in place and the edge reads it after the unit restart.

# 1. Anchor into the node trust store (Ubuntu) — before touching the gateway files
sudo cp new-root-ca.pem /usr/local/share/ca-certificates/<name>.crt
sudo update-ca-certificates

# 2. Anchor in place and the vhost certificate with a chain to the new issuer
sudo cp --preserve=mode,ownership new-root-ca.pem /etc/amfa/tls/root-ca.pem
sudo cp --preserve=mode,ownership new-gateway.crt /etc/amfa/tls/gateway.crt

# 3. Does the chain reach the new anchor
sudo openssl verify -CAfile /etc/amfa/tls/root-ca.pem /etc/amfa/tls/gateway.crt

# 4. The edge loads the new material (N = node number)
sudo systemctl restart amfa-gateway-vm<N>.service

Stations with pinning receive the new anchor through the machine store (LocalMachine/TrustedPeople, for example by Group Policy); without it the station refuses the connection even when the gateway certificate is correct.

The gateway does not renew the vhost certificates by itself — it shows the date and warns, and the administrator performs the replacement on the node that holds the file. The internal material of the HA cluster (database and quorum) is renewed by a deployment timer; it does not cover the certificates in the table above.