5.2. Securing the boot menu with password by using the bootloader RHEL system role
You can use the bootloader RHEL system role to set a password to the GRUB2 boot menu in an automated fashion. This way you can efficiently prevent unauthorized users from modifying boot parameters, and to have better control over the system boot.
Prerequisites
- You have prepared the control node and the managed nodes.
- You are logged in to the control node as a user who can run playbooks on the managed nodes.
-
The account you use to connect to the managed nodes has
sudopermissions for these nodes.
Procedure
Store your sensitive variables in an encrypted file:
Create the vault:
$ ansible-vault create ~/vault.yml New Vault password: <vault_password> Confirm New Vault password: <vault_password>After the
ansible-vault createcommand opens an editor, enter the sensitive data in the<key>: <value>format:pwd: <password>- Save the changes, and close the editor. Ansible encrypts the data in the vault.
Create a playbook file, for example,
~/playbook.yml, with the following content:--- - name: Configuration and management of GRUB2 boot loader hosts: managed-node-01.example.com vars_files: - ~/vault.yml tasks: - name: Set the bootloader password ansible.builtin.include_role: name: redhat.rhel_system_roles.bootloader vars: bootloader_password: "{{ pwd }}" bootloader_reboot_ok: trueThe settings specified in the example playbook include the following:
bootloader_password: "{{ pwd }}"- The variable ensures protection of boot parameters with a password.
bootloader_reboot_ok: true- The role detects that a reboot is needed for the changes to take effect and performs a restart of the managed node.
重要Changing the boot loader password is not an idempotent transaction. This means that if you apply the same Ansible playbook again, the result will not be the same, and the state of the managed node will change.
For details about all variables used in the playbook, see the
/usr/share/ansible/roles/rhel-system-roles.bootloader/README.mdfile on the control node.Validate the playbook syntax:
$ ansible-playbook --syntax-check --ask-vault-pass ~/playbook.ymlNote that this command only validates the syntax and does not protect against a wrong but valid configuration.
Run the playbook:
$ ansible-playbook --ask-vault-pass ~/playbook.yml
Verification
On your managed node during the GRUB2 boot menu screen, press the e key for edit.
You will be prompted for a username and a password:
Enter username: root-
The boot loader username is always
rootand you do not need to specify it in your Ansible playbook. Enter password: <password>-
The boot loader password corresponds to the
pwdvariable that you defined in thevault.ymlfile.
You can view or edit configuration of the particular boot loader entry: