-
Notifications
You must be signed in to change notification settings - Fork 102
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
Changes from 8 commits
a30934a
756230c
1788c4e
de7a10d
58b512b
db41696
1661c68
0fde60f
b8dcd68
d671674
467f1fd
2de45fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# === Copyright | ||
# | ||
# Copyright 2018, Kumina B.V., Tim Stoop | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
|
||
# == Class: os_hardening::grub | ||
# | ||
# Hardens the grub config | ||
# | ||
class os_hardening::grub ( | ||
Boolean $enable = false, | ||
String $user = 'root', | ||
String $password_hash = false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. default to |
||
Boolean $boot_without_password = true, | ||
) { | ||
|
||
case $::operatingsystem { | ||
debian, ubuntu: { | ||
$grub_cfg = '/boot/grub/grub.cfg' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it a better way to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't bother:
This is more consistent, imho. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :) |
||
$grub_cmd = "/usr/sbin/grub-mkconfig" | ||
} | ||
redhat, fedora: { | ||
$grub_cfg = '/boot/grub2/grub.cfg' | ||
$grub_cmd = "/usr/sbin/grub2-mkconfig" | ||
} | ||
} | ||
|
||
if $enable { | ||
file { '/etc/grub.d/01_hardening': | ||
content => template('os_hardening/grub_hardening.erb'), | ||
notify => Exec['Grub configuration recreate for os_hardening::grub'], | ||
} | ||
|
||
file { $grub_cfg: | ||
owner => 'root', | ||
group => 'root', | ||
mode => '0600', | ||
} | ||
|
||
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': | ||
command => "/bin/sed -i -e 's/^CLASS=\"\\(.*\\)\"/CLASS=\"\\1 --unrestricted\"/' /etc/grub.d/10_linux;", | ||
unless => '/bin/grep -e "^CLASS=" /etc/grub.d/10_linux | /bin/grep -q -- "--unrestricted"', | ||
notify => Exec['Grub configuration recreate for os_hardening::grub'], | ||
} | ||
} else { | ||
exec { 'Remove addition for keeping system bootable without credentials': | ||
command => "/bin/sed -i -e 's/^CLASS=\"\\(.*\\) --unrestricted\\(.*\\)\"/CLASS=\"\\1\\2\"/' /etc/grub.d/10_linux;", | ||
onlyif => '/bin/grep -e "^CLASS=" /etc/grub.d/10_linux | /bin/grep -q -- "--unrestricted"', | ||
notify => Exec['Grub configuration recreate for os_hardening::grub'], | ||
} | ||
} | ||
} else { | ||
file { '/etc/grub.d/01_hardening': | ||
ensure => absent, | ||
notify => Exec['Grub configuration recreate for os_hardening::grub'], | ||
} | ||
} | ||
|
||
exec { 'Grub configuration recreate for os_hardening::grub': | ||
command => "${grub_cmd} -o ${grub_cfg}", | ||
refreshonly => true, | ||
} | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,11 @@ | |
Boolean $enable_stack_protection = true, | ||
Boolean $enable_rpfilter = true, | ||
Boolean $enable_log_martians = true, | ||
|
||
Boolean $enable_grub_hardening = false, | ||
String $grub_user = 'root', | ||
String $grub_password_hash = false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. default to |
||
Boolean $boot_without_password = true, | ||
) { | ||
|
||
# Prepare | ||
|
@@ -180,4 +185,11 @@ | |
} | ||
} | ||
|
||
class { 'os_hardening::grub': | ||
enable => $enable_grub_hardening, | ||
user => $grub_user, | ||
password_hash => $grub_password_hash, | ||
boot_without_password => $boot_without_password, | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
echo set superusers="<%= @user %>" | ||
echo password_pbkdf2 <%= @user %> <%= @password_hash %> | ||
|
There was a problem hiding this comment.
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
, notBoolean
), otherwise I get an error here ...There was a problem hiding this comment.
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!