security-test-image: auto include layers if present.
PATCH 1/9 security-test-image: auto include layers if present.
This is to simplify tesing to build one image and include pkgs depending on the layers included in the BBLAYERS.
--- recipes-core/images/security-test-image.bb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
recipes-core/images/security-test-image.bb +10 -1
@@ -4,7 +4,16 @@ require security-build-image.bb IMAGE_FEATURES += "ssh-server-openssh" -TEST_SUITES = "ssh ping ptest apparmor clamav samhain sssd tripwire checksec smack suricata" +IMAGE_INSTALL:append = "\ + ${@bb.utils.contains("DISTRO_FEATURES", "smack", "smack-test", "",d)} \ + ${@bb.utils.contains("BBFILE_COLLECTIONS", "tpm-layer", "packagegroup-security-tpm","", d)} \ + ${@bb.utils.contains("BBFILE_COLLECTIONS", "tpm-layer", "packagegroup-security-tpm2","", d)} \ + ${@bb.utils.contains("BBFILE_COLLECTIONS", "parsec-layer", "packagegroup-security-parsec","", d)} \ + ${@bb.utils.contains("BBFILE_COLLECTIONS", "integrity", "packagegroup-ima-evm-utils","", d)} \ +" + +TEST_SUITES = "ssh ping apparmor clamav samhain sssd checksec smack suricata" +TEST_SUITES:append = " parsec tpm2 swtpm ima" INSTALL_CLAMAV_CVD = "1"
Signature · 1 line
2.25.1
PATCH 2/9 smack-test: more py3 covertion
--- recipes-mac/smack/smack-test/notroot.py | 12 ++++++------ .../smack/smack-test/smack_test_file_access.sh | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-)
recipes-mac/smack/smack-test/notroot.py +6 -6
@@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Script used for running executables with custom labels, as well as custom uid/gid # Process label is changed by writing to /proc/self/attr/curent
@@ -9,8 +9,8 @@ # """By default, each user in Debian GNU/Linux is given a corresponding group # with the same name. """ # -# Usage: root@desk:~# python notroot.py <uid> <label> <full_path_to_executable> [arguments ..] -# eg: python notroot.py 1000 User::Label /bin/ping -c 3 192.168.1.1 +# Usage: root@desk:~# python3 notroot.py <uid> <label> <full_path_to_executable> [arguments ..] +# eg: python3 notroot.py 1000 User::Label /bin/ping -c 3 192.168.1.1 # # Author: Alexandru Cornea <[email protected]> import os
@@ -28,6 +28,6 @@ try: os.setuid(uid) os.execv(path,sys.argv) -except Exception,e: - print e.message - sys.exit(1) +except Exception as e: + print(e.strerror) + sys.exit(-1)
recipes-mac/smack/smack-test/smack_test_file_access.sh +5 -5
@@ -8,7 +8,7 @@ CAT=`which cat` ECHO=`which echo` uid=1000 initial_label=`cat /proc/self/attr/current` -python $TMP/notroot.py $uid "TheOther" $ECHO 'TEST' > $test_file +python3 $TMP/notroot.py $uid "TheOther" $ECHO 'TEST' > $test_file chsmack -a "TheOther" $test_file # 12345678901234567890123456789012345678901234567890123456
@@ -17,7 +17,7 @@ rule_ro="TheOne TheOther r----" # Remove pre-existent rules for "TheOne TheOther <access>" echo -n "$delrule" > $SMACK_PATH/load -python $TMP/notroot.py $uid "TheOne" $CAT $test_file 2>&1 1>/dev/null | grep -q "Permission denied" || RC=$? +python3 $TMP/notroot.py $uid "TheOne" $CAT $test_file 2>&1 1>/dev/null | grep -q "Permission denied" || RC=$? if [ $RC -ne 0 ]; then echo "Process with different label than the test file and no read access on it can read it" exit $RC
@@ -25,7 +25,7 @@ fi # adding read access echo -n "$rule_ro" > $SMACK_PATH/load -python $TMP/notroot.py $uid "TheOne" $CAT $test_file | grep -q "TEST" || RC=$? +python3 $TMP/notroot.py $uid "TheOne" $CAT $test_file | grep -q "TEST" || RC=$? if [ $RC -ne 0 ]; then echo "Process with different label than the test file but with read access on it cannot read it" exit $RC
@@ -36,7 +36,7 @@ echo -n "$delrule" > $SMACK_PATH/load # changing label of test file to * # according to SMACK documentation, read access on a * object is always permitted chsmack -a '*' $test_file -python $TMP/notroot.py $uid "TheOne" $CAT $test_file | grep -q "TEST" || RC=$? +python3 $TMP/notroot.py $uid "TheOne" $CAT $test_file | grep -q "TEST" || RC=$? if [ $RC -ne 0 ]; then echo "Process cannot read file with * label" exit $RC
@@ -45,7 +45,7 @@ fi # changing subject label to * # according to SMACK documentation, every access requested by a star labeled subject is rejected TOUCH=`which touch` -python $TMP/notroot.py $uid '*' $TOUCH $TMP/test_file_2 +python3 $TMP/notroot.py $uid '*' $TOUCH $TMP/test_file_2 ls -la $TMP/test_file_2 2>&1 | grep -q 'No such file or directory' || RC=$? if [ $RC -ne 0 ];then echo "Process with label '*' should not have any access"
Signature · 1 line
2.25.1
PATCH 3/9 oeqa: update smack runtime test
In reply to Armin Kusterdrop test_smack_mmap_enforced as is was skipped do to possible licensing issues
--- lib/oeqa/runtime/cases/smack.py | 103 +++++--------------------------- 1 file changed, 15 insertions(+), 88 deletions(-)
lib/oeqa/runtime/cases/smack.py +15 -88
@@ -15,17 +15,16 @@ class SmackBasicTest(OERuntimeTestCase): @classmethod def setUpClass(cls): - cls.smack_path = "" cls.current_label = "" cls.uid = 1000 + status, output = cls.tc.target.run("grep smack /proc/mounts | awk '{print $2}'") + cls.smack_path = output @skipIfNotFeature('smack', 'Test requires smack to be in DISTRO_FEATURES') @OEHasPackage(['smack-test']) @OETestDepends(['ssh.SSHTest.test_ssh']) def test_smack_basic(self): - status, output = self.target.run("grep smack /proc/mounts | awk '{print $2}'") - self.smack_path = output status,output = self.target.run("cat /proc/self/attr/current") self.current_label = output.strip()
@@ -41,11 +40,11 @@ class SmackBasicTest(OERuntimeTestCase): "Status and output: %d %s" %(status, output)) status, output = self.target.run("chsmack %s" %filename) self.target.run("rm %s" %filename) - m = re.search('(?<=access=")\S+(?=")', output) + m = re.search('(access=")\S+(?=")', output) if m is None: self.fail("Did not find access attribute") else: - label_retrieved = m .group(0) + label_retrieved = re.split("access=\"", output)[1][:-1] self.assertEqual( LABEL, label_retrieved, "label not set correctly. expected and gotten: "
@@ -64,11 +63,11 @@ class SmackBasicTest(OERuntimeTestCase): "Status and output: %d %s" %(status, output)) status, output = self.target.run("chsmack %s" %filename) self.target.run("rm %s" %filename) - m= re.search('(?<=execute=")\S+(?=")', output) + m= re.search('(execute=")\S+(?=")', output) if m is None: self.fail("Did not find execute attribute") else: - label_retrieved = m.group(0) + label_retrieved = re.split("execute=\"", output)[1][:-1] self.assertEqual( LABEL, label_retrieved, "label not set correctly. expected and gotten: " +
@@ -87,11 +86,11 @@ class SmackBasicTest(OERuntimeTestCase): "Status and output: %d %s" %(status, output)) status, output = self.target.run("chsmack %s" %filename) self.target.run("rm %s" %filename) - m = re.search('(?<=mmap=")\S+(?=")', output) + m = re.search('(mmap=")\S+(?=")', output) if m is None: self.fail("Did not find mmap attribute") else: - label_retrieved = m.group(0) + label_retrieved = re.split("mmap=\"", output)[1][:-1] self.assertEqual( LABEL, label_retrieved, "label not set correctly. expected and gotten: " +
@@ -109,11 +108,11 @@ class SmackBasicTest(OERuntimeTestCase): "Status and output: %d %s" %(status, output)) status, output = self.target.run("chsmack %s" %directory) self.target.run("rmdir %s" %directory) - m = re.search('(?<=transmute=")\S+(?=")', output) + m = re.search('(transmute=")\S+(?=")', output) if m is None: self.fail("Did not find transmute attribute") else: - label_retrieved = m.group(0) + label_retrieved = re.split("transmute=\"", output)[1][:-1] self.assertEqual( "TRUE", label_retrieved, "label not set correctly. expected and gotten: " +
@@ -127,10 +126,10 @@ class SmackBasicTest(OERuntimeTestCase): ''' labelf = "/proc/self/attr/current" - command = "/bin/sh -c 'echo PRIVILEGED >%s; cat %s'" %(labelf, labelf) + command = "/bin/sh -c 'echo PRIVILEGED >%s'; cat %s" %(labelf, labelf) status, output = self.target.run( - "notroot.py 0 %s %s" %(self.current_label, command)) + "/usr/sbin/notroot.py 0 %s %s" %(self.current_label, command)) self.assertIn("PRIVILEGED", output, "Privilege process did not change label.Output: %s" %output)
@@ -142,7 +141,7 @@ class SmackBasicTest(OERuntimeTestCase): command = "/bin/sh -c 'echo %s >/proc/self/attr/current'" %LABEL status, output = self.target.run( - "notroot.py %d %s %s" + "/usr/sbin/notroot.py %d %s %s" %(self.uid, self.current_label, command) + " 2>&1 | grep 'Operation not permitted'" )
@@ -160,9 +159,9 @@ class SmackBasicTest(OERuntimeTestCase): filename = "/tmp/test_unprivileged_change_file_label" self.target.run("touch %s" % filename) - self.target.run("notroot.py %d %s" %(self.uid, self.current_label)) + self.target.run("/usr/sbin/notroot.py %d %s" %(self.uid, self.current_label)) status, output = self.target.run( - "notroot.py " + + "/usr/sbin/notroot.py " + "%d unprivileged %s -a %s %s 2>&1 " %(self.uid, chsmack, LABEL, filename) + "| grep 'Operation not permitted'" )
@@ -346,78 +345,6 @@ class SmackBasicTest(OERuntimeTestCase): self.assertEqual(status, 0, output) - @OETestDepends(['smack.SmackBasicTest.test_smack_basic']) - def test_smack_mmap_enforced(self): - '''Test if smack mmap access is enforced''' - raise unittest.SkipTest("Depends on mmap_test, which was removed from the layer while investigating its license.") - - # 12345678901234567890123456789012345678901234567890123456 - delr1="mmap_label mmap_test_label1 -----" - delr2="mmap_label mmap_test_label2 -----" - delr3="mmap_file_label mmap_test_label1 -----" - delr4="mmap_file_label mmap_test_label2 -----" - - RuleA="mmap_label mmap_test_label1 rw---" - RuleB="mmap_label mmap_test_label2 r--at" - RuleC="mmap_file_label mmap_test_label1 rw---" - RuleD="mmap_file_label mmap_test_label2 rwxat" - - mmap_label="mmap_label" - file_label="mmap_file_label" - test_file = "/usr/sbin/smack_test_mmap" - mmap_exe = "/tmp/mmap_test" - status, echo = self.target.run("which echo") - status, output = self.target.run( - "notroot.py %d %s %s 'test' > %s" \ - %(self.uid, self.current_label, echo, test_file)) - status, output = self.target.run("ls %s" %test_file) - self.assertEqual(status, 0, "Could not create mmap test file") - self.target.run("chsmack -m %s %s" %(file_label, test_file)) - self.target.run("chsmack -e %s %s" %(mmap_label, mmap_exe)) - - # test with no rules with mmap label or exec label as subject - # access should be granted - self.target.run('echo -n "%s" > %s/load' %(delr1, self.smack_path)) - self.target.run('echo -n "%s" > %s/load' %(delr2, self.smack_path)) - self.target.run('echo -n "%s" > %s/load' %(delr3, self.smack_path)) - self.target.run('echo -n "%s" > %s/load' %(delr4, self.smack_path)) - status, output = self.target.run("%s %s 0 2" % (mmap_exe, test_file)) - self.assertEqual( - status, 0, - "Should have mmap access without rules. Output: %s" %output) - - # add rules that do not match access required - self.target.run('echo -n "%s" > %s/load' %(RuleA, self.smack_path)) - self.target.run('echo -n "%s" > %s/load' %(RuleB, self.smack_path)) - status, output = self.target.run("%s %s 0 2" % (mmap_exe, test_file)) - self.assertNotEqual( - status, 0, - "Should not have mmap access with unmatching rules. " + - "Output: %s" %output) - self.assertIn( - "Permission denied", output, - "Mmap access should be denied with unmatching rules") - - # add rule to match only partially (one way) - self.target.run('echo -n "%s" > %s/load' %(RuleC, self.smack_path)) - status, output = self.target.run("%s %s 0 2" %(mmap_exe, test_file)) - self.assertNotEqual( - status, 0, - "Should not have mmap access with partial matching rules. " + - "Output: %s" %output) - self.assertIn( - "Permission denied", output, - "Mmap access should be denied with partial matching rules") - - # add rule to match fully - self.target.run('echo -n "%s" > %s/load' %(RuleD, self.smack_path)) - status, output = self.target.run("%s %s 0 2" %(mmap_exe, test_file)) - self.assertEqual( - status, 0, - "Should have mmap access with full matching rules." + - "Output: %s" %output) - - @OETestDepends(['smack.SmackBasicTest.test_smack_basic']) def test_smack_transmute_dir(self): '''Test if smack transmute attribute works
Signature · 1 line
2.25.1
PATCH 4/9 aide: add a few more config options
In reply to Armin Kuster--- recipes-ids/aide/aide_0.17.4.bb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
recipes-ids/aide/aide_0.17.4.bb +3 -1
@@ -12,7 +12,7 @@ SRC_URI[sha256sum] = "c81505246f3ffc2e76036d43a77212ae82895b5881d9b9e25c1361b1a9 inherit autotools pkgconfig -PACKAGECONFIG ??=" mhash zlib e2fsattrs \ +PACKAGECONFIG ??=" mhash zlib e2fsattrs posix capabilities curl \ ${@bb.utils.contains('DISTRO_FEATURES', 'selinux', 'selinux audit', '', d)} \ ${@bb.utils.contains('DISTRO_FEATURES', 'xattr', 'xattr', '', d)} \ "
@@ -24,6 +24,8 @@ PACKAGECONFIG[audit] = "--with-audit, --without-audit,audit" PACKAGECONFIG[gcrypt] = "--with-gcrypt, --without-gcrypt, libgcrypt, libgcrypt" PACKAGECONFIG[mhash] = "--with-mhash, --without-mhash, libmhash, libmhash" PACKAGECONFIG[e2fsattrs] = "--with-e2fsattrs, --without-e2fsattrs, e2fsprogs, e2fsprogs" +PACKAGECONFIG[capabilities] = "--with-capabilities, --without-capabilities, libcap, libcap" +PACKAGECONFIG[posix] = "--with-posix-acl, --without-posix-acl, acl, acl" do_install:append () { install -d ${D}${libdir}/${PN}/logs
Signature · 1 line
2.25.1
PATCH 5/9 oeqa: add aide test
In reply to Armin Kuster--- lib/oeqa/runtime/cases/aide.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 lib/oeqa/runtime/cases/aide.py
lib/oeqa/runtime/cases/aide.py new file +26 -0
@@ -0,0 +1,26 @@ +# Copyright (C) 2022 Armin Kuster <[email protected]> +# +import re + +from oeqa.runtime.case import OERuntimeTestCase +from oeqa.core.decorator.depends import OETestDepends +from oeqa.runtime.decorator.package import OEHasPackage + + +class AideTest(OERuntimeTestCase): + + @OEHasPackage(['aide']) + @OETestDepends(['ssh.SSHTest.test_ssh']) + def test_aide_help(self): + status, output = self.target.run('aide --help') + msg = ('Aide help command does not work as expected. ' + 'Status and output:%s and %s' % (status, output)) + self.assertEqual(status, 0, msg = msg) + + @OETestDepends(['aide.AideTest.test_aide_help']) + def test_aide_dbinit(self): + status, output = self.target.run('aide --init') + match = re.search('Number of entries:', output) + if not match: + msg = ('Aide db init failed: output is:\n%s' % output) + self.assertEqual(status, 0, msg = msg)
Signature · 1 line
2.25.1
PATCH 6/9 libmhash: add native pkg support
In reply to Armin Kuster--- recipes-security/libmhash/libmhash_0.9.9.9.bb | 2 ++ 1 file changed, 2 insertions(+)
recipes-security/libmhash/libmhash_0.9.9.9.bb +2 -0
@@ -35,3 +35,5 @@ do_compile_ptest() { do_install_ptest() { install -m 0755 ${S}/demo/mhash ${D}${PTEST_PATH} } + +BBCLASSEXTEND = "native"
Signature · 1 line
2.25.1
PATCH 7/9 classes: add aide routines
In reply to Armin Kuster--- classes/aide-base.bbclass | 11 ++++++++ classes/aide-db-init.bbclass | 52 ++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 classes/aide-base.bbclass create mode 100644 classes/aide-db-init.bbclass
classes/aide-base.bbclass new file +11 -0
@@ -0,0 +1,11 @@ +# +# Copyright 2022 Armin Kuster <[email protected]> +# + +STAGING_AIDE_DIR ?= "${TMPDIR}/work-shared/${MACHINE}/aida" +AIDE_INCLUDE_DIRS ?= "/lib" +AIDE_SKIP_DIRS ?= "/lib/modules/.\*" + +AIDE_SCAN_POSTINIT ?= "0" +AIDE_RESCAN_POSTINIT ?= "0" +
classes/aide-db-init.bbclass new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH 8/9 aide: add native support for build time db creation
In reply to Armin KusterThis will help create a aide db during build that is then installed on the rootfs for verification at boot time.
This work was inspired by:
Marco Cavallini
Yocto Project Ambassador
--- recipes-ids/aide/aide_0.17.4.bb | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)
recipes-ids/aide/aide_0.17.4.bb +30 -2
@@ -10,7 +10,7 @@ SRC_URI = "https://github.com/aide/aide/releases/download/v${PV}/${BPN}-${PV}.ta SRC_URI[sha256sum] = "c81505246f3ffc2e76036d43a77212ae82895b5881d9b9e25c1361b1a9b7a846" -inherit autotools pkgconfig +inherit autotools pkgconfig aide-base PACKAGECONFIG ??=" mhash zlib e2fsattrs posix capabilities curl \ ${@bb.utils.contains('DISTRO_FEATURES', 'selinux', 'selinux audit', '', d)} \
@@ -27,10 +27,31 @@ PACKAGECONFIG[e2fsattrs] = "--with-e2fsattrs, --without-e2fsattrs, e2fsprogs, e2 PACKAGECONFIG[capabilities] = "--with-capabilities, --without-capabilities, libcap, libcap" PACKAGECONFIG[posix] = "--with-posix-acl, --without-posix-acl, acl, acl" + +do_install[nostamp] = "1" + do_install:append () { install -d ${D}${libdir}/${PN}/logs install -d ${D}${sysconfdir} install ${WORKDIR}/aide.conf ${D}${sysconfdir}/ + + for dir in ${AIDE_INCLUDE_DIRS}; do + echo "${dir} NORMAL" >> ${D}${sysconfdir}/aide.conf + done + for dir in ${AIDE_SKIP_DIRS}; do + echo "!${dir}" >> ${D}${sysconfdir}/aide.conf + done +} + +do_install:class-native () { + install -d ${STAGING_AIDE_DIR}/bin + install -d ${STAGING_AIDE_DIR}/lib/logs + + install ${B}/aide ${STAGING_AIDE_DIR}/bin + install ${WORKDIR}/aide.conf ${STAGING_AIDE_DIR}/ + + sed -i -s "s:\@\@define DBDIR.*:\@\@define DBDIR ${STAGING_AIDE_DIR}/lib:" ${STAGING_AIDE_DIR}/aide.conf + sed -i -e "s:\@\@define LOGDIR.*:\@\@define LOGDIR ${STAGING_AIDE_DIR}/lib/logs:" ${STAGING_AIDE_DIR}/aide.conf } CONF_FILE = "${sysconfdir}/aide.conf"
@@ -38,7 +59,14 @@ CONF_FILE = "${sysconfdir}/aide.conf" FILES:${PN} += "${libdir}/${PN} ${sysconfdir}/aide.conf" pkg_postinst_ontarget:${PN} () { - /usr/bin/aide -i + if [ ${AIDE_SCAN_POSTINIT} ]; then + ${bindir}/aide -i + fi + if [ ${AIDE_RESCAN_POSTINIT} && -e ${libdir}/aide/aide.db.gz ]; then + ${bindir}/aide -C + fi } RDEPENDS:${PN} = "bison libpcre" + +BBCLASSEXTEND = "native"
Signature · 1 line
2.25.1
PATCH 9/9 aide.conf: adjust to allow for build time db creation
In reply to Armin Kuster--- recipes-ids/aide/aide/aide.conf | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
recipes-ids/aide/aide/aide.conf +4 -7
@@ -51,7 +51,7 @@ report_url=stdout #crc32: crc32 checksum (MHASH only) #whirlpool: whirlpool checksum (MHASH only) -FIPSR = p+i+n+u+g+s+m+c+acl+selinux+xattrs+sha256 +FIPSR = p+u+g+s+acl+xattrs+sha256 #R: p+i+n+u+g+s+m+c+acl+selinux+xattrs+md5 #L: p+i+n+u+g+acl+selinux+xattrs
@@ -70,10 +70,10 @@ EVERYTHING = R+ALLXTRAHASHES NORMAL = FIPSR+sha512 # For directories, don't bother doing hashes -DIR = p+i+n+u+g+acl+selinux+xattrs +DIR = p+u+g+acl+xattrs # Access control only -PERMS = p+i+u+g+acl+selinux +PERMS = p+u+g+acl # Logfile are special, in that they often change LOG = >
@@ -83,12 +83,9 @@ LSPP = FIPSR+sha512 # Some files get updated automatically, so the inode/ctime/mtime change # but we want to know when the data inside them changes -DATAONLY = p+n+u+g+s+acl+selinux+xattrs+sha256 +DATAONLY = p+u+g+s+acl+xattrs+sha256 # Next decide what directories/files you want in the database. # Check only permissions, inode, user and group for /etc, but # cover some important files closely. -/bin NORMAL -/sbin NORMAL -/lib NORMAL
Signature · 1 line
2.25.1