A Private CA for Device Trust at the Price of a Coffee: step-ca on KMS vs Managed CAs

low-cost private CA

A private CA that issues 10,000 device certificates a month can now run for about the price of a coffee via a serverless workload. A low-cost private CA built on step-ca and a cloud KMS key costs about $3 on AWS and about $5.50 on Google Cloud at that volume.

The managed-CA design the earlier posts in this series used costs $4,700 on AWS and $5,430 on Google Cloud for the same 10,000 certificates, and about $930 to $1,550 for a fleet of 1,000 devices. Almost all of that money pays for two managed certificate authorities: Google’s Enterprise tier are $200 each per month plus $0.50 per certificate, or AWS Private CAs at $400 each plus $0.75 per certificate for the first thousand. They hold a root key that signs one certificate every few years and an intermediate that signs short-lived device certificates. The low-cost private CA design keeps what device trust relies on, a verifiable chain of trust and a key nobody can copy, and drops the rest.

This post compares the deployments in the project repository: the standard builds on managed CAs, and two “lite” builds that hold the intermediate key in a cloud KMS and run step-ca, nginx and the webhook in a container that exists only while it is serving a request, Cloud Run on Google Cloud or a Lambda function on AWS. It covers how they differ, what each gives up, and which to run. It builds on the original design for device trust with step-ca and Google Cloud CAS, the Terraform blueprint, the device trust gateway that consumes the certificates, and the last post, “A Per-Device SCEP Challenge“, whose webhook runs unchanged in both lite builds.

The deployments side by side

Standard GCPStandard AWS (beta)gcp-liteaws-lite (Fargate)aws-lambda
Who holds the CA keysTwo CA Service CAs (root, intermediate)Two AWS Private CAs (root, subordinate)Cloud KMS keys, non-exportableAWS KMS keys, non-exportableAWS KMS keys, non-exportable
Role of step-caRegistration authority on a VM; CA Service signsNone; the Private CA Connector for SCEP is the SCEP serverA full CA that signs through KMSA full CA that signs through KMSA full CA that signs through KMS
RuntimeOne VM and an external HTTPS load balancerManaged connectorCloud Run: nginx, step-ca and the webhookOne Fargate task: nginx, step-ca and the webhookOne Lambda function from a container image
HTTPS front endLoad balancer certificateConnector endpointGoogle-managed run.app certificateALB with a certificate you supply and renewAmazon-issued function URL certificate
StateSQLite on a persistent diskNothing of oursFirestoreDynamoDBDynamoDB
Per-device challengeYes, optionalNo: the connector takes a static challengeYesYesYes
Cost at 10,000 certificates a monthabout $5,430about $4,700about $5.50about $40about $3
StatusOn mainBeta on the aws-support branchOn mainOn mainOn main

The standard AWS build stays a beta for two reasons that live outside this repository. The connector rejects the DES-CBC encryption the stock scepclient uses, so it needs a patched client that uses AES, and as far as I know that change has not landed upstream. And a manual step has to happen in the middle of the apply: the intermediate CA must be shared with the connector service through AWS RAM, which Terraform cannot do for service principals. Neither applies to the lite builds, because step-ca accepts AES already.

Where the money goes

A managed CA bundles a key generated and held in an HSM, an API that enforces what a CA may sign, a store of issued certificates, revocation lists and OCSP, and a console. A closed fleet of managed devices with certificates that last 30 to 45 days needs four things:

  1. A CA key that nobody can copy.
  2. A record of every signature that does not depend on the application’s own code.
  3. Rules about what gets signed.
  4. A list of what was issued.

A KMS key covers the first two: the key never leaves the service, and every certificate is one signing call that Cloud Audit Logs or CloudTrail records. step-ca and the webhook cover the other two. Everything the lite designs give up comes from what is left out, and the table further down lists it.

Total per month atStandard GCPStandard AWSgcp-lite (Cloud Run)aws-lite (Fargate)aws-lambda
100 certificates$480$875$5.32$39.59$2.85
1,000 certificates$930$1,550$5.35$39.61$2.88
10,000 certificates$5,430$4,700$5.51$39.76$3.06
100,000 certificates$27,930$4,790$9.13$41.26$4.57
1,000,000 certificates$28,830$5,690$77.21$65.50$20.20

These are totals, fixed cost included, so nothing is added to them. The standard columns use list prices read from the vendors’ pricing pages on 2026-12-02, with a $30 estimate for the VM and load balancer: CA Service Enterprise at $0.50 per certificate for the first 50,000, $0.05 up to 100,000 and $0.001 beyond, and AWS Private CA at $0.75 for the first 1,000, $0.35 up to 10,000 and $0.001 beyond, on top of $430 and $800 of CA fees. A fleet that renews monthly generates about one certificate per device per month, so 1,000 certificates is a 1,000-device fleet. At a million certificates a month the standard builds cost $0.029 and $0.0057 per certificate, and the lite builds between $0.00002 and $0.00008.

Keeping one instance warm removes the cold start for about $13 to $16.50 a month on Cloud Run. On aws it is not needed: one provisioned-concurrency environment would add about $5.40 a month to avoid a 0.8 to 1.5 second first request that SCEP clients do not notice.

The gap between the two lite builds is small and structural, not free-tier eligibility: both bill per request, include their own HTTPS front end and run nothing while idle. Free tiers save gcp-lite only about $0.40 to $1.90 a month, and the $5 floor on Google Cloud is the two HSM key versions; SOFTWARE protection drops it to about $0.12.

The low-cost design in one picture

flowchart LR
  subgraph Standard["Standard on GCP: two managed CAs"]
    D1["Device"] -->|"SCEP over HTTPS"| LB["External HTTPS load balancer"]
    LB --> VM["step-ca VM in RA mode<br/>+ webhook + SQLite disk"]
    VM -->|"sign request, billed per certificate"| CAS["CA Service<br/>root CA + intermediate CA"]
  end
  subgraph Lite["Lite on GCP or AWS: a KMS intermediate"]
    D2["Device"] -->|"SCEP over HTTPS"| FU["Cloud Run URL or Lambda function URL<br/>provider-managed certificate"]
    FU --> NG["nginx: only /scep/*"]
    NG --> SC["step-ca: a full CA, no database"]
    SC -->|"SCEPCHALLENGE and NOTIFYING webhooks"| WH["webhook"]
    WH --- DB[("Firestore or DynamoDB:<br/>devices, phrases, uses, pins, ledger")]
    SC -->|"one Sign call per certificate"| KMS["KMS intermediate key<br/>non-exportable"]
  end

Everything a device sees stays the same. The install scripts, the two SCEP provisioners, the challenge formula, the key-handling modes and the opt-in rule are shared, and the lite builds differ from the standard one only in the SCEP URL given to the scripts. What changes is where the CA key lives, where the code runs, and where the device list is kept.

The design differences, one at a time

1. step-ca stops being a registration authority

In the standard GCP build, step-ca runs in registration authority mode: it decides whether to allow a request and hands the signing to CA Service. That is what makes the managed intermediate necessary, and it is why every certificate is billed.

In the lite builds step-ca is the intermediate Device Trust CA. Its ca.json points the intermediate key at the KMS (cloudkms: or awskms:), so step-ca never holds the key and has no database. A shared Terraform module, modules/stepca_kms_config, renders the same provisioners for both clouds. An excerpt, trimmed:

ca_json = {
  root     = "${var.config_dir}/root.crt"
  crt      = "${var.config_dir}/intermediate.crt"
  key      = var.intermediate_key_uri
  kms      = { for k, v in var.kms : k => v if v != null }
  address  = ":${var.port}"
  authority = {
    provisioners = local.provisioners   # the same two SCEP provisioners, each with two webhooks
  }
}

The runtime identity may call sign on that one key and nothing else. It has no permission on the root key, so a compromised instance can sign device certificates but cannot create a new intermediate. Smallstep documents the KMS options for the CA key, and the step-kms-plugin lets the step command create and sign with those keys.

2. The root becomes a choice

A managed root is one option among three, because the runtime only consumes the intermediate certificate and key. root_mode = "kms" creates a second KMS key, uses it once to sign the intermediate, and is then disabled. root_mode = "external" leaves the root wherever it is kept: an offline machine, a hardware token, or a managed CA. Only the public certificate comes in, and the ceremony hands out a CSR to be signed elsewhere.

The ceremony is split in two. Making the intermediate’s CSR with --key forces the key’s own signature, and signing it needs the root. If one identity does both, that identity needs sign access on both keys. Splitting them keeps the root signer away from the intermediate key, and with an external root it only ever sees a CSR.

sequenceDiagram
  autonumber
  participant I as Intermediate holder
  participant R as Root signer
  participant KI as KMS intermediate key
  participant KR as Root key (KMS or external)
  participant S as Secret store
  I->>KI: make a CSR signed by the intermediate's own key
  I->>R: hand over only the CSR
  R->>KR: sign it as a CA: pathlen 0, certSign and crlSign only
  KR-->>R: intermediate certificate
  R-->>I: certificate and root certificate
  I->>I: verify the chain, issue the decrypter and webhook certificates from the intermediate
  I->>S: upload public certificates and the two software keys
  Note over KR: root key disabled after signing

In pki.sh the two steps are separate commands, so one script serves both modes. This is the excerpt from gcp-lite/scripts/pki.sh with root_mode = "kms":

step certificate create --csr --kms cloudkms: --key "$INTERMEDIATE_KEY" \
  "$INTERMEDIATE_CN" int.csr --force

cat > intermediate.tpl <<'TPL'
{
  "subject": {{ toJson .Subject }},
  "keyUsage": ["certSign", "crlSign"],
  "basicConstraints": { "isCA": true, "maxPathLen": 0 }
}
TPL
step certificate sign --kms cloudkms: --template intermediate.tpl \
  --not-after "$INTERMEDIATE_LIFETIME" int.csr root.crt "$ROOT_KEY" > intermediate.crt

A managed CA Service root works as the external signer, and it is the option that keeps key handling with the cloud. Granting an identity certificateRequester on the pool and pointing it at a certificate template does not confine it: the template only restricts requests that name it, and the same identity can ask the root for a plain certificate with no template. The control that holds is the pool’s issuance policy, which applies to every request: a maximum lifetime, RSA-3072 keys only, the exact subject name, a baseline of CA with path length 0 and certificate signing only, and no extension passthrough. The policy YAML and the commands are in the gcp-lite README.

3. Containers that exist only while they are needed

Google Cloud: one Cloud Run service with three containers. nginx is the ingress container because Cloud Run speaks plain HTTP to the container and step-ca only speaks TLS. nginx proxies /scep/* to step-ca on localhost and answers 404 to everything else, including step-ca’s own /roots.pem and /provisioners, which replaces the load balancer’s path restriction in the standard build. The webhook runs as a sidecar. There is no load balancer and no certificate to manage, because the run.app address carries a Google-managed certificate.

With min_instances = 0 nothing is billed while idle, and the first request after 15 idle minutes waited 5.8 seconds and the next took 0.12 seconds. SCEP clients retry and a device calls rarely. min_instances = 1 answered in 0.18 seconds after 20 idle minutes.

AWS: one Lambda function from a container image. The image holds nginx, step-ca, the webhook and the AWS Lambda Web Adapter, about 145 MB. The adapter turns each function URL request into an HTTP request to nginx, which forwards /scep/* to step-ca exactly as on Cloud Run. The function URL has the form https://<id>.lambda-url.<region>.on.aws and carries an Amazon-issued certificate that stock clients trust, so there is no load balancer, no public address to pay for, and no certificate to import or rotate.

Lambda limits environment variables to 4 KB, so a start-up step, dtw bootstrap, reads the certificates, the two software keys and the device list from Parameter Store and Secrets Manager and writes them to /tmp, and nothing else on the filesystem is writable. step-ca signs through the function’s execution role, which can call sign on the intermediate key and nothing else.

Measured on a live aws lambda container function with real KMS and DynamoDB:

  • Startup: the first start after a deployment took between 1 and 15 seconds, because Lambda loads the image lazily: 8.5 seconds in one run, 2.95 s in another, and once the full 10-second init limit, which made the first request take 14.6 seconds. Later new environments initialized in 0.3 to 0.9 seconds, the first request from outside took 0.8 to 1.5 seconds, and a warm request took about 130 ms. After 5 and 30 idle minutes the next renewal succeeded.
  • Latency inside the function: PKIOperation p50 43 ms, p95 80 ms and p99 136 ms with a small device list; renewals p50 55 ms and p99 91 ms over 3,996 requests. Peak memory was 158 MB of the 512 MB allocated.
  • Fleet: with the devices in DynamoDB, 4,990 devices each enrolled with their own phrase at 12-way parallelism (98.4% on the first try, all within four), and 3,996 of 4,000 renewals succeeded on the first try at 42 a second. About 27,000 invocations used 734 GB-seconds, inside the free tier.
  • Audit: CloudTrail held 9,017 function-role kms:Sign events for 9,007 ledger rows plus 10 environment starts, and no event came from any other principal. The function role, cut down to read and write items, produced no access-denied error in the run.
  • Public surface: only SCEP paths answered; other paths returned 404, other methods 403 or 405, bodies over 1 MiB 413. None of 154,677 log events held a phrase, challenge, serial number or key.

A function URL cannot carry a custom domain, and an unauthenticated one needs a resource policy that lets anyone call it, which an organization policy can forbid.

Unprivileged by default. Lambda runs the function as a non-root user with a read-only filesystem apart from /tmp. Cloud Run has no container setting for user, read-only root or capabilities, so gcp-lite relies on images that run as non-root users.

4. State moves out of the container, and the device list moves with it

The standard build keeps phrases, uses and pins in SQLite on a persistent disk. Ephemeral containers lose their disks, and that state has to be correct, because single-use phrases are a security property. In the lite builds the webhook talks to a Store interface with SQLite, Firestore and DynamoDB implementations behind it, picked by one setting.

The device allowlist can live in the same datastore. By default it is a file in a secret, which suits fleets up to about 1,500 devices: one secret version holds 64 KiB, which is 1,000 to 2,850 device lines depending on their length, and every change needs a new revision.

With devices_source = "store" each device is one record, looked up by key (one read per request, whatever the fleet size). A datastore holding 100,000 devices is about 40 MB and costs cents a month. Importing 5,000 devices took 21 seconds on DynamoDB and 80 seconds on Firestore.

5. Nothing to rotate at the front door

On Google Cloud and on AWS the lite builds terminate TLS with a certificate the provider issues and renews. The only certificates managed by hand are the SCEP decrypter’s and the webhook’s, which last a year, and scripts/pki.sh renew-leaves reissues them.

6. Images are pinned and immutable

Every base image is pinned by digest, and images/pin-base-images.sh reports whether each pin is current and rewrites it on request. The push scripts publish one content-derived tag per image and write images.auto.tfvars with repository@sha256: references, so a revision or function always runs exactly the image that was pushed, and both registries default to immutable tags. step-ca is copied by digest from the Smallstep image. The tools image that runs the ceremony, which holds the operator’s cloud credentials, checks each downloaded archive against a SHA-256 recorded in its Dockerfile. nginx logs requests without the query string, so SCEP GET messages, which carry the encrypted request and challenge, stay out of the cloud log.

7. Secrets stay out of Terraform state

Terraform cannot sign with a KMS key, and private keys should not sit in its state. So the lite builds apply in stages, with the PKI ceremony and the image push between the two applies:

cd gcp-lite
terraform init && terraform apply     # 1. foundation: keys, database, secrets, service account
scripts/pki.sh init                   # 2. the ceremony: certificates and software keys go straight to the secret store
scripts/push-images.sh                # 3. mirror step-ca, build nginx and the webhook, push by digest
# set service_enabled = true and devices_file = "devices.csv", then:
terraform apply                       # 4. the service

The ceremony writes the certificates and the two software keys, the SCEP decrypter and the webhook’s TLS key, directly to Secret Manager or Parameter Store. Only the device allowlist is managed by Terraform, and not even that in datastore mode. Preconditions in the code stop the steps running out of order.

What you give up, and what replaces it

Lost against a managed CAReplacementStrength
Per-certificate audit logsEvery certificate is one KMS sign call in Cloud Audit Logs or CloudTrail, independent of the application’s codeStrong. Data Access logging for Cloud KMS is off by default and has to be switched on
A list of issued certificatesThe NOTIFYING webhook records each issuance in a ledger (dtw issued list)Good, but step-ca ignores a failed notification, so it is best effort
Revocation (CRL, OCSP)Short lifetimes (30 days by default), removal from the device list stops renewals within minutes (immediately in datastore mode), and an optional /validate endpoint a gateway can callAdequate for short-lived certificates. Not equal to CRL or OCSP
A CA consoleLogs and the ledgerA real gap if others need to operate the CA
Template enforcement by the CA APIstep-ca provisioner rules and the webhookWeaker, see below

The optional /validate endpoint is the closest thing to revocation. A gateway’s auth_request sends the certificate serial, and the webhook allows it only if the serial is in the ledger, unexpired, the host is still on the device list, and the host’s pinned key is the key in the certificate. Re-enrolling a host with a new key therefore invalidates every certificate for the old key, and dtw pins clear HOST invalidates them all at once, without a CRL. The lite builds do not expose it: the webhook is not reachable from outside the function or instance, and nginx forwards only /scep/*. Exposing it would make a bearer token the only thing in front of the webhook, so whether to expose it is an open design question.

A stolen certificate stays valid until it expires unless the relying party consults the validation endpoint. Whether that is acceptable is a policy decision for each deployment.

Security trade-offs, side by side

Managed CAsLite with a KMS intermediate
Where the CA key isManaged HSM CANon-exportable KMS key (HSM or software protection)
What limits what is signedThe CA API, which can carry a pool issuance policy (the standard build sets none)step-ca and the webhook; KMS signs whatever it is asked
Independent audit of signingCA Service audit logs, CloudTrail for Private CAKMS audit logs
If the runtime is compromisedThe attacker can request certificates through the CA’s API as that identity. In the standard GCP build nothing limits the names: its pool has no issuance policy, and step-ca’s requests use no templateSame, plus: while the attacker holds the runtime’s credentials they can ask KMS to sign any certificate under that intermediate, not only what step-ca would approve
What ends the compromiseRevoking the identityRevoking the identity. The key cannot be taken away, and every signature is logged

The fourth row is the one to take seriously. Without a pool policy a managed CA’s requester can ask for any name too, so the gap is smaller than it looks; what a managed CA offers is a configurable control (the pool policy) and requests that pass through its API.

Because KMS signs any digest it receives, the runtime role’s permission is effectively “mint device certificates”, and step-ca’s rules sit in front of that permission, not under it. That is why the intermediate carries path length 0, why gateways can trust the intermediate rather than the root, so replacing a compromised one is a gateway change, and why the root key is out-of-band.

One key is not in the KMS. The SCEP decrypter, the key that decrypts the request, stays in the secret store, because Cloud KMS and AWS KMS decrypt only with RSA-OAEP while SCEP clients use PKCS#1 v1.5 key transport. It can read requests but cannot sign certificates.

Limits, stated plainly

  • No CRL or OCSP. Revocation is expiry, the device list and an optional /validate endpoint that the lite builds do not expose by default.
  • You run the CA software. step-ca is pinned at 0.30.2, and base images are pinned by digest, so fixes arrive when the pins are refreshed and the images rebuilt and rolled. A managed CA’s operator does that for you.
  • The runtime can sign anything under the intermediate while its credentials last. The mitigations are path length 0, short lifetimes, the root key kept out of reach, and the audit log. They do not make the permission smaller.
  • Devices trust the root for everything. The install scripts add the root as a general trust anchor (macOS trustRoot in the login keychain, Windows’ enterprise root store), and the CA has no name constraints. With the previous limit, whoever holds the runtime’s credentials can mint a certificate for any website those devices visit. Three mitigations: do not install the root system-wide (a gateway can trust it to verify client certificates without devices trusting it); issue client-authentication-only leaves, which stops a device’s own certificate working as a server certificate but not a forged one; or give devices fully qualified names under one domain and put a name constraint on the intermediate, which also rejects today’s bare-hostname certificates. None of these is how the scripts work today.
  • The webhook is protected by the network, not by a signature. step-ca’s static configuration cannot hold a webhook signing secret, so it signs with an empty key, and the lite builds run the webhook in the mode that accepts that (-no-signing-secret). The listener is reachable only from inside the function or instance, but anything that can reach it can write to the issuance ledger.
  • A function URL has no custom domain and needs a public resource policy; Cloud Run needs allUsers invoker access. An organization policy can forbid either.
  • The first Lambda start after a deployment is slow. It took 1 to 15 seconds and once hit the 10-second init limit.
  • A bad configuration is billed. It fails closed, but each request costs the full 30 seconds until it is fixed.
  • step-ca logs query strings. For a GET PKIOperation that is the whole encrypted message; nginx no longer logs it, step-ca’s own request log does.
  • Cost figures are modelled from list prices, apart from the measured usage above.
  • This is still not attestation. The hostname is a claim, and the serial number is the only link to hardware.

Which one should you run?

flowchart TD
  A["Do you need CRL or OCSP, a CA console that others operate,<br/>or a vendor who runs the CA software?"] -->|"yes"| M["Standard: managed CAs on GCP, or AWS Private CA (beta)"]
  A -->|"no: short-lived certificates are enough"| B{"Which cloud?"}
  B -->|"Google Cloud"| G["gcp-lite: about $5.50 a month at 10,000 certificates"]
  B -->|"AWS"| W["aws-lite: about $3 a month at 10,000 certificates"]
  G --> R{"Where does the root live?"}
  W --> R
  R -->|"cheapest: a KMS key used once, then disabled"| K["root_mode = kms"]
  R -->|"you already have one: offline, HSM or managed CA"| X["root_mode = external"]

For a fleet of hundreds to hundreds of thousands of managed devices that renews certificates every month or so, start with the lite design on the cloud you already use, and keep the root outside the runtime. On Google Cloud the standard build only wins if you need what a managed CA provides beyond signing. On AWS the lite build is also the only one of the two AWS builds that can run the per-device webhook, because the Private CA connector accepts only a static challenge.

Compared with two managed CAs, a low-cost private CA like this one costs more than 99 percent less at 10,000 certificates a month, and the price is revocation you do not have, a CA you operate, and a signing permission you have to guard. If a stolen certificate living out its 30 days is a risk you cannot accept, pay for the managed CA, if it is not, the money buys capabilities this fleet may never use.

Where to go next

If you run one of these, I would like to hear what breaks. The sharpest open question is whether to expose /validate from the lite builds, and what should sit in front of it.