Can a template generate certificates, and should it?
AdvancedConceptTemplating: Go Templates & Sprig
Answer
Yes, Sprig has genCA, genSignedCert, genSelfSignedCert and genPrivateKey:
{{- $ca := genCA "shop-webhook-ca" 365 }}
{{- $cert := genSignedCert (printf "%s.%s.svc" (include "shop.fullname" .) .Release.Namespace) nil nil 365 $ca }}
tls.crt: {{ $cert.Cert | b64enc }}
tls.key: {{ $cert.Key | b64enc }}
It is common for admission webhook CAs, but every render produces a new cert, so upgrades rotate them, GitOps tools show permanent drift, and certificates expire silently. In production we prefer cert-manager to issue and rotate them.
More on Templating: Go Templates & Sprig
What template language does Helm use?BeginnerWhat does the dot (`.`) mean in a Helm template?BeginnerWhat is `$` and when do you need it?IntermediateHow does whitespace control (`{{-` and `-}}`) work?BeginnerHow do `if`, `else if` and `else` evaluate truthiness?BeginnerWhat do `and`, `or`, `not`, `eq`, `ne`, `lt`, `gt` look like in Helm?Beginner