-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathindex.html
More file actions
684 lines (661 loc) · 29.1 KB
/
index.html
File metadata and controls
684 lines (661 loc) · 29.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="author" content="The CloudNativePG Contributors" />
<link rel="shortcut icon" href="../img/favicon.ico" />
<title>Certificates - CloudNativePG v1.25</title>
<link rel="stylesheet" href="../css/theme.css" />
<link rel="stylesheet" href="../css/theme_extra.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/github.min.css" />
<link href="../css/override.css" rel="stylesheet" />
<script>
// Current page data
var mkdocs_page_name = "Certificates";
var mkdocs_page_input_path = "certificates.md";
var mkdocs_page_url = null;
</script>
<!--[if lt IE 9]>
<script src="../js/html5shiv.min.js"></script>
<![endif]-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href=".." class="icon icon-home"> CloudNativePG v1.25
</a><div role="search">
<form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" title="Type search term here" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<ul>
<li class="toctree-l1"><a class="reference internal" href="..">CloudNativePG</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../before_you_start/">Before You Start</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../use_cases/">Use cases</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../architecture/">Architecture</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../installation_upgrade/">Installation and upgrades</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../quickstart/">Quickstart</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../image_catalog/">Image Catalog</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../bootstrap/">Bootstrap</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../database_import/">Importing Postgres databases</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../security/">Security</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../instance_manager/">Postgres instance manager</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../scheduling/">Scheduling</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../resource_management/">Resource management</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../failure_modes/">Failure Modes</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../rolling_update/">Rolling Updates</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../replication/">Replication</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../logical_replication/">Logical Replication</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../backup/">Backup</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../backup_barmanobjectstore/">Backup on object stores</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../wal_archiving/">WAL archiving</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../backup_volumesnapshot/">Backup on volume snapshots</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../recovery/">Recovery</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../service_management/">Service Management</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../postgresql_conf/">PostgreSQL Configuration</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../declarative_role_management/">PostgreSQL Role Management</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../declarative_database_management/">PostgreSQL Database Management</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../tablespaces/">Tablespaces</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../operator_conf/">Operator configuration</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../cluster_conf/">Instance pod configuration</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../storage/">Storage</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../labels_annotations/">Labels and annotations</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../monitoring/">Monitoring</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../logging/">Logging</a>
</li>
</ul>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal current" href="#">Certificates</a>
<ul class="current">
<li class="toctree-l2"><a class="reference internal" href="#operator-managed-mode">Operator-Managed Mode</a>
<ul>
<li class="toctree-l3"><a class="reference internal" href="#server-certificates">Server certificates</a>
<ul>
<li class="toctree-l4"><a class="reference internal" href="#server-ca-secret">Server CA secret</a>
</li>
<li class="toctree-l4"><a class="reference internal" href="#server-tls-secret">Server TLS secret</a>
</li>
<li class="toctree-l4"><a class="reference internal" href="#server-alternative-dns-names">Server alternative DNS names</a>
</li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#client-certificates">Client certificates</a>
<ul>
<li class="toctree-l4"><a class="reference internal" href="#client-ca-secret">Client CA secret</a>
</li>
<li class="toctree-l4"><a class="reference internal" href="#client-streaming_replica-certificate">Client streaming_replica certificate</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#user-provided-certificates-mode">User-provided certificates mode</a>
<ul>
<li class="toctree-l3"><a class="reference internal" href="#server-certificates_1">Server certificates</a>
<ul>
<li class="toctree-l4"><a class="reference internal" href="#example">Example</a>
</li>
<li class="toctree-l4"><a class="reference internal" href="#cert-manager-example">Cert-manager example</a>
</li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#client-certificate">Client certificate</a>
<ul>
<li class="toctree-l4"><a class="reference internal" href="#cert-manager-example_1">Cert-manager example</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../ssl_connections/">Client TLS/SSL connections</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../applications/">Connecting from an application</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../connection_pooling/">Connection pooling</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../replica_cluster/">Replica clusters</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../kubernetes_upgrade/">Kubernetes Upgrade and Maintenance</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../kubectl-plugin/">Kubectl Plugin</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../failover/">Automated failover</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../troubleshooting/">Troubleshooting</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../fencing/">Fencing</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../declarative_hibernation/">Declarative hibernation</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../postgis/">PostGIS</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../e2e/">End-to-End Tests</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../container_images/">Container Image Requirements</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../operator_capability_levels/">Operator capability levels</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../controller/">Custom Pod Controller</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../samples/">Examples</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../networking/">Networking</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../benchmarking/">Benchmarking</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../faq/">Frequently Asked Questions (FAQ)</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../cloudnative-pg.v1/">API Reference</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../supported_releases/">Supported releases</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../preview_version/">Preview Versions</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../release_notes/">Release notes</a>
</li>
</ul>
<p class="caption"><span class="caption-text">CNCF Projects Integrations</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../cncf-projects/external-secrets/">External Secrets</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../cncf-projects/cilium/">Cilium</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Appendixes</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../appendixes/object_stores/">Appendix A - Common object stores for backups</a>
</li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="Mobile navigation menu">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="..">CloudNativePG v1.25</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content"><div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href=".." class="icon icon-home" aria-label="Docs"></a></li>
<li class="breadcrumb-item active">Certificates</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div class="section" itemprop="articleBody">
<h1 id="certificates">Certificates</h1>
<!-- SPDX-License-Identifier: CC-BY-4.0 -->
<p>CloudNativePG was designed to natively support TLS certificates.
To set up a cluster, the operator requires:</p>
<ul>
<li>A server certification authority (CA) certificate</li>
<li>A server TLS certificate signed by the server CA</li>
<li>A client CA certificate</li>
<li>A streaming replication client certificate generated by the client CA</li>
</ul>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>You can find all the secrets used by the cluster and their expiration dates
in the cluster's status.</p>
</div>
<p>CloudNativePG is very flexible when it comes to TLS certificates. It
primarily operates in two modes:</p>
<ol>
<li><a href="#operator-managed-mode"><strong>Operator managed</strong></a> – Certificates are internally
managed by the operator in a fully automated way and signed using a CA created
by CloudNativePG.</li>
<li><a href="#user-provided-certificates-mode"><strong>User provided</strong></a> – Certificates are
generated outside the operator and imported in the cluster definition as
secrets. CloudNativePG integrates itself with <a href="https://cert-manager.io/">cert-manager</a>
(See <a href="#cert-manager-example">Cert-manager example</a>.)</li>
</ol>
<p>You can also choose a hybrid approach, where only part of the certificates is
generated outside CNPG.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The operator and instances verify server certificates against the CA only,
disregarding the DNS name. This approach is due to the typical absence of DNS
names in user-provided certificates for the <code><cluster>-rw</code> service used for
communication within the cluster.</p>
</div>
<h2 id="operator-managed-mode">Operator-Managed Mode</h2>
<p>By default, the operator automatically generates a single Certificate Authority
(CA) to issue both client and server certificates. These certificates are
managed continuously by the operator, with automatic renewal 7 days before
expiration (within a 90-day validity period).</p>
<div class="admonition info">
<p class="admonition-title">Info</p>
<p>You can adjust this default behavior by configuring the
<code>CERTIFICATE_DURATION</code> and <code>EXPIRING_CHECK_THRESHOLD</code> environment variables.
For detailed guidance, refer to the <a href="../operator_conf/">Operator Configuration</a>.</p>
</div>
<div class="admonition important">
<p class="admonition-title">Important</p>
<p>Certificate renewal does not cause any downtime for the PostgreSQL server,
as a simple reload operation is sufficient. However, any user-managed
certificates not controlled by CloudNativePG must be re-issued following the
renewal process.</p>
</div>
<p>When generating certificates, the operator assumes that the Kubernetes
cluster's DNS zone is set to <code>cluster.local</code> by default. This behavior can be
customized by setting the <code>KUBERNETES_CLUSTER_DOMAIN</code> environment variable. A
convenient alternative is to use the <a href="../operator_conf/">operator's configuration capability</a>.</p>
<h3 id="server-certificates">Server certificates</h3>
<h4 id="server-ca-secret">Server CA secret</h4>
<p>The operator generates a self-signed CA and stores it in a generic secret
containing the following keys:</p>
<ul>
<li><code>ca.crt</code> – CA certificate used to validate the server certificate, used as
<code>sslrootcert</code> in clients' connection strings.</li>
<li><code>ca.key</code> – The key used to sign the server SSL certificate automatically.</li>
</ul>
<h4 id="server-tls-secret">Server TLS secret</h4>
<p>The operator uses the generated self-signed CA to sign a server TLS
certificate. It's stored in a secret of type <code>kubernetes.io/tls</code> and configured
to be used as <code>ssl_cert_file</code> and <code>ssl_key_file</code> by the instances. This
approach enables clients to verify their identity and connect securely.</p>
<h4 id="server-alternative-dns-names">Server alternative DNS names</h4>
<p>In addition to the default ones, you can specify DNS server alternative names
as part of the generated server TLS secret.</p>
<h3 id="client-certificates">Client certificates</h3>
<h4 id="client-ca-secret">Client CA secret</h4>
<p>By default, the same self-signed CA as the server CA is used. The public part
is passed as <code>ssl_ca_file</code> to all the instances so it can verify client
certificates it signed. The private key is stored in the same secret and used
to sign client certificates generated by the <code>kubectl cnpg</code> plugin.</p>
<h4 id="client-streaming_replica-certificate">Client <code>streaming_replica</code> certificate</h4>
<p>The operator uses the generated self-signed CA to sign a client certificate for
the user <code>streaming_replica</code>, storing it in a secret of type
<code>kubernetes.io/tls</code>. To allow secure connection to the primary instance, this
certificate is passed as <code>sslcert</code> and <code>sslkey</code> in the replicas' connection
strings.</p>
<h2 id="user-provided-certificates-mode">User-provided certificates mode</h2>
<h3 id="server-certificates_1">Server certificates</h3>
<p>If required, you can also provide the two server certificates, generating them
using a separate component such as <a href="https://cert-manager.io/">cert-manager</a>.
To use a custom server TLS certificate for a cluster, you must specify
the following parameters:</p>
<ul>
<li><code>serverTLSSecret</code> – The name of a secret of type <code>kubernetes.io/tls</code>
containing the server TLS certificate. It must contain both the standard
<code>tls.crt</code> and <code>tls.key</code> keys.</li>
<li><code>serverCASecret</code> – The name of a secret containing the <code>ca.crt</code> key.</li>
</ul>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The operator still creates and manages the two secrets related to client
certificates.</p>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The operator and instances verify server certificates against the CA only,
disregarding the DNS name. This approach is due to the typical absence of DNS
names in user-provided certificates for the <code><cluster>-rw</code> service used for
communication within the cluster.</p>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>If you want ConfigMaps and secrets to be reloaded by instances, you can add
a label with the key <code>cnpg.io/reload</code> to it. Otherwise you must reload the
instances using the <code>kubectl cnpg reload</code> subcommand.</p>
</div>
<h4 id="example">Example</h4>
<p>Given the following files:</p>
<ul>
<li><code>server-ca.crt</code> – The certificate of the CA that signed the server TLS certificate.</li>
<li><code>server.crt</code>– The certificate of the server TLS certificate.</li>
<li><code>server.key</code> – The private key of the server TLS certificate.</li>
</ul>
<p>Create a secret containing the CA certificate:</p>
<pre><code class="language-sh">kubectl create secret generic my-postgresql-server-ca \
--from-file=ca.crt=./server-ca.crt
</code></pre>
<p>Create a secret with the TLS certificate:</p>
<pre><code class="language-sh">kubectl create secret tls my-postgresql-server \
--cert=./server.crt --key=./server.key
</code></pre>
<p>Create a PostgreSQL cluster referencing those secrets:</p>
<pre><code class="language-bash">kubectl apply -f - <<EOF
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-example
spec:
instances: 3
certificates:
serverCASecret: my-postgresql-server-ca
serverTLSSecret: my-postgresql-server
storage:
storageClass: standard
size: 1Gi
EOF
</code></pre>
<p>The new cluster uses the provided server certificates for TLS connections.</p>
<h4 id="cert-manager-example">Cert-manager example</h4>
<p>This simple example shows how to use <a href="https://cert-manager.io/">cert-manager</a>
to set up a self-signed CA and generate the needed TLS server certificate:</p>
<pre><code class="language-yaml">---
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: selfsigned-issuer
spec:
selfSigned: {}
---
apiVersion: v1
kind: Secret
metadata:
name: my-postgres-server-cert
labels:
cnpg.io/reload: ""
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: my-postgres-server-cert
spec:
secretName: my-postgres-server-cert
usages:
- server auth
dnsNames:
- cluster-example-lb.internal.mydomain.net
- cluster-example-rw
- cluster-example-rw.default
- cluster-example-rw.default.svc
- cluster-example-r
- cluster-example-r.default
- cluster-example-r.default.svc
- cluster-example-ro
- cluster-example-ro.default
- cluster-example-ro.default.svc
issuerRef:
name: selfsigned-issuer
kind: Issuer
group: cert-manager.io
</code></pre>
<p>Cert-manager creates a secret named <code>my-postgres-server-cert</code>. It contains all
the needed files and can be referenced from a cluster as follows:</p>
<pre><code class="language-yaml">apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-example
spec:
instances: 3
certificates:
serverTLSSecret: my-postgres-server-cert
serverCASecret: my-postgres-server-cert
storage:
size: 1Gi
</code></pre>
<p>You can find a complete example using cert-manager to manage both server and
client CA and certificates in the
<a href="../samples/cluster-example-cert-manager.yaml">cluster-example-cert-manager.yaml</a>
deployment manifest.</p>
<h3 id="client-certificate">Client certificate</h3>
<p>If required, you can also provide the two client certificates, generating them
using a separate component such as <a href="https://cert-manager.io/">cert-manager</a> or
<a href="https://www.vaultproject.io/docs/secrets/pki">HashiCorp vault</a>. To
use a custom CA to verify client certificates for a cluster, you must specify
the following parameters:</p>
<ul>
<li><code>replicationTLSSecret</code> – The name of a secret of type <code>kubernetes.io/tls</code>
containing the client certificate for user <code>streaming_replica</code>. It must contain
both the standard <code>tls.crt</code> and <code>tls.key</code> keys.</li>
<li><code>clientCASecret</code>– The name of a secret containing the <code>ca.crt</code> key of the CA
to use to verify client certificate.</li>
</ul>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The operator still creates and manages the two secrets related to server
certificates.</p>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>As the cluster isn't in control of the client CA secret key, you can no
longer generate client certificates using <code>kubectl cnpg certificate</code>.</p>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>If you want ConfigMaps and secrets to be automatically reloaded by
instances, you can add a label with the key <code>cnpg.io/reload</code> to it. Otherwise,
you must reload the instances using the <code>kubectl cnpg reload</code> subcommand.</p>
</div>
<h4 id="cert-manager-example_1">Cert-manager example</h4>
<p>This simple example shows how to use <a href="https://cert-manager.io/">cert-manager</a>
to set up a self-signed CA and generate the needed TLS server certificate:</p>
<pre><code class="language-yaml">---
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: selfsigned-issuer
spec:
selfSigned: {}
---
apiVersion: v1
kind: Secret
metadata:
name: my-postgres-client-cert
labels:
cnpg.io/reload: ""
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: my-postgres-client-cert
spec:
secretName: my-postgres-client-cert
usages:
- client auth
commonName: streaming_replica
issuerRef:
name: selfsigned-issuer
kind: Issuer
group: cert-manager.io
</code></pre>
<p>Cert-manager creates a secret named <code>my-postgres-client-cert</code> that contains all
the needed files. You can reference it from a cluster as follows:</p>
<pre><code class="language-yaml">apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-example
spec:
instances: 3
certificates:
clientCASecret: my-postgres-client-cert
replicationTLSSecret: my-postgres-client-cert
storage:
size: 1Gi
</code></pre>
<p>You can find a complete example using cert-manager to manage both server and
client CA and certificates in the
<a href="../samples/cluster-example-cert-manager.yaml">cluster-example-cert-manager.yaml</a>
deployment manifest.</p>
</div>
</div><footer>
<div class="rst-footer-buttons" role="navigation" aria-label="Footer Navigation">
<a href="../logging/" class="btn btn-neutral float-left" title="Logging"><span class="icon icon-circle-arrow-left"></span> Previous</a>
<a href="../ssl_connections/" class="btn btn-neutral float-right" title="Client TLS/SSL connections">Next <span class="icon icon-circle-arrow-right"></span></a>
</div>
<hr/>
<div role="contentinfo">
<!-- Copyright etc -->
<p>Copyright © CloudNativePG a Series of LF Projects, LLC</p>
</div>
Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<div class="rst-versions" role="note" aria-label="Versions">
<span class="rst-current-version" data-toggle="rst-current-version">
<span><a href="../logging/" style="color: #fcfcfc">« Previous</a></span>
<span><a href="../ssl_connections/" style="color: #fcfcfc">Next »</a></span>
</span>
</div>
<script src="../js/jquery-3.6.0.min.js"></script>
<script>var base_url = "..";</script>
<script src="../js/theme_extra.js"></script>
<script src="../js/theme.js"></script>
<script src="../search/main.js"></script>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>