Deploy an SSH Server and an SSH User with PKI Manager — Operator Reference Guide
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.
0. Mental model & prerequisites
Section titled “0. Mental model & prerequisites”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.)
The #1 principals trap
Section titled “The #1 principals trap”A principal is a role label (e.g. admins, developers). For a login to succeed the same principal must appear in two places:
- inside the user’s certificate, AND
- 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
nowoutside 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-clientrejects a payload whosevalid_untilis 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 itselfAfter=time-sync.target, and the Ansible role preflights time-sync and fails fast (ssh_host_cert_require_timesync, defaulttrue).
Prerequisites checklist
Section titled “Prerequisites checklist”| 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. |
1. One-time platform setup
Section titled “1. One-time platform setup”1.1 Create the dual CA (User + Host)
Section titled “1.1 Create the dual CA (User + Host)”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 carrysign-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).
2.1 Minimal path
Section titled “2.1 Minimal path”Step 1 — Install the collection (once, on the controller). It pulls in community.crypto automatically:
ansible-galaxy collection install oriolrius.pki_managerStep 2 — Put the fleet token in Vault (never in plain inventory):
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):
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:
- 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_certDefaults 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:
ansible-playbook -i inventory.yml site.yml -e @secrets.yml --ask-vault-passOne 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 theauth_principalsfile 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: truessh_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 serverssh_host_cert_krl_client_man_src: <path>ssh_host_cert_krl_client_interval_minutes: 15ssh_host_cert_scheduler: systemd# backend (required): SSH_ECIES_ENABLED=trueNTP 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.
2.3 Server gotchas
Section titled “2.3 Server gotchas”- A default run enables NO live revocation.
ssh_host_cert_ecies_enabledisfalse, soRevokedKeysis 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. Setssh_host_cert_renew_enabled: falseto renew by re-running the playbook from the controller instead. - ECIES is P-256-only: an ed25519 host key gets
409 ECIES_KEY_UNSUPPORTEDonregister-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 withoutSSH_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: commandso sshd is reloaded via SIGHUP instead of the service module. - Never hand-edit
60-ssh-ca.conf. It is fetched verbatim fromGET /ssh/hosts/<id>/sshd-configand is algorithm-aware (an ecdsa/ECIES host gets ecdsaHostKey/HostCertificatepaths automatically). Re-render server-side.
3. Deploy a USER
Section titled “3. Deploy a USER”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.
Step 1 — Create the user identity
Section titled “Step 1 — Create the user identity”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.exampleREST POST /api/v1/ssh/identities body: { subject, email?, externalSubject? }UI /ssh/users/new → New IdentityStep 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=developersREST POST /api/v1/ssh/principals body: { name, description? }UI /ssh → Principals → Principal catalogStep 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’sauth_principalsfile. Neither issuance norenforceEntitlementchecks host maps — the issue form only warns (viamappingsByPrincipal); 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 filesREST POST /api/v1/ssh/principals/map · GET /api/v1/ssh/hosts/:id/auth-principalsThe 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:
enforceEntitlementchecks the identity’s catalog entitlements (step 2b), not host maps. PassingenforceEntitlement:truestill 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):
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519cat ~/.ssh/id_ed25519.pub # send THIS to the operatorThe 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*).
Step 5 — Issue the user certificate
Section titled “Step 5 — Issue the user certificate”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):
# paste the returned cert into ~/.ssh/id_ed25519-cert.pubchmod 644 ~/.ssh/id_ed25519-cert.pubSaving under the wrong base name means ssh won’t auto-present the cert.
Step 7 — Configure ~/.ssh/config
Section titled “Step 7 — Configure ~/.ssh/config”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 yesVerify the cert’s principals and validity window locally:
ssh-keygen -L -f ~/.ssh/id_ed25519-cert.pubWhen 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:
curl "https://pki.example.com/ssh/cert-authority?pattern=*.example.com" >> ~/.ssh/known_hostsThis 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.)
4. Verify it works
Section titled “4. Verify it works”Log in as the mapped local account (the account must map to one of the cert’s principals — §3 step 3):
ssh <account>@server.example.com # e.g. ssh deploy@server1.example.comSuccess looks like:
- You land in a shell as
<account>with no password / no per-userauthorized_keys— the server honored your user cert viaTrustedUserCAKeys, and the account’sauth_principalsfile contained one of the cert’s principals. - No TOFU: there is no
The authenticity of host … can't be establishedprompt and no changed-fingerprint warning — because the client’s~/.ssh/known_hostscarries the Host CA@cert-authorityline (fromGET /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).
5. Revocation
Section titled “5. Revocation”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
RevokedKeysfile it reads; on the ECIES channel thekrl-clientpuller 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-clientverifies it against--ca-pubkey(default/etc/ssh/ssh-host-ca.pub, fromGET /ssh/host-ca-keys) — not the User CA. - Fail-closed: sshd re-reads
RevokedKeyson 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-clientfails-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 makeskrl-clientfail 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.
6.1 Fastest — the zero-infra sandbox
Section titled “6.1 Fastest — the zero-infra sandbox”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:
ansible/tests/e2e/run.shIt 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_certPlay 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_principalsis 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 withValid certificate but Permission denied.
Log in as the mapped account — no password, no TOFU prompt:
ssh -o UserKnownHostsFile=~/.ssh/known_hosts_acme deploy@server1.acme.exampleRevoke — 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_unblock7. See also
Section titled “7. See also”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_managercollection (Galaxy) — thepki_managermodule (every SSH action) + thessh_host_certrole + the completeexamples/ssh_deploy_server_and_user.ymlthis 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.