Skip to content

Commit b67e773

Browse files
committed
fix(cozy-lib): add PKCS8 encoding, scope docs, and normalize error messages
Address review feedback from lexfrei: - Set privateKey.encoding to PKCS8 for modern TLS compatibility - Document helper scope as leaf certs only (not CA certificates) - Add namespace and cert-manager prerequisite documentation - Normalize em-dashes to double-dashes in error messages for ASCII consistency Signed-off-by: Arsolitt <[email protected]>
1 parent 4a42159 commit b67e773

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

‎packages/library/cozy-lib/README.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ Provides reusable template helpers:
1111
- **Resource presets** (`_resourcepresets.tpl`) — resource preset management
1212
- **Resources** (`_resources.tpl`) — Kubernetes resource helpers
1313
- **Strings** (`_strings.tpl`) — string manipulation utilities
14-
- **TLS** (`_tls.tpl`) — cert-manager Certificate CR generation and TLS secret name resolution
14+
- **TLS** (`_tls.tpl`) — cert-manager Certificate CR generation and TLS secret name resolution (leaf/end-entity certs only; CA certificates should be hand-crafted)
1515

1616
Helpers are documented inline in their respective `_*.tpl` files.
1717

1818
This chart has no configurable `values.yaml` parameters; all configuration is passed
1919
via template arguments at call sites.
20+
21+
## Prerequisites
22+
23+
cert-manager CRDs must be present in the cluster for `cozy-lib.tls.*` helpers
24+
to produce functional resources. These helpers do not install or vendor
25+
cert-manager itself.

‎packages/library/cozy-lib/templates/_tls.tpl‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{{/*
22
TLS certificate helpers for cert-manager integration.
33
These helpers render cert-manager Certificate CRs for services that need TLS.
4+
5+
Scope: leaf (end-entity) TLS certificates only. For CA certificates that
6+
need isCA: true, commonName, signing/cert-sign usages, rotationPolicy: Never,
7+
or subject fields, write the Certificate CR by hand.
48
*/}}
59

610
{{/*
@@ -25,8 +29,9 @@ Parameters:
2529
- duration (optional) - certificate duration, defaults to 8760h (1 year); empty strings are treated as unset. Non-empty values are passed through without validation.
2630
- renewBefore (optional) - renewal window, defaults to 720h (30 days)
2731
- usages (optional) - list of key usages, defaults to ["server auth"] (not cert-manager's default of "digital signature, key encipherment"; this is a deliberate choice for TLS server certificates). An empty list also falls back to the default.
28-
Private key is hardcoded to RSA-2048 with rotationPolicy: Always; these are not configurable via this helper.
32+
Private key is hardcoded to RSA-2048 PKCS#8 with rotationPolicy: Always; these are not configurable via this helper.
2933
extraDnsNames: nil is treated as an empty list (zero extra names appended).
34+
metadata.namespace is always Release.Namespace; cross-namespace rendering is not supported.
3035
*/}}
3136
{{- define "cozy-lib.tls.certificate" -}}
3237
{{- if not .Release -}}
@@ -42,13 +47,13 @@ Parameters:
4247
{{- fail "ERROR: \"dnsNames\" is required for cozy-lib.tls.certificate. Provide at least one DNS name as a list." -}}
4348
{{- end -}}
4449
{{- if not (kindIs "slice" .dnsNames) -}}
45-
{{- fail "ERROR: \"dnsNames\" must be a list for cozy-lib.tls.certificate. Got a string — wrap it in a list." -}}
50+
{{- fail "ERROR: \"dnsNames\" must be a list for cozy-lib.tls.certificate. Got a string -- wrap it in a list." -}}
4651
{{- end -}}
4752
{{- if and .extraDnsNames (not (kindIs "slice" .extraDnsNames)) -}}
48-
{{- fail "ERROR: \"extraDnsNames\" must be a list for cozy-lib.tls.certificate. Got a string — wrap it in a list." -}}
53+
{{- fail "ERROR: \"extraDnsNames\" must be a list for cozy-lib.tls.certificate. Got a string -- wrap it in a list." -}}
4954
{{- end -}}
5055
{{- if and .usages (not (kindIs "slice" .usages)) -}}
51-
{{- fail "ERROR: \"usages\" must be a list for cozy-lib.tls.certificate. Got a string — wrap it in a list." -}}
56+
{{- fail "ERROR: \"usages\" must be a list for cozy-lib.tls.certificate. Got a string -- wrap it in a list." -}}
5257
{{- end -}}
5358
{{- if not .issuerRef -}}
5459
{{- fail "ERROR: \"issuerRef\" is required for cozy-lib.tls.certificate. Provide a dict with \"name\" and \"kind\"." -}}
@@ -76,6 +81,7 @@ spec:
7681
renewBefore: {{ ternary "720h" .renewBefore (empty .renewBefore) | quote }}
7782
privateKey:
7883
algorithm: RSA
84+
encoding: PKCS8
7985
size: 2048
8086
rotationPolicy: Always
8187
usages:

‎packages/tests/cozy-lib-tests/tests/tls_test.yaml‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ tests:
3636
- equal:
3737
path: spec.privateKey.rotationPolicy
3838
value: Always
39+
- equal:
40+
path: spec.privateKey.encoding
41+
value: PKCS8
3942

4043
# dnsNames are correctly set and quoted
4144
- it: sets dnsNames correctly
@@ -477,7 +480,7 @@ tests:
477480
kind: ClusterIssuer
478481
asserts:
479482
- failedTemplate:
480-
errorMessage: 'ERROR: "dnsNames" must be a list for cozy-lib.tls.certificate. Got a string — wrap it in a list.'
483+
errorMessage: 'ERROR: "dnsNames" must be a list for cozy-lib.tls.certificate. Got a string -- wrap it in a list.'
481484

482485
# String extraDnsNames triggers a type error
483486
- it: errors when extraDnsNames is a string instead of a list
@@ -497,7 +500,7 @@ tests:
497500
extraDnsNames: extra.example.com
498501
asserts:
499502
- failedTemplate:
500-
errorMessage: 'ERROR: "extraDnsNames" must be a list for cozy-lib.tls.certificate. Got a string — wrap it in a list.'
503+
errorMessage: 'ERROR: "extraDnsNames" must be a list for cozy-lib.tls.certificate. Got a string -- wrap it in a list.'
501504

502505
# String usages triggers a type error
503506
- it: errors when usages is a string instead of a list
@@ -517,4 +520,4 @@ tests:
517520
usages: server auth
518521
asserts:
519522
- failedTemplate:
520-
errorMessage: 'ERROR: "usages" must be a list for cozy-lib.tls.certificate. Got a string — wrap it in a list.'
523+
errorMessage: 'ERROR: "usages" must be a list for cozy-lib.tls.certificate. Got a string -- wrap it in a list.'

0 commit comments

Comments
 (0)