community.crypto.openssl_csr_pipe (2.18.0) — module

Generate OpenSSL Certificate Signing Request (CSR)

| "added in version" 1.3.0 of community.crypto"

Authors: Yanis Guenane (@Spredzy), Felix Fontein (@felixfontein)

Install collection

Install with ansible-galaxy collection install community.crypto:==2.18.0


Add to requirements.yml

  collections:
    - name: community.crypto
      version: 2.18.0

Description

Please note that the module regenerates an existing CSR if it does not match the module's options, or if it seems to be corrupt.

This module allows one to (re)generate OpenSSL certificate signing requests.

This module supports the subjectAltName, keyUsage, extendedKeyUsage, basicConstraints and OCSP Must Staple extensions.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Generate an OpenSSL Certificate Signing Request
  community.crypto.openssl_csr_pipe:
    privatekey_path: /etc/ssl/private/ansible.com.pem
    common_name: www.ansible.com
  register: result
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Print CSR
  ansible.builtin.debug:
    var: result.csr
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Generate an OpenSSL Certificate Signing Request with an inline CSR
  community.crypto.openssl_csr:
    content: "{{ lookup('ansible.builtin.file', '/etc/ssl/csr/www.ansible.com.csr') }}"
    privatekey_content: "{{ private_key_content }}"
    common_name: www.ansible.com
  register: result
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Store CSR
  ansible.builtin.copy:
    dest: /etc/ssl/csr/www.ansible.com.csr
    content: "{{ result.csr }}"
  when: result is changed

Inputs

    
digest:
    default: sha256
    description:
    - The digest used when signing the certificate signing request with the private key.
    type: str

content:
    description:
    - The existing CSR.
    type: str

subject:
    description:
    - Key/value pairs that will be present in the subject name field of the certificate
      signing request.
    - If you need to specify more than one value with the same key, use a list as value.
    - If the order of the components is important, use O(subject_ordered).
    - Mutually exclusive with O(subject_ordered).
    type: dict

version:
    choices:
    - 1
    default: 1
    description:
    - The version of the certificate signing request.
    - The only allowed value according to L(RFC 2986,https://tools.ietf.org/html/rfc2986#section-4.1)
      is 1.
    - This option no longer accepts unsupported values since community.crypto 2.0.0.
    type: int

key_usage:
    aliases:
    - keyUsage
    description:
    - This defines the purpose (for example encipherment, signature, certificate signing)
      of the key contained in the certificate.
    elements: str
    type: list

common_name:
    aliases:
    - CN
    - commonName
    description:
    - The commonName field of the certificate signing request subject.
    type: str

country_name:
    aliases:
    - C
    - countryName
    description:
    - The countryName field of the certificate signing request subject.
    type: str

email_address:
    aliases:
    - E
    - emailAddress
    description:
    - The emailAddress field of the certificate signing request subject.
    type: str

locality_name:
    aliases:
    - L
    - localityName
    description:
    - The localityName field of the certificate signing request subject.
    type: str

privatekey_path:
    description:
    - The path to the private key to use when signing the certificate signing request.
    - Either O(privatekey_path) or O(privatekey_content) must be specified, but not both.
    type: path

subject_ordered:
    description:
    - A list of dictionaries, where every dictionary must contain one key/value pair.
      This key/value pair will be present in the subject name field of the certificate
      signing request.
    - If you want to specify more than one value with the same key in a row, you can use
      a list as value.
    - Mutually exclusive with O(subject), and any other subject field option, such as
      O(country_name), O(state_or_province_name), O(locality_name), O(organization_name),
      O(organizational_unit_name), O(common_name), or O(email_address).
    elements: dict
    type: list
    version_added: 2.0.0
    version_added_collection: community.crypto

ocsp_must_staple:
    aliases:
    - ocspMustStaple
    default: false
    description:
    - Indicates that the certificate should contain the OCSP Must Staple extension (U(https://tools.ietf.org/html/rfc7633)).
    type: bool

subject_alt_name:
    aliases:
    - subjectAltName
    description:
    - Subject Alternative Name (SAN) extension to attach to the certificate signing request.
    - Values must be prefixed by their options. (These are C(email), C(URI), C(DNS), C(RID),
      C(IP), C(dirName), C(otherName), and the ones specific to your CA).
    - Note that if no SAN is specified, but a common name, the common name will be added
      as a SAN except if O(use_common_name_for_san) is set to V(false).
    - More at U(https://tools.ietf.org/html/rfc5280#section-4.2.1.6).
    elements: str
    type: list

basic_constraints:
    aliases:
    - basicConstraints
    description:
    - Indicates basic constraints, such as if the certificate is a CA.
    elements: str
    type: list

organization_name:
    aliases:
    - O
    - organizationName
    description:
    - The organizationName field of the certificate signing request subject.
    type: str

extended_key_usage:
    aliases:
    - extKeyUsage
    - extendedKeyUsage
    description:
    - Additional restrictions (for example client authentication, server authentication)
      on the allowed purposes for which the public key may be used.
    elements: str
    type: list

key_usage_critical:
    aliases:
    - keyUsage_critical
    default: false
    description:
    - Should the keyUsage extension be considered as critical.
    type: bool

privatekey_content:
    description:
    - The content of the private key to use when signing the certificate signing request.
    - Either O(privatekey_path) or O(privatekey_content) must be specified, but not both.
    type: str

authority_cert_issuer:
    description:
    - Names that will be present in the authority cert issuer field of the certificate
      signing request.
    - Values must be prefixed by their options. (That is, C(email), C(URI), C(DNS), C(RID),
      C(IP), C(dirName), C(otherName), and the ones specific to your CA)
    - 'Example: V(DNS:ca.example.org)'
    - If specified, O(authority_cert_serial_number) must also be specified.
    - Please note that commercial CAs ignore this value, respectively use a value of their
      own choice. Specifying this option is mostly useful for self-signed certificates
      or for own CAs.
    - Note that this is only supported if the C(cryptography) backend is used!
    - The C(AuthorityKeyIdentifier) extension will only be added if at least one of O(authority_key_identifier),
      O(authority_cert_issuer) and O(authority_cert_serial_number) is specified.
    elements: str
    type: list

privatekey_passphrase:
    description:
    - The passphrase for the private key.
    - This is required if the private key is password protected.
    type: str

select_crypto_backend:
    choices:
    - auto
    - cryptography
    default: auto
    description:
    - Determines which crypto backend to use.
    - The default choice is V(auto), which tries to use C(cryptography) if available.
    - If set to V(cryptography), will try to use the L(cryptography,https://cryptography.io/)
      library.
    type: str

state_or_province_name:
    aliases:
    - ST
    - stateOrProvinceName
    description:
    - The stateOrProvinceName field of the certificate signing request subject.
    type: str

subject_key_identifier:
    description:
    - The subject key identifier as a hex string, where two bytes are separated by colons.
    - 'Example: V(00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33)'
    - Please note that commercial CAs ignore this value, respectively use a value of their
      own choice. Specifying this option is mostly useful for self-signed certificates
      or for own CAs.
    - Note that this option can only be used if O(create_subject_key_identifier) is V(false).
    - Note that this is only supported if the C(cryptography) backend is used!
    type: str

crl_distribution_points:
    description:
    - Allows to specify one or multiple CRL distribution points.
    - Only supported by the C(cryptography) backend.
    elements: dict
    suboptions:
      crl_issuer:
        description:
        - Information about the issuer of the CRL.
        elements: str
        type: list
      full_name:
        description:
        - Describes how the CRL can be retrieved.
        - Mutually exclusive with O(crl_distribution_points[].relative_name).
        - 'Example: V(URI:https://ca.example.com/revocations.crl).'
        elements: str
        type: list
      reasons:
        choices:
        - key_compromise
        - ca_compromise
        - affiliation_changed
        - superseded
        - cessation_of_operation
        - certificate_hold
        - privilege_withdrawn
        - aa_compromise
        description:
        - List of reasons that this distribution point can be used for when performing
          revocation checks.
        elements: str
        type: list
      relative_name:
        description:
        - Describes how the CRL can be retrieved relative to the CRL issuer.
        - Mutually exclusive with O(crl_distribution_points[].full_name).
        - 'Example: V(/CN=example.com).'
        - Can only be used when cryptography >= 1.6 is installed.
        elements: str
        type: list
    type: list
    version_added: 1.4.0
    version_added_collection: community.crypto

use_common_name_for_san:
    aliases:
    - useCommonNameForSAN
    default: true
    description:
    - If set to V(true), the module will fill the common name in for O(subject_alt_name)
      with C(DNS:) prefix if no SAN is specified.
    type: bool

authority_key_identifier:
    description:
    - The authority key identifier as a hex string, where two bytes are separated by colons.
    - 'Example: V(00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33)'
    - Please note that commercial CAs ignore this value, respectively use a value of their
      own choice. Specifying this option is mostly useful for self-signed certificates
      or for own CAs.
    - Note that this is only supported if the C(cryptography) backend is used!
    - The C(AuthorityKeyIdentifier) extension will only be added if at least one of O(authority_key_identifier),
      O(authority_cert_issuer) and O(authority_cert_serial_number) is specified.
    type: str

organizational_unit_name:
    aliases:
    - OU
    - organizationalUnitName
    description:
    - The organizationalUnitName field of the certificate signing request subject.
    type: str

name_constraints_critical:
    default: false
    description:
    - Should the Name Constraints extension be considered as critical.
    type: bool

name_constraints_excluded:
    description:
    - For CA certificates, this specifies a list of identifiers which describe subtrees
      of names that this CA is B(not) allowed to issue certificates for.
    - Values must be prefixed by their options. (That is, C(email), C(URI), C(DNS), C(RID),
      C(IP), C(dirName), C(otherName), and the ones specific to your CA).
    elements: str
    type: list

ocsp_must_staple_critical:
    aliases:
    - ocspMustStaple_critical
    default: false
    description:
    - Should the OCSP Must Staple extension be considered as critical.
    - Note that according to the RFC, this extension should not be marked as critical,
      as old clients not knowing about OCSP Must Staple are required to reject such certificates
      (see U(https://tools.ietf.org/html/rfc7633#section-4)).
    type: bool

subject_alt_name_critical:
    aliases:
    - subjectAltName_critical
    default: false
    description:
    - Should the subjectAltName extension be considered as critical.
    type: bool

basic_constraints_critical:
    aliases:
    - basicConstraints_critical
    default: false
    description:
    - Should the basicConstraints extension be considered as critical.
    type: bool

name_constraints_permitted:
    description:
    - For CA certificates, this specifies a list of identifiers which describe subtrees
      of names that this CA is allowed to issue certificates for.
    - Values must be prefixed by their options. (That is, C(email), C(URI), C(DNS), C(RID),
      C(IP), C(dirName), C(otherName), and the ones specific to your CA).
    elements: str
    type: list

extended_key_usage_critical:
    aliases:
    - extKeyUsage_critical
    - extendedKeyUsage_critical
    default: false
    description:
    - Should the extkeyUsage extension be considered as critical.
    type: bool

authority_cert_serial_number:
    description:
    - The authority cert serial number.
    - If specified, O(authority_cert_issuer) must also be specified.
    - Note that this is only supported if the C(cryptography) backend is used!
    - Please note that commercial CAs ignore this value, respectively use a value of their
      own choice. Specifying this option is mostly useful for self-signed certificates
      or for own CAs.
    - The C(AuthorityKeyIdentifier) extension will only be added if at least one of O(authority_key_identifier),
      O(authority_cert_issuer) and O(authority_cert_serial_number) is specified.
    - This option accepts an B(integer). If you want to provide serial numbers as colon-separated
      hex strings, such as C(11:22:33), you need to convert them to an integer with P(community.crypto.parse_serial#filter).
    type: int

create_subject_key_identifier:
    default: false
    description:
    - Create the Subject Key Identifier from the public key.
    - Please note that commercial CAs can ignore the value, respectively use a value of
      their own choice instead. Specifying this option is mostly useful for self-signed
      certificates or for own CAs.
    - Note that this is only supported if the C(cryptography) backend is used!
    type: bool

Outputs

basicConstraints:
  description: Indicates if the certificate belongs to a CA
  elements: str
  returned: changed or success
  sample:
  - CA:TRUE
  - pathLenConstraint:0
  type: list
csr:
  description: The (current or generated) CSR's content.
  returned: changed or success
  type: str
extendedKeyUsage:
  description: Additional restriction on the public key purposes
  elements: str
  returned: changed or success
  sample:
  - clientAuth
  type: list
keyUsage:
  description: Purpose for which the public key may be used
  elements: str
  returned: changed or success
  sample:
  - digitalSignature
  - keyAgreement
  type: list
name_constraints_excluded:
  description: List of excluded subtrees the CA cannot sign certificates for.
  elements: str
  returned: changed or success
  sample:
  - email:.com
  type: list
name_constraints_permitted:
  description: List of permitted subtrees to sign certificates for.
  elements: str
  returned: changed or success
  sample:
  - email:.somedomain.com
  type: list
ocsp_must_staple:
  description: Indicates whether the certificate has the OCSP Must Staple feature
    enabled
  returned: changed or success
  sample: false
  type: bool
privatekey:
  description:
  - Path to the TLS/SSL private key the CSR was generated for
  - Will be V(none) if the private key has been provided in O(privatekey_content).
  returned: changed or success
  sample: /etc/ssl/private/ansible.com.pem
  type: str
subject:
  description: A list of the subject tuples attached to the CSR
  elements: list
  returned: changed or success
  sample:
  - - CN
    - www.ansible.com
  - - O
    - Ansible
  type: list
subjectAltName:
  description: The alternative names this CSR is valid for
  elements: str
  returned: changed or success
  sample:
  - DNS:www.ansible.com
  - DNS:m.ansible.com
  type: list

See also