New in version 3008.0.
cryptography
Note
Certificate operations require at least cryptography release 40
Certificate operations with force-command and source-address
(or any critical option/extension with a value) should only be relied
upon in releases >= 41.0.2 (https://github.com/pyca/cryptography/issues/9207)
Operations with encrypted private keys require the
bcrypt module, which is installable as cryptography[ssh] as well.
To be able to remotely sign certificates, it is required to configure the Salt master to allow Peer Communication:
# /etc/salt/master.d/peer.conf
peer:
.*:
- ssh_pki.sign_remote_certificate
In order for the Compound Matcher to work with restricting signing
policies to a subset of minions, in addition calls to match.compound
by the minion acting as the CA must be permitted:
# /etc/salt/master.d/peer.conf
peer:
.*:
- ssh_pki.sign_remote_certificate
ca_server:
- match.compound
In addition, the minion representing the CA needs to have at least one signing policy configured, remote calls not referencing one are always rejected.
The parameters specified in this signing policy override any
parameters passed from the minion requesting the certificate. It can be
configured in the CA minion's pillar, which takes precedence, or any
location config.get looks up in.
Signing policies are defined under ssh_signing_policies.
In addition to forcing some arguments to a specific value, signing policies can also specify default and allowed values.
A list of critical option names that can be requested to be set under
this policy. Defaults to all (["*"]).
A list of extension names that can be requested to be set under
this policy. Defaults to all (["*"]).
A list of principals that can be requested to be set under
this policy. This is an alias for valid_principals since
requesting less permissions is always possible.
Defines default critical options that can be overridden by the requester.
Defines default extensions that can be overridden by the requester.
Defines default principals that can be overridden by the requester.
Defaults to allowed_valid_principals
Values set here are forced as usual, but per critical option.
Values set here are forced as usual, but per extension.
The maximum TTL that can be requested under this policy.
The default TTL that can be overridden by the requester.
Defaults to max_ttl.
You can restrict which minions can request a certificate under a configured
signing policy by specifying a matcher in minions. This can be a glob
or compound matcher (for the latter, see the notes above).
ssh_signing_policies:
www_host:
- minions: 'www*'
- signing_private_key: /etc/pki/ssh/ca.key
- ttl: 30d
- copypath: /etc/pki/ssh/issued_certs/
Create an OpenSSH certificate and return an encoded version of it.
Note
All parameters that take a public key or private key can be specified either as a string or a path to a local file encoded for OpenSSH.
CLI Example:
salt '*' ssh_pki.create_certificate private_key=/root/.ssh/id_rsa signing_private_key='/etc/pki/ssh/myca.key'
Request a remotely signed certificate from another minion acting as
a CA server. For this to work, a signing_policy must be specified,
and that same policy must be configured on the ca_server. See Signing policies
for details. Also, the Salt master must permit peers to call the
sign_remote_certificate function, see Peer communication.
The name of a configured signing policy. Parameters specified in there are hardcoded and cannot be overridden. This is required for remote signing, otherwise optional. See Signing policies for details.
Create a copy of the issued certificate in this directory.
The file will be named <serial_number>.crt.
Instead of returning the certificate, write it to this file path.
If path is specified and the file exists, do not overwrite it.
Defaults to false.
Return the encoded raw bytes instead of a string. Defaults to false.
The certificate type to generate. Either user or host.
Required if not specified in the signing policy.
The private key corresponding to the public key the certificate should
be issued for. Either this or public_key is required.
If private_key is specified and encrypted, the passphrase to decrypt it.
The public key the certificate should be issued for. Either this or
private_key is required.
The private key of the CA that should be used to sign the certificate. Required.
If signing_private_key is encrypted, the passphrase to decrypt it.
A serial number to be embedded in the certificate. If unspecified, will autogenerate one. This should be an integer, either in decimal or hexadecimal notation.
Set a specific date the certificate should not be valid before.
The format should follow %Y-%m-%d %H:%M:%S and will be interpreted as GMT/UTC.
Defaults to the time of issuance.
Set a specific date the certificate should not be valid after.
The format should follow %Y-%m-%d %H:%M:%S and will be interpreted as GMT/UTC.
If unspecified, defaults to the current time plus ttl.
If not_after is unspecified, a time string (like 30d or 12h)
or the number of seconds from the time of issuance the certificate
should be valid for. Defaults to 30d for host certificates
and 24h for client certificates.
A mapping of critical option name to option value to set on the certificate.
If an option does not take a value, specify it as true.
Example:
salt-call ssh_pki.create_certificate [...] critical_options='{"force-command": "/usr/bin/id", "verify-required": true}'
A mapping of extension name to extension value to set on the certificate.
If an extension does not take a value, specify it as true.
Example:
salt-call ssh_pki.create_certificate [...] extensions='{"custom-option@my.org": "foobar", "permit-pty": true}'
A list of valid principals.
Allow any principals. Defaults to false.
Specify a string-valued key ID for the signed public key. When the certificate is used for authentication, this value will be logged in plaintext.
This function is an alias of create_certificate.
Create an OpenSSH certificate and return an encoded version of it.
Note
All parameters that take a public key or private key can be specified either as a string or a path to a local file encoded for OpenSSH.
CLI Example:
salt '*' ssh_pki.create_certificate private_key=/root/.ssh/id_rsa signing_private_key='/etc/pki/ssh/myca.key'
- ca_server
Request a remotely signed certificate from another minion acting as a CA server. For this to work, a
signing_policymust be specified, and that same policy must be configured on the ca_server. See Signing policies for details. Also, the Salt master must permit peers to call thesign_remote_certificatefunction, see Peer communication.- signing_policy
The name of a configured signing policy. Parameters specified in there are hardcoded and cannot be overridden. This is required for remote signing, otherwise optional. See Signing policies for details.
- copypath
Create a copy of the issued certificate in this directory. The file will be named
<serial_number>.crt.- path
Instead of returning the certificate, write it to this file path.
- overwrite
If
pathis specified and the file exists, do not overwrite it. Defaults to false.- raw
Return the encoded raw bytes instead of a string. Defaults to false.
- cert_type
The certificate type to generate. Either
userorhost. Required if not specified in the signing policy.- private_key
The private key corresponding to the public key the certificate should be issued for. Either this or
public_keyis required.- private_key_passphrase
If
private_keyis specified and encrypted, the passphrase to decrypt it.- public_key
The public key the certificate should be issued for. Either this or
private_keyis required.- signing_private_key
The private key of the CA that should be used to sign the certificate. Required.
- signing_private_key_passphrase
If
signing_private_keyis encrypted, the passphrase to decrypt it.- serial_number
A serial number to be embedded in the certificate. If unspecified, will autogenerate one. This should be an integer, either in decimal or hexadecimal notation.
- not_before
Set a specific date the certificate should not be valid before. The format should follow
%Y-%m-%d %H:%M:%Sand will be interpreted as GMT/UTC. Defaults to the time of issuance.- not_after
Set a specific date the certificate should not be valid after. The format should follow
%Y-%m-%d %H:%M:%Sand will be interpreted as GMT/UTC. If unspecified, defaults to the current time plusttl.- ttl
If
not_afteris unspecified, a time string (like30dor12h) or the number of seconds from the time of issuance the certificate should be valid for. Defaults to30dfor host certificates and24hfor client certificates.- critical_options
A mapping of critical option name to option value to set on the certificate. If an option does not take a value, specify it as
true.Example:
salt-call ssh_pki.create_certificate [...] critical_options='{"force-command": "/usr/bin/id", "verify-required": true}'- extensions
A mapping of extension name to extension value to set on the certificate. If an extension does not take a value, specify it as
true.Example:
salt-call ssh_pki.create_certificate [...] extensions='{"custom-option@my.org": "foobar", "permit-pty": true}'- valid_principals
A list of valid principals.
- all_principals
Allow any principals. Defaults to false.
- key_id
Specify a string-valued key ID for the signed public key. When the certificate is used for authentication, this value will be logged in plaintext.
Create a private key.
CLI Example:
salt '*' ssh_pki.create_private_key algo=ec keysize=384
The digital signature scheme the private key should be based on.
Available: rsa, ec, ed25519. Defaults to rsa.
For rsa, specifies the bitlength of the private key (2048, 3072, 4096).
For ec, specifies the NIST curve to use (256, 384, 521).
Irrelevant for ed25519.
Defaults to 3072 for RSA and 256 for EC.
If this is specified, the private key will be encrypted using this passphrase. The encryption algorithm cannot be selected, it will be determined automatically as the best available one.
Instead of returning the private key, write it to this file path.
The file will be written with 0600 permissions if it does not exist.
If path is specified, write the corresponding pubkey to the same path
as the private key with this suffix. Set this to false to skip
writing the public key. Defaults to .pub.
If path is specified and the file exists, overwrite it.
Defaults to false.
Return the encoded raw bytes instead of a string. Defaults to false.
Create an encoded representation of a private key.
CLI Example:
salt '*' ssh_ppki.encode_private_key /root/.ssh/id_rsa passphrase=hunter1
The private key to encode.
The passphrase that protects the private key. Leave unspecified if there is none currently.
If this is specified, the private key will be encrypted using this passphrase. The encryption algorithm cannot be selected, it will be determined automatically as the best available one.
Return the encoded raw bytes instead of a string. Defaults to false.
Determine whether a certificate will expire or has expired already. Returns a boolean only.
CLI Example:
salt '*' ssh_pki.expires /root/.ssh/id_rsa.crt days=7
The certificate to check.
If specified, determine expiration x seconds in the future.
Can also be specified as a time string like 30d or 1.5h.
Defaults to 0, which checks for the current time.
Return information about the key size of a private key (RSA/EC).
CLI Example:
salt '*' ssh_pki.get_private_key_size /root/.ssh/id_rsa
The private key to check.
If private_key is encrypted, the passphrase to decrypt it.
Returns a public key derived from some reference. The reference should be a public key, certificate or private key.
CLI Example:
salt '*' ssh_pki.get_public_key /root/.ssh/id_rsa
A reference to the structure to look the public key up for.
If key is encrypted, the passphrase to decrypt it.
Returns the specified named signing policy.
CLI Example:
salt '*' ssh_pki.get_signing_policy www
The name of the signing policy to return.
If this is set, the CA server will be queried for the signing policy instead of looking it up locally.
Returns a dict containing details of a certificate.
CLI Example:
salt '*' ssh_pki.read_certificate /root/.ssh/id_rsa.crt
The certificate to read.
Request a certificate to be remotely signed according to a signing policy. This is mostly for internal use and does not make much sense on the CLI.
CLI Example:
salt '*' ssh_pki.sign_remote_certificate www kwargs="{'public_key': '/etc/pki/ssh/www.key'}"
The name of the signing policy to use. Required.
A dict containing all the arguments to be passed into the
ssh_pki.create_certificate function.
Only return the named signing policy. Defaults to false.
Verify that a private key belongs to the specified public key.
CLI Example:
salt '*' ssh_pki.verify_private_key /root/.ssh/id_rsa /root/.ssh/id_rsa.crt
The private key to check.
The certificate (or any reference that can be passed
to get_public_key) to retrieve the public key from.
If private_key is encrypted, the passphrase to decrypt it.
Verify that a signature on a certificate was made by the private key corresponding to the public key associated with the specified certificate.
CLI Example:
salt '*' ssh_pki.verify_signature /root/.ssh/id_rsa.crt /etc/pki/ssh/myca.pub
The certificate to check the signature on.
Any reference that can be passed to get_public_key to retrieve
the public key of the signing entity from.
If signing_pub_key is encrypted, the passphrase to decrypt it.