Skip to content

Deploy an SSH Server and an SSH User with PKI Manager — Operator Reference Guide

Source: docs/ssh/deploy-server-and-user.md

Zones: on a multi-zone installation (SSH zones) a host and an identity each belong to exactly one zone, and a host trusts only that zone’s User CA. Register the host, create the identity and issue certs in the same zone; pick it from the zone switcher (UI) or pass zone (API). Single-zone installs follow this guide unchanged.

Automation-first, end-to-end. This is the current counterpart to the legacy manual/UI walkthrough in operator-quickstart.md.

What you’ll end up with: a fleet of SSH servers that trust user certificates issued by PKI Manager (no per-user authorized_keys), clients that connect with no host-key TOFU prompt, principal-based RBAC deciding which local accounts a user may log into, unattended host-cert renewal, and a live revocation channel. User certs are short-lived (default 7 days); host certs long-lived (default ~1 year). Private keys never leave the KMS (CA keys) or the user’s laptop (login keys).

In a hurry? Jump to §6 — the complete, copy-paste worked example (or run the zero-infra sandbox ansible/tests/e2e/run.sh). §0–§5 explain why each step is there.


The two trust directions (both must be wired, or auth is half-broken)

Section titled “The two trust directions (both must be wired, or auth is half-broken)”

PKI Manager runs two CAs whose private keys live in the Cosmian KMS: a User CA (signs people’s login certs) and a Host CA (signs servers’ host certs). Trust flows in two opposite, independent directions:

Direction What is installed, where Referenced by Public download
Servers trust users User CA public key → /etc/ssh/ssh-user-ca.pub on each server sshd TrustedUserCAKeys GET /ssh/trusted-user-ca-keys
Clients trust servers Host CA @cert-authority line → each client’s ~/.ssh/known_hosts OpenSSH known-hosts CA marker GET /ssh/cert-authority?pattern=*.example.com

Wire only one side and you get a classic half-config: user certs are ignored if the server has no TrustedUserCAKeys; clients still get host-key/TOFU prompts if they lack the @cert-authority line. (The Ansible role in §2 installs the server side automatically; §3/§4 cover the client side.)

A principal is a role label (e.g. admins, developers). For a login to succeed the same principal must appear in two places:

  1. inside the user’s certificate, AND
  2. in the server’s /etc/ssh/auth_principals/<account> for the local account being logged into.

If the principal exists in only one place, OpenSSH accepts the certificate signature but still DENIES the login — you see Valid certificate but Permission denied. This is the single most common mistake. Only the host map (§3, step 3) populates auth_principals; issuing a cert never blocks on a missing map (the form only warns).

NTP is a HARD prerequisite (every server AND every client)

Section titled “NTP is a HARD prerequisite (every server AND every client)”

Certificate validity windows and KRL freshness depend on an accurate clock, so a time daemon (chrony / systemd-timesyncd / ntp, or a synced timedatectl) must be running everywhere.

  • Validity windows: user certs ~1 week, host certs ~1 year. Clock drift puts now outside the cert’s window, so a signature that verifies is still rejected as not-yet-valid or expired.
  • KRL freshness (ECIES channel): each ECIES payload carries a valid_until. krl-client rejects a payload whose valid_until is in the past beyond --clock-skew (default 300s) with exit code 5 (“payload expired”) — a drifted host then fails every run and silently freezes on its last-good KRL. The shipped systemd unit orders itself After=time-sync.target, and the Ansible role preflights time-sync and fails fast (ssh_host_cert_require_timesync, default true).
Prerequisite Notes
Both User CA and Host CA exist in PKI Manager KMS reachable. See §1.
Fleet token pkimg_…, scoped to ONE Host CA Correct ops (see §1). Store in Ansible Vault.
community.crypto collection on the Ansible controller ansible-galaxy collection install -r ansible/requirements.yml
NTP/chrony on every server and client Hard requirement (above).
User has an SSH keypair; only the public key reaches the operator ed25519 (default) or ecdsa-sha2-nistp256.
Auth gate With OIDC disabled the SSH REST/tRPC surface is fail-closed; set ALLOW_UNAUTHENTICATED_SSH_CA=true for local dev, else these endpoints return 403.

In the UI: /ssh → Certificate Authorities → Create SSH CA.

  • Create the User CA (caType: user). Issuing a user cert throws “no active User CA — create one first” if none is active.
  • Create the Host CA.

Then hand out CA trust in both directions (the Ansible role installs the server side and the Host-CA anchor for you; distribute the @cert-authority line to clients — see §3/§4).

1.2 Mint the fleet token with the ops a self-provisioning host needs

Section titled “1.2 Mint the fleet token with the ops a self-provisioning host needs”

Mint with the module (pki_manager: action=ssh_token_mint), the REST endpoint POST /api/v1/ssh/tokens, or the UI — scoped to the one Host CA this fleet belongs to. The required ops depend on whether the host uses the ECIES revocation channel (§2.2):

Server profile Token ops Backing endpoints
Without live revocation sign-host, get-principals POST /sign-host, GET …/hosts/<fqdn>/auth-principals
With KRL revocation (ECIES — recommended) sign-host, get-principals, register-host-pubkey + POST /register-host-pubkey
  • The token is shown once. The backend rejects any request whose token lacks the required op with 403 FORBIDDEN.
  • The API base is derived by the role as ssh_ca_api_url = {{ ssh_ca_base_url }}/api/v1/external/ssh.
  • Store the token in Ansible Vault, never in plain inventory. With unattended renewal on (default), the host stores this token at /etc/pki-manager/ssh-renew.env (0600) to re-mint itself — which is why the token must carry sign-host (and why a compromised host can then sign host certs for any FQDN under that Host CA; see the renewal gotcha in §2).

2. Deploy a SERVER (Ansible ssh_host_cert role)

Section titled “2. Deploy a SERVER (Ansible ssh_host_cert role)”

Everything here uses the oriolrius.pki_manager collection — the ssh_host_cert role plus the pki_manager module that drives the PKI Manager REST API (no curl, no tRPC).

Step 1 — Install the collection (once, on the controller). It pulls in community.crypto automatically:

Terminal window
ansible-galaxy collection install oriolrius.pki_manager

Step 2 — Put the fleet token in Vault (never in plain inventory):

Terminal window
ansible-vault create secrets.yml # set: ssh_ca_fleet_token: pkimg_…

Step 3 — Write a YAML inventory (inventory.yml). The play gathers facts (the role needs ansible_fqdn + ansible_all_ipv4_addresses):

inventory.yml
all:
children:
sshservers:
hosts:
server1.example.com: {}
server2.example.com: {}

Step 4 — Write the playbook (site.yml). Only ssh_ca_base_url is set here; the vaulted ssh_ca_fleet_token comes from -e @secrets.yml:

site.yml
- name: Provision SSH-CA servers
hosts: sshservers
become: true
gather_facts: true
vars:
ssh_ca_base_url: https://pki.example.com
roles:
- oriolrius.pki_manager.ssh_host_cert

Defaults already ON: ssh_host_cert_principals_enabled (login RBAC), ssh_host_cert_renew_enabled (unattended renewal). KRL revocation is OFF by default — a plain run installs only a fail-closed empty RevokedKeys placeholder, so enable the ECIES krl-client channel in §2.2 for live revocation. Other useful defaults: ssh_host_cert_reload_method (service; use command for init-less containers), ssh_host_cert_scheduler (cron). Full variable table: roles/ssh_host_cert/README.md.

Step 5 — Run it:

Terminal window
ansible-playbook -i inventory.yml site.yml -e @secrets.yml --ask-vault-pass

One run does, in order:

Phase What happens
1 — Key + cert + trust Use (or generate) the ecdsa-sha2-nistp256 host key on the node → POST /sign-host, install …-cert.pub (0444) → fetch & install the User-CA (GET /ssh/trusted-user-ca-keys) and Host-CA (GET /ssh/host-ca-keys) trust anchors.
2 — Principals (RBAC) GET …/hosts/<fqdn>/auth-principals → write /etc/ssh/auth_principals/<account> + a fail-closed RevokedKeys placeholder.
3 — sshd drop-in GET /ssh/hosts/<id>/sshd-config → install /etc/ssh/sshd_config.d/60-ssh-ca.conf, run sshd -t, flush handlers to reload sshd.
4 — Renewal Install the renewal cron/job.

Re-runs are idempotent (sign-host is keyed on host+fingerprint via an Idempotency-Key of <inventory_hostname>-<fingerprint>; the renewal job instead uses renew-<fqdn>-<bucket>). The Host-CA trust anchor at /etc/ssh/ssh-host-ca.pub is installed here in Phase 1 — this must exist before any composed-KRL cutover, since composed KRLs are Host-CA-signed and krl-client verifies against this file.

Ordering — auth_principals is populated at run time. Phase 2 writes /etc/ssh/auth_principals/<account> from the host maps that exist when the role runs. A first §2 run performed before any maps exist (they are created in §3 Step 3) installs an empty principals set, so §4 login will be denied until you re-run this §2 role (or re-push the auth_principals file and click Mark pushed) after creating the maps. Plan the order: deploy the host (§2) → create identity / principals / maps (§3) → re-run §2 → log in (§4).

2.2 Enable KRL revocation (ECIES krl-client)

Section titled “2.2 Enable KRL revocation (ECIES krl-client)”

Live revocation is OFF by default — a plain run installs only an empty, fail-closed RevokedKeys placeholder. Enable the encrypted ECIES krl-client channel to make revocations and per-host blocks land automatically. Its properties:

ECIES krl-client
Transport Encrypted to the host’s own key; signature-verified before install
Signature verified? Yes — composed-KRL Host-CA signature checked against /etc/ssh/ssh-host-ca.pub
Host key type switched to ecdsa-sha2-nistp256 (ECIES is P-256 only)
Backend flag SSH_ECIES_ENABLED=true (required)
Token ops sign-host, get-principals, register-host-pubkey

Enabling it registers the host’s ECDSA pubkey (POST /register-host-pubkey, asserted 200), installs the krl-client binary + config + scheduler + a first-run pull, and verifies each composed-KRL signature against the Host-CA anchor at /etc/ssh/ssh-host-ca.pub before installing it:

ssh_host_cert_ecies_enabled: true
ssh_host_cert_krl_client_url: https://artifacts.example.com/krl-client-linux-amd64 # required (https or file:///abs)
ssh_host_cert_krl_client_checksum: "sha256:<hex>" # idempotence + tamper guard
# optional:
ssh_host_cert_krl_client_ca_bundle: <path> # TLS roots for a private-CA server
ssh_host_cert_krl_client_man_src: <path>
ssh_host_cert_krl_client_interval_minutes: 15
ssh_host_cert_scheduler: systemd
# backend (required): SSH_ECIES_ENABLED=true

NTP is enforced on this path (ssh_host_cert_require_timesync, default true). If SSH_ECIES_ENABLED is not set, register-host-pubkey returns 501 and the role fails with an actionable message.

  • A default run enables NO live revocation. ssh_host_cert_ecies_enabled is false, so RevokedKeys is just an empty fail-closed placeholder until you enable the ECIES channel (§2.2).
  • Unattended renewal stores the token on the host (0600, /etc/pki-manager/ssh-renew.env) so it can re-mint itself; a compromised host can then sign host certs for any FQDN under that Host CA. Set ssh_host_cert_renew_enabled: false to renew by re-running the playbook from the controller instead.
  • ECIES is P-256-only: an ed25519 host key gets 409 ECIES_KEY_UNSUPPORTED on register-host-pubkey. The role always uses an ecdsa host key (ssh_host_cert_key_type: ecdsa), and the backend rejects any other host key type — do not force an ed25519 key. The role accepts 200/404/409/501 from the URI call but then asserts status == 200, so a backend without SSH_ECIES_ENABLED (501) or a host not yet signed (404) fails the play with an explicit message.
  • Init-less containers: set ssh_host_cert_reload_method: command so sshd is reloaded via SIGHUP instead of the service module.
  • Never hand-edit 60-ssh-ca.conf. It is fetched verbatim from GET /ssh/hosts/<id>/sshd-config and is algorithm-aware (an ecdsa/ECIES host gets ecdsa HostKey/HostCertificate paths automatically). Re-render server-side.

Prerequisites for this section: an active User CA exists; the target host is already deployed (§2) and serving user certs (its drop-in sets TrustedUserCAKeys /etc/ssh/ssh-user-ca.pub, AuthorizedPrincipalsFile /etc/ssh/auth_principals/%u, RevokedKeys); the local UNIX accounts the principals map to (e.g. root, deploy) already exist on the host.

Creates an sshIdentities row. subject is required (“identity subject is required”); email / externalSubject optional. New identities are active with pubkeySource='per_request'; a disabled identity cannot be issued certs. Returns the identity’s id, which you pass as the identityId input to every later step.

module pki_manager: action=ssh_identity_create identity_subject=alice@acme.example
REST POST /api/v1/ssh/identities body: { subject, email?, externalSubject? }
UI /ssh/users/new → New Identity

Step 2 — Create the principals (role labels)

Section titled “Step 2 — Create the principals (role labels)”

Create each role label the user will carry (e.g. developers, sysadmins, client-acme). Names must match the grammar ^[A-Za-z0-9](?:[A-Za-z0-9._@-]{0,62})$. A principal grants nothing on its own — reuse existing principals rather than minting one per person.

module pki_manager: action=ssh_principal_create principal_name=developers
REST POST /api/v1/ssh/principals body: { name, description? }
UI /ssh → Principals → Principal catalog

Step 2b — (Optional) Grant the identity the entitlement to encode each principal

Section titled “Step 2b — (Optional) Grant the identity the entitlement to encode each principal”

Inserts an sshUserPrincipals (identity→principal) row: a catalog entitlement, distinct from host mapping. It is enforced only at issue time when enforceEntitlement:true is passed (then assertEntitled() rejects “identity not entitled to principals: …”).

module pki_manager: action=ssh_principal_grant identity_id=… principal_id=…
REST POST /api/v1/ssh/principals/grant body: { identityId, principalId }

Step 3 — Ensure principal → local-account host maps exist (the #1 login gotcha)

Section titled “Step 3 — Ensure principal → local-account host maps exist (the #1 login gotcha)”

For each host the user should reach, map each of their principals to a local account. This inserts sshHostPrincipalMaps (hostId, principalId, localAccount) and is the only thing that populates /etc/ssh/auth_principals/<account>.

Skip this and you get the classic “authenticated but denied” trap: the certificate signature verifies but the login is refused with Valid certificate but Permission denied. Login succeeds only when the same principal is in both the cert and the host’s auth_principals file. Neither issuance nor enforceEntitlement checks host maps — the issue form only warns (via mappingsByPrincipal); it does not block.

module pki_manager: action=ssh_principal_map host_id=… principal_id=… local_account=deploy
pki_manager: action=ssh_host_list host_fqdn=… # resolve host_id by fqdn
pki_manager: action=ssh_auth_principals host_id=… # render/verify the exact files
REST POST /api/v1/ssh/principals/map · GET /api/v1/ssh/hosts/:id/auth-principals

The rendered file uses the dual form (bare P plus P@<fqdn>) plus AuthorizedPrincipalsFile /etc/ssh/auth_principals/%u. Mapping bumps host.updatedAt, marking the host Stale until the file is re-deployed and Mark pushed is clicked. Because the server’s auth_principals file is written by the §2 role at run time, re-run the §2 role (or re-push the file and click Mark pushed) after creating these maps — otherwise the host still carries the empty set installed on its first §2 run and §4 login will be denied.

Two “permission” layers are easy to conflate: enforceEntitlement checks the identity’s catalog entitlements (step 2b), not host maps. Passing enforceEntitlement:true still guarantees nothing about login — that depends entirely on the step-3 host maps.

Step 4 — User generates a keypair and sends only the public key

Section titled “Step 4 — User generates a keypair and sends only the public key”

On the user’s own machine (private key never leaves it):

Terminal window
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub # send THIS to the operator

The backend rejects private keys / garbage early via parseSshPublicKey; the parsed algorithm drives the client-side filenames later. ecdsa-sha2-nistp256 is also supported (filenames become id_ecdsa*).

Signs the user’s public key against the User CA with their principals.

module pki_manager: action=ssh_user_issue identity_id=… user_ca_id=…
ssh_public_key="{{ lookup('file','~/.ssh/id_ed25519.pub') }}" principals=[developers]
REST POST /api/v1/ssh/users/issue
body: { identityId, sshPublicKey, principals[], caId?, validForSeconds?, enforceEntitlement? }
UI /ssh/users/new → Issue Certificate
Field Rule / default
identityId, sshPublicKey, principals[] required; principals must be ≥1 (“at least one principal (role) is required”)
caId defaults to the active User CA
extensions default = all five DEFAULT_USER_EXTENSIONS
validForSeconds default 7 days (604800)
keyId defaults to the identity subject
sourceAddress comma-separated CIDRs (validated)
enforceEntitlement set true to constrain principals to the step-2b grants

The response returns cert.certOpenssh, the keyType, and a ready-to-paste sshClientConfig. Automation alternative: POST /api/v1/external/ssh/sign-user (fleet-token auth, sourceType=automation, auto-creates the identity by subject) does not pass enforceEntitlement, so catalog grants are not enforced there.

Step 6 — Install the certificate client-side (next to the private key)

Section titled “Step 6 — Install the certificate client-side (next to the private key)”

Save certOpenssh using the algorithm-matched filename so ssh auto-presents it (ed25519 → id_ed25519-cert.pub; ecdsa-sha2-nistp256 → id_ecdsa-cert.pub):

Terminal window
# paste the returned cert into ~/.ssh/id_ed25519-cert.pub
chmod 644 ~/.ssh/id_ed25519-cert.pub

Saving under the wrong base name means ssh won’t auto-present the cert.

Use the block returned in sshClientConfig (narrow the Host pattern from * to your fleet):

Host *.example.com
IdentityFile ~/.ssh/id_ed25519
CertificateFile ~/.ssh/id_ed25519-cert.pub
IdentitiesOnly yes

Verify the cert’s principals and validity window locally:

Terminal window
ssh-keygen -L -f ~/.ssh/id_ed25519-cert.pub

When the cert expires (~1 week) request a fresh one — no new key needed.

Step 8 — Trust the servers’ Host CA (client side — this is what suppresses TOFU)

Section titled “Step 8 — Trust the servers’ Host CA (client side — this is what suppresses TOFU)”

Step 7 only wired the servers-trust-users direction. To wire the other mandatory direction from §0 — clients trust servers — add the Host CA @cert-authority line to the user’s ~/.ssh/known_hosts on the user’s own machine. Without it, the first login shows the The authenticity of host … can't be established TOFU prompt. The automation fetches it with pki_manager: action=ssh_cert_authority (see §6); a user doing it by hand can also just:

Terminal window
curl "https://pki.example.com/ssh/cert-authority?pattern=*.example.com" >> ~/.ssh/known_hosts

This line makes the client trust any host cert signed by the Host CA directly, so there is no per-host key-acceptance prompt and no changed-fingerprint warning. (The server side of this — the host’s own signed cert — was installed by the Ansible role in §2.)


Log in as the mapped local account (the account must map to one of the cert’s principals — §3 step 3):

Terminal window
ssh <account>@server.example.com # e.g. ssh deploy@server1.example.com

Success looks like:

  • You land in a shell as <account> with no password / no per-user authorized_keys — the server honored your user cert via TrustedUserCAKeys, and the account’s auth_principals file contained one of the cert’s principals.
  • No TOFU: there is no The authenticity of host … can't be established prompt and no changed-fingerprint warning — because the client’s ~/.ssh/known_hosts carries the Host CA @cert-authority line (from GET /ssh/cert-authority?pattern=*.example.com, added in §3 Step 8), so it trusts the server’s host cert directly.

If you instead see Valid certificate but Permission denied, the certificate is fine but the principal is not in that account’s /etc/ssh/auth_principals/<account> — revisit §3 step 3 (and re-run the §2 role / re-deploy + Mark pushed if the host shows Stale).


Revocation is two-tier:

  • Tier 1 — short TTL (primary). User certs expire ~weekly, host certs ~yearly; expiry is the main revocation mechanism — to revoke, stop re-issuing (or just re-issue). This stays load-bearing because sshd itself does not verify a signature on the RevokedKeys file it reads; on the ECIES channel the krl-client puller verifies the composed KRL’s Host-CA signature before installing it (a tampered KRL is rejected, not applied), and short TTLs backstop the whole scheme.
  • Tier 2 — the KRL (emergency kill switch) for a key you must revoke NOW.

Note the asymmetry: a server’s RevokedKeys gates user logins; host-cert revocation is enforced client-side, not by the server’s revoked_keys. And blocks are not revocations — a per-host block denies an identity on that host while its certs stay valid everywhere else.

How the ECIES channel propagates a revoke or a block

Section titled “How the ECIES channel propagates a revoke or a block”

The host’s krl-client pulls POST /api/v1/external/ssh/krl (returns 304 with X-KRL-Version, or 200 with the ECIES ciphertext). Both a plain revoke and a per-host block land on the host’s next pull: each rebuilds the composed per-host KRL the endpoint serves (SSH_HOST_KRL_SERVE, default ON).

  • The composed per-host KRL = host-CA revocations ∪ all user-CA revocations ∪ resolved active blocks, signed with the Host-CA key; krl-client verifies it against --ca-pubkey (default /etc/ssh/ssh-host-ca.pub, from GET /ssh/host-ca-keys) — not the User CA.
  • Fail-closed: sshd re-reads RevokedKeys on every auth, so no reload is needed once the file lands.
  • Latency is bounded by the pull interval: ≤ 1 interval, median ≈ 7.5 min at the default 15-min timer. An offline host keeps its last-good KRL and is never shown Effective.
  • If the composed KRL is unsigned (e.g. KMS signing failed), krl-client fails-stale on last-good (exit 4) unless run with --allow-unsigned; this surfaces as (unsigned) in the UI pill and audit log. And remember: clock drift makes krl-client fail every run with exit 5, silently freezing a host on its last KRL (§0).

6. Try it end-to-end — complete worked example

Section titled “6. Try it end-to-end — complete worked example”

Scenario used throughout: onboard user alice (principal developers → local account deploy) onto server1.acme.example, under a fleet CA named acme, with the ECIES revocation channel. Everything is driven by the oriolrius.pki_manager collection (REST API) — no curl. This whole flow is what the sandbox in §6.1 runs and what the collection’s tests/ validate against a live backend.

The quickest way to watch the whole process run — deploy servers, onboard a user, log in with a cert (no TOFU), and prove revocation — needs no real hosts (containers act as managed hosts) and skips cleanly if docker/KMS is unavailable:

Terminal window
ansible/tests/e2e/run.sh

It builds the krl-client binary, stands up backend+KMS, applies the role, asserts idempotence, then drives real ssh. See tests/e2e/README.md for what each phase asserts, and ansible/tests/e2e/seed.py for the same bootstrap expressed as API calls.

6.2 Against your own backend and host (Ansible, module-driven)

Section titled “6.2 Against your own backend and host (Ansible, module-driven)”

Prerequisites: the collection installed (ansible-galaxy collection install oriolrius.pki_manager); a reachable backend (OIDC off ⇒ ALLOW_UNAUTHENTICATED_SSH_CA=true, and SSH_ECIES_ENABLED=true for the revocation channel); the target host reachable by Ansible with a deploy UNIX account. The complete, ready-to-run playbook is examples/ssh_deploy_server_and_user.yml — the essentials are below.

inventory.yml:

all: {children: {sshservers: {hosts: {server1.acme.example: {}}}}}

Play 1 — platform (localhost): dual CA + fleet token + principal.

- hosts: localhost
gather_facts: false
module_defaults:
oriolrius.pki_manager.pki_manager: {api_url: "https://pki.example.com/api/v1"}
tasks:
- name: Create the dual CA
oriolrius.pki_manager.pki_manager: {action: ssh_ca_create, ssh_ca_type: "{{ item }}"}
loop: [user, host]
register: cas
- name: Mint the fleet token
oriolrius.pki_manager.pki_manager:
action: ssh_token_mint
token_name: acme-fleet
host_ca_id: "{{ cas.results[1].ca_id }}"
token_ops: [sign-host, get-principals, register-host-pubkey]
register: fleet
no_log: true
- name: Create the 'developers' principal
oriolrius.pki_manager.pki_manager: {action: ssh_principal_create, principal_name: developers}
register: principal
- name: Stash platform facts for later plays
ansible.builtin.set_fact:
acme_user_ca: "{{ cas.results[0].ca_id }}"
acme_fleet_token: "{{ fleet.token }}"
acme_principal_id: "{{ principal.principal_id }}"

Play 2 — server: apply the role (ECIES channel).

- hosts: sshservers
become: true
gather_facts: true
vars:
ssh_ca_base_url: https://pki.example.com
ssh_ca_fleet_token: "{{ hostvars['localhost'].acme_fleet_token }}"
ssh_host_cert_ecies_enabled: true
ssh_host_cert_krl_client_url: https://artifacts.example.com/krl-client-linux-amd64
ssh_host_cert_krl_client_checksum: "sha256:<hex>"
roles:
- oriolrius.pki_manager.ssh_host_cert

Play 3 — user: identity → map → issue cert → client config.

- hosts: localhost
gather_facts: false
module_defaults:
oriolrius.pki_manager.pki_manager: {api_url: "https://pki.example.com/api/v1"}
tasks:
- name: Create alice + entitle her to 'developers'
oriolrius.pki_manager.pki_manager: {action: ssh_identity_create, identity_subject: "alice@acme.example"}
register: ident
- name: Grant the entitlement
oriolrius.pki_manager.pki_manager: {action: ssh_principal_grant, identity_id: "{{ ident.identity_id }}", principal_id: "{{ hostvars['localhost'].acme_principal_id }}"}
- name: Resolve each host id by fqdn
oriolrius.pki_manager.pki_manager: {action: ssh_host_list, host_fqdn: "{{ hostvars[item].ansible_fqdn }}"}
loop: "{{ groups['sshservers'] }}"
register: hs
- name: Map 'developers' -> deploy on each host
oriolrius.pki_manager.pki_manager: {action: ssh_principal_map, host_id: "{{ item.host_id }}", principal_id: "{{ hostvars['localhost'].acme_principal_id }}", local_account: deploy}
loop: "{{ hs.results }}"
- name: Issue alice's cert (she generated ~/.ssh/id_ed25519 on her machine)
oriolrius.pki_manager.pki_manager:
action: ssh_user_issue
identity_id: "{{ ident.identity_id }}"
user_ca_id: "{{ hostvars['localhost'].acme_user_ca }}"
ssh_public_key: "{{ lookup('file', '~/.ssh/id_ed25519.pub') }}"
principals: [developers]
register: usercert
- name: Install the cert + the @cert-authority trust line locally
ansible.builtin.copy: {content: "{{ usercert.cert_openssh }}\n", dest: "~/.ssh/id_ed25519-cert.pub", mode: '0644'}
- name: Fetch the client trust line (kills TOFU)
oriolrius.pki_manager.pki_manager: {action: ssh_cert_authority, cert_authority_pattern: "*.acme.example"}
register: ca
- ansible.builtin.copy: {content: "{{ ca.cert_authority }}\n", dest: "~/.ssh/known_hosts_acme", mode: '0644'}

Ordering — the #1 gotcha. auth_principals is written when the role runs, so the play-3 mapping only lands after you run play 2 again (or run the whole playbook twice). Until then the host serves an empty principals set and login is denied with Valid certificate but Permission denied.

Log in as the mapped account — no password, no TOFU prompt:

Terminal window
ssh -o UserKnownHostsFile=~/.ssh/known_hosts_acme deploy@server1.acme.example

Revoke — block alice on one host (her cert stays valid elsewhere); her krl-client installs the signed KRL on its next pull:

- name: Block alice on the compromised host
oriolrius.pki_manager.pki_manager:
action: ssh_block
api_url: "https://pki.example.com/api/v1"
host_id: "{{ blocked_host_id }}" # from play 3's `hs.results`
identity_id: "{{ alice_identity_id }}"
# force the pull now on the host: krl-client --config /etc/krl-client/config.yaml
# lift it later with action: ssh_unblock

Relative to docs/ssh/:

  • concept.md — read-first mental model (two CAs, two trust directions, the principals trap, two-tier revocation, the canonical order). Link, don’t restate.
  • principals-guide.md — the RBAC / principals design and the mapping detail behind §3.
  • setup.md — the by-hand server + client procedure the Ansible role automates; also the source for the user/client-side steps.
  • operator-quickstart.md — the legacy manual web-UI “zero to first login” flow this guide supersedes for automation.
  • host-blocks-runbook.md — per-host access-block cutover / rollback runbook (revocation after the fleet is deployed).
  • oriolrius.pki_manager collection (Galaxy) — the pki_manager module (every SSH action) + the ssh_host_cert role + the complete examples/ssh_deploy_server_and_user.yml this guide is built on.
  • ../../ansible/tests/e2e/README.md — the dockerized containers-as-hosts e2e that proves the same end-to-end deploy (converge + idempotence + real ssh login + revocation).
  • ../ssh-api-contract.md — the REST endpoints the module calls, and the honest KRL trust model + env gates.