Skip to main content
Video tutorial · 2:13

HAProxy module

Deploys the certificate to HAProxy over SSH. The module does not need to be told where the files are. It reads the configuration files HAProxy was started with to find the certificate files its TLS bind lines load. Those are files named with crt, the files of a crt directory and the entries of a crt-list. It replaces the ones that hold this certificate's names and checks the result with HAProxy itself.

Then it activates them. A file the running HAProxy already loaded is updated in memory over the Runtime API, and open connections keep running. Anything else reloads HAProxy, and the module waits for the new worker. If anything fails after a file was replaced, the previous files are put back.

HAProxy's configuration itself is never edited.

Every behaviour on this page was measured on the official HAProxy 2.4, 2.6, 2.8, 3.0, 3.2 and 3.4 builds and on the distribution packages of Ubuntu 22.04 (2.4), Ubuntu 24.04 (2.8), Debian 12 (2.6) and Rocky Linux 9 (2.8).

Overview​

  • Type and credential: type haproxy; credential ssh_private_key or ssh_password (the SSH credentials), slot default.
  • Connection: the target's SSH part — host name, optional IP, port, user — with the same host-key verification as an SSH target.
  • Per deploy:
    1. Find the HAProxy instance, read its configuration files and check them with haproxy -c.
    2. Pick the certificate files.
    3. Stage the new files and check them with haproxy -c on a scratch configuration.
    4. Replace them (each file is renamed into place).
    5. Run haproxy -c on the live configuration.
    6. Activate: the Runtime API, or a reload.
    7. Ask each changed listener which certificate it serves.
  • Rollback: supported — a rollback deploys the previous retained version to the same files (Rollback). Auto-rollback is available.

What the module deliberately does NOT do​

  • Edit HAProxy's configuration or a crt-list. It never adds a crt argument or a crt-list line. For a first install, name the file once; renewals replace the same file.
  • Add a certificate at runtime. The Runtime API updates files HAProxy already loaded. A new file is activated by a reload.
  • Encrypted keys. A file holding an encrypted key is not replaced (HAPROXY_UNSUPPORTED); CertAutoPilot writes unencrypted keys.
  • crt-store entries. A crt @store/name argument is listed as not followed.
  • SCT lists. A file with an .sctl beside it is refused (HAPROXY_UNSUPPORTED). The list belongs to the current certificate and HAProxy would send it with the new one.
  • Containers. An HAProxy that runs only inside a container on the host is refused (HAPROXY_CONTAINERIZED). A process counts as containerized when its root directory is another filesystem or its cgroup belongs to Docker, containerd, Kubernetes, Podman, LXC or CRI-O; a systemd-nspawn container is caught by the first rule (measured). A systemd service with its own mount namespace (Ubuntu's haproxy.service uses BindReadOnlyPaths) and HAProxy's own chroot are not containers. When the master runs as another account and its root directory cannot be read without sudo, whether it runs in a container cannot be told: that is refused (HAPROXY_PRIVILEGE — choose sudo, or connect as the account HAProxy runs as), also when only the Runtime API would be used.
  • Backend client certificates. server … crt lines are not touched.
  • Configurations whose variables grow without end. setenv A "${A}${A}" doubles a variable on every line, and HAProxy itself accepts such values (268 MB measured on 2.4 and 3.2). CertAutoPilot reads the configuration with its own bounds: no argument longer than 64 KiB once its variables are expanded, and at most 16 MiB expanded in one read. A configuration beyond either is refused as a whole (HAPROXY_UNSUPPORTED), never read in part.

Requirements​

The SSH account must be able to:

  • read the configuration files and every certificate file they name;
  • write the certificate files, and create a .cap-staging directory beside them (a real directory, mode 0700, owned by that account — anything else at that name is refused);
  • keep each replaced file's owner, mode, SELinux label and ACL;
  • use the admin-level stats socket or the master CLI (for the Runtime API);
  • reload HAProxy (when a reload is needed).

Its login shell must be a Bourne-style shell (sh, bash, dash, ksh, zsh, busybox ash; fish works too — measured). CertAutoPilot sends each host script as one command of many lines, and csh / tcsh end such a command at its first line and read the rest as their own commands (measured). An account with a csh-style login shell is therefore refused when it connects, before any script is sent (SSH_VALIDATION, naming the shell): give the account another login shell (chsh -s /bin/sh <account>) or connect with another account.

In practice that is root. Choose the privilege:

PrivilegeWhat runsNeeds
Run as the SSH userevery step as the SSH useran account with the rights above
sudo -nevery step under sudo -n shNOPASSWD sudo for the account. sudo -n never asks for a password: a sudo that wants one fails at once (HAPROXY_PRIVILEGE). This is root on the host.

Tools the host must have: a POSIX shell, awk, sed, dd, stat, df, xargs, flock (it keeps two deploys apart) and sha256sum (or openssl). These are present on every distribution measured.

The Runtime API needs a socket client. The module uses socat, perl or python3, whichever the host has:

  • Debian and Ubuntu always have perl.
  • RHEL and Rocky have python3.
  • The official HAProxy images have socat.

Every request gives up after 30 seconds without an answer. HAProxy 2.4 now and then never serves a new connection to its socket (measured: a few in a few thousand requests; 2.6 and later never) — such a request was not run, so it is sent once more; a request that got any answer is never sent twice.

openssl is used for the served-certificate check. chcon, getfacl/setfacl and setsid are used when present.

Whose HAProxy it manages​

CertAutoPilot acts as root on the host, so it only ever runs a program — and only ever checks a configuration — whose owner it may trust.

  • Root's HAProxy is managed as before. Without sudo, the SSH account's own HAProxy is.
  • A process of any other account named haproxy is ignored: its program is not run, it does not count as an instance, and its -sf <pid> does not make it the replacement of a real one (only a process of the same account running the same program takes over). It is reported with the warning HAPROXY_MASTER_IGNORED.
  • An HAProxy a service account runs is managed when the target lists that account under Accounts it runs as besides root (run_as_accounts, names or numeric uids, at most 8; needs sudo -n). CertAutoPilot then runs that HAProxy's own program (haproxy -vv, -c) as that account, never as root, with su -s /bin/sh <account> — the account's login may be closed. haproxy -c runs the Lua files a configuration loads, which is why it is never run as root for another account. Files are still written by root and keep their owner; the Runtime API and the reload signal are used by root. The host needs su (HAPROXY_UNSUPPORTED otherwise). A listed account's HAProxy in the legacy daemon mode outside systemd is not reloaded by CertAutoPilot (HAPROXY_LEGACY_RELOAD_REFUSED): starting a replacement for another account is not measured.
  • The program that is run must belong to root or to the account running it, with no write permission for anyone else, in directories no other account can change (HAPROXY_PRIVILEGE otherwise). The HAProxy binary field follows the same rule, and the program must answer -vv like HAProxy before -c is run with it (HAPROXY_NOT_FOUND otherwise).
  • A configuration no running HAProxy uses is checked only when it belongs to root or the account the steps run as (HAPROXY_PERMISSION otherwise).

Directories it writes into​

A certificate and its key are written only into directories no other account can change. Each directory a file is written into, and every directory above it (the path as written and as the links resolve), must:

  • belong to root, to the account the deploy runs as, to the account HAProxy's workers run as (user), or to the account a file holding the private key belongs to (it gets the key anyway) — a directory that receives only a certificate file may also belong to that file's owner, one that receives the key may not;
  • not be writable by its group or by others — a POSIX ACL that lets another account write shows up the same way. Above the file's own directory, a directory with the sticky bit (/tmp) is fine.

Every symbolic link on the path as written must belong to one of those accounts too: another account could point its own link elsewhere between two steps (in /tmp it may replace its link).

Otherwise nothing is written (HAPROXY_PERMISSION, naming the directory). The reason: a shell cannot hold a directory open, so in a directory another account can write, the name of the file being written could be replaced by a link or a pipe between two steps, and the key would reach that account. The preview and the dry run show the same refusal. The work directory follows the same rule and is made private (mode 0700, owned by the account the deploy runs as); one another account owns is refused before anything in it is created or changed.

Target configuration​

FieldMeaning
SSH host / IP / port / useras for an SSH target
PrivilegeRun as the SSH user or sudo -n (above)
HAProxy instance (config_paths)the configuration files and directories the master was started with (-f, in order). Empty = the only HAProxy running. Required when several run (the error lists them).
Which certificate filesFind by certificate names (default) or Listed files (below)
ActivationAutomatic (the Runtime API, else a reload), Runtime API only, or Always reload — see Activation
Stats socketthe socket the Runtime API uses. Empty = the first admin-level unix stats socket of the configuration, else the master CLI (-S).
ReloadAutomatic (systemctl reload <unit> when the master runs in a systemd service, else USR2 to the master), systemctl reload, or USR2
Reload waithow long to wait for the new worker, 5–300 s (default 30). The longest grace of the configuration (global, defaults, frontend or listen) is added: the old worker keeps those listeners that long after a good reload.
Allow reloading a legacy HAProxysee Legacy daemon mode (default off)
haproxy binaryempty = the running master's own executable, else haproxy on PATH
Work directoryjournal and backups, mode 0700. Empty = /var/lib/certautopilot with sudo, ~/.certautopilot without.
Accounts it runs as besides root (run_as_accounts)empty = root's HAProxy only. See Whose HAProxy it manages.
Check served certificateask each changed listener on the host which certificate it serves afterwards (default on)
Reload despite pending changessee Unapplied configuration changes (default off)

The HAProxy instance paths, the HAProxy binary, the stats socket and the work directory are plain absolute paths: ASCII letters, digits and . _ - + = @ % only. A path with a space, a quote, $, ,, ! or another character is refused when the target is saved (and again before anything runs on the host) — the stats socket path, for one, is handed to the socket client, which reads , and !! as its own syntax.

Find by certificate names​

Every bind line with ssl in a frontend or listen section is read, with the certificate files it loads:

  • crt <file>: the file itself.
  • crt <directory>: every file of the directory except .key, .ocsp, .issuer and .sctl files. HAProxy 2.4 also loads dot-files; 2.6 and later skip them.
  • crt-list <file>: each line's file, with its SNI filters.

A file is updated when:

  • the certificate it holds now is covered by the deployed certificate — every one of its names (a wildcard covers one label); or
  • an earlier deploy of this certificate wrote it. This keeps a rollback to a version with fewer names working.

A file holding another certificate is left alone. A file another CertAutoPilot certificate wrote stops the deploy (HAPROXY_CONFLICT). The first time a file is taken over because the deployed certificate covers the one it holds, the result carries the warning HAPROXY_ADOPTED. When a crt-list line names SNI filters for a written file that the deployed certificate does not cover, the result carries HAPROXY_NAMES_NOT_COVERED and the job log names them; the file is still written. A path holding a control character (a file in a crt directory named with a newline, say) is listed and skipped, never written.

Whose files. A file found by its names is taken over only when it and its directory belong to root or to an account HAProxy runs as. A file in another account's directory is left alone and reported (HAPROXY_OWNER_SKIPPED): writing a certificate that covers more names there — a wildcard, for example — would hand that account its key. Name the file under Listed files to write it on purpose. A file this certificate already wrote stays its own.

Optional filters narrow the search to some frontends or some ports. A port is a whole number from 1 to 65535, at most 32 of them; the form refuses anything else.

Relative paths are resolved as HAProxy resolves them: against crt-base, else against the master's working directory (not the configuration file's directory). A crt-list file's own path ignores crt-base and is resolved against the working directory; the lines inside it use crt-base (measured on 2.4, 2.8 and 3.2). A crt-list line names a file: HAProxy refuses a directory there (2.4) or never finishes reading the configuration (2.6 to 3.4 — measured). Environment variables in double quotes are expanded with the master's own environment; only the variables the configuration names are read — every name in every .if branch, also one a setenv or presetenv in another branch would set (in the master that branch may not be taken). A configuration naming more than 256 variables, or one whose name cannot be read from the master (longer than 128 characters, or with a character other than letters, digits and _), is refused rather than read in part (HAPROXY_UNSUPPORTED). .if blocks are evaluated. A bind inside a block whose condition the module cannot evaluate counts only when the stats socket lists its file as loaded (HAPROXY_UNCERTAIN_BINDING otherwise).

Listed files​

Absolute paths of certificate files. A path must not contain $ (in an HAProxy configuration it names an environment variable, so it is not one fixed file; refused when the target or the override is saved). By default the key is written into the file, which is HAProxy's usual layout. Tick Key in <file>.key to write it beside the file; <file>.key is the only separate key file HAProxy reads.

  • A listed file that holds a certificate this one does not cover is refused (HAPROXY_CONFLICT), not overwritten.
  • A missing file is created with mode 0600. Its directory must exist.
  • A listed file no bind loads yet is written but not served (HAPROXY_NOT_BOUND, nothing activated). Name it once. A new listed file inside a crt <dir> is loaded by that directory's binds at the next reload: it is activated by a reload (the Runtime API cannot add a file — measured), unless its name is one HAProxy does not load from a directory (.key, .ocsp, .issuer, .sctl; a dot-file from 2.6).

File layout​

An existing file keeps its layout:

  • key inside the certificate file, written as leaf + chain + key; or
  • key in <file>.key beside it, with both files written.

With ssl-load-extra-files excluding key, a file without a key inside cannot be served and is not replaced. With ssl-load-extra-del-ext, HAProxy removes only a .crt extension when it looks for the key (measured on 2.8): site.crt reads site.key, but site.pem still reads site.pem.key.

RSA and ECDSA files​

When one bind loads an RSA and an ECDSA file for the same names, HAProxy chooses by the client's signature algorithms. Only the file of the deployed certificate's key type is replaced. The other keeps its certificate and its own expiry (HAPROXY_OTHER_KEY_TYPE_KEPT).

Measured: turning the RSA file into a second ECDSA file would leave RSA-only clients with no certificate.

OCSP responses​

An .ocsp file beside a replaced certificate belongs to the old certificate. HAProxy ignores it after a reload, and a Runtime API update drops the staple. It is left in place, and the deploy warns HAPROXY_OCSP_STALE so you refresh it.

Activation​

ActivationWhat happens
Automatic (default)Every changed file the running HAProxy already loaded is updated over the Runtime API (set ssl cert + commit ssl cert), through an admin-level stats socket or the master CLI. When that cannot be used, HAProxy is reloaded and the deploy warns HAPROXY_RELOADED with the reason. Reasons: no admin-level socket and no master CLI, no socket client, a file HAProxy has not loaded yet, nbproc on 2.4, a file too large for one Runtime API command, a file whose name a Runtime API command cannot carry (see below). One command carries a whole file and must fit in HAProxy's buffer (tune.bufsize, 16384 bytes unless set — measured on 2.8: a 16557-byte command was refused, 15907 bytes passed); a certificate with several hundred names, a long chain or an RSA-4096 key can exceed it.
Runtime API onlyThe same, but refused instead of reloading (HAPROXY_RUNTIME_UNAVAILABLE, nothing written).
Always reloadAlways reload.

Measured under load (20 parallel fresh handshakes and 10 idle keep-alive connections, five changes):

  • Runtime API: no handshake failed and every connection stayed open.
  • Reload: no handshake failed, but every idle keep-alive connection was closed. The old worker stops gracefully and clients reconnect.

The files on disk are always written too, so a later reload serves the same certificate.

File names the Runtime API cannot carry. A file's name is part of the command (show ssl cert <file>, set ssl cert <file>). Measured on HAProxy 2.4 and 3.2: the CLI ends a command at ; and runs what follows as the next command, and a blank, a tab or a backslash in the name makes the file "Not found" — while HAProxy itself loads such files from a crt directory. A file whose path holds a blank, ;, a backslash or a control character is therefore never named over the Runtime API: nothing is asked about it, and it is activated by a reload (HAPROXY_RELOADED; with Runtime API only, HAPROXY_RUNTIME_UNAVAILABLE and nothing written). Quotes, #, $, *, brackets and non-ASCII names are carried as they are. Before this rule a dry run of a file named x;set maxconn global 7;.pem changed HAProxy's global maxconn (measured).

After a Runtime API commit, show ssl cert must report the new certificate — compared by its SHA-1 fingerprint, which show ssl cert prints (two certificates may share a serial). A commit whose answer was lost counts as applied when show ssl cert then reports the new certificate: the deploy goes on (HAProxy 2.4 now and then drops a CLI connection — measured). When HAProxy refuses one commit, the deploy puts things back and fails (HAPROXY_RUNTIME_REFUSED):

  • the certificates already committed in this run are sent back from the backups — also those whose commit answer was lost but which HAProxy applied;
  • the files on disk are restored.

HAProxy keeps one Runtime API transaction at a time; one left open blocks updates of every other file. A transaction an interrupted deploy left on one of its own files is aborted first; one on a file the deploy does not write belongs to someone else, so the deploy stops with HAPROXY_RUNTIME_REFUSED naming the file and leaves it open.

If HAProxy refuses to take a previous certificate back, it serves a certificate the files no longer hold: the deploy fails with HAPROXY_RECOVERY_FAILED naming the files. Reload HAProxy, or deploy again, to make memory and disk agree.

When HAProxy gives no answer at all about a file — show ssl cert stays empty after a commit (asked three times, two seconds apart), or a commit's answer was lost and nothing can be read after it — HAProxy may hold either certificate. Nothing is put back then: the new files stay on disk (they passed haproxy -c), and the deploy fails with HAPROXY_ACTIVATION_UNKNOWN (retried). The next run finds the files current but not activated, and activates them without writing. That next run comes by itself (the automatic re-run of a failed or partial run); auto-rollback does not answer this failure — rolling back would write the previous version over files that are in order.

How a reload is judged​

A reload counts as done only on evidence, never on time alone:

  • The master CLI's answer. With a master socket (-S; Debian and Ubuntu start HAProxy with one) the reload is sent through it on 2.8 and later — once: a reload whose answer was lost is never sent again — and HAProxy answers Success=1 or Success=0 once the new worker has started or failed (measured on 2.8, 3.0, 3.2 and 3.4). Success=0 puts the files back at once (HAPROXY_RELOAD_FAILED, quoting HAProxy's alerts).
  • The old workers stop listening. After a good reload every old worker stops listening at once (also while it still finishes open connections); after a failed one it keeps listening (measured on 2.4, 2.8, 3.2 and 3.4). This needs the workers' sockets to be readable: root, or the account HAProxy runs as.
  • The master's counters, on 2.6 to 3.0: show proc and HAProxy's own environment count a failed reload at once (measured), so a reload counted with no new failure is a good one.
  • Before 3.1, a failed reload starts no new worker (measured), so a new worker that stays up for 5 seconds started.

On 3.1 and later, a reload that fails still starts a new worker that exits a few seconds later, and show proc counts the failure only then (measured on 3.2 and 3.4). Without the master CLI and without readable worker sockets, the outcome could not be seen: the deploy is refused before anything is written (HAPROXY_UNSUPPORTED). Start HAProxy with a master socket, choose the sudo privilege, or use the Runtime API. If the master CLI's answer is lost and the sockets cannot be read, the outcome is unknown: the new files stay, and the deploy fails with HAPROXY_ACTIVATION_UNKNOWN.

A systemd unit without a reload command (CanReload=no) is not used for the reload: Automatic signals the master instead, and a target set to systemctl reload is refused before anything is written. systemctl reload is bounded by the reload wait.

A reload applies pending configuration changes

On HAProxy 2.4, 2.8 and 3.0, a reload whose new worker fails after it started (measured with a chroot directory that does not exist; haproxy -c does not catch it) makes the master stop every worker: HAProxy is down until it is started again. A certificate change alone cannot cause this (the certificates are loaded before the new worker starts), but with Reload despite pending changes on, the deploy's reload applies whatever else changed in the configuration.

Debian and Ubuntu packages start HAProxy with an admin-level stats socket and a master CLI. Rocky Linux 9 has neither by default, so it reloads unless you add stats socket … level admin.

Legacy daemon mode​

HAProxy can run without master-worker mode (-D alone): one process, no master. Reloading it means starting a replacement process with -sf <old pid>. The old process then finishes its connections and exits.

The Ubuntu, Debian and Rocky packages and the official images all use master-worker mode.

In legacy mode, a deploy proceeds as follows:

  • Runtime API possible: it is used as usual.
  • A reload is needed: the deploy is refused unless Allow reloading a legacy HAProxy is on (HAPROXY_LEGACY_RELOAD_REFUSED).
  • Allowed, with a systemd unit: the process is reloaded through its unit, whose reload starts a replacement process. An error answer from systemctl reload alone does not put the files back — the reload may have started the replacement before something else failed; the evidence below decides, and a replacement that took over despite the error is logged as a warning.
  • Allowed, no systemd unit: CertAutoPilot starts the replacement itself: it uses the running process's own arguments and environment, adds -sf (and -x for an expose-fd listeners socket), and starts it with setsid. A replacement that refuses its configuration (exit code other than 0) puts the files back at once.

Either way, a reload counts only when the replacement — the process the unit or the pidfile names, else one found on the host — runs the instance's own binary, names the old process in -sf (or -st), started after the reload began, is not a zombie, and stays up while the old process is gone or listens on nothing, for 5 seconds. Another HAProxy on the host is never taken for it. Otherwise the files are put back and the old process keeps serving (HAPROXY_RELOAD_FAILED). A relative pidfile is read from HAProxy's start directory.

A chrooted legacy HAProxy reports its chroot directory as its working directory, so where it started is unknown. It is taken from an absolute -C, else from its systemd unit's WorkingDirectory; with neither, a relative path in its command line or configuration (-f, -p, crt, crt-list, crt-base, pidfile) is refused (HAPROXY_UNSUPPORTED). Absolute paths need nothing.

Measured: a legacy reload failed no handshake; idle keep-alive connections closed as in master-worker mode.

A process started from the SSH session

Outside systemd the replacement is started from CertAutoPilot's SSH session. On a host whose logind kills session processes at logout (KillUserProcesses=yes), give such an HAProxy a systemd unit instead.

How a deploy runs​

  1. Discover.

    • Find the HAProxy masters from /proc: argv, working directory, systemd unit.
    • Read the configuration files of the -f list; a directory gives its *.cfg files in name order.
    • Run haproxy -vv.
    • When a stats socket answers, read its list of loaded certificate files (show ssl cert) and the running worker's start time (show info).
    • The current configuration must pass haproxy -c; otherwise nothing is changed (HAPROXY_CONFIG_INVALID).
  2. Plan. Inspect every candidate file:

    • whether it exists, what it resolves to, its owner, mode and SHA-256;
    • the certificate it holds, and whether a key is inside or in <file>.key;
    • an .ocsp or .sctl beside it.

    A key's content is never read back, only its first line and hash.

  3. Refuse before writing on:

    • a conflict, an encrypted key or an SCT list;
    • an unreadable file or a missing directory;
    • too little free space next to a file;
    • too little free space in the work directory: the deploy asks for 512 KB plus twice the size of the files it writes there (its journal, its answer and the backups) and stops with HAPROXY_NO_SPACE before anything is staged;
    • unapplied configuration changes (when a reload is needed);
    • an activation the target does not allow.
  4. Stage. Each file is written into a .cap-staging directory beside it, as <file name>.captmp.<run id>. A crt directory loads every file in it, a stray staged copy included (measured); it never loads a sub-directory. A restore's temporary copy goes there too, never beside a loaded file. Copies a killed run left there are removed by the next run. Steps:

    1. Read exactly its byte count from the SSH session's standard input; secrets are never on a command line.
    2. Check its SHA-256.
    3. Give it the replaced file's owner, mode, SELinux label and ACL.
    4. haproxy -c loads the staged files in a scratch configuration. A file it refuses stops the deploy with nothing replaced (HAPROXY_STAGE_REFUSED).
  5. Swap.

    1. The configuration files must still read as planned.
    2. Per file: the file must still have the hash the plan read (HAPROXY_CHANGED_DURING_DEPLOY otherwise), it is copied to the backup directory, and the staged file is renamed over it.
  6. Check. haproxy -c on the live configuration, as the master would read it:

    • from its working directory;
    • in master-worker mode (-W) when the master runs that way: a configuration with program sections passes the check only then (measured on 2.4, 2.8 and 3.2);
    • with the master's -L (the local peer name a peers section looks for);
    • with its environment — your own HAPROXY_* variables included — minus HAProxy's master-worker state (HAPROXY_MWORKER*, HAPROXY_PROCESSES): with those set, haproxy -c exits 2 on 2.6, 2.8 and 3.0 — measured.
  7. Activate (see Activation).

    • Runtime API: per file set ssl cert and commit ssl cert.
    • Reload: through the master CLI (2.8+, when there is a master socket), else systemctl reload <unit> or kill -USR2 <master>; then judged as How a reload is judged says. A child of the master that runs something else — a program section's process, such as the Data Plane API — is not a worker. A reload that does not take over keeps the old worker: the files are put back and the deploy fails (HAPROXY_RELOAD_FAILED).
  8. Verify. For every TCP address of a bind loading a changed file, openssl s_client on the host asks for the certificate with the deployed certificate's key type and a name it covers. A listener still serving another certificate makes the target partial (HAPROXY_SERVED_MISMATCH). When the check cannot run — openssl is not installed on the host, or a listener does not answer it — the target succeeds with the warning HAPROXY_SERVED_UNVERIFIED. A load balancer in front is checked by validation endpoints.

  9. Commit. The backups are deleted. The target's state records which files the certificate wrote.

When HAProxy is not running, the files are written and checked with haproxy -c, nothing is activated, and HAProxy serves them when it starts (HAPROXY_NOT_RUNNING). HAProxy's own output about configuration files no running HAProxy uses is not shown (it could quote any file on the host): run haproxy -c on the host to see it.

Recovery​

  • Any failure after a file was replaced puts every replaced file back from the backups (and, after a Runtime API commit, sends the previous certificate back to HAProxy). A file another writer changed after the swap is left as it is: the deploy fails with HAPROXY_RECOVERY_FAILED and names it.
  • A restore that cannot finish fails the deploy with HAPROXY_RECOVERY_FAILED. The message names the files and the backup directory, which stays until you remove it; fix by hand. The same code reports a certificate HAProxy would not take back over the Runtime API.
  • When the SSH session or the CertAutoPilot worker dies in the middle, the script on the host ignores the hang-up and finishes (or restores) on its own. Its journal stays in <work dir>/haproxy/txn-<id>/. Files already current on disk but not yet in HAProxy's memory are activated by the next run without being written again: it compares the certificate (SHA-1 fingerprint) HAProxy reports.
  • Two deploys to one host never overlap: CertAutoPilot runs one deploy per host at a time, and a host-side lock (flock) answers a second one with HAPROXY_IN_PROGRESS (retried). A host without flock is refused before anything is written (HAPROXY_UNSUPPORTED). The lock lives in the work directory: two installations, or two targets with different work directories, do not share it — use one work directory per host. A staged copy carries its run's id, so such runs never take each other's copy; the one that swaps second finds the files changed (HAPROXY_CHANGED_DURING_DEPLOY) or its staged copy gone (HAPROXY_STAGE_REFUSED), with nothing replaced.
  • A work directory that fills up while the deploy runs never loses the result: a failed run puts the files back and answers with its code; a run that finished answers HAPROXY_SCRIPT ("the deploy finished on the host, but its answer could not be kept"), and the next run finds the files current and activates only what is still needed.

Unapplied configuration changes​

A reload applies everything in HAProxy's configuration — also changes someone saved but has not applied yet. When a reload is needed and a configuration or crt-list file is newer than the running worker, the deploy is refused before anything is written (HAPROXY_PENDING_CHANGES), naming the files.

The Runtime API applies no configuration change, so this check does not apply to it. Reload HAProxy yourself, or turn on Reload despite pending changes on the target. If the start time of the running worker cannot be read, the deploy goes on with the warning HAPROXY_PENDING_UNKNOWN.

Live pickers and preview​

On a saved target:

  • the instance picker lists the HAProxy masters on the host, with their mode;
  • the listed-file picker lists every certificate file a TLS bind loads;
  • Preview certificate files answers what a deploy would do, from the deploy's own plan. Each file shows the certificate it holds now and the binds that load it, and whether it would be replaced, kept or refused. It also shows how the deploy would activate the files, and why it would reload.

A distribution's override row offers the same preview for its certificate. All of them only read.

A picker or preview that names another instance's configuration files, or listed files the saved target does not name, needs a project admin (403 for an operator): it reads those paths on the host with the target's privilege, the same choice that needs the Admin role when it is saved as an override. An operator can preview the saved target as it is, filter by frontends and ports, and run a dry run of a saved distribution.

Per-distribution overrides​

An override row can name the HAProxy instance (its configuration files, picked from the host) and replace the target's placement (find by names, with its filters, or listed files) for one distribution. The instance is chosen field by field: the first row that names one — the target's own row, its group's row, then the Default row — else the target's own. The first row that sets a placement replaces the target's placement as a whole (Overrides). When several HAProxy instances run on the host and none is named, the run stops and lists them.

An instance started with several -f paths is one value of several paths: picked from the host it comes as a whole; typed by hand it is one entry per path, in order. A find-by-names row carries its own filters — frontends and ports. The target's filters do not apply to the distribution once a row sets a placement, and the row's summary names the filters it has.

Setting or changing the instance or a listed file in an override needs the Admin role; for an operator whose change does not go through approval, the drawer says so on those inputs and the save is refused (403).

Runs over many servers​

  • Hosts at once. One run works on up to five hosts at a time (the module configuration's concurrency, 1–50); the targets of one host run one after another. The SSH Max Concurrency setting (Settings → General) is a ceiling on it — it never raises the module's own value — and with Parallel Execution off a run takes one host at a time.
  • A time budget per target. A target that takes the login and then stops answering is given up after 5 minutes plus twice its reload wait (6 minutes with the default 30 s; a grace the configuration sets is not counted). It fails with HAPROXY_SCRIPT, and the other hosts go on. The script on the host ignores a cut session and finishes on its own; the next run reads what it did.
  • A partial run is run again. When some targets succeeded and others did not, the distribution sweep runs the distribution again for the targets that failed, were not reached, or failed their post-deploy check — up to three times per certificate version, one scheduler cycle apart (hourly by default). The targets that hold the version are not contacted; the job log says what a re-run covers, and the distribution's result always describes every target. A run started by hand covers every target. After the third attempt the distribution stays partial until it is run by hand. This is the rule of a distribution that runs in one job; one large enough to fan out retries inside its batches instead (transient failures and targets not reached, three waves), and its final partial is not run again.
  • Auto-rollback. A host the run could not connect to was sent nothing: with auto-rollback on it does not roll the other hosts back — it is run again like any failed target. Refusals made before anything is written do not roll back either. A lost answer, a failed reload or a failed restore still does; HAPROXY_ACTIVATION_UNKNOWN does not — the files are new and the next run only activates them (Rollback).
  • Fan-out. Batches are sized from the targets' time budgets, and a target a batch did not reach before its time ended is retried together with the transient failures (Fan-out).

Identity, idempotency and state​

Per certificate the target records the files it wrote — the name HAProxy uses and the file it resolved to — the deployed leaf and the version HAProxy was last activated for. A name that now resolves to another file (a link pointed elsewhere) is judged by the names its certificate holds again; a file another certificate recorded is refused under any name (HAPROXY_CONFLICT). Files already holding exactly what would be written are not written again. When the target is pointed at another machine (another host name or IP, or port), this certificate's record no longer counts: the files there are judged by their names again and its activation marks are not reused. Another certificate's record on the target still claims its files, whatever the address — it deploys through the same target. A host name written in other letter case or with a trailing dot is the same machine. The record is saved as each target finishes, so a run that is interrupted keeps the records of the targets it finished.

Health check​

Connects, runs sudo -n when chosen, finds the instance, reads the configuration, runs haproxy -c and asks the socket what it loaded. Reports the HAProxy version, the configuration files, the master and its mode, and the Runtime API socket. It warns when:

  • a deploy would reload instead of using the Runtime API;
  • the instance runs in legacy mode;
  • the configuration changed after the running worker started;
  • openssl is missing.

Error codes​

See Error codes → HAProxy. A certificate or a target that cannot be used as given is HAPROXY_VALIDATION (not retried): an expired certificate, a key that does not belong to it, several HAProxy instances without an instance on the target, a missing directory, a path on the target that is not a plain path, or an HAProxy that only an account the target does not list runs. A connection that cannot be made uses the SSH codes (SSH_CONNECT, SSH_AUTH, SSH_HOST_KEY_CHANGED, SSH_HOST_KEY_ALGO, CREDENTIAL_MISSING; SSH_VALIDATION for a csh-style login shell). A connection lost after it was up — while a script ran — is HAPROXY_SCRIPT (retried). A job an operator cancelled carries no code and is not retried.

Video tutorial

Short, hands-on videos showing this feature working for real. English audio, English and Turkish subtitles. All video tutorials →

Deploy Certificates to HAProxy Without Dropping ConnectionsYouTube ↗