]> git.proxmox.com Git - pmg-docs.git/blame - pmg-ssl-certificate.adoc
asciidoc: make thumbnail path relative to images/
[pmg-docs.git] / pmg-ssl-certificate.adoc
CommitLineData
8c889e95
TL
1[[sysadmin_certificate_management]]
2Certificate Management
3----------------------
81b3c41f 4
b908760c
DW
5Access to the web-based administration interface is always encrypted through
6`https`. Each {pmg} host creates by default its own (self-signed) certificate.
c7fd1dd8 7This certificate is used for encrypted communication with the host's `pmgproxy`
b908760c
DW
8service, for any API call between a user and the web-interface or between nodes
9in a cluster.
c7fd1dd8
TL
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
b908760c 19{pmg} uses two different certificates:
8c889e95
TL
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
b908760c 26You have the following options for these certificates:
8c889e95 27
b908760c
DW
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
8c889e95 30Certificate Authority (CA)).
b908760c
DW
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 web interface.
8c889e95
TL
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
b908760c 42can simply upload that certificate over the web interface.
8c889e95 43
38d14519 44[thumbnail="screenshot/pmg-gui-certs-upload-custom.png"]
8c889e95 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
b908760c
DW
53**M**anagement **E**nvironment (**ACME**) protocol, allowing {pmg} admins to
54use an ACME provider like Let's Encrypt for easy setup of TLS certificates,
55which are accepted and trusted by modern operating systems and web browsers
d7457185 56out of the box.
8c889e95 57
c7fd1dd8 58Currently, the two ACME endpoints implemented are the
b908760c
DW
59https://letsencrypt.org[Let's Encrypt (LE)] production and staging
60environments. 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
38d14519 68[thumbnail="screenshot/pmg-gui-acme-create-account.png"]
8c889e95 69
b908760c
DW
70You need to register an ACME account per cluster, with the endpoint you want to
71use. The email address used for that account will serve as the 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
db96e742 75`Certificates -> ACME Accounts` or using the `pmgconfig` command-line tool.
8c889e95
TL
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
b908760c 89The ACME plugin's role is to provide automatic verification that you, and thus
8c889e95 90the {pmg} cluster under your operation, are the real owner of a domain. This is
b908760c 91the basic building block of automatic certificate management.
8c889e95
TL
92
93The ACME protocol specifies different types of challenges, for example the
b908760c 94`http-01`, where a web server provides a file with a specific token to prove
c7fd1dd8 95that it controls a domain. Sometimes this isn't possible, either because of
d7457185 96technical limitations or if the address of a record is not reachable from the
b908760c 97public internet. The `dns-01` challenge can be used in such cases. This
d7457185 98challenge is fulfilled by creating a certain DNS record in the domain's zone.
8c889e95 99
38d14519 100[thumbnail="screenshot/pmg-gui-acme-create-challenge-plugin.png"]
8c889e95 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
38d14519 115[thumbnail="screenshot/pmg-gui-acme-add-domain.png"]
8c889e95
TL
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
b908760c 119web-interface. On success, the interface will reload after roughly 10 seconds.
8c889e95
TL
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
b908760c 128`http-01` challenges via the built-in web server spawned on port 80.
8c889e95 129
b908760c
DW
130NOTE: The name `standalone` means that it can provide the validation on its
131own, without any third party service. So this plugin also works for cluster
8c889e95
TL
132nodes.
133
b908760c 134There are a few prerequisites to use this for certificate management with Let's
8c889e95
TL
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 156{pmg} re-uses the DNS plugins developed for the `acme.sh`
b908760c 157footnote:[acme.sh https://github.com/acmesh-official/acme.sh] project. Please
c7fd1dd8 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
38d14519 163[thumbnail="screenshot/pmg-gui-acme-create-challenge-plugin.png"]
8c889e95 164
b908760c
DW
165Here you can add a new challenge plugin by selecting your API provider and
166entering the credential data to access your account over their API.
8c889e95
TL
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
b908760c 172quotes; for some plugins that is even an error.
8c889e95 173
b908760c
DW
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 those
176you will see a bigger text area, into which you simply need to copy all the
177credential's `KEY`=`VALUE` pairs.
8c889e95
TL
178
179DNS Validation through CNAME Alias
180^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
181
b908760c 182A special `alias` mode can be used to handle validation on a different
8c889e95
TL
183domain/DNS server, in case your primary/real DNS does not support provisioning
184via an API. Manually set up a permanent `CNAME` record for
b908760c 185`_acme-challenge.domain1.example` pointing to `_acme-challenge.domain2.example`,
8c889e95
TL
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
b908760c 196`*.domain.example` is valid for `foo.domain.example` and
3419e609
SI
197`bar.domain.example`, but not for `baz.foo.domain.example`.
198
b908760c 199Currently, you can only create wildcard certificates with the
3419e609
SI
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
b908760c
DW
220renewed automatically by the `pmg-daily.service`. Currently, renewal is
221triggered if the certificate either has already expired or if it will expire in
222the next 30 days.
8c889e95 223
db96e742 224Manually Change Certificate over the Command Line
8c889e95 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
b908760c 230Log in 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
b908760c 236Follow the instructions on the screen, for example:
81b3c41f
DM
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
b908760c 252After you have finished the certificate request, you have to send the file
81b3c41f 253`req.pem` to your Certification Authority (CA). The CA will issue the
b908760c 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
b908760c 269Test your new certificate, using your browser.
81b3c41f 270
b908760c 271NOTE: To transfer files to and from your {pmg}, you can use secure copy: If your
db96e742 272desktop runs Linux, you can use the `scp` command-line tool. If your desktop PC
b908760c 273runs windows, please use an 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.