blob: e9e4a4bf08b859759d40c7fe84eb3bc59b0c6a86 [file] [log] [blame]
Piotr Dobrowolski79ddbc52019-04-02 13:20:15 +02001# Deploy a per-cluster cert-manager
2
3local kube = import "../../../kube/kube.libsonnet";
4
5{
6 local cm = self,
7 Environment: {
8 local env = self,
9 local cfg = env.cfg,
10
11 cfg:: {
12 namespace: "cert-manager",
Piotr Dobrowolski2afe6042019-04-02 14:43:34 +020013 enableWebhook: false,
Sergiusz Bazanskid16454b2019-08-29 17:21:49 +020014 version: "v0.9.1",
Piotr Dobrowolski79ddbc52019-04-02 13:20:15 +020015 },
16
17 metadata:: {
18 namespace: cfg.namespace,
19 },
20
21 namespace: kube.Namespace(cfg.namespace) {
22 metadata+: {
23 labels: { "certmanager.k8s.io/disable-validation": "true" },
24 },
25 },
26
27 crds: {
28 certificates: kube.CustomResourceDefinition("certmanager.k8s.io", "v1alpha1", "Certificate") {
29 spec+: {
30 additionalPrinterColumns: [
31 { name: "Ready", type: "string", JSONPath: ".status.conditions[?(@.type==\"Ready\")].status" },
32 { name: "Secret", type: "string", JSONPath: ".spec.secretName" },
33 { name: "Issuer", type: "string", JSONPath: ".spec.issuerRef.name", priority: 1 },
34 { name: "Status", type: "string", JSONPath: ".status.conditions[?(@.type==\"Ready\")].message", priority: 1 },
35 { name: "Age", type: "date", JSONPath: ".metadata.creationTimestamp" },
36 ],
37 names+: {
38 shortNames+: ["cert", "certs"],
39 },
40 scope: "Namespaced",
41 validation: {
42 # Converted from official YAML
43 "openAPIV3Schema": {
44 "properties": {
45 "apiVersion": {
46 "description": "APIVersion defines the versioned schema of this representation\nof an object. Servers should convert recognized schemas to the latest\ninternal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources",
47 "type": "string"
48 },
49 "kind": {
50 "description": "Kind is a string value representing the REST resource this\nobject represents. Servers may infer this from the endpoint the client\nsubmits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds",
51 "type": "string"
52 },
53 "metadata": {
54 "type": "object"
55 },
56 "spec": {
57 "properties": {
58 "acme": {
59 "description": "ACME contains configuration specific to ACME Certificates.\nNotably, this contains details on how the domain names listed on this\nCertificate resource should be 'solved', i.e. mapping HTTP01 and DNS01\nproviders to DNS names.",
60 "properties": {
61 "config": {
62 "items": {
63 "properties": {
64 "domains": {
65 "description": "Domains is the list of domains that this SolverConfig\napplies to.",
66 "items": {
67 "type": "string"
68 },
69 "type": "array"
70 }
71 },
72 "required": [
73 "domains"
74 ],
75 "type": "object"
76 },
77 "type": "array"
78 }
79 },
80 "required": [
81 "config"
82 ],
83 "type": "object"
84 },
85 "commonName": {
86 "description": "CommonName is a common name to be used on the Certificate",
87 "type": "string"
88 },
89 "dnsNames": {
90 "description": "DNSNames is a list of subject alt names to be used on the\nCertificate",
91 "items": {
92 "type": "string"
93 },
94 "type": "array"
95 },
96 "duration": {
97 "description": "Certificate default Duration",
98 "type": "string"
99 },
100 "ipAddresses": {
101 "description": "IPAddresses is a list of IP addresses to be used on the\nCertificate",
102 "items": {
103 "type": "string"
104 },
105 "type": "array"
106 },
107 "isCA": {
108 "description": "IsCA will mark this Certificate as valid for signing. This\nimplies that the 'signing' usage is set",
109 "type": "boolean"
110 },
111 "issuerRef": {
112 "description": "IssuerRef is a reference to the issuer for this certificate.\nIf the 'kind' field is not set, or set to 'Issuer', an Issuer resource\nwith the given name in the same namespace as the Certificate will\nbe used. If the 'kind' field is set to 'ClusterIssuer', a ClusterIssuer\nwith the provided name will be used. The 'name' field in this stanza\nis required at all times.",
113 "properties": {
114 "kind": {
115 "type": "string"
116 },
117 "name": {
118 "type": "string"
119 }
120 },
121 "required": [
122 "name"
123 ],
124 "type": "object"
125 },
126 "keyAlgorithm": {
127 "description": "KeyAlgorithm is the private key algorithm of the corresponding\nprivate key for this certificate. If provided, allowed values are\neither \"rsa\" or \"ecdsa\" If KeyAlgorithm is specified and KeySize is\nnot provided, key size of 256 will be used for \"ecdsa\" key algorithm\nand key size of 2048 will be used for \"rsa\" key algorithm.",
128 "enum": [
129 "rsa",
130 "ecdsa"
131 ],
132 "type": "string"
133 },
134 "keySize": {
135 "description": "KeySize is the key bit size of the corresponding private\nkey for this certificate. If provided, value must be between 2048\nand 8192 inclusive when KeyAlgorithm is empty or is set to \"rsa\",\nand value must be one of (256, 384, 521) when KeyAlgorithm is set\nto \"ecdsa\".",
136 "format": "int64",
137 "type": "integer"
138 },
139 "organization": {
140 "description": "Organization is the organization to be used on the Certificate",
141 "items": {
142 "type": "string"
143 },
144 "type": "array"
145 },
146 "renewBefore": {
147 "description": "Certificate renew before expiration duration",
148 "type": "string"
149 },
150 "secretName": {
151 "description": "SecretName is the name of the secret resource to store\nthis secret in",
152 "type": "string"
153 }
154 },
155 "required": [
156 "secretName",
157 "issuerRef"
158 ],
159 "type": "object"
160 },
161 "status": {
162 "properties": {
163 "conditions": {
164 "items": {
165 "properties": {
166 "lastTransitionTime": {
167 "description": "LastTransitionTime is the timestamp corresponding\nto the last status change of this condition.",
168 "format": "date-time",
169 "type": "string"
170 },
171 "message": {
172 "description": "Message is a human readable description of the details\nof the last transition, complementing reason.",
173 "type": "string"
174 },
175 "reason": {
176 "description": "Reason is a brief machine readable explanation for\nthe condition's last transition.",
177 "type": "string"
178 },
179 "status": {
180 "description": "Status of the condition, one of ('True', 'False',\n'Unknown').",
181 "enum": [
182 "True",
183 "False",
184 "Unknown"
185 ],
186 "type": "string"
187 },
188 "type": {
189 "description": "Type of the condition, currently ('Ready').",
190 "type": "string"
191 }
192 },
193 "required": [
194 "type",
195 "status",
196 "lastTransitionTime",
197 "reason",
198 "message"
199 ],
200 "type": "object"
201 },
202 "type": "array"
203 },
204 "lastFailureTime": {
205 "format": "date-time",
206 "type": "string"
207 },
208 "notAfter": {
209 "description": "The expiration time of the certificate stored in the secret\nnamed by this resource in spec.secretName.",
210 "format": "date-time",
211 "type": "string"
212 }
213 },
214 "type": "object"
215 }
216 }
217 }
218 }
219 },
220 },
221 challenges: kube.CustomResourceDefinition("certmanager.k8s.io", "v1alpha1", "Challenge") {
222 spec+: {
223 additionalPrinterColumns: [
224 { name: "State", type: "string", JSONPath: ".status.state" },
225 { name: "Domain", type: "string", JSONPath: ".spec.dnsName" },
226 { name: "Reason", type: "string", JSONPath: ".status.reason", priority: 1 },
227 { name: "Age", type: "date", JSONPath: ".metadata.creationTimestamp" },
228 ],
229 validation: {
230 # ...
231 },
232 },
233 },
234 clusterissuers: kube.CustomResourceDefinition("certmanager.k8s.io", "v1alpha1", "ClusterIssuer") {
235 spec+: {
236 validation: {
237 # ...
238 },
239 scope: "Cluster",
240 },
241 },
242 issuers: kube.CustomResourceDefinition("certmanager.k8s.io", "v1alpha1", "Issuer") {
243 spec+: {
244 validation: {
245 # ...
246 },
247 scope: "Namespaced",
248 },
249 },
250 orders: kube.CustomResourceDefinition("certmanager.k8s.io", "v1alpha1", "Order") {
251 spec+: {
252 additionalPrinterColumns: [
253 { name: "State", type: "string", JSONPath: ".status.state" },
254 { name: "Issuer", type: "string", JSONPath: ".spec.issuerRef.name", priority: 1 },
255 { name: "Reason", type: "string", JSONPath: ".status.reason", priority: 1 },
256 { name: "Age", type: "date", JSONPath: ".metadata.creationTimestamp" },
257 ],
258 validation: {
259 # ...
260 },
261 scope: "Namespaced",
262 },
263 },
264 },
265
266 sas: {
267 cainjector: kube.ServiceAccount("cert-manager-cainjector") {
268 metadata+: env.metadata,
269 },
270 webhook: kube.ServiceAccount("cert-manager-webhook") {
271 metadata+: env.metadata,
272 },
273 certmanager: kube.ServiceAccount("cert-manager") {
274 metadata+: env.metadata,
275 },
276 },
277
278 crs: {
279 cainjector: kube.ClusterRole("cert-manager-cainjector") {
280 rules: [
281 {
282 apiGroups: ["certmanager.k8s.io"],
283 resources: ["certificates"],
284 verbs: ["get", "list", "watch"],
285 },
286 {
287 apiGroups: [""],
288 resources: ["secrets"],
289 verbs: ["get", "list", "watch"],
290 },
291 {
292 apiGroups: [""],
293 resources: ["configmaps", "events"],
294 verbs: ["*"],
295 },
296
297 {
298 apiGroups: ["admissionregistration.k8s.io"],
299 resources: ["validatingwebhookconfigurations", "mutatingwebhookconfigurations"],
300 verbs: ["*"],
301 },
302 {
303 apiGroups: ["apiregistration.k8s.io"],
304 resources: ["apiservices"],
305 verbs: ["*"],
306 },
307 ],
308 },
309 certmanager: kube.ClusterRole("cert-manager") {
310 rules: [
311 {
312 apiGroups: ["certmanager.k8s.io"],
313 resources: ["certificates", "certificates/finalizers", "issuers", "clusterissuers", "orders", "orders/finalizers", "challenges"],
314 verbs: ["*"],
315 },
316 {
317 apiGroups: [""],
318 resources: ["configmaps", "secrets", "events", "services", "pods"],
319 verbs: ["*"],
320 },
321 {
322 apiGroups: ["extensions"],
323 resources: ["ingresses"],
324 verbs: ["*"],
325 },
326 ],
327 },
328 certmanagerView: kube.ClusterRole("cert-manager-view") {
329 rules: [
330 {
331 apiGroups: ["certmanager.k8s.io"],
332 resources: ["certificates", "issuers"],
333 verbs: ["get", "list", "watch"],
334 },
335 ],
336 },
337 certmanagerEdit: kube.ClusterRole("cert-manager-edit") {
338 rules: [
339 {
340 apiGroups: ["certmanager.k8s.io"],
341 resources: ["certificates", "issuers"],
342 verbs: ["create", "delete", "deletecollection", "patch", "update"],
343 },
344 ],
345 },
346 webhookRequester: kube.ClusterRole("cert-manager-webhook:webhook-requester") {
347 rules: [
348 {
349 apiGroups: ["admission.certmanager.k8s.io"],
350 resources: ["certificates", "issuers", "clusterissuers"],
351 verbs: ["create"],
352 },
353 ],
354 },
355 },
356 rbs: {
357 cainjector: kube.ClusterRoleBinding("cert-manager-cainjector") {
358 roleRef_: env.crs.cainjector,
359 subjects_: [ env.sas.cainjector ],
360 },
361 certmanager: kube.ClusterRoleBinding("cert-manager") {
362 roleRef_: env.crs.certmanager,
363 subjects_: [ env.sas.certmanager ],
364 },
365 webhookAuthDelegator: kube.ClusterRoleBinding("cert-manager-webhook:auth-delegator") {
366 roleRef_: {
367 kind: "ClusterRole",
368 metadata: { name: "system:auth-delegator" },
369 },
370 subjects_: [ env.sas.webhook ],
371 },
372 webhookAuthReader: kube.RoleBinding("cert-manager-webhook:webhook-authentication-reader") {
373 metadata+: {
374 namespace: "kube-system",
375 },
376 roleRef_: {
377 kind: "Role",
378 metadata: { name: "extension-apiserver-authentication-reader" },
379 },
380 subjects_: [ env.sas.webhook ],
381 },
382 },
383 deployments: {
384 cainjector: kube.Deployment("cert-manager-cainjector") {
385 metadata+: env.metadata,
386 spec+: {
387 replicas: 1,
388 template+: {
389 spec+: {
390 serviceAccountName: env.sas.cainjector.metadata.name,
391 containers_: {
392 cainjector: kube.Container("cainjector") {
Sergiusz Bazanskid16454b2019-08-29 17:21:49 +0200393 image: "quay.io/jetstack/cert-manager-cainjector:" + cfg.version,
Piotr Dobrowolski79ddbc52019-04-02 13:20:15 +0200394 args: [
395 "--leader-election-namespace=%s" % [cfg.namespace],
396 ],
397 env_: {
398 POD_NAMESPACE: kube.FieldRef("metadata.namespace"),
399 },
400 },
401 },
402 },
403 },
404 },
405 },
406 webhook: kube.Deployment("cert-manager-webhook") {
407 metadata+: env.metadata {
408 labels: {
409 app: "webhook",
410 },
411 },
412 spec+: {
413 replicas: 1,
414 template+: {
415 spec+: {
416 serviceAccountName: env.sas.webhook.metadata.name,
417 containers_: {
418 webhook: kube.Container("webhook") {
Sergiusz Bazanskid16454b2019-08-29 17:21:49 +0200419 image: "quay.io/jetstack/cert-manager-webhook:" + cfg.version,
Piotr Dobrowolski79ddbc52019-04-02 13:20:15 +0200420 args: [
421 "--v=12",
422 "--secure-port=6443",
423 "--tls-cert-file=/certs/tls.crt",
424 "--tls-private-key-file=/certs/tls.key",
425 ],
426 env_: {
427 POD_NAMESPACE: kube.FieldRef("metadata.namespace"),
428 },
429 ports_: { // changed
430 https: { containerPort: 6443 },
431 },
432 volumeMounts_: {
433 certs: { mountPath: "/certs" },
434 },
435 },
436 },
437 volumes_: {
438 certs: {
439 secret: { secretName: env.certificates.webhookTLS.spec.secretName },
440 },
441 // kube.SecretVolume(env.secrets.webhook_tls),
442 },
443 },
444 },
445 },
446 },
447 certmanager: kube.Deployment("cert-manager") {
448 metadata+: env.metadata,
449 spec+: {
450 replicas: 1,
451 template+: {
452 spec+: {
453 serviceAccountName: env.sas.certmanager.metadata.name,
454 containers_: {
455 webhook: kube.Container("cert-manager") {
Sergiusz Bazanskid16454b2019-08-29 17:21:49 +0200456 image: "quay.io/jetstack/cert-manager-controller:" + cfg.version,
Piotr Dobrowolski79ddbc52019-04-02 13:20:15 +0200457 args: [
458 "--cluster-resource-namespace=%s" % [cfg.namespace],
459 "--leader-election-namespace=%s" % [cfg.namespace],
460 ],
461 env_: {
462 POD_NAMESPACE: kube.FieldRef("metadata.namespace"),
463 },
464 ports_: {
465 metrics: { containerPort: 9402 },
466 },
467 resources: {
468 requests: {
469 cpu: "10m",
470 memory: "32Mi",
471 },
472 },
473 },
474 },
475 },
476 },
477 },
478 },
479 },
480 service: kube.Service("cert-manager-webhook") {
481 metadata+: env.metadata,
482 target_pod:: env.deployments.webhook.spec.template,
483 spec+: {
484 type: "ClusterIP",
485 ports: [
486 { name: "https", port: 443, targetPort: 6443, protocol: "TCP" },
487 ],
488 },
489 },
Piotr Dobrowolskifc514a92019-05-05 12:12:13 +0200490 apiservice: if cfg.enableWebhook then kube._Object("apiregistration.k8s.io/v1beta1", "APIService", "v1beta1.admission.certmanager.k8s.io") {
Piotr Dobrowolski79ddbc52019-04-02 13:20:15 +0200491 spec+: {
492 version: "v1beta1",
493 group: "admission.certmanager.k8s.io",
494 groupPriorityMinimum: 1000,
495 versionPriority: 15,
496 service: {
497 name: env.service.metadata.name,
498 namespace: cfg.namespace,
499 },
500 },
501 },
Piotr Dobrowolskifc514a92019-05-05 12:12:13 +0200502
Piotr Dobrowolski79ddbc52019-04-02 13:20:15 +0200503 issuers: {
504 webhookSelfsign: cm.Issuer("cert-manager-webhook-selfsign") {
505 metadata+: env.metadata,
506 spec: {
507 selfSigned: {},
508 },
509 },
510 webhookCA: cm.Issuer("cert-manager-webhook-ca") {
511 metadata+: env.metadata,
512 spec: {
513 ca: {
514 secretName: env.certificates.webhookCA.spec.secretName,
515 },
516 },
517 },
518 },
519 certificates: {
520 webhookCA: cm.Certificate("cert-manager-webhook-ca") {
521 metadata+: env.metadata,
522 spec: {
523 secretName: "cert-manager-webhook-ca",
Piotr Dobrowolski2afe6042019-04-02 14:43:34 +0200524 duration: "43800h0m0s", // 5 years
Piotr Dobrowolski79ddbc52019-04-02 13:20:15 +0200525 issuerRef: {
526 name: env.issuers.webhookSelfsign.metadata.name,
527 },
528 commonName: "ca.webhook.cert-manager",
529 isCA: true,
530 },
531 },
532 webhookTLS: cm.Certificate("cert-manager-webhook-webhook-tls") {
533 metadata+: env.metadata,
534 spec: {
535 secretName: "cert-manager-webhook-webhook-tls",
Piotr Dobrowolski2afe6042019-04-02 14:43:34 +0200536 duration: "8760h0m0s", // 1 year
Piotr Dobrowolski79ddbc52019-04-02 13:20:15 +0200537 issuerRef: {
538 name: env.issuers.webhookSelfsign.metadata.name,
539 },
540 dnsNames: [
541 "cert-manager-webhook",
542 "cert-manager-webhook.cert-manager",
543 "cert-manager-webhook.cert-manager.svc",
544 ],
545 },
546 },
547 },
Piotr Dobrowolskifc514a92019-05-05 12:12:13 +0200548 admission: if cfg.enableWebhook then kube._Object("admissionregistration.k8s.io/v1beta1", "ValidatingWebhookConfiguration", "cert-manager-webhook") {
Piotr Dobrowolski79ddbc52019-04-02 13:20:15 +0200549 metadata+: {
550 annotations: {
Piotr Dobrowolski79ddbc52019-04-02 13:20:15 +0200551 },
552 },
Piotr Dobrowolski2afe6042019-04-02 14:43:34 +0200553 // Copied from official yaml
Piotr Dobrowolskifc514a92019-05-05 12:12:13 +0200554 webhooks: [
Piotr Dobrowolski79ddbc52019-04-02 13:20:15 +0200555 {
556 "name": "certificates.admission.certmanager.k8s.io",
557 "namespaceSelector": {
558 "matchExpressions": [
559 {
560 "key": "certmanager.k8s.io/disable-validation",
561 "operator": "NotIn",
562 "values": [
563 "true"
564 ]
565 },
566 {
567 "key": "name",
568 "operator": "NotIn",
569 "values": [
570 "cert-manager"
571 ]
572 }
573 ]
574 },
575 "rules": [
576 {
577 "apiGroups": [
578 "certmanager.k8s.io"
579 ],
580 "apiVersions": [
581 "v1alpha1"
582 ],
583 "operations": [
584 "CREATE",
585 "UPDATE"
586 ],
587 "resources": [
588 "certificates"
589 ]
590 }
591 ],
592 "failurePolicy": "Fail",
593 "clientConfig": {
594 "service": {
595 "name": "kubernetes",
596 "namespace": "default",
597 "path": "/apis/admission.certmanager.k8s.io/v1beta1/certificates"
598 },
599 "caBundle": "",
600 }
601 },
602 {
603 "name": "issuers.admission.certmanager.k8s.io",
604 "namespaceSelector": {
605 "matchExpressions": [
606 {
607 "key": "certmanager.k8s.io/disable-validation",
608 "operator": "NotIn",
609 "values": [
610 "true"
611 ]
612 },
613 {
614 "key": "name",
615 "operator": "NotIn",
616 "values": [
617 "cert-manager"
618 ]
619 }
620 ]
621 },
622 "rules": [
623 {
624 "apiGroups": [
625 "certmanager.k8s.io"
626 ],
627 "apiVersions": [
628 "v1alpha1"
629 ],
630 "operations": [
631 "CREATE",
632 "UPDATE"
633 ],
634 "resources": [
635 "issuers"
636 ]
637 }
638 ],
639 "failurePolicy": "Fail",
640 "clientConfig": {
641 "service": {
642 "name": "kubernetes",
643 "namespace": "default",
644 "path": "/apis/admission.certmanager.k8s.io/v1beta1/issuers"
645 },
646 "caBundle": "",
647 }
648 },
649 {
650 "name": "clusterissuers.admission.certmanager.k8s.io",
651 "namespaceSelector": {
652 "matchExpressions": [
653 {
654 "key": "certmanager.k8s.io/disable-validation",
655 "operator": "NotIn",
656 "values": [
657 "true"
658 ]
659 },
660 {
661 "key": "name",
662 "operator": "NotIn",
663 "values": [
664 "cert-manager"
665 ]
666 }
667 ]
668 },
669 "rules": [
670 {
671 "apiGroups": [
672 "certmanager.k8s.io"
673 ],
674 "apiVersions": [
675 "v1alpha1"
676 ],
677 "operations": [
678 "CREATE",
679 "UPDATE"
680 ],
681 "resources": [
682 "clusterissuers"
683 ]
684 }
685 ],
686 "failurePolicy": "Fail",
687 "clientConfig": {
688 "service": {
689 "name": "kubernetes",
690 "namespace": "default",
691 "path": "/apis/admission.certmanager.k8s.io/v1beta1/clusterissuers"
692 },
693 "caBundle": "",
694 }
695 }
Piotr Dobrowolskifc514a92019-05-05 12:12:13 +0200696 ],
Piotr Dobrowolski79ddbc52019-04-02 13:20:15 +0200697 },
698 },
699
Piotr Dobrowolski79ddbc52019-04-02 13:20:15 +0200700 Issuer(name): kube._Object("certmanager.k8s.io/v1alpha1", "Issuer", name) {
701 spec: error "spec must be specified",
702 },
703
Piotr Dobrowolski2afe6042019-04-02 14:43:34 +0200704 ClusterIssuer(name): kube._Object("certmanager.k8s.io/v1alpha1", "ClusterIssuer", name) {
705 spec: error "spec must be specified",
706 },
707
Piotr Dobrowolski79ddbc52019-04-02 13:20:15 +0200708 Certificate(name): kube._Object("certmanager.k8s.io/v1alpha1", "Certificate", name) {
709 spec: error "spec must be specified",
710 },
711}