openssh_cert – Generate OpenSSH host or user certificates
openssh_cert – Generate OpenSSH host or user certificates
New in version 2.8.
Synopsis
- Generate and regenerate OpenSSH host or user certificates.
Requirements
The below requirements are needed on the host that executes this module.
- ssh-keygen
Parameters
Parameter | Choices/Defaults | Comments |
---|---|---|
attributes string added in 2.3 |
The attributes the resulting file or directory should have. To get supported flags look at the man page for chattr on the target system. This string should contain the attributes in the same order as the one displayed by lsattr. The
| |
force boolean |
|
Should the certificate be regenerated even if it already exists and is valid. |
group string |
Name of the group that should own the file/directory, as would be fed to chown. | |
identifier string |
Specify the key identity when signing a public key. The identifier that is logged by the server when the certificate is used for authentication. | |
mode string |
The permissions the resulting file or directory should have. For those used to /usr/bin/chmod remember that modes are actually octal numbers. You must either add a leading zero so that Ansible's YAML parser knows it is an octal number (like Giving Ansible a number without following one of these rules will end up with a decimal number which will have unexpected results. As of Ansible 1.8, the mode may be specified as a symbolic mode (for example, | |
options list |
Specify certificate options when signing a key. The option that are valid for user certificates are:
At present, no options are valid for host keys. | |
owner string |
Name of the user that should own the file/directory, as would be fed to chown. | |
path path / required |
Path of the file containing the certificate. | |
principals list |
Certificates may be limited to be valid for a set of principal (user/host) names. By default, generated certificates are valid for all users or hosts. | |
public_key path / required |
The path to the public key that will be signed with the signing key in order to generate the certificate. | |
selevel string |
Default: "s0" |
The level part of the SELinux file context. This is the MLS/MCS attribute, sometimes known as the When set to |
serial_number integer |
Specify the certificate serial number. The serial number is logged by the server when the certificate is used for authentication. The certificate serial number may be used in a KeyRevocationList. The serial number may be omitted for checks, but must be specified again for a new certificate. Note: The default value set by ssh-keygen is 0. | |
serole string |
The role part of the SELinux file context. When set to | |
setype string |
The type part of the SELinux file context. When set to | |
seuser string |
The user part of the SELinux file context. By default it uses the When set to | |
signing_key path / required |
The path to the private openssh key that is used for signing the public key in order to generate the certificate. | |
state string |
|
Whether the host or user certificate should exist or not, taking action if the state is different from what is stated. |
type string / required |
|
Whether the module should generate a host or a user certificate. |
unsafe_writes boolean added in 2.2 |
|
Influence when to use atomic operation to prevent data corruption or inconsistent reads from the target file. By default this module uses atomic operations to prevent data corruption or inconsistent reads from the target files, but sometimes systems are configured or just broken in ways that prevent this. One example is docker mounted files, which cannot be updated atomically from inside the container and can only be written in an unsafe manner. This option allows Ansible to fall back to unsafe methods of updating files when atomic operations fail (however, it doesn't force Ansible to perform unsafe writes). IMPORTANT! Unsafe writes are subject to race conditions and can lead to data corruption. |
valid_at string |
Check if the certificate is valid at a certain point in time. If it is not the certificate will be regenerated. Time will always be interpreted as UTC. Mainly to be used with relative timespec for valid_from and / or valid_to. Note that if using relative time this module is NOT idempotent. | |
valid_from string / required |
The point in time the certificate is valid from. Time can be specified either as relative time or as absolute timestamp. Time will always be interpreted as UTC. Valid formats are: | |
valid_to string / required |
The point in time the certificate is valid to. Time can be specified either as relative time or as absolute timestamp. Time will always be interpreted as UTC. Valid formats are: |
Examples
# Generate an OpenSSH user certificate that is valid forever and for all users
- openssh_cert:
type: user
signing_key: /path/to/private_key
public_key: /path/to/public_key.pub
path: /path/to/certificate
valid_from: always
valid_to: forever
# Generate an OpenSSH host certificate that is valid for 32 weeks from now and will be regenerated
# if it is valid for less than 2 weeks from the time the module is being run
- openssh_cert:
type: host
signing_key: /path/to/private_key
public_key: /path/to/public_key.pub
path: /path/to/certificate
valid_from: +0s
valid_to: +32w
valid_at: +2w
# Generate an OpenSSH host certificate that is valid forever and only for example.com and examplehost
- openssh_cert:
type: host
signing_key: /path/to/private_key
public_key: /path/to/public_key.pub
path: /path/to/certificate
valid_from: always
valid_to: forever
principals:
- example.com
- examplehost
# Generate an OpenSSH host Certificate that is valid from 21.1.2001 to 21.1.2019
- openssh_cert:
type: host
signing_key: /path/to/private_key
public_key: /path/to/public_key.pub
path: /path/to/certificate
valid_from: "2001-01-21"
valid_to: "2019-01-21"
# Generate an OpenSSH user Certificate with clear and force-command option:
- openssh_cert:
type: user
signing_key: /path/to/private_key
public_key: /path/to/public_key.pub
path: /path/to/certificate
valid_from: always
valid_to: forever
options:
- "clear"
- "force-command=/tmp/bla/foo"
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key | Returned | Description |
---|---|---|
filename string |
changed or success |
path to the certificate
Sample: /tmp/certificate-cert.pub |
info list |
change or success |
Information about the certificate. Output of
|
type string |
changed or success |
type of the certificate (host or user)
Sample: host |
Status
- This module is not guaranteed to have a backwards compatible interface. [preview]
- This module is maintained by the Ansible Community. [community]
Authors
- David Kainz (@lolcube)
© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.8/modules/openssh_cert_module.html