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

Cookstyle Bot Auto Corrections with Cookstyle 7.31.1 #277

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

#
# Cookbook Name:: os-hardening
# Cookbook:: os-hardening
# Attributes:: default
#
# Copyright 2012, Dominik Richter
# Copyright 2014, Deutsche Telekom AG
# Copyright:: 2012, Dominik Richter
# Copyright:: 2014, Deutsche Telekom AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,7 @@

default['os-hardening'].tap do |os_hardening|
# components of this cookbook
%w[packages limits login_defs minimize_access pam profile securetty].each do |cp|
%w(packages limits login_defs minimize_access pam profile securetty).each do |cp|
os_hardening['components'][cp] = true
end

Expand Down Expand Up @@ -76,7 +76,7 @@
auth['timeout'] = 60
auth['allow_homeless'] = false
auth['login_defs']['template_cookbook'] = 'os-hardening'
auth['root_ttys'] = %w[console tty1 tty2 tty3 tty4 tty5 tty6]
auth['root_ttys'] = %w(console tty1 tty2 tty3 tty4 tty5 tty6)
auth['uid_min'] = 1000
auth['uid_max'] = 60000
auth['gid_min'] = 1000
Expand All @@ -86,8 +86,7 @@

# PAM settings
auth['pam'].tap do |pam|
case node['platform_family']
when 'rhel', 'fedora', 'amazon'
if platform_family?('rhel', 'fedora', 'amazon')
if node['platform_version'].to_f < 7
pam['passwdqc']['enable'] = true
pam['pwquality']['enable'] = false
Expand All @@ -109,8 +108,7 @@
end

# RH has a bit different defaults on some places
case node['platform_family']
when 'rhel', 'amazon'
if platform_family?('rhel', 'amazon')
os_hardening['env']['umask'] = '077'
os_hardening['auth']['sys_uid_min'] = 201
os_hardening['auth']['sys_gid_min'] = 201
Expand All @@ -124,7 +122,7 @@
# may contain: change_user
security['users']['allow'] = []
security['kernel']['enable_module_loading'] = true
security['kernel']['disable_filesystems'] = %w[cramfs freevxfs jffs2 hfs hfsplus squashfs udf vfat]
security['kernel']['disable_filesystems'] = %w(cramfs freevxfs jffs2 hfs hfsplus squashfs udf vfat)
security['kernel']['enable_sysrq'] = false
security['kernel']['enable_core_dump'] = false
security['suid_sgid']['enforce'] = true
Expand All @@ -145,13 +143,13 @@
# remove packages with known issues
security['packages']['clean'] = true
# list of packages with known issues
security['packages']['list'] = [
'xinetd',
'inetd',
'ypserv',
'telnet-server',
'rsh-server'
]
security['packages']['list'] = %w(
xinetd
inetd
ypserv
telnet-server
rsh-server
)

# SELinux enforcing (enforcing, permissive, unmanaged)
security['selinux_mode'] = 'unmanaged'
Expand Down
9 changes: 4 additions & 5 deletions attributes/sysctl.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

#
# Cookbook Name:: os-hardening
# Cookbook:: os-hardening
# Attributes:: sysctl
#
# Copyright 2014, Deutsche Telekom AG
# Copyright:: 2014, Deutsche Telekom AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -92,10 +92,9 @@
default['sysctl']['params']['net']['ipv6']['conf']['default']['accept_ra'] = 0

# ExecShield protection against buffer overflows
case node['platform_family']
when 'rhel', 'fedora'
if platform_family?('rhel', 'fedora')
# on Oracle Linux with UEK it is not available; this helps address UEK on Oracle Linux 6
is_oracle_uek = (node['platform'] == 'oracle' && node['kernel']['release'] =~ /^4\..*uek/)
is_oracle_uek = (platform?('oracle') && node['kernel']['release'] =~ /^4\..*uek/)

# on RHEL 7 its enabled per default and can't be disabled
if node['platform_version'].to_f < 7 && !is_oracle_uek
Expand Down
6 changes: 3 additions & 3 deletions libraries/apt_package_extras.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

#
# Cookbook Name:: os-hardening
# Cookbook:: os-hardening
# Library:: apt_package_extras
#
# Copyright 2008, Chef Software, Inc.
# Copyright 2015, Hardening Framework Team
# Copyright:: 2008, Chef Software, Inc.
# Copyright:: 2015, Hardening Framework Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
6 changes: 3 additions & 3 deletions libraries/cookbook_version.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

#
# Cookbook Name:: os-hardening
# Cookbook:: os-hardening
# Library:: cookbook_version
#
# Copyright 2014, Dominik Richter
# Copyright 2014, Deutsche Telekom AG
# Copyright:: 2014, Dominik Richter
# Copyright:: 2014, Deutsche Telekom AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
6 changes: 3 additions & 3 deletions libraries/gpgcheck.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

#
# Cookbook Name:: os-hardening
# Cookbook:: os-hardening
# Library:: gpgcheck
#
# Copyright 2012, Dominik Richter
# Copyright 2014, Deutsche Telekom AG
# Copyright:: 2012, Dominik Richter
# Copyright:: 2014, Deutsche Telekom AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
6 changes: 3 additions & 3 deletions libraries/helpers_param.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

#
# Cookbook Name:: os-hardening
# Cookbook:: os-hardening
# Library:: gpgcheck
#
# Copyright 2012, Dominik Richter
# Copyright 2014, Deutsche Telekom AG
# Copyright:: 2012, Dominik Richter
# Copyright:: 2014, Deutsche Telekom AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
12 changes: 6 additions & 6 deletions libraries/suid_sgid.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

#
# Cookbook Name:: os-hardening
# Cookbook:: os-hardening
# Library:: suid_sgid
#
# Copyright 2012, Dominik Richter
# Copyright 2014, Deutsche Telekom AG
# Copyright:: 2012, Dominik Richter
# Copyright:: 2014, Deutsche Telekom AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,9 +46,9 @@ def self.find_all_suid_sgid_files(start_at = '/')
end

def self.remove_suid_sgid_from_blacklist(blacklist)
blacklist.
select { |file| File.exist?(file) }.
each do |file|
blacklist
.select { |file| File.exist?(file) }
.each do |file|
Chef::Log.info "suid_sgid: Blacklist SUID/SGID for '#{file}', removing bit..."
remove_suid_sgid_from(file)
end
Expand Down
13 changes: 1 addition & 12 deletions metadata.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

#
# Copyright 2014, Deutsche Telekom AG
# Copyright:: 2014, Deutsche Telekom AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,6 @@
maintainer_email '[email protected]'
license 'Apache-2.0'
description 'Installs and configures operating system hardening'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '4.0.0'
source_url 'https://github.com/dev-sec/chef-os-hardening'
issues_url 'https://github.com/dev-sec/chef-os-hardening/issues'
Expand All @@ -37,13 +36,3 @@
supports 'fedora', '>= 28.0'
supports 'suse'
supports 'opensuseleap', '>= 42.1'

recipe 'os-hardening::default', 'harden the operating system (all recipes)'
recipe 'os-hardening::limits', 'prevent core dumps'
recipe 'os-hardening::login_defs', 'harden /etc/login.defs'
recipe 'os-hardening::minimize_access', 'enforce minimal file permissions'
recipe 'os-hardening::pam', 'configure sane values for PAM'
recipe 'os-hardening::profile', 'harden settings in /etc/profile.d'
recipe 'os-hardening::securetty', 'limit the allowed TTYs for root login'
recipe 'os-hardening::suid_sgid', 'reduce SUID and SGID bits in the filesystem'
recipe 'os-hardening::sysctl', 'set sane sysctl values'
4 changes: 2 additions & 2 deletions recipes/apt.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

#
# Cookbook Name: os-hardening
# Cookbook:: Name: os-hardening
# Recipe: apt.rb
#
# Copyright 2015, Hardening Framework Team
# Copyright:: 2015, Hardening Framework Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
12 changes: 6 additions & 6 deletions recipes/auditd.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

#
# Cookbook Name: os-hardening
# Cookbook:: Name: os-hardening
# Recipe: auditd.rb
#
# Copyright 2017, Artem Sidorenko
# Copyright:: 2017, Artem Sidorenko
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -22,10 +22,10 @@
package node['os-hardening']['packages']['auditd']

service 'auditd' do
supports %i[start stop restart reload status]
if (node['platform_family'] == 'rhel' && node['platform_version'].to_f >= 7) ||
(node['platform_family'] == 'fedora' && node['platform_version'].to_f >= 27) ||
(node['platform_family'] == 'amazon' && node['platform_version'].to_f >= 2)
supports %i(start stop restart reload status)
if (platform_family?('rhel') && node['platform_version'].to_f >= 7) ||
(platform_family?('fedora') && node['platform_version'].to_f >= 27) ||
(platform_family?('amazon') && node['platform_version'].to_f >= 2)
restart_command 'service auditd restart'
end
action [:enable]
Expand Down
8 changes: 4 additions & 4 deletions recipes/default.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

#
# Cookbook Name: os-hardening
# Cookbook:: Name: os-hardening
# Recipe: default
#
# Copyright 2012, Dominik Richter
# Copyright 2014, Deutsche Telekom AG
# Copyright:: 2012, Dominik Richter
# Copyright:: 2014, Deutsche Telekom AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,7 +36,7 @@

# selinux should be included only on RH based systems
node.default['os-hardening']['components']['selinux'] =
node['platform_family'] == 'rhel' || node['platform_family'] == 'fedora'
platform_family?('rhel', 'fedora')
end

# include all required components
Expand Down
4 changes: 2 additions & 2 deletions recipes/limits.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

#
# Cookbook Name: os-hardening
# Cookbook:: Name: os-hardening
# Recipe: limits.rb
#
# Copyright 2014, Deutsche Telekom AG
# Copyright:: 2014, Deutsche Telekom AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions recipes/login_defs.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

#
# Cookbook Name: os-hardening
# Cookbook:: Name: os-hardening
# Recipe: login_defs.rb
#
# Copyright 2014, Deutsche Telekom AG
# Copyright:: 2014, Deutsche Telekom AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
10 changes: 5 additions & 5 deletions recipes/minimize_access.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

#
# Cookbook Name: os-hardening
# Cookbook:: Name: os-hardening
# Recipe: minimize_access
#
# Copyright 2014, Deutsche Telekom AG
# Copyright:: 2014, Deutsche Telekom AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,7 @@

# remove write permissions from path folders ($PATH) for all regular users
# this prevents changing any system-wide command from normal users
paths = %w[/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin] + node['os-hardening']['env']['extra_user_paths']
paths = %w(/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin) + node['os-hardening']['env']['extra_user_paths']
paths.each do |folder|
execute "remove write permission from #{folder}" do
command "chmod go-w -R #{folder}"
Expand Down Expand Up @@ -59,7 +59,7 @@
directory '/var/log' do
owner 'root'
# ubuntu with containers does not have rsyslog installed and syslog group does not exist
if node['platform'] == 'ubuntu' && node['packages']['rsyslog']
if platform?('ubuntu') && node['packages']['rsyslog']
group 'syslog'
else
group 'root'
Expand All @@ -72,7 +72,7 @@
only_if { ::File.exist?('/etc/crontab') }
end

cron_directories = %w[/etc/cron.hourly /etc/cron.daily /etc/cron.weekly /etc/cron.monthly /etc/cron.d]
cron_directories = %w(/etc/cron.hourly /etc/cron.daily /etc/cron.weekly /etc/cron.monthly /etc/cron.d)
cron_directories.each do |cron_path|
next unless ::Dir.exist?(cron_path)

Expand Down
14 changes: 4 additions & 10 deletions recipes/packages.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

#
# Cookbook Name: os-hardening
# Cookbook:: Name: os-hardening
# Recipe: packages.rb
#
# Copyright 2014, Deutsche Telekom AG
# Copyright:: 2014, Deutsche Telekom AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -20,13 +20,7 @@
#

# do package config for ubuntu
case node['platform_family']
when 'debian'
include_recipe('os-hardening::apt')
end
include_recipe 'os-hardening::apt' if platform_family?('debian')

# do package config for rhel-family
case node['platform_family']
when 'rhel', 'fedora', 'amazon'
include_recipe('os-hardening::yum')
end
include_recipe 'os-hardening::yum' if platform_family?('rhel', 'fedora', 'amazon')
Loading