summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArmin Kuster <akuster808@gmail.com>2020-07-26 13:10:31 -0700
committerArmin Kuster <akuster808@gmail.com>2020-09-13 07:05:50 -0700
commit0d72d40772c18f0632c8f9964c010110a7158208 (patch)
treef6f6f6edea425741c67b5ccd0b3f69aeb9b42482
parent0ba605980565f71c546f1985fa3a2f0d5153a549 (diff)
downloadmeta-security-0d72d40772c18f0632c8f9964c010110a7158208.tar.gz
meta-harden: Add a layer to demo harding OE/YP
Signed-off-by: Armin Kuster <akuster808@gmail.com>
-rw-r--r--meta-hardening/README86
-rw-r--r--meta-hardening/conf/distro/harden.conf11
-rw-r--r--meta-hardening/conf/layer.conf13
-rw-r--r--meta-hardening/recipes-connectivity/openssh/openssh_%.bbappend13
-rw-r--r--meta-hardening/recipes-core/base-files/base-files_%.bbappend4
-rw-r--r--meta-hardening/recipes-core/images/harden-image-minimal.bb25
-rwxr-xr-xmeta-hardening/recipes-core/initscripts/files/mountall.sh41
-rw-r--r--meta-hardening/recipes-core/initscripts/initscripts_1.0.bbappend8
-rw-r--r--meta-hardening/recipes-core/packagegroups/packagegroup-hardening.bb19
-rw-r--r--meta-hardening/recipes-extended/shadow/shadow_%.bbappend10
-rw-r--r--meta-hardening/recipes-extended/sudo/sudo_%.bbappend7
11 files changed, 237 insertions, 0 deletions
diff --git a/meta-hardening/README b/meta-hardening/README
new file mode 100644
index 0000000..37a0b7e
--- /dev/null
+++ b/meta-hardening/README
@@ -0,0 +1,86 @@
1# This is an example for Security hardening an OE or Poky image
2
3
4Meta-hardening
5=============
6
7This layer provides examples for hardening OE/Yocto images.
8This layer does not provide 100% security protection. This is only
9a framework from which a user can build from and can possible contribute to.
10The goal here is to capture use cases and examples the community decided shares for
11everyones benefit.
12
13Building the meta-hardening layer
14-------------------------------
15In order to add hardening support to the poky/OE build this layer should be added
16to your projects bblayers.conf file.
17
18By default the hardening components are disabled. This conforms to the
19Yocto Project compatible guideline that indicate that simply including a
20layer should not change the system behavior.
21
22In order to use the components in this layer to take affect the 'harden' keyword must
23set the DISTRO as in "DISTRO = harden". This enables the "NO ROOT access" idea or framework.
24
25If one wants the a more complete example of a hardened image, one must also build the image:
26harden-image-minimal
27
28There are default example userid and passwards:
29These can be over written in your local.conf via:
30ROOT_DEFAULT_PASSWORD ?= "1SimplePw!"
31DEFAULT_ADMIN_ACCOUNT ?= "myadmin"
32
33example:
34local.conf
35DISTRO = "harden"
36
37The default user and password are:
38User: "myadmin"
39Password: "1SimplePw!"
40
41bitbake {qemu machine} harden-image-minimal
42
43Dependencies
44============
45
46Branch: master
47
48This layer depends on:
49
50URI: git://git.yoctoproject.org/poky
51
52or this normal combo:
53
54URI: git://git.openembedded.org/meta-openembedded/meta-oe
55
56URI: git://git.openembedded.org/bitbake
57
58plus:
59
60URI: git://git.openembedded.org/meta-openembedded
61layers: meta-oe
62
63
64Maintenance
65-----------
66
67Send pull requests, patches, comments or questions to yocto@yoctoproject.org
68
69When sending single patches, please using something like:
70'git send-email -1 --to yocto@yoctoproject.org --subject-prefix=meta-hardening][PATCH'
71
72These values can be set as defaults for this repository:
73
74$ git config sendemail.to yocto@yoctoproject.org
75$ git config format.subjectPrefix meta-hardening][PATCH
76
77Now you can just do 'git send-email origin/master' to send all local patches.
78
79Maintainers: Armin Kuster <akuster808@gmail.com>
80
81License
82=======
83
84All metadata is MIT licensed unless otherwise stated. Source code included
85in tree for individual recipes is under the LICENSE stated in each recipe
86(.bb file) unless otherwise stated.
diff --git a/meta-hardening/conf/distro/harden.conf b/meta-hardening/conf/distro/harden.conf
new file mode 100644
index 0000000..66db9b7
--- /dev/null
+++ b/meta-hardening/conf/distro/harden.conf
@@ -0,0 +1,11 @@
1DISTRO = "harden"
2DISTRO_NAME = "Simple Security hardening example"
3DISTRO_VERSION = "1.0"
4
5DISTRO_FEATURES = " acl xattr pci ext2 pam ipv4 ipv6 ipsec largefile usbhost"
6
7VIRTUAL-RUNTIME_base-utils-syslog ?= "rsyslog"
8IMAGE_ROOTFS_EXTRA_SPACE = "524288"
9EXTRA_IMAGE_FEATURES_remove = "debug-tweaks"
10
11DISABLE_ROOT ?= "True"
diff --git a/meta-hardening/conf/layer.conf b/meta-hardening/conf/layer.conf
new file mode 100644
index 0000000..5896214
--- /dev/null
+++ b/meta-hardening/conf/layer.conf
@@ -0,0 +1,13 @@
1# We have a conf and classes directory, add to BBPATH
2BBPATH .= ":${LAYERDIR}"
3
4# We have a recipes directory, add to BBFILES
5BBFILES += "${LAYERDIR}/recipes*/*/*.bb ${LAYERDIR}/recipes*/*/*.bbappend"
6
7BBFILE_COLLECTIONS += "harden-layer"
8BBFILE_PATTERN_harden-layer = "^${LAYERDIR}/"
9BBFILE_PRIORITY_harden-layer = "10"
10
11LAYERSERIES_COMPAT_harden-layer = "dunfell"
12
13LAYERDEPENDS_harden-layer = "core openembedded-layer"
diff --git a/meta-hardening/recipes-connectivity/openssh/openssh_%.bbappend b/meta-hardening/recipes-connectivity/openssh/openssh_%.bbappend
new file mode 100644
index 0000000..67be3f3
--- /dev/null
+++ b/meta-hardening/recipes-connectivity/openssh/openssh_%.bbappend
@@ -0,0 +1,13 @@
1do_install_append_harden () {
2 # to hardend
3 sed -i -e 's:#AllowTcpForwarding yes:AllowTcpForwarding no:' ${D}${sysconfdir}/ssh/sshd_config
4 sed -i -e 's:ClientAliveCountMax 4:ClientAliveCountMax 2:' ${D}${sysconfdir}/ssh/sshd_config
5 sed -i -e 's:#LogLevel INFO:LogLevel VERBOSE:' ${D}${sysconfdir}/ssh/sshd_config
6 sed -i -e 's:#MaxSessions.*:MaxSessions 2:' ${D}${sysconfdir}/ssh/sshd_config
7 sed -i -e 's:#TCPKeepAlive yes:TCPKeepAlive no:' ${D}${sysconfdir}/ssh/sshd_config
8 sed -i -e 's:#AllowAgentForwarding yes:AllowAgentForwarding no:' ${D}${sysconfdir}/ssh/sshd_config
9
10 if [ "${@bb.utils.contains('DISABLE_ROOT', 'True', 'yes', 'no', d)}" = "yes" ]; then
11 sed -i -e 's:#PermitRootLogin.*:PermitRootLogin prohibit-password:' ${D}${sysconfdir}/ssh/sshd_config
12 fi
13}
diff --git a/meta-hardening/recipes-core/base-files/base-files_%.bbappend b/meta-hardening/recipes-core/base-files/base-files_%.bbappend
new file mode 100644
index 0000000..3956304
--- /dev/null
+++ b/meta-hardening/recipes-core/base-files/base-files_%.bbappend
@@ -0,0 +1,4 @@
1
2do_install_append_harden () {
3 sed -i 's/umask.*/umask 027/g' ${D}/${sysconfdir}/profile
4}
diff --git a/meta-hardening/recipes-core/images/harden-image-minimal.bb b/meta-hardening/recipes-core/images/harden-image-minimal.bb
new file mode 100644
index 0000000..daed3fb
--- /dev/null
+++ b/meta-hardening/recipes-core/images/harden-image-minimal.bb
@@ -0,0 +1,25 @@
1SUMMARY = "A small image for an example hardening OE."
2
3IMAGE_INSTALL = "packagegroup-core-boot packagegroup-hardening"
4IMAGE_INSTALL_append = " os-release"
5
6IMAGE_FEATURES = ""
7IMAGE_LINGUAS = " "
8
9LICENSE = "MIT"
10
11IMAGE_ROOTFS_SIZE ?= "8192"
12
13inherit core-image extrausers
14
15ROOT_DEFAULT_PASSWORD ?= "1SimplePw!"
16DEFAULT_ADMIN_ACCOUNT ?= "myadmin"
17DEFAULT_ADMIN_GROUP ?= "wheel"
18DEFAULT_ADMIN_ACCOUNT_PASSWORD ?= "1SimplePw!"
19
20EXTRA_USERS_PARAMS = "${@bb.utils.contains('DISABLE_ROOT', 'True', "usermod -L root;", "usermod -P '${ROOT_DEFAULT_PASSWORD}' root;", d)}"
21
22EXTRA_USERS_PARAMS += "useradd ${DEFAULT_ADMIN_ACCOUNT};"
23EXTRA_USERS_PARAMS += "groupadd ${DEFAULT_ADMIN_GROUP};"
24EXTRA_USERS_PARAMS += "usermod -P '${DEFAULT_ADMIN_ACCOUNT_PASSWORD}' ${DEFAULT_ADMIN_ACCOUNT};"
25EXTRA_USERS_PARAMS += "usermod -aG ${DEFAULT_ADMIN_GROUP} ${DEFAULT_ADMIN_ACCOUNT};"
diff --git a/meta-hardening/recipes-core/initscripts/files/mountall.sh b/meta-hardening/recipes-core/initscripts/files/mountall.sh
new file mode 100755
index 0000000..e093f96
--- /dev/null
+++ b/meta-hardening/recipes-core/initscripts/files/mountall.sh
@@ -0,0 +1,41 @@
1#!/bin/sh
2### BEGIN INIT INFO
3# Provides: mountall
4# Required-Start: mountvirtfs
5# Required-Stop:
6# Default-Start: S
7# Default-Stop:
8# Short-Description: Mount all filesystems.
9# Description:
10### END INIT INFO
11
12. /etc/default/rcS
13
14#
15# Mount local filesystems in /etc/fstab. For some reason, people
16# might want to mount "proc" several times, and mount -v complains
17# about this. So we mount "proc" filesystems without -v.
18#
19test "$VERBOSE" != no && echo "Mounting local filesystems..."
20mkdir -p /home
21mkdir -p /var
22mount -at nonfs,nosmbfs,noncpfs 2>/dev/null
23
24#
25# We might have mounted something over /dev, see if /dev/initctl is there.
26#
27if test ! -p /dev/initctl
28then
29 rm -f /dev/initctl
30 mknod -m 600 /dev/initctl p
31fi
32kill -USR1 1
33
34#
35# Execute swapon command again, in case we want to swap to
36# a file on a now mounted filesystem.
37#
38[ -x /sbin/swapon ] && swapon -a
39
40: exit 0
41
diff --git a/meta-hardening/recipes-core/initscripts/initscripts_1.0.bbappend b/meta-hardening/recipes-core/initscripts/initscripts_1.0.bbappend
new file mode 100644
index 0000000..896b039
--- /dev/null
+++ b/meta-hardening/recipes-core/initscripts/initscripts_1.0.bbappend
@@ -0,0 +1,8 @@
1FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
2
3SRC_URI_append_harden = " file://mountall.sh"
4
5do_install_append_harden() {
6 install -d ${D}${sysconfdir}/init.d
7 install -m 0755 ${WORKDIR}/mountall.sh ${D}${sysconfdir}/init.d
8}
diff --git a/meta-hardening/recipes-core/packagegroups/packagegroup-hardening.bb b/meta-hardening/recipes-core/packagegroups/packagegroup-hardening.bb
new file mode 100644
index 0000000..1dcd5fc
--- /dev/null
+++ b/meta-hardening/recipes-core/packagegroups/packagegroup-hardening.bb
@@ -0,0 +1,19 @@
1#
2#
3#
4
5SUMMARY = "Hardening example group"
6
7inherit packagegroup
8
9PROVIDES = "${PACKAGES}"
10PACKAGES = "${PN} \
11 packagegroup-${PN} \
12"
13
14RDEPENDS_${PN} = "\
15 init-ifupdown \
16 ${VIRTUAL-RUNTIME_base-utils-syslog} \
17 sudo \
18 ${@bb.utils.contains("DISTRO_FEATURES", "pam", "pam-plugin-wheel", "",d)} \
19"
diff --git a/meta-hardening/recipes-extended/shadow/shadow_%.bbappend b/meta-hardening/recipes-extended/shadow/shadow_%.bbappend
new file mode 100644
index 0000000..3f363f0
--- /dev/null
+++ b/meta-hardening/recipes-extended/shadow/shadow_%.bbappend
@@ -0,0 +1,10 @@
1do_install_append_harden () {
2 # to hardend
3 sed -i -e 's:UMASK.*:UMASK 027:' ${D}${sysconfdir}/login.defs
4 sed -i -e 's:PASS_MAX_DAYS.*:PASS_MAX_DAYS 365:' ${D}${sysconfdir}/login.defs
5 sed -i -e 's:PASS_MIN_DAYS.*:PASS_MIN_DAYS 1:' ${D}${sysconfdir}/login.defs
6 sed -i -e 's:#PASS_MIN_LEN.*:PASS_MIN_LEN 11:' ${D}${sysconfdir}/login.defs
7 sed -i -e 's:PASS_WARN_AGE.*:PASS_WARN_AGE 14:' ${D}${sysconfdir}/login.defs
8 sed -i -e 's:LOGIN_RETRIES.*:LOGIN_RETRIES 3:' ${D}${sysconfdir}/login.defs
9 sed -i -e 's:LOGIN_TIMEOUT.*:LOGIN_TIMEOUT 30:' ${D}${sysconfdir}/login.defs
10}
diff --git a/meta-hardening/recipes-extended/sudo/sudo_%.bbappend b/meta-hardening/recipes-extended/sudo/sudo_%.bbappend
new file mode 100644
index 0000000..a31c081
--- /dev/null
+++ b/meta-hardening/recipes-extended/sudo/sudo_%.bbappend
@@ -0,0 +1,7 @@
1
2PACKAGECONFIG_append_harden = " pam-wheel"
3do_install_append_harden () {
4 if [ "${@bb.utils.contains('DISABLE_ROOT', 'True', 'yes', 'no', d)}" = "yes" ]; then
5 sed -i -e 's:root ALL=(ALL) ALL:#root ALL=(ALL) ALL:' ${D}${sysconfdir}/sudoers
6 fi
7}