Skip to content

Commit 86e940a

Browse files
scotwellsclaude
andcommitted
feat: replace cert-manager webhook Certificate with CSI volume mount for TLS
Provision the webhook serving certificate through the cert-manager CSI driver instead of a cert-manager Certificate + cainjection. The manager mounts the cert directly from a csi.cert-manager.io volume, so there is no standalone Certificate resource, no CA-injection wiring on the webhook configurations, and no cluster-wide cert-manager Certificate dependency in the production overlay. - Remove the config/base/certmanager base (Issuer/Certificate + kustomize name-reference + CA-injection replacements). - Add a generic config/components/csi-webhook-cert component that mounts the webhook-server-tls CSI volume on the manager Deployment. The issuer is intentionally left unset so each consuming overlay (or the infra repo) patches csi.cert-manager.io/issuer-kind and issuer-name for its environment. - Drop the optional compute-webhook-cert Secret volume/mount from the base manager Deployment; the CSI volume now supplies serving-certs. - single-cluster overlay: drop the certmanager base, the cainjection patch, and the dnsName/CA replacement blocks; wire in the csi-webhook-cert component instead. - dev overlay: keep an inline self-signed Issuer + Certificate for the local host.docker.internal webhook (no CSI driver in the dev kind/docker setup) and annotate the webhook configs with inject-ca-from directly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a4d81a4 commit 86e940a

11 files changed

Lines changed: 74 additions & 233 deletions

File tree

config/base/certmanager/certificate.yaml

Lines changed: 0 additions & 27 deletions
This file was deleted.

config/base/certmanager/kustomization.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

config/base/certmanager/kustomizeconfig.yaml

Lines changed: 0 additions & 8 deletions
This file was deleted.

config/base/manager/manager.yaml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,9 @@ spec:
6666
volumeMounts:
6767
- name: config
6868
mountPath: /config
69-
- name: webhook-cert
70-
mountPath: /tmp/k8s-webhook-server/serving-certs
71-
readOnly: true
7269
serviceAccountName: compute
7370
terminationGracePeriodSeconds: 10
7471
volumes:
7572
- name: config
7673
configMap:
7774
name: compute-config
78-
# Optional so the manager can run without admission webhooks: when
79-
# `webhookServer:` is omitted from the server config, the binary
80-
# skips the webhook server entirely and the missing Secret is fine.
81-
- name: webhook-cert
82-
secret:
83-
secretName: compute-webhook-cert
84-
defaultMode: 420
85-
optional: true
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: kustomize.config.k8s.io/v1alpha1
2+
kind: Component
3+
4+
patches:
5+
# Add the CSI webhook cert volume and volumeMount to the manager Deployment.
6+
# The issuer (csi.cert-manager.io/issuer-kind and csi.cert-manager.io/issuer-name)
7+
# must be patched in by the consuming overlay or infra repo.
8+
- target:
9+
kind: Deployment
10+
name: compute-manager
11+
patch: |-
12+
apiVersion: apps/v1
13+
kind: Deployment
14+
metadata:
15+
name: compute-manager
16+
spec:
17+
template:
18+
spec:
19+
containers:
20+
- name: manager
21+
volumeMounts:
22+
- name: webhook-server-tls
23+
mountPath: /tmp/k8s-webhook-server/serving-certs
24+
readOnly: true
25+
volumes:
26+
- name: webhook-server-tls
27+
csi:
28+
driver: csi.cert-manager.io
29+
readOnly: true
30+
volumeAttributes:
31+
csi.cert-manager.io/fs-group: "65532"
32+
csi.cert-manager.io/dns-names: compute-webhook.compute-system.svc,compute-webhook.compute-system.svc.cluster.local

config/overlays/dev/config.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,4 @@ apiVersion: apiserver.config.datumapis.com/v1alpha1
22
kind: WorkloadOperator
33
metricsServer:
44
bindAddress: "0"
5-
6-
webhookServer:
7-
tls:
8-
secretRef:
9-
name: compute-webhook-cert
10-
namespace: kube-system
5+
webhookServer: {}
Lines changed: 22 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,29 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
namespace: compute-system
5+
16
resources:
27
- ../../base/crd
38
- ../../base/webhook
4-
- ../../base/certmanager
9+
- webhook-cert.yaml
510

6-
replacements:
7-
- source:
8-
kind: Certificate
9-
group: cert-manager.io
10-
version: v1
11-
name: compute-serving-cert
12-
fieldPath: .metadata.namespace
13-
targets:
14-
- select:
15-
kind: ValidatingWebhookConfiguration
16-
fieldPaths:
17-
- .metadata.annotations.[cert-manager.io/inject-ca-from]
18-
options:
19-
delimiter: '/'
20-
index: 0
21-
create: true
22-
- select:
23-
kind: MutatingWebhookConfiguration
24-
fieldPaths:
25-
- .metadata.annotations.[cert-manager.io/inject-ca-from]
26-
options:
27-
delimiter: '/'
28-
index: 0
29-
create: true
30-
- source:
31-
kind: Certificate
32-
group: cert-manager.io
33-
version: v1
34-
name: compute-serving-cert
35-
fieldPath: .metadata.name
36-
targets:
37-
- select:
38-
kind: ValidatingWebhookConfiguration
39-
fieldPaths:
40-
- .metadata.annotations.[cert-manager.io/inject-ca-from]
41-
options:
42-
delimiter: '/'
43-
index: 1
44-
create: true
45-
- select:
46-
kind: MutatingWebhookConfiguration
47-
fieldPaths:
48-
- .metadata.annotations.[cert-manager.io/inject-ca-from]
49-
options:
50-
delimiter: '/'
51-
index: 1
52-
create: true
11+
patches:
12+
# Wire cainjector to the dev cert so the API server can verify the webhook.
13+
- patch: |-
14+
apiVersion: admissionregistration.k8s.io/v1
15+
kind: MutatingWebhookConfiguration
16+
metadata:
17+
name: compute-mutating
18+
annotations:
19+
cert-manager.io/inject-ca-from: compute-system/compute-serving-cert
20+
- patch: |-
21+
apiVersion: admissionregistration.k8s.io/v1
22+
kind: ValidatingWebhookConfiguration
23+
metadata:
24+
name: compute-validating
25+
annotations:
26+
cert-manager.io/inject-ca-from: compute-system/compute-serving-cert
5327
5428
transformers:
5529
- webhook_patch.yaml
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: cert-manager.io/v1
2+
kind: Issuer
3+
metadata:
4+
name: selfsigned-issuer
5+
spec:
6+
selfSigned: {}
7+
---
8+
apiVersion: cert-manager.io/v1
9+
kind: Certificate
10+
metadata:
11+
name: compute-serving-cert
12+
spec:
13+
dnsNames:
14+
- host.docker.internal
15+
issuerRef:
16+
kind: Issuer
17+
name: selfsigned-issuer
18+
secretName: compute-webhook-cert

config/overlays/dev/webhook_patch.yaml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
---
22
apiVersion: builtin
33
kind: PatchTransformer
4-
metadata:
5-
name: webhook-cert-patch
6-
patch: |-
7-
- op: replace
8-
path: /spec/dnsNames
9-
value: ["host.docker.internal"]
10-
- op: replace
11-
path: /spec/secretName
12-
value: compute-webhook-cert
13-
target:
14-
kind: Certificate
15-
group: cert-manager.io
16-
version: v1
17-
name: compute-serving-cert
18-
---
19-
apiVersion: builtin
20-
kind: PatchTransformer
214
metadata:
225
name: mutatingwebhook-url-patch
236
patch: |-

config/overlays/single-cluster/kustomization.yaml

Lines changed: 1 addition & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -9,100 +9,9 @@ resources:
99
- ../../base/crd
1010
- ../../base/manager
1111
- ../../base/webhook
12-
- ../../base/certmanager
1312
components:
1413
- ../../components/leader_election
1514
- ../../components/controller_rbac
1615
- ../../components/resource-metrics
1716
- ../../components/high-availability
18-
19-
patches:
20-
- path: webhookcainjection_patch.yaml
21-
22-
replacements:
23-
# Fill in SERVICE_NAME / SERVICE_NAMESPACE placeholders in the Certificate's
24-
# dnsNames so the cert is issued for the actual webhook Service location.
25-
- source:
26-
kind: Service
27-
version: v1
28-
name: compute-webhook
29-
fieldPath: .metadata.name
30-
targets:
31-
- select:
32-
kind: Certificate
33-
group: cert-manager.io
34-
version: v1
35-
name: compute-serving-cert
36-
fieldPaths:
37-
- .spec.dnsNames.0
38-
- .spec.dnsNames.1
39-
options:
40-
delimiter: '.'
41-
index: 0
42-
create: true
43-
- source:
44-
kind: Service
45-
version: v1
46-
name: compute-webhook
47-
fieldPath: .metadata.namespace
48-
targets:
49-
- select:
50-
kind: Certificate
51-
group: cert-manager.io
52-
version: v1
53-
name: compute-serving-cert
54-
fieldPaths:
55-
- .spec.dnsNames.0
56-
- .spec.dnsNames.1
57-
options:
58-
delimiter: '.'
59-
index: 1
60-
create: true
61-
# Wire the Certificate namespace + name into the cert-manager.io/inject-ca-from
62-
# annotation on the webhook configurations so cainjector populates caBundle.
63-
- source:
64-
kind: Certificate
65-
group: cert-manager.io
66-
version: v1
67-
name: compute-serving-cert
68-
fieldPath: .metadata.namespace
69-
targets:
70-
- select:
71-
kind: ValidatingWebhookConfiguration
72-
fieldPaths:
73-
- .metadata.annotations.[cert-manager.io/inject-ca-from]
74-
options:
75-
delimiter: '/'
76-
index: 0
77-
create: true
78-
- select:
79-
kind: MutatingWebhookConfiguration
80-
fieldPaths:
81-
- .metadata.annotations.[cert-manager.io/inject-ca-from]
82-
options:
83-
delimiter: '/'
84-
index: 0
85-
create: true
86-
- source:
87-
kind: Certificate
88-
group: cert-manager.io
89-
version: v1
90-
name: compute-serving-cert
91-
fieldPath: .metadata.name
92-
targets:
93-
- select:
94-
kind: ValidatingWebhookConfiguration
95-
fieldPaths:
96-
- .metadata.annotations.[cert-manager.io/inject-ca-from]
97-
options:
98-
delimiter: '/'
99-
index: 1
100-
create: true
101-
- select:
102-
kind: MutatingWebhookConfiguration
103-
fieldPaths:
104-
- .metadata.annotations.[cert-manager.io/inject-ca-from]
105-
options:
106-
delimiter: '/'
107-
index: 1
108-
create: true
17+
- ../../components/csi-webhook-cert

0 commit comments

Comments
 (0)