Skip to content

Commit 8768b25

Browse files
committed
Clear up public key source handling docs
This commit clears up input types for x509_v2 certificate parameters relating to the certificate's public key. It also documents a breaking change versus the previous modules that was forgotten about and can cause confusion. See: #66889
1 parent 90dba23 commit 8768b25

File tree

2 files changed

+72
-38
lines changed

2 files changed

+72
-38
lines changed

salt/modules/x509_v2.py

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@
118118
119119
Breaking changes versus the previous ``x509`` modules
120120
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
121+
* The ``public_key`` parameter to ``x509.certificate_managed`` (and corresponding
122+
``x509.create_certificate``) used to accept a private key.
123+
The new modules require an actual public key if this parameter is specified.
124+
You can pass a private key in the ``private_key`` parameter instead.
125+
126+
Failing to ensure it really is a public key you are passing as ``public_key`` fails
127+
with ``Could not load PEM-encoded public key.``.
128+
121129
* The output format has changed for all ``read_*`` functions as well as the state return dict.
122130
* The formatting of some extension definitions might have changed, but should
123131
be stable for most basic use cases.
@@ -267,33 +275,48 @@ def create_certificate(
267275
The hashing algorithm to use for the signature. Valid values are:
268276
sha1, sha224, sha256, sha384, sha512, sha512_224, sha512_256, sha3_224,
269277
sha3_256, sha3_384, sha3_512. Defaults to ``sha256``.
270-
This will be ignored for ``ed25519`` and ``ed448`` key types.
278+
Ignored for ``ed25519`` and ``ed448`` key types.
271279
272280
private_key
273-
The private key corresponding to the public key the certificate should
274-
be issued for. This is one way of specifying the public key that will
275-
be included in the certificate, the other ones being ``public_key`` and ``csr``.
281+
A **private key**, which is used to derive the public key the certificate
282+
is issued for. If unset, checks ``public_key`` or ``csr`` to derive it.
283+
284+
Ignored when creating self-signed certificates (missing ``signing_cert``).
285+
286+
.. hint::
287+
When ``encoding`` is ``pkcs12``, this private key is embedded into
288+
the resulting container.
276289
277290
private_key_passphrase
278291
If ``private_key`` is specified and encrypted, the passphrase to decrypt it.
279292
280293
public_key
281-
The public key the certificate should be issued for. Other ways of passing
282-
the required information are ``private_key`` and ``csr``. If neither are set,
283-
the public key of the ``signing_private_key`` will be included, i.e.
284-
a self-signed certificate is generated.
294+
A **public key**, which is used as the public key the certificate is issued for,
295+
but only if ``private_key`` is **not** specified.
296+
297+
If this is unset, checks ``csr`` to derive it.
298+
299+
Ignored when creating self-signed certificates (missing ``signing_cert``).
285300
286301
csr
287-
A certificate signing request to use as a base for generating the certificate.
288-
The following information will be respected, depending on configuration:
289-
* public key
290-
* extensions, if not otherwise specified (arguments, signing_policy)
302+
A **certificate signing request** to use as a base for generating the certificate:
303+
304+
- Extensions not otherwise specified (arguments, signing_policy) are copied.
305+
- If ``private_key`` and ``public_key`` are both unspecified, copies the embedded
306+
public key into the certificate. This step is skipped when creating self-signed
307+
certificates (missing ``signing_cert``).
291308
292309
signing_cert
293310
The CA certificate to be used for signing the issued certificate.
294311
312+
Leave empty to create a self-signed certificate.
313+
295314
signing_private_key
296-
The private key corresponding to the public key in ``signing_cert``. Required.
315+
The private key to be used for signing the new certificate. Required.
316+
317+
Usually, this is the private key corresponding to the public key in ``signing_cert``.
318+
When creating self-signed certificates (missing ``signing_cert``), derives
319+
the new certificate's embedded public key from this private key.
297320
298321
signing_private_key_passphrase
299322
If ``signing_private_key`` is encrypted, the passphrase to decrypt it.
@@ -385,10 +408,9 @@ def create_certificate(
385408
386409
.. code-block:: yaml
387410
388-
# mind this being a list, not a dict
389411
- subjectAltName:
390-
- email:me@example.com
391-
- DNS:example.com
412+
- email:me@example.com # list items can be strings
413+
- dns: example.com # or single-key dicts
392414
393415
issuerAltName
394416
The syntax is the same as for ``subjectAltName``, except that the additional
@@ -846,7 +868,7 @@ def create_crl(
846868
The hashing algorithm to use for the signature. Valid values are:
847869
sha1, sha224, sha256, sha384, sha512, sha512_224, sha512_256, sha3_224,
848870
sha3_256, sha3_384, sha3_512. Defaults to ``sha256``.
849-
This will be ignored for ``ed25519`` and ``ed448`` key types.
871+
Ignored for ``ed25519`` and ``ed448`` key types.
850872
851873
encoding
852874
Specify the encoding of the resulting certificate revocation list.
@@ -1059,7 +1081,7 @@ def create_csr(
10591081
The hashing algorithm to use for the signature. Valid values are:
10601082
sha1, sha224, sha256, sha384, sha512, sha512_224, sha512_256, sha3_224,
10611083
sha3_256, sha3_384, sha3_512. Defaults to ``sha256``.
1062-
This will be ignored for ``ed25519`` and ``ed448`` key types.
1084+
Ignored for ``ed25519`` and ``ed448`` key types.
10631085
10641086
encoding
10651087
Specify the encoding of the resulting certificate signing request.

salt/states/x509_v2.py

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def certificate_managed(
249249
Ensure an X.509 certificate is present as specified.
250250
251251
This function accepts the same arguments as :py:func:`x509.create_certificate <salt.modules.x509_v2.create_certificate>`,
252-
as well as most ones for `:py:func:`file.managed <salt.states.file.managed>`.
252+
as well as most ones for :py:func:`file.managed <salt.states.file.managed>`.
253253
254254
name
255255
The path the certificate should be present at.
@@ -295,37 +295,49 @@ def certificate_managed(
295295
The hashing algorithm to use for the signature. Valid values are:
296296
sha1, sha224, sha256, sha384, sha512, sha512_224, sha512_256, sha3_224,
297297
sha3_256, sha3_384, sha3_512. Defaults to ``sha256``.
298-
This will be ignored for ``ed25519`` and ``ed448`` key types.
298+
Ignored for ``ed25519`` and ``ed448`` key types.
299+
300+
signing_cert
301+
The CA certificate to be used for signing the issued certificate.
302+
303+
Leave empty to create a self-signed certificate.
299304
300305
signing_private_key
301-
The private key corresponding to the public key in ``signing_cert``. Required.
306+
The private key to be used for signing the new certificate. Required.
307+
308+
Usually, this is the private key corresponding to the public key in ``signing_cert``.
309+
When creating self-signed certificates (missing ``signing_cert``), derives
310+
the new certificate's embedded public key from this private key.
302311
303312
signing_private_key_passphrase
304313
If ``signing_private_key`` is encrypted, the passphrase to decrypt it.
305314
306-
signing_cert
307-
The CA certificate to be used for signing the issued certificate.
315+
private_key
316+
A **private key**, which is used to derive the public key the certificate
317+
is issued for. If this is unset, checks ``public_key`` or ``csr`` to derive it.
308318
309-
public_key
310-
The public key the certificate should be issued for. Other ways of passing
311-
the required information are ``private_key`` and ``csr``. If neither are set,
312-
the public key of the ``signing_private_key`` will be included, i.e.
313-
a self-signed certificate is generated.
319+
Ignored when creating self-signed certificates (missing ``signing_cert``).
314320
315-
private_key
316-
The private key corresponding to the public key the certificate should
317-
be issued for. This is one way of specifying the public key that will
318-
be included in the certificate, the other ones being ``public_key`` and ``csr``.
321+
.. hint::
322+
When ``encoding`` is ``pkcs12``, this private key is embedded into
323+
the resulting container.
319324
320325
private_key_passphrase
321326
If ``private_key`` is specified and encrypted, the passphrase to decrypt it.
322327
328+
public_key
329+
A **public key**, which is used as the public key the certificate is issued for,
330+
but only if ``private_key`` is **not** specified. If this is unset, checks ``csr`` to derive it.
331+
332+
Ignored when creating self-signed certificates (missing ``signing_cert``).
333+
323334
csr
324-
A certificate signing request to use as a base for generating the certificate.
325-
The following information will be respected, depending on configuration:
335+
A **certificate signing request** to use as a base for generating the certificate:
326336
327-
* public key
328-
* extensions, if not otherwise specified (arguments, signing_policy)
337+
- Extensions not otherwise specified (arguments, signing_policy) are copied.
338+
- If ``private_key`` and ``public_key`` are both unspecified, copies the embedded
339+
public key into the certificate. This step is skipped when creating self-signed
340+
certificates (missing ``signing_cert``).
329341
330342
subject
331343
The subject's distinguished name embedded in the certificate. This is one way of
@@ -740,7 +752,7 @@ def crl_managed(
740752
The hashing algorithm to use for the signature. Valid values are:
741753
sha1, sha224, sha256, sha384, sha512, sha512_224, sha512_256, sha3_224,
742754
sha3_256, sha3_384, sha3_512. Defaults to ``sha256``.
743-
This will be ignored for ``ed25519`` and ``ed448`` key types.
755+
Ignored for ``ed25519`` and ``ed448`` key types.
744756
745757
encoding
746758
Specify the encoding of the resulting certificate revocation list.
@@ -1045,7 +1057,7 @@ def csr_managed(
10451057
The hashing algorithm to use for the signature. Valid values are:
10461058
sha1, sha224, sha256, sha384, sha512, sha512_224, sha512_256, sha3_224,
10471059
sha3_256, sha3_384, sha3_512. Defaults to ``sha256``.
1048-
This will be ignored for ``ed25519`` and ``ed448`` key types.
1060+
Ignored for ``ed25519`` and ``ed448`` key types.
10491061
10501062
encoding
10511063
Specify the encoding of the resulting certificate revocation list.

0 commit comments

Comments
 (0)