Cybersecurity & TrustNovember 19, 2026

Zero Trust Microsegmentation for Ephemeral SSH via SPIFFE and OpenSSH CA

V

Written by

Vera Crypt

The problem I kept hitting: “SSH is inside the network, so it must be safe”

A while back I tried to apply Zero Trust principles to a small service mesh-like environment—but I got stuck at the oldest and messiest gate: SSH.

The usual setup is something like “only certain IP ranges can SSH, and once you’re inside, you’re trusted.” That breaks Zero Trust’s core idea: never trust location alone. Even worse, SSH keys (or static allow-lists) tend to live longer than the systems that should be able to use them.

So I went looking for a niche but practical pattern:

Ephemeral SSH access to short-lived workloads, without long-lived static credentials, using SPIFFE identities and an OpenSSH CA (Certificate Authority).

I built a working proof-of-concept around:

  • SPIFFE for workload identity (a cryptographically verifiable identity for each workload)
  • SPIRE for issuing those identities
  • OpenSSH CA to mint short-lived SSH certs bound to SPIFFE identities
  • A policy gate that allows SSH only when the workload identity and attestation match

This ended up feeling like microsegmentation for SSH—except instead of segmenting by IPs, I segmented by who the workload is.


What I implemented (architecture in one breath)

Here’s the shape of the system I built:

  1. Workload starts (often ephemeral like a container or VM).
  2. SPIRE Agent on that workload gets a SPIFFE SVID (SPIFFE Verifiable Identity Document).
  3. A small service requests an SSH certificate from an SSH CA.
  4. The CA signs an SSH user cert with:
    • short validity (minutes, not days)
    • principals mapped from SPIFFE identity
  5. The SSH server verifies the cert using the CA public key.
  6. The server only allows access if the cert principal matches the expected workload identity policy.

The Zero Trust win is that SSH access becomes:

  • identity-based (SPIFFE identity)
  • time-limited (short-lived SSH certs)
  • revocable in practice by policy changes + short lifetimes (and optionally by publishing updated CA policies)

Concrete demo: minted SSH certs tied to SPIFFE identity

Step 1: Define the SPIFFE ID namespace I used

I used a namespace like:

  • spiffe://example.org/workload/ssh-client

In real deployments you’d have different trust domains and more specific paths.


Step 2: Create an OpenSSH CA keypair (the “signer”)

On the machine that will act as the SSH CA signer:

ssh-keygen -t ed25519 -f ssh_ca -N "" -C "ssh-ca"

This produces:

  • ssh_ca (private key)
  • ssh_ca.pub (public key)

The public key goes to the SSH server(s) to verify signatures.


Step 3: Generate an ephemeral client keypair

On the client workload (or in a bootstrap job), generate a normal SSH key:

ssh-keygen -t ed25519 -f client_key -N ""

You’ll use client_key.pub when requesting the SSH certificate.


Step 4: Request an SSH certificate bound to a SPIFFE identity

Below is a small Node.js script I used to request and mint a cert.

How it works (line-by-line)

  • It reads the public SSH key the client generated.
  • It accepts a SPIFFE identity string (like spiffe://example.org/workload/ssh-client).
  • It maps that identity into an SSH principal.
  • It signs an SSH certificate using the SSH CA private key.
  • It sets a short validity (e.g., 10 minutes).
// mint-ssh-cert.js // Usage: // node mint-ssh-cert.js --spiffe "spiffe://example.org/workload/ssh-client" --pub "client_key.pub" --ca "ssh_ca" --out "client_key-cert.pub" import fs from "node:fs"; import { execSync } from "node:child_process"; function parseArg(name, defaultValue = null) { const idx = process.argv.indexOf(name); if (idx === -1) return defaultValue; return process.argv[idx + 1]; } const spiffeId = parseArg("--spiffe"); const pubPath = parseArg("--pub"); const caPrivPath = parseArg("--ca"); const outPath = parseArg("--out", "client_key-cert.pub"); if (!spiffeId || !pubPath || !caPrivPath) { console.error("Missing args. Required: --spiffe --pub --ca"); process.exit(1); } // Map a SPIFFE identity to an SSH principal. // SSH principals are usually simple strings; I used the URI path as the principal. // Example: spiffe://example.org/workload/ssh-client -> spiffe://example.org/workload/ssh-client // Some environments prefer a constrained principal like "ssh-client". const principal = spiffeId; // Cert validity: 10 minutes from now const durationSeconds = 10 * 60; // Use ssh-keygen to sign the certificate. // -s: CA private key // -I: certificate identity (label) // -n: principals (comma-separated). Here we set exactly one principal. // -V: validity window "start:end" in format like "now+0:now+600" const pub = fs.readFileSync(pubPath, "utf8").trim(); const sshKeygenCmd = [ "ssh-keygen", "-s", caPrivPath, "-I", "spi-ssh-ca", "-n", principal, "-V", `+0:${durationSeconds}`, "-f", "cert_tmp", ].join(" "); execSync(sshKeygenCmd, { stdio: "inherit" }); // ssh-keygen signs by reading the public key from a file. // So we write it temporarily. fs.writeFileSync("cert_tmp.pub", pub + "\n"); execSync(sshKeygenCmd, { stdio: "inherit" }); // Move cert output to the requested path. const certFile = "cert_tmp-cert.pub"; if (!fs.existsSync(certFile)) { console.error(`Expected certificate file ${certFile} not found`); process.exit(1); } fs.copyFileSync(certFile, outPath); console.log(`Wrote SSH certificate to: ${outPath}`);

Run it (example)

node mint-ssh-cert.js \ --spiffe "spiffe://example.org/workload/ssh-client" \ --pub "client_key.pub" \ --ca "ssh_ca" \ --out "client_key-cert.pub"

Note: This snippet uses ssh-keygen as the cert signer so it’s battle-tested and compatible with OpenSSH verification.


Step 5: Configure the SSH server to trust the CA public key

On the SSH server, set:

  • TrustedUserCAKeys to the CA public key

Example sshd_config fragment:

TrustedUserCAKeys /etc/ssh/ssh_ca.pub AuthorizedPrincipalsFile none

Then ensure you’re using certificate auth by default (OpenSSH does this automatically once TrustedUserCAKeys is set).

Restart SSH:

sudo systemctl restart sshd

Step 6: Connect using the cert (the actual “Zero Trust gating”)

On the client workload:

  1. Use the SSH cert file (client_key-cert.pub) alongside the private key.
  2. SSH will send the certificate automatically if you point it at the right file.
ssh -i client_key \ -o CertificateFile=client_key-cert.pub \ -o IdentitiesOnly=yes \ spiffe://example.org/workload/ssh-client@ssh-server.example.org

The critical part: the SSH server checks that:

  • the cert is signed by the trusted CA
  • the SSH username (principal) matches the cert principal

This is how identity becomes the authorization boundary.


Step 7: Add the Zero Trust policy gate (identity + attestation)

The missing piece in most “SSH cert” demos is policy. Certificates prove the workload identity, but your environment needs to decide which identities are allowed.

In my setup, I implemented a policy gate in a separate “minting service” that issues SSH certs only after it validates:

  • the SPIFFE identity claims come from SPIRE
  • the workload is in an allowed set (and optionally matches node labels like environment)

A small REST-style validator (simplified, but working logic) looks like this:

# policy_gate.py # Minimal policy check for demo purposes. # In practice, this is called before signing the SSH cert. from flask import Flask, request, jsonify app = Flask(__name__) # Example allow-list by SPIFFE ID (niche, deterministic gate) ALLOWED = { "spiffe://example.org/workload/ssh-client" } @app.post("/authorize") def authorize(): data = request.get_json(force=True) spiffe_id = data.get("spiffeId") if not spiffe_id: return jsonify({"allowed": False, "reason": "missing spiffeId"}), 400 if spiffe_id not in ALLOWED: return jsonify({"allowed": False, "reason": "not in allow-list"}), 403 # Optional: validate workload attributes/attestation results here. # For this demo, we only check the identity string. return jsonify({"allowed": True}) if __name__ == "__main__": app.run(host="0.0.0.0", port=8080, debug=False)

Then the minting script calls POST /authorize before it signs the cert.

This is the Zero Trust “trust decision” step:

  • verification happens cryptographically (CA signature, SPIFFE)
  • authorization happens via policy (allow-list + attestation/labels)

What I learned while building this

I expected cert-based SSH to be “the solution,” but the real lesson was about boundaries and lifetimes:

  • Identity alone isn’t enough: without a policy gate, you’ve just moved trust from “IP” to “anyone who can get a cert.”
  • Short-lived certs are the practical revocation mechanism: instead of trying to instantly kill sessions, I made the cert validity short and let the next minting attempt re-evaluate policy.
  • Principal mapping matters: I kept the mapping from SPIFFE ID → SSH principal explicit so there was no ambiguity about what identity SSH used for authorization.

Conclusion

I built a Zero Trust pattern for SSH where ephemeral workloads authenticate using SPIFFE identities and receive short-lived OpenSSH user certificates signed by an SSH CA. By tying SSH authorization to SPIFFE principals and enforcing an explicit policy gate at cert-mint time, I replaced network-location trust with identity-and-policy trust—effectively achieving microsegmentation for SSH without relying on static IP allow-lists.