Skip to content

Commit a7de1a2

Browse files
authored
Support cert-manager for controller tls (googleforgames#2453)
* Support cert-manager for controller tls * fix missing annotations * fix spacing * fix * fix spacing * Fix typo * miss another one * fix test * add missing annotation to APIService * update values * review * minor fix * Allow disable of ca-bundle * camelcase
1 parent e4060cc commit a7de1a2

File tree

3 files changed

+100
-3
lines changed

3 files changed

+100
-3
lines changed

‎install/helm/agones/templates/extensions.yaml‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,24 @@ metadata:
2828
chart: {{template "agones.chart" . }}
2929
release: {{.Release.Name }}
3030
heritage: {{.Release.Service }}
31+
{{- if .Values.agones.controller.allocationApiService.annotations }}
32+
annotations:
33+
{{- toYaml .Values.agones.controller.allocationApiService.annotations | indent 4 }}
34+
{{- end }}
3135
spec:
3236
group: allocation.agones.dev
3337
groupPriorityMinimum: 1000
3438
versionPriority: 15
3539
service:
3640
name: agones-controller-service
3741
namespace: {{.Release.Namespace }}
38-
{{- if .Values.agones.controller.generateTLS }}
42+
{{- if not .Values.agones.controller.allocationApiService.disableCaBundle }}
43+
{{- if .Values.agones.controller.generateTLS }}
3944
caBundle: {{b64enc $ca.Cert }}
40-
{{- else }}
45+
{{- else }}
4146
caBundle: {{default (.Files.Get "certs/server.crt") .Values.agones.controller.tlsCert | b64enc }}
42-
{{- end }}
47+
{{- end }}
48+
{{- end }}
4349
version: v1
4450
{{- end}}
4551
{{- if .Values.agones.registerWebhooks }}
@@ -48,6 +54,10 @@ apiVersion: admissionregistration.k8s.io/v1
4854
kind: ValidatingWebhookConfiguration
4955
metadata:
5056
name: agones-validation-webhook
57+
{{- if .Values.agones.controller.validatingWebhook.annotations }}
58+
annotations:
59+
{{- toYaml .Values.agones.controller.validatingWebhook.annotations | indent 4 }}
60+
{{- end }}
5161
labels:
5262
component: controller
5363
app: {{template "agones.name" . }}
@@ -65,10 +75,12 @@ webhooks:
6575
name: agones-controller-service
6676
namespace: {{.Release.Namespace }}
6777
path: /validate
78+
{{- if not .Values.agones.controller.validatingWebhook.disableCaBundle }}
6879
{{- if .Values.agones.controller.generateTLS }}
6980
caBundle: {{b64enc $ca.Cert }}
7081
{{- else }}
7182
caBundle: {{default (.Files.Get "certs/server.crt") .Values.agones.controller.tlsCert | b64enc }}
83+
{{- end }}
7284
{{- end }}
7385
rules:
7486
- apiGroups:
@@ -105,6 +117,10 @@ apiVersion: admissionregistration.k8s.io/v1
105117
kind: MutatingWebhookConfiguration
106118
metadata:
107119
name: agones-mutation-webhook
120+
{{- if .Values.agones.controller.mutatingWebhook.annotations }}
121+
annotations:
122+
{{- toYaml .Values.agones.controller.mutatingWebhook.annotations | indent 4 }}
123+
{{- end }}
108124
labels:
109125
component: controller
110126
app: {{template "agones.name" . }}
@@ -122,10 +138,12 @@ webhooks:
122138
name: agones-controller-service
123139
namespace: {{.Release.Namespace }}
124140
path: /mutate
141+
{{- if not .Values.agones.controller.mutatingWebhook.disableCaBundle }}
125142
{{- if .Values.agones.controller.generateTLS }}
126143
caBundle: {{b64enc $ca.Cert }}
127144
{{- else }}
128145
caBundle: {{default (.Files.Get "certs/server.crt") .Values.agones.controller.tlsCert | b64enc }}
146+
{{- end }}
129147
{{- end }}
130148
rules:
131149
- apiGroups:
@@ -147,6 +165,7 @@ webhooks:
147165
- CREATE
148166
- UPDATE
149167
{{- end }}
168+
{{- if not .Values.agones.controller.disableSecret }}
150169
---
151170
apiVersion: v1
152171
kind: Secret
@@ -167,3 +186,4 @@ data:
167186
server.crt: {{default (.Files.Get "certs/server.crt") .Values.agones.controller.tlsCert | b64enc }}
168187
server.key: {{default (.Files.Get "certs/server.key") .Values.agones.controller.tlsKey | b64enc }}
169188
{{- end }}
189+
{{- end }}

‎install/helm/agones/values.yaml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ agones:
6767
generateTLS: true
6868
tlsCert: ""
6969
tlsKey: ""
70+
disableSecret: false
71+
allocationApiService:
72+
annotations: {}
73+
disableCaBundle: false
74+
validatingWebhook:
75+
annotations: {}
76+
disableCaBundle: false
77+
mutatingWebhook:
78+
annotations: {}
79+
disableCaBundle: false
7080
safeToEvict: false
7181
persistentLogs: true
7282
persistentLogsSizeLimitMB: 10000

‎site/content/en/docs/Installation/Install Agones/helm.md‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ The following tables lists the configurable parameters of the Agones chart and t
209209
| Parameter | Description | Default |
210210
| --------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ---------------------- |
211211
||||
212+
|`agones.controller.disableSecret`| Disables the creation of any allocator secrets. If true, you MUST provide the `{agones.releaseName}-cert` secrets before installation. |`false`|
213+
|`agones.controller.allocationApiService.annotations`|[Annotations][annotations] added to the Agones apiregistration |`{}`|
214+
|`agones.controller.allocationApiService.disableCaBundle`| Disable ca-bundle so it can be injected by cert-manager |`false`|
215+
|`agones.controller.validatingWebhook.annotations`|[Annotations][annotations] added to the Agones validating webhook |`{}`|
216+
|`agones.controller.validatingWebhook.disableCaBundle`| Disable ca-bundle so it can be injected by cert-manager |`false`|
217+
|`agones.controller.mutatingWebhook.annotations`|[Annotations][annotations] added to the Agones mutating webhook |`{}`|
218+
|`agones.controller.mutatingWebhook.disableCaBundle`| Disable ca-bundle so it can be injected by cert-manager |`false`|
212219
{{% /feature %}}
213220

214221
[toleration]: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/
@@ -276,12 +283,72 @@ That means that you skipped the `--cleanup` flag and you should either delete th
276283
## Controller TLS Certificates
277284

278285
By default agones chart generates tls certificates used by the admission controller, while this is handy, it requires the agones controller to restart on each `helm upgrade` command.
286+
287+
### Manual
288+
279289
For most use cases the controller would have required a restart anyway (eg: controller image updated). However if you really need to avoid restarts we suggest that you turn off tls automatic generation (`agones.controller.generateTLS` to `false`) and provide your own certificates (`certs/server.crt`,`certs/server.key`).
280290

281291
{{< alert title="Tip" color="info">}}
282292
You can use our script located at{{< ghlink href="install/helm/agones/certs/cert.sh" >}}cert.sh{{< /ghlink >}} to generate them.
283293
{{< /alert >}}
284294

295+
{{% feature publishVersion="1.22.0" %}}
296+
### Cert-Manager
297+
298+
Another approach is to use [cert-manager.io](https://cert-manager.io/) solution for cluster level certificate management.
299+
300+
In order to use the cert-manager solution, first [install cert-manager](https://cert-manager.io/docs/installation/kubernetes/) on the cluster.
301+
Then, [configure](https://cert-manager.io/docs/configuration/) an `Issuer`/`ClusterIssuer` resource and
302+
last [configure](https://cert-manager.io/docs/usage/certificate/) a `Certificate` resource to manage controller `Secret`.
303+
Make sure to configure the `Certificate` based on your system's requirements, including the validity `duration`.
304+
305+
Here is an example of using a self-signed `ClusterIssuer` for configuring controller `Secret` where secret name is `my-release-cert` or `{{template "agones.fullname" . }}-cert`:
306+
307+
```bash
308+
#!/bin/bash
309+
# Create a self-signed ClusterIssuer
310+
cat <<EOF | kubectl apply -f -
311+
apiVersion: cert-manager.io/v1
312+
kind: ClusterIssuer
313+
metadata:
314+
name: selfsigned
315+
spec:
316+
selfSigned:{}
317+
EOF
318+
319+
# Create a Certificate with IP for the my-release-cert )
320+
cat <<EOF | kubectl apply -f -
321+
apiVersion: cert-manager.io/v1
322+
kind: Certificate
323+
metadata:
324+
name: my-release-cert
325+
namespace: agones-system
326+
spec:
327+
ipAddresses:
328+
- agones-controller-service.agones-system.svc
329+
secretName: my-release-cert
330+
issuerRef:
331+
name: selfsigned
332+
kind: ClusterIssuer
333+
EOF
334+
```
335+
336+
After the certificates are generated, we will want to [inject caBundle](https://cert-manager.io/docs/concepts/ca-injector/) into controller webhook and disable controller secret creation by setting the following:
337+
338+
```bash
339+
helm install my-release \
340+
--set agones.controller.disableSecret=true \
341+
--set agones.controller.allocationApiService.annotations={'cert-manager.io/inject-ca-from': 'agones-system/my-release-cert'} \
342+
--set agones.controller.allocationApiService.disableCaBundle=true \
343+
--set agones.controller.validatingWebhook.annotations={'cert-manager.io/inject-ca-from': 'agones-system/my-release-cert'} \
344+
--set agones.controller.validatingWebhook.disableCaBundle=true \
345+
--set agones.controller.mutatingWebhook.annotations={'cert-manager.io/inject-ca-from': 'agones-system/my-release-cert'} \
346+
--set agones.controller.mutatingWebhook.disableCaBundle=true \
347+
--namespace agones-system --create-namespace \
348+
agones/agones
349+
```
350+
{{% /feature %}}
351+
285352
## Reserved Allocator Load Balancer IP
286353

287354
In order to reuse the existing load balancer IP on upgrade or install the `agones-allocator` service as a `LoadBalancer` using a reserved static IP, a user can specify the load balancer's IP with the `agones.allocator.http.loadBalancerIP` helm configuration parameter value. By setting the `loadBalancerIP` value:

0 commit comments

Comments
(0)