Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy GRUB hardening #137

Merged
merged 12 commits into from
Aug 15, 2018
Merged

Deploy GRUB hardening #137

merged 12 commits into from
Aug 15, 2018

Conversation

timstoop
Copy link
Contributor

This patch adds the option to harden GRUB. For this to work, it requires a password created with grub-mkpasswd-pbkdf2 provided to it. Optionally, but enabled by default, this also modifies the Grub config to allow for unattended booting of these servers.

This was created to fulfil CIS DIL Benchmark 1.4.1 and 1.4.2. It was only tested on Debian Stretch, so I'd welcome someone to test on something else as well and let me know what I need to change to make it work on other OSes as well. Also, I'm not sure if I should wrap the exec that enables unattended booting in a case statement to select the operating system.

HardeningFramework-DCO-1.1-Signed-off-by: Tim Stoop <github@timstoop.nl> (github: timstoop)
Now only a password is required when someone wants to change the boot
parameters. Normal boot is allowed without password.

HardeningFramework-DCO-1.1-Signed-off-by: Tim Stoop <github@timstoop.nl> (github: timstoop)
HardeningFramework-DCO-1.1-Signed-off-by: Tim Stoop <github@timstoop.nl> (github: timstoop)
HardeningFramework-DCO-1.1-Signed-off-by: Tim Stoop <github@timstoop.nl> (github: timstoop)
HardeningFramework-DCO-1.1-Signed-off-by: Tim Stoop <github@timstoop.nl> (github: timstoop)
HardeningFramework-DCO-1.1-Signed-off-by: Tim Stoop <github@timstoop.nl> (github: timstoop)
HardeningFramework-DCO-1.1-Signed-off-by: Tim Stoop <github@timstoop.nl> (github: timstoop)
@artem-sidorenko
Copy link
Member

@timstoop great! Thanks!

I have a similar implementation in chef:) I'll review the grub part in the next days

@artem-sidorenko artem-sidorenko self-assigned this Jun 28, 2018

if $boot_without_password {
# This sets up Grub on Debian Stretch so you can still boot the system without a password
exec { 'Keep system bootable without credentials':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should better use file_line to make changes / substitutions in files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's possible to do back references with file_line? As I want to leave all other options there without touching them. The docs do not seem to discuss back references either.

notify => Exec['Grub configuration recreate for os_hardening::grub'],
}

if $boot_without_password {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if you switch from boot_without_password = true to boot_without_password = false? --> undo the change in the file

refreshonly => true,
}

file { '/boot/grub/grub.cfg':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On CentOS / RedHat + OpenSUSE / SLES this file is located here: /boot/grub2/grub.cfg

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the value for $::operatingsystem on OpenSUSE/SLES? So I can fix the case statement correctly :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is the value for $::operatingsystem - OpenSUSE for the free distro, SLES for the commercial one
You could also refer to $::osfamily, here we have Suse for both

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or I default to /boot/grub2/grub.cfg and make debian/ubuntu the exception...

}

exec { 'Grub configuration recreate for os_hardening::grub':
command => '/usr/sbin/update-grub',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no such helper script in CentOS / RedHat or OpenSUSE / SLES you should better use this:
grub-mkconfig -o /boot/grub/grub.cfg (Ubuntu / Debian) or grub2-mkconfig -o /boot/grub2/grub.cfg

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I assume that grub2-mkconfig is in /usr/sbin or is it somewhere else?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/usr/sbin

@@ -180,4 +185,12 @@
}
}

if $enable_grub_hardening {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On switching back enable_grub_hardening -> cleanup changes on grub

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, but I'd slightly worried that this may actually cause problem for people who make these kind of changes with other modules? There's no way to check if the change was done by this module or by something else.

HardeningFramework-DCO-1.1-Signed-off-by: Tim Stoop <github@timstoop.nl> (github: timstoop)
Copy link
Member

@artem-sidorenko artem-sidorenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timstoop grub things look good to me, even the sed expression is the same like I got :)

@mcgege I did not deeply check the puppet part, however it looks good to me on the first view


case $::operatingsystem {
debian, ubuntu: {
$grub_cfg = '/boot/grub/grub.cfg'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it a better way to call update-grub on ubuntu/debian?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't bother:

~$ cat /usr/sbin/update-grub
#!/bin/sh
set -e
exec grub-mkconfig -o /boot/grub/grub.cfg "$@"

This is more consistent, imho.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D I did not check the file itself, but I saw it in all possible man pages :)
Fine for me as is now

HardeningFramework-DCO-1.1-Signed-off-by: Tim Stoop <github@timstoop.nl> (github: timstoop)
README.md Outdated
set to true to enable some grub hardening rules
* `grub_user = 'root'`
the grub username that needs to be provided when changing config on the grub prompt
* `grub_password_hash = false`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value for grub_password_hash must be set to '' (String, not Boolean), otherwise I get an error here ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly hadn't tested it with the default settings... 😊 Fixing!

class os_hardening::grub (
Boolean $enable = false,
String $user = 'root',
String $password_hash = false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default to ''


Boolean $enable_grub_hardening = false,
String $grub_user = 'root',
String $grub_password_hash = false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default to ''

HardeningFramework-DCO-1.1-Signed-off-by: Tim Stoop <github@timstoop.nl> (github: timstoop)
HardeningFramework-DCO-1.1-Signed-off-by: Tim Stoop <github@timstoop.nl> (github: timstoop)
@mcgege
Copy link
Member

mcgege commented Aug 11, 2018

@timstoop Ok, the code compiles now, but ... I have configured it for one of my test systems (Ubuntu 16.04) like this:

class { 'os_hardening':
    allow_change_user     => true,
    enable_grub_hardening => true,
    boot_without_password => false,
    grub_user             => 'root',
    grub_password_hash    => 'grub.pbkdf2.sha512.10000.FD97C47AEE086E73BD6B80ECC7879CA7812AF0E5538DC7242DBA2A7BE329507449C7339E16E68C0DD204BD0BC84000E3EE363FC58D1B7F3F882C60C3B0770446.D863FCAE6EF7BDB40C2D3D0777B17EDF7ABD1B31995124D29E584AA243DEEFC8F26BC4FF1AC78E902ED0483B4B2F7C2CA88D8919E6A2A401A6870D3D65735BF1',
    ignore_users          => ['mutuv'],
    passwdqc_enabled      => false,
    password_max_age      => 99999,
    password_min_age      => 0,
    pe_environment        => true,
    usergroups            => false,
  }

... and after a puppet run the grub.cfg is just the same as before (and of course on reboot there is no password prompt). If I change boot_without_password to true, the menuentry get the --unrestricted flag, but still no password prompt.

Am I missing something?

@timstoop
Copy link
Contributor Author

Can you check if the file /etc/grub.d/01_hardening is created? And if running update-grub solves the issue? That would give me some clues as to what is going wrong. Maybe the grub scripts work a bit different on Ubuntu, I sort of assumed that it would be the same as Debian.

@mcgege
Copy link
Member

mcgege commented Aug 15, 2018

If have tested this now also on CentOS 7.5 and OpenSUSE 15.0, it's the same ... the file /etc/grub.d/01_hardening is correctly created and the new grub.cfg is written (via update-grub), but there's no password prompt.
What should differ in grub.cfg if this feature is active?

HardeningFramework-DCO-1.1-Signed-off-by: Tim Stoop <github@timstoop.nl> (github: timstoop)
@timstoop
Copy link
Contributor Author

I have too many branches locally :(
Please try again with this very small change...
The output of that script should be added to the grub.cfg.

@mcgege
Copy link
Member

mcgege commented Aug 15, 2018

Hah! That did it ... thanks!

@mcgege mcgege merged commit f1bb999 into dev-sec:master Aug 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants