Skip to content

Instantly share code, notes, and snippets.

@tim-tx
Last active March 26, 2026 18:26
Show Gist options
  • Select an option

  • Save tim-tx/d278555de9697431eefb5f3cde5ed745 to your computer and use it in GitHub Desktop.

Select an option

Save tim-tx/d278555de9697431eefb5f3cde5ed745 to your computer and use it in GitHub Desktop.
step-ca root and intermediate certs with name constraints

This repo contains templates for generating root and intermediate CAs with step-ca and name constraints. Links:

To generate:

  • step-cli certificate create "my-pki root-ca" root-ca.crt root-ca.key --template root.tpl --not-after 87600h
  • step-cli certificate create "my-pki intermediate-ca" intermediate-ca.crt intermediate-ca.key --template intermediate.tpl --ca root-ca.crt --ca-key root-ca.key, first you will enter the password to decrypt the root key, then enter a new password for the intermediate key

Notes:

  • Performed on ArchLinux, other systems may use step instead of step-cli.
  • The quoted strings like "my-pki root-ca" can be whatever you want, this sets the common name or CN= field in the certificates
  • You can set an organization or other fields by modifying the template
  • The step-ca default (if you used step-cli ca init or step-cli certificate create --profile root-ca) is 10 year expiration (87600 hours) (ref)
  • Templates in this repository are based on step-ca defaults (ref)
  • If you use step-cli ca init it doesn't set a password on the root CA, it's assumed that one is stored offline, you can also use --no-password --insecure with the command above
{
"subject": {{ toJson .Subject }},
"keyUsage": ["certSign", "crlSign"],
"basicConstraints": {
"isCA": true,
"maxPathLen": 0
}
}
{
"subject": {{ toJson .Subject }},
"issuer": {{ toJson .Subject }},
"keyUsage": ["certSign", "crlSign"],
"basicConstraints": {
"isCA": true,
"maxPathLen": 1
},
"nameConstraints": {
"critical": true,
"permittedDNSDomains": ["my.domain"]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment