-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a30934a
Harden the grub prompt.
timstoop 756230c
Add code to allow the system to boot without password.
timstoop 1788c4e
Add docs and ability to set the variable.
timstoop de7a10d
Merge branch 'upstream' into cis-dil-bechmark-1
timstoop 58b512b
Fix the unless condition.
timstoop db41696
Fix template (was using a different branch to test...).
timstoop 1661c68
More fixes to template.
timstoop 0fde60f
Work on the comments that were given.
timstoop b8dcd68
Make everything not-Debian the default.
timstoop d671674
Fix default case.
timstoop 467f1fd
Merge branch 'upstream' into cis-dil-bechmark-1
timstoop 2de45fb
Set mode of the new snippet.
timstoop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# === 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 = '', | ||
Boolean $boot_without_password = true, | ||
) { | ||
|
||
case $::operatingsystem { | ||
debian, ubuntu: { | ||
$grub_cfg = '/boot/grub/grub.cfg' | ||
$grub_cmd = "/usr/sbin/grub-mkconfig" | ||
} | ||
default: { | ||
$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'], | ||
mode => '0755', | ||
} | ||
|
||
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, | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is it a better way to call
update-grub
on ubuntu/debian?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 wouldn't bother:
This is more consistent, imho.
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.
:D I did not check the file itself, but I saw it in all possible man pages :)
Fine for me as is now