.txt file. The example highlights the flexibility and increased security of keys stored on the CryptoHub, allowing Ansible to perform signing and verification operations instead of relying on password-based authentication.
Ansible Playbooks
Ansible uses Playbooks, which are YAML-formatted files, to carry out automated tasks on a set of managed hosts. Within the Playbook file, you can use the Futurex PKCS #11 library to execute various functions by using the CryptoHub, including safeguarding, using SSH private keys, and signing data. For more information on Ansible Playbooks, see the Ansible documentation.Inventory file
An inventory file in Ansible defines the hosts that Ansible will manage. It can list IP addresses, hostnames, and groupings of machines, allowing you to organize and target them in playbooks. The file can be written in INI or YAML format.Example (INI format):Ini
local, is targeted for local execution, common in test setups.
The following examples demonstrate using Playbook:
Testing Ansible integration with CryptoHub
Prerequisites
Perform the following two tasks to create a key pair:Set Futurex environment variables
Perform the following steps to set Futurex PKCS #11 environment variables: In a terminal, run the following commands to set the required FXPKCS11 environment variables:Shell
Be sure to modify the file path to match the location where the
libfxpkcs11.so is on your system.Generate a key pair
Perform the following steps by using the pkcs11-tool available from the OpenSC suite ( github.com/OpenSC/OpenSC) to generate keys. On both DEB-based and RPM-based distributions, the package is calledopensc.
In a terminal, run the following command to create a new RSA key pair on the CryptoHub by usingpkcs11-tool:
Text
<CRYPTO-OPR-PASS> tag in the fxpkcs11.cfg file.
If successful, the command output lists the keys that pkcs11-tool created on the CryptoHub.
For both SSH examples: Adding public key to SSH authorized keys
Before proceeding with the SSH example, the public key foransible_rsa must be added to /home/<target user>/.ssh/authorized_keys on the target host. When the client initiates a connection, it queries the CryptoHub for its public keys, which are then sent to the server. The server checks its authorized_keys file to see if any of the public keys match. If a match is found, the server issues a challenge that the client must sign. The client passes this challenge to CryptoHub, which signs it using the corresponding private key. Once the server verifies the signature, the client is allowed to connect, eliminating the need for passwords entirely.
Perform the following steps to get the public key from CryptoHub, put it in a format that OpenSSH understands, and add it to the authorized_keys file:
1
Get the pulic key from the
ansible_rsa key pair and output the information to a .der file:Shell
2
Convert the public key file from
.der to .pem:Shell
3
Re-encode the
.pem file into PKCS#8 so that OpenSSH can read the file:Shell
4
Put the information in the
.pub file in authorized_keys.
If the SSH server is remote, first move the .pub file to the target destination before running this command:Shell
Use Futurex PKCS #11 with Ansible: Local SSH example
Perform the following steps to use Futurex PKCS #11 with Ansible for testing Ansible SSH on a local machine:1
Create a working directory for a new Ansible project and change into it:
Shell
2
Create an inventory file.Enter the following information for local SSH testing:
Shell
Ini
3
Create a playbook file
local_ssh_playbook.yml:Shell
4
The playbook file will test Ansible’s SSH connection using the private key created on the CryptoHub in the previous section (ansible_rsa).Enter the following information for local SSH testing with the playbook
YAML
5
Run the following command to execute the playbook while referencing the private key stored on the HSM during the SSH connection step.
Text
6
When prompted for the password of the user you are connecting to the machine with through SSH, enter it to complete the process.You can verify the successful pulling of the private key within the FXPKCS11 log file.
If successful, you see a response similar to the following:The remote command output should match the hostname of your local machine.
None
Use Futurex PKCS #11 with Ansible: Remote SSH example
1
In the same directory as the example before, create a new inventory file.Enter the following information for remote SSH testing:
Shell
Ini
2
Create a playbook file
remote_ssh_playbook.yml:Shell
3
The playbook file will test Ansible’s SSH connection using the private key created on the CryptoHub in the previous section (ansible_rsa).Enter the following information for local SSH testing with the playbook
YAML
4
Run the following command to execute the playbook while referencing the private key stored on the HSM during the SSH connection step.
Text
5
If successful, you see a response similar to the following:The remote command output should match the hostname of your target machine.
None
Use Futurex PKCS #11 with Ansible: Signing data example
Perform the following steps to use Futurex PKCS #11 with Ansible: Signing data example:1
Create a working directory for a new Ansible project.
Text
2
Create an inventory file.The following example inventory file uses localhost:
Text
Text
3
Create a The following is an example Ansible Playbook file for signing data by using the private key created on the CryptoHub (
sign_playbook.yml file.Text
ansible_rsa).YAML
- Replace pkcs11_module with the location of the Futurex PKCS #11 library on your system.
4
Run the following command to execute the playbook, while referencing the private key stored on the CryptoHub to perform the signing operation.When prompted, enter the identity password configured inside the
Text
<CRYPTO-OPR-PASS> tag in the fxpkcs11.cfg file.5
If successful, you see a response similar to the following:
None

