]> git.proxmox.com Git - pmg-docs.git/blame - pmg-ssl-certificate.adoc
certs: add wildcard certificate support
[pmg-docs.git] / pmg-ssl-certificate.adoc
CommitLineData
8c889e95
TL
1[[sysadmin_certificate_management]]
2Certificate Management
3----------------------
81b3c41f 4
8c889e95 5Access to the administration web-interface is always encrypted through `https`.
c7fd1dd8
TL
6Each {pmg} host creates by default its own (self-signed) certificate.
7This certificate is used for encrypted communication with the host's `pmgproxy`
ce64ae40 8service for any API call, between an user and the web-interface or between
c7fd1dd8
TL
9nodes in a cluster.
10
11Certificate verification in a {pmg} cluster is done based on pinning the
12certificate fingerprints in the cluster configuration and verifying that they
13match on connection.
8c889e95
TL
14
15[[sysadmin_certs_api_gui]]
16Certificates for the API and SMTP
17~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18
19{pmg} knows two different certificates:
20
21* `/etc/pmg/pmg-api.pem`: the required certificate used for {pmg} API requests.
22* `/etc/pmg/pmg-tls.pem`: the optional certificate used for SMTP TLS
23 connections, see xref:pmgconfig_mailproxy_tls[mailproxy TLS configuration]
24 for details.
25
26You have the following options for those certificates:
27
281. keep using the default self-signed certificate in `/etc/pmg/pmg-api.pem`.
292. use an externally provided certificate (for example, signed by a commercial
30Certificate Authority (CA)).
313. use an ACME provider like Let's Encrypt to get a trusted certificate with
32automatic renewal, this is also integrated in the {pmg} API and Webinterface.
33
34Certificates are managed through the {pmg} web-interface/API or using the
35the `pmgconfig` CLI tool.
36
37[[sysadmin_certs_upload_custom]]
38Upload Custom Certificate
39~~~~~~~~~~~~~~~~~~~~~~~~~
40
41If you already have a certificate which you want to use for a {pmg} host, you
42can upload that certificate simply over the web interface.
43
44[thumbnail="pmg-gui-certs-upload-custom.png"]
45
ce64ae40 46Note that any certificate key files must not be password protected.
8c889e95
TL
47
48[[sysadmin_certs_get_trusted_acme_cert]]
49Trusted certificates via Let's Encrypt (ACME)
50~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51
52{PMG} includes an implementation of the **A**utomatic **C**ertificate
53**M**anagement **E**nvironment **ACME** protocol, allowing {pmg} admins to
d7457185
SI
54use an ACME provider like Let's Encrypt for easy setup of TLS certificates
55which are accepted and trusted from modern operating systems and web browsers
56out of the box.
8c889e95 57
c7fd1dd8 58Currently, the two ACME endpoints implemented are the
8c889e95
TL
59https://letsencrypt.org[Let's Encrypt (LE)] production and its staging
60environment. Our ACME client supports validation of `http-01` challenges using
c7fd1dd8 61a built-in web server and validation of `dns-01` challenges using a DNS plugin
8c889e95
TL
62supporting all the DNS API endpoints https://acme.sh[acme.sh] does.
63
64[[sysadmin_certs_acme_account]]
65ACME Account
66^^^^^^^^^^^^
67
68[thumbnail="pmg-gui-acme-create-account.png"]
69
70You need to register an ACME account per cluster with the endpoint you want to
ce64ae40 71use. The email address used for that account will serve as contact point for
8c889e95
TL
72renewal-due or similar notifications from the ACME endpoint.
73
74You can register or deactivate ACME accounts over the web interface
75`Certificates -> ACME Accounts` or using the `pmgconfig` command line tool.
76----
77 pmgconfig acme account register <account-name> <mail@example.com>
78----
79
80TIP: Because of https://letsencrypt.org/docs/rate-limits/[rate-limits] you
81should use LE `staging` for experiments or if you use ACME for the very first
82time until all is working there, and only then switch over to the production
83directory.
84
85[[sysadmin_certs_acme_plugins]]
86ACME Plugins
87^^^^^^^^^^^^
88
89The ACME plugins task is to provide automatic verification that you, and thus
90the {pmg} cluster under your operation, are the real owner of a domain. This is
91the basis building block for automatic certificate management.
92
93The ACME protocol specifies different types of challenges, for example the
c7fd1dd8
TL
94`http-01` where a web server provides a file with a certain content to prove
95that it controls a domain. Sometimes this isn't possible, either because of
d7457185
SI
96technical limitations or if the address of a record is not reachable from the
97public internet. The `dns-01` challenge can be used in these cases. The
98challenge is fulfilled by creating a certain DNS record in the domain's zone.
8c889e95
TL
99
100[thumbnail="pmg-gui-acme-create-challenge-plugin.png"]
101
c7fd1dd8
TL
102{pmg} supports both of those challenge types out of the box, you can configure
103plugins either over the web interface under `Certificates -> ACME Challenges`,
104or using the `pmgconfig acme plugin add` command.
8c889e95 105
c7fd1dd8 106ACME Plugin configurations are stored in `/etc/pmg/acme/plugins.cfg`.
8c889e95
TL
107A plugin is available for all nodes in the cluster.
108
109Domains
110^^^^^^^
111
112You can add new or manage existing domain entries under `Certificates`, or
113using the `pmgconfig` command.
114
115[thumbnail="pmg-gui-acme-add-domain.png"]
116
117After configuring the desired domain(s) for a node and ensuring that the
118desired ACME account is selected, you can order your new certificate over the
119web-interface. On success the interface will reload after circa 10 seconds.
120
121Renewal will happen xref:sysadmin_certs_acme_automatic_renewal[automatically].
122
123[[sysadmin_certs_acme_http_challenge]]
124ACME HTTP Challenge Plugin
125~~~~~~~~~~~~~~~~~~~~~~~~~~
126
127There is always an implicitly configured `standalone` plugin for validating
128`http-01` challenges via the built-in webserver spawned on port 80.
129
130NOTE: The name `standalone` means that it can provide the validation on it's
131own, without any third party service. So, this plugin works also for cluster
132nodes.
133
134There are a few prerequisites to use it for certificate management with Let's
135Encrypts ACME.
136
137* You have to accept the ToS of Let's Encrypt to register an account.
138* **Port 80** of the node needs to be reachable from the internet.
139* There **must** be no other listener on port 80.
140* The requested (sub)domain needs to resolve to a public IP of the {pmg} host.
141
142
143[[sysadmin_certs_acme_dns_challenge]]
144ACME DNS API Challenge Plugin
145~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
146
147On systems where external access for validation via the `http-01` method is
148not possible or desired, it is possible to use the `dns-01` validation method.
149This validation method requires a DNS server that allows provisioning of `TXT`
150records via an API.
151
152[[sysadmin_certs_acme_dns_api_config]]
153Configuring ACME DNS APIs for validation
154^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
155
c7fd1dd8
TL
156{pmg} re-uses the DNS plugins developed for the `acme.sh`
157footnote:[acme.sh https://github.com/acmesh-official/acme.sh] project, please
158refer to its documentation for details on configuration of specific APIs.
8c889e95
TL
159
160The easiest way to configure a new plugin with the DNS API is using the web
161interface (`Certificates -> ACME Accounts/Challenges`).
162
163[thumbnail="pmg-gui-acme-create-challenge-plugin.png"]
164
165Add a new challenge plugin, here you can select your API provider, enter the
166credential data to access your account over their API.
167
168TIP: See the acme.sh
169https://github.com/acmesh-official/acme.sh/wiki/dnsapi#how-to-use-dns-api[How to use DNS API]
170wiki for more detailed information about getting API credentials for your
171provider. Configuration values do not need to be quoted with single or double
172quotes, for some plugins that is even an error.
173
c7fd1dd8
TL
174As there are many DNS providers and API endpoints {pmg} automatically generates
175the form for the credentials, but not all providers are annotated yet. For
176those you will see a bigger text area, simply copy all the credentials
177`KEY`=`VALUE` pairs in there.
8c889e95
TL
178
179DNS Validation through CNAME Alias
180^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
181
182A special `alias` mode can be used to handle the validation on a different
183domain/DNS server, in case your primary/real DNS does not support provisioning
184via an API. Manually set up a permanent `CNAME` record for
185`_acme-challenge.domain1.example` pointing to `_acme-challenge.domain2.example`
186and set the `alias` property in the {pmg} node configuration file
187`/etc/pmg/node.conf` to `domain2.example` to allow the DNS server of
188`domain2.example` to validate all challenges for `domain1.example`.
189
3419e609
SI
190[[sysadmin_certs_acme_dns_wildcard]]
191Wildcard Certificates
192^^^^^^^^^^^^^^^^^^^^^
193
194Wildcard DNS names start with a `*.` prefix and are considered valid for all
195(one-level) subdomain names of the verified domain. So a certificate for
196`*.domain.example` is valid for example for `foo.domain.example` and
197`bar.domain.example`, but not for `baz.foo.domain.example`.
198
199You can currently create wildcard certificates only with the
200https://letsencrypt.org/docs/challenge-types/#dns-01-challenge[DNS challenge type].
201
8c889e95
TL
202
203Combination of Plugins
204^^^^^^^^^^^^^^^^^^^^^^
205
206Combining `http-01` and `dns-01` validation is possible in case your node is
207reachable via multiple domains with different requirements / DNS provisioning
208capabilities. Mixing DNS APIs from multiple providers or instances is also
209possible by specifying different plugin instances per domain.
210
211TIP: Accessing the same service over multiple domains increases complexity and
212should be avoided if possible.
213
214[[sysadmin_certs_acme_automatic_renewal]]
215Automatic renewal of ACME certificates
216~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
217
218If a node has been successfully configured with an ACME-provided certificate
219(either via pmgconfig or via the web-interface/API), the certificate will be
220automatically renewed by the `pmg-daily.service`. Currently, renewal is
221triggered if the certificate either already expired or if it will expire in the
222next 30 days.
223
224Manually Change Certificate over Command-Line
225~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
81b3c41f 226
ce64ae40
SI
227If you want to get rid of certificate verification warnings, you have to
228generate a valid certificate for your server.
81b3c41f 229
f7198e12 230Login to your {pmg} via ssh or use the console:
81b3c41f
DM
231
232----
233openssl req -newkey rsa:2048 -nodes -keyout key.pem -out req.pem
234----
235
236Follow the instructions on the screen, see this example:
237
238----
239Country Name (2 letter code) [AU]: AT
240State or Province Name (full name) [Some-State]:Vienna
241Locality Name (eg, city) []:Vienna
242Organization Name (eg, company) [Internet Widgits Pty Ltd]: Proxmox GmbH
243Organizational Unit Name (eg, section) []:Proxmox Mail Gateway
244Common Name (eg, YOUR name) []: yourproxmox.yourdomain.com
245Email Address []:support@yourdomain.com
246
247Please enter the following 'extra' attributes to be sent with your certificate request
248A challenge password []: not necessary
249An optional company name []: not necessary
250----
251
252After you finished this certificate request you have to send the file
253`req.pem` to your Certification Authority (CA). The CA will issue the
254certificate (BASE64 encoded) based on your request – save this file as
f7198e12 255`cert.pem` to your {pmg}.
81b3c41f 256
f7198e12 257To activate the new certificate, do the following on your {pmg}:
81b3c41f
DM
258
259----
260cat key.pem cert.pem >/etc/pmg/pmg-api.pem
261----
262
f7198e12 263Then restart the API servers:
81b3c41f
DM
264
265----
266systemctl restart pmgproxy
267----
268
269Test your new certificate by using your browser.
270
8c889e95
TL
271NOTE: To transfer files from and to your {pmg}, you can use secure copy: If you
272desktop is Linux, you can use the `scp` command line tool. If your desktop PC
273is windows, please use a scp client like WinSCP (see https://winscp.net/).
0fe083dc
DM
274
275Change Certificate for Cluster Setups
276~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
277
8c889e95
TL
278If you change the API certificate of an active cluster node manually, you also
279need to update the pinned fingerprint inside the cluster configuration.
0fe083dc 280
8c889e95
TL
281You can do that by executing the following command on the host where the
282certificate changed:
0fe083dc
DM
283
284----
8c889e95 285pmgcm update-fingerprints
0fe083dc 286----
8c889e95
TL
287
288Note, this will be done automatically if using the integrated ACME (for
289example, through Let's Encrypt) feature.