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

SELinux libs and tools: 2.4 -> 2.7 #36978

Merged
merged 11 commits into from Mar 27, 2018
Merged

SELinux libs and tools: 2.4 -> 2.7 #36978

merged 11 commits into from Mar 27, 2018

Conversation

xeji
Copy link
Contributor

@xeji xeji commented Mar 14, 2018

Motivation for this change

Our SELinux 2.4 is >3 yrs old and produces some build fails with gcc7.
[WIP] since this update involves multiple packages which will be added here incrementally.

/cc @Phreedom @andir

@Mic92
Copy link
Member

Mic92 commented Mar 14, 2018

Has anyone a working selinux on NixOS actually? I did not even manage to enable it.

@xeji
Copy link
Contributor Author

xeji commented Mar 14, 2018

I want to give it a try, that's why I am doing this first.

@Mic92
Copy link
Member

Mic92 commented Mar 15, 2018

I would be glad to see this. I currently have to boot fedora to test selinux support in https://github.com/Mic92/cntr

@Mic92
Copy link
Member

Mic92 commented Mar 15, 2018

I would not be surprise that I was not able to enable it because of the age of selinux tools in comparison to the kernel.

@Mic92
Copy link
Member

Mic92 commented Mar 15, 2018

@GrahamcOfBorg build libsepool libselinux libsemanage policycoreutils checkpolicy

@GrahamcOfBorg
Copy link

No attempt on x86_64-darwin

The following builds were skipped because they don't evaluate on x86_64-darwin: libsepool, libselinux, libsemanage, policycoreutils, checkpolicy

No log is available.

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: libselinux, libsemanage, policycoreutils, checkpolicy

The following builds were skipped because they don't evaluate on x86_64-linux: libsepool

Partial log (click to expand)

strip is /nix/store/b0zlxla7dmy1iwc3g459rjznx59797xy-binutils-2.28.1/bin/strip
stripping (with command strip and flags -S) in /nix/store/276dvgnylyflqnv8f8gs9j4r4yvf8s5i-policycoreutils-2.7/libexec  /nix/store/276dvgnylyflqnv8f8gs9j4r4yvf8s5i-policycoreutils-2.7/bin  /nix/store/276dvgnylyflqnv8f8gs9j4r4yvf8s5i-policycoreutils-2.7/sbin
patching script interpreter paths in /nix/store/276dvgnylyflqnv8f8gs9j4r4yvf8s5i-policycoreutils-2.7
/nix/store/276dvgnylyflqnv8f8gs9j4r4yvf8s5i-policycoreutils-2.7/sbin/fixfiles: interpreter directive changed from "/bin/bash" to "/nix/store/zqh3l3lyw32q1ayb15bnvg9f24j5v2p0-bash-4.4-p12/bin/bash"
checking for references to /build in /nix/store/276dvgnylyflqnv8f8gs9j4r4yvf8s5i-policycoreutils-2.7...
moving /nix/store/276dvgnylyflqnv8f8gs9j4r4yvf8s5i-policycoreutils-2.7/sbin/* to /nix/store/276dvgnylyflqnv8f8gs9j4r4yvf8s5i-policycoreutils-2.7/bin
/nix/store/zw1m95k8rhhzn13ipz3p5b56gb4qr93w-libselinux-2.7
/nix/store/xyi7sq79bkpx6wwqqbgjp3l3rasd3c7q-libsemanage-2.7
/nix/store/276dvgnylyflqnv8f8gs9j4r4yvf8s5i-policycoreutils-2.7
/nix/store/xzifskgagi70z9cw77z9cib1mfd59vv0-checkpolicy-2.7

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: libselinux, libsemanage, policycoreutils, checkpolicy

The following builds were skipped because they don't evaluate on aarch64-linux: libsepool

Partial log (click to expand)

strip is /nix/store/lvx1acn1ig1j2km8jds5x3ggh3f2wa8v-binutils-2.28.1/bin/strip
stripping (with command strip and flags -S) in /nix/store/hq0m5kfq923299n3k6sh8mjm63b5aq56-policycoreutils-2.7/libexec  /nix/store/hq0m5kfq923299n3k6sh8mjm63b5aq56-policycoreutils-2.7/bin  /nix/store/hq0m5kfq923299n3k6sh8mjm63b5aq56-policycoreutils-2.7/sbin
patching script interpreter paths in /nix/store/hq0m5kfq923299n3k6sh8mjm63b5aq56-policycoreutils-2.7
/nix/store/hq0m5kfq923299n3k6sh8mjm63b5aq56-policycoreutils-2.7/sbin/fixfiles: interpreter directive changed from "/bin/bash" to "/nix/store/lnws52qanbi5vz8qg24v4ym57nznfndg-bash-4.4-p12/bin/bash"
checking for references to /build in /nix/store/hq0m5kfq923299n3k6sh8mjm63b5aq56-policycoreutils-2.7...
moving /nix/store/hq0m5kfq923299n3k6sh8mjm63b5aq56-policycoreutils-2.7/sbin/* to /nix/store/hq0m5kfq923299n3k6sh8mjm63b5aq56-policycoreutils-2.7/bin
/nix/store/k39qmghs50z7igga6bcplx2jqy8syjfx-libselinux-2.7
/nix/store/0sr2ywbc4j62z2yfsagj6f20fn8zpd88-libsemanage-2.7
/nix/store/hq0m5kfq923299n3k6sh8mjm63b5aq56-policycoreutils-2.7
/nix/store/mh6gcyvsamz0icnbnkq3144mlsip4v31-checkpolicy-2.7

@xeji
Copy link
Contributor Author

xeji commented Mar 16, 2018

@GrahamcOfBorg build libsepol libselinux libsemanage policycoreutils checkpolicy

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: libsepol, libselinux, libsemanage, policycoreutils, checkpolicy

Partial log (click to expand)

stripping (with command strip and flags -S) in /nix/store/n6lb7r5yxccgdq9z7wvp3v8pzbj3kv8w-policycoreutils-2.7/libexec  /nix/store/n6lb7r5yxccgdq9z7wvp3v8pzbj3kv8w-policycoreutils-2.7/bin  /nix/store/n6lb7r5yxccgdq9z7wvp3v8pzbj3kv8w-policycoreutils-2.7/sbin
patching script interpreter paths in /nix/store/n6lb7r5yxccgdq9z7wvp3v8pzbj3kv8w-policycoreutils-2.7
/nix/store/n6lb7r5yxccgdq9z7wvp3v8pzbj3kv8w-policycoreutils-2.7/sbin/fixfiles: interpreter directive changed from "/bin/bash" to "/nix/store/q1g0rl8zfmz7r371fp5p42p4acmv297d-bash-4.4-p19/bin/bash"
checking for references to /build in /nix/store/n6lb7r5yxccgdq9z7wvp3v8pzbj3kv8w-policycoreutils-2.7...
moving /nix/store/n6lb7r5yxccgdq9z7wvp3v8pzbj3kv8w-policycoreutils-2.7/sbin/* to /nix/store/n6lb7r5yxccgdq9z7wvp3v8pzbj3kv8w-policycoreutils-2.7/bin
/nix/store/6ri8425ij5f1bjmhr0wx722dhml1ir78-libsepol-2.7
/nix/store/5gl66m6kgrpyy8i80fmbyqvsfxvj9phg-libselinux-2.7
/nix/store/0jn58hb0k4zc3jnd79pj20nbng0910jf-libsemanage-2.7
/nix/store/n6lb7r5yxccgdq9z7wvp3v8pzbj3kv8w-policycoreutils-2.7
/nix/store/3igiz2cgimbqhc2fzka0p8crv8qlmqnv-checkpolicy-2.7

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: libsepol, libselinux, libsemanage, policycoreutils, checkpolicy

Partial log (click to expand)

stripping (with command strip and flags -S) in /nix/store/7749nh3bly19q38srw4yjv43wi2fw2am-policycoreutils-2.7/libexec  /nix/store/7749nh3bly19q38srw4yjv43wi2fw2am-policycoreutils-2.7/bin  /nix/store/7749nh3bly19q38srw4yjv43wi2fw2am-policycoreutils-2.7/sbin
patching script interpreter paths in /nix/store/7749nh3bly19q38srw4yjv43wi2fw2am-policycoreutils-2.7
/nix/store/7749nh3bly19q38srw4yjv43wi2fw2am-policycoreutils-2.7/sbin/fixfiles: interpreter directive changed from "/bin/bash" to "/nix/store/3gg2p6n4kv2f0lsxd41f5iz1ivkbzyzr-bash-4.4-p19/bin/bash"
checking for references to /build in /nix/store/7749nh3bly19q38srw4yjv43wi2fw2am-policycoreutils-2.7...
moving /nix/store/7749nh3bly19q38srw4yjv43wi2fw2am-policycoreutils-2.7/sbin/* to /nix/store/7749nh3bly19q38srw4yjv43wi2fw2am-policycoreutils-2.7/bin
/nix/store/xvhmxmkx2jmis72nywgn5ha5qp20b8ba-libsepol-2.7
/nix/store/xrs3h0d8iby18mk0vr1wiiqmkrxnc9r3-libselinux-2.7
/nix/store/1prjv8gm5pydr2cpnhskq6738kccxnim-libsemanage-2.7
/nix/store/7749nh3bly19q38srw4yjv43wi2fw2am-policycoreutils-2.7
/nix/store/73ms89sm8kl67jf5fc5icrknmdby1n9r-checkpolicy-2.7

@xeji
Copy link
Contributor Author

xeji commented Mar 20, 2018

@GrahamcOfBorg build setools

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: setools

Partial log (click to expand)

RoleTransition default role ... ok
test_060_conditional (tests.policyrep.rbacrule.RoleTransitionTest)
RoleTransition conditional expression ... ok
test_100_statement (tests.policyrep.rbacrule.RoleTransitionTest)
RoleTransition statement. ... ok

----------------------------------------------------------------------
Ran 1358 tests in 4.913s

OK (skipped=17, expected failures=1)

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: setools

Partial log (click to expand)

Boolean query with exact match ... ok
test_002_name_regex (tests.boolquery.BoolQueryTest)
Boolean query with regex match. ... ok
test_010_default (tests.boolquery.BoolQueryTest)
Boolean query with default state match. ... ok

----------------------------------------------------------------------
Ran 1358 tests in 27.757s

OK (skipped=17, expected failures=1)

@xeji
Copy link
Contributor Author

xeji commented Mar 20, 2018

@GrahamcOfBorg build selinux-python

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: selinux-python

Partial log (click to expand)

/nix/store/5hhzhs1z8dl2h09sm018ygvyg8nn7433-selinux-python-2.7/bin/sepolicy: interpreter directive changed from " /usr/bin/python -Es" to "/nix/store/b8gd0cbvkm59x8flbc53bvsvmskyig5a-python3-3.6.4/bin/python -Es"
/nix/store/5hhzhs1z8dl2h09sm018ygvyg8nn7433-selinux-python-2.7/lib/python3.6/site-packages/seobject.py: interpreter directive changed from " /usr/bin/python -Es" to "/nix/store/b8gd0cbvkm59x8flbc53bvsvmskyig5a-python3-3.6.4/bin/python -Es"
/nix/store/5hhzhs1z8dl2h09sm018ygvyg8nn7433-selinux-python-2.7/sbin/semanage: interpreter directive changed from " /usr/bin/python -Es" to "/nix/store/b8gd0cbvkm59x8flbc53bvsvmskyig5a-python3-3.6.4/bin/python -Es"
checking for references to /tmp/nix-build-selinux-python-2.7.drv-0 in /nix/store/5hhzhs1z8dl2h09sm018ygvyg8nn7433-selinux-python-2.7...
moving /nix/store/5hhzhs1z8dl2h09sm018ygvyg8nn7433-selinux-python-2.7/sbin/* to /nix/store/5hhzhs1z8dl2h09sm018ygvyg8nn7433-selinux-python-2.7/bin
wrapping `/nix/store/5hhzhs1z8dl2h09sm018ygvyg8nn7433-selinux-python-2.7/bin/sepolgen-ifgen'...
wrapping `/nix/store/5hhzhs1z8dl2h09sm018ygvyg8nn7433-selinux-python-2.7/bin/audit2allow'...
wrapping `/nix/store/5hhzhs1z8dl2h09sm018ygvyg8nn7433-selinux-python-2.7/bin/chcat'...
wrapping `/nix/store/5hhzhs1z8dl2h09sm018ygvyg8nn7433-selinux-python-2.7/bin/semanage'...
wrapping `/nix/store/5hhzhs1z8dl2h09sm018ygvyg8nn7433-selinux-python-2.7/bin/sepolicy'...

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: selinux-python

Partial log (click to expand)

/nix/store/ajh6zd3l1w5vahl3hqhcbckakrrmb3rq-selinux-python-2.7/bin/sepolicy: interpreter directive changed from " /usr/bin/python -Es" to "/nix/store/143hazf8s5236kvprxlrgw9fdgzkrg0v-python3-3.6.4/bin/python -Es"
/nix/store/ajh6zd3l1w5vahl3hqhcbckakrrmb3rq-selinux-python-2.7/lib/python3.6/site-packages/seobject.py: interpreter directive changed from " /usr/bin/python -Es" to "/nix/store/143hazf8s5236kvprxlrgw9fdgzkrg0v-python3-3.6.4/bin/python -Es"
checking for references to /build in /nix/store/ajh6zd3l1w5vahl3hqhcbckakrrmb3rq-selinux-python-2.7...
moving /nix/store/ajh6zd3l1w5vahl3hqhcbckakrrmb3rq-selinux-python-2.7/sbin/* to /nix/store/ajh6zd3l1w5vahl3hqhcbckakrrmb3rq-selinux-python-2.7/bin
wrapping `/nix/store/ajh6zd3l1w5vahl3hqhcbckakrrmb3rq-selinux-python-2.7/bin/semanage'...
wrapping `/nix/store/ajh6zd3l1w5vahl3hqhcbckakrrmb3rq-selinux-python-2.7/bin/sepolicy'...
wrapping `/nix/store/ajh6zd3l1w5vahl3hqhcbckakrrmb3rq-selinux-python-2.7/bin/audit2allow'...
wrapping `/nix/store/ajh6zd3l1w5vahl3hqhcbckakrrmb3rq-selinux-python-2.7/bin/sepolgen-ifgen'...
wrapping `/nix/store/ajh6zd3l1w5vahl3hqhcbckakrrmb3rq-selinux-python-2.7/bin/chcat'...
/nix/store/ajh6zd3l1w5vahl3hqhcbckakrrmb3rq-selinux-python-2.7

nativeBuildInputs = [ autoreconfHook pkgconfig python swig2 bison flex ];
buildInputs = [ tcl libxml2 sqlite bzip2 ];
preBuild = ''
export SEPOL="${libsepol}/lib/libsepol.a"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is libsepol supposed to be statically linked?

@xeji
Copy link
Contributor Author

xeji commented Mar 20, 2018 via email

@xeji
Copy link
Contributor Author

xeji commented Mar 20, 2018

@GrahamcOfBorg build selinux-sandbox

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: selinux-sandbox

Partial log (click to expand)

strip is /nix/store/fzcs0fn6bb04m82frhlb78nc03ny3w55-binutils-2.28.1/bin/strip
stripping (with command strip and flags -S) in /nix/store/qnqjfzw4fyr8pcspv3rdnfcplyda9dcr-selinux-sandbox-2.7/bin  /nix/store/qnqjfzw4fyr8pcspv3rdnfcplyda9dcr-selinux-sandbox-2.7/sbin
patching script interpreter paths in /nix/store/qnqjfzw4fyr8pcspv3rdnfcplyda9dcr-selinux-sandbox-2.7
/nix/store/qnqjfzw4fyr8pcspv3rdnfcplyda9dcr-selinux-sandbox-2.7/share/sandbox/start: interpreter directive changed from " /usr/bin/python -Es" to "/nix/store/b8gd0cbvkm59x8flbc53bvsvmskyig5a-python3-3.6.4/bin/python -Es"
/nix/store/qnqjfzw4fyr8pcspv3rdnfcplyda9dcr-selinux-sandbox-2.7/share/sandbox/sandboxX.sh: interpreter directive changed from "/bin/bash" to "/nix/store/q1g0rl8zfmz7r371fp5p42p4acmv297d-bash-4.4-p19/bin/bash"
/nix/store/qnqjfzw4fyr8pcspv3rdnfcplyda9dcr-selinux-sandbox-2.7/bin/sandbox: interpreter directive changed from " /usr/bin/python -Es" to "/nix/store/b8gd0cbvkm59x8flbc53bvsvmskyig5a-python3-3.6.4/bin/python -Es"
checking for references to /tmp/nix-build-selinux-sandbox-2.7.drv-0 in /nix/store/qnqjfzw4fyr8pcspv3rdnfcplyda9dcr-selinux-sandbox-2.7...
moving /nix/store/qnqjfzw4fyr8pcspv3rdnfcplyda9dcr-selinux-sandbox-2.7/sbin/* to /nix/store/qnqjfzw4fyr8pcspv3rdnfcplyda9dcr-selinux-sandbox-2.7/bin
wrapping `/nix/store/qnqjfzw4fyr8pcspv3rdnfcplyda9dcr-selinux-sandbox-2.7/bin/sandbox'...
/nix/store/qnqjfzw4fyr8pcspv3rdnfcplyda9dcr-selinux-sandbox-2.7

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: selinux-sandbox

Partial log (click to expand)

strip is /nix/store/3zq400fri5dv7d30lpxlqm2v9y1iis6j-binutils-2.28.1/bin/strip
stripping (with command strip and flags -S) in /nix/store/dy8vlsl18x439sbydss4bw0718gfdc7n-selinux-sandbox-2.7/bin  /nix/store/dy8vlsl18x439sbydss4bw0718gfdc7n-selinux-sandbox-2.7/sbin
patching script interpreter paths in /nix/store/dy8vlsl18x439sbydss4bw0718gfdc7n-selinux-sandbox-2.7
/nix/store/dy8vlsl18x439sbydss4bw0718gfdc7n-selinux-sandbox-2.7/share/sandbox/start: interpreter directive changed from " /usr/bin/python -Es" to "/nix/store/143hazf8s5236kvprxlrgw9fdgzkrg0v-python3-3.6.4/bin/python -Es"
/nix/store/dy8vlsl18x439sbydss4bw0718gfdc7n-selinux-sandbox-2.7/share/sandbox/sandboxX.sh: interpreter directive changed from "/bin/bash" to "/nix/store/3gg2p6n4kv2f0lsxd41f5iz1ivkbzyzr-bash-4.4-p19/bin/bash"
/nix/store/dy8vlsl18x439sbydss4bw0718gfdc7n-selinux-sandbox-2.7/bin/sandbox: interpreter directive changed from " /usr/bin/python -Es" to "/nix/store/143hazf8s5236kvprxlrgw9fdgzkrg0v-python3-3.6.4/bin/python -Es"
checking for references to /build in /nix/store/dy8vlsl18x439sbydss4bw0718gfdc7n-selinux-sandbox-2.7...
moving /nix/store/dy8vlsl18x439sbydss4bw0718gfdc7n-selinux-sandbox-2.7/sbin/* to /nix/store/dy8vlsl18x439sbydss4bw0718gfdc7n-selinux-sandbox-2.7/bin
wrapping `/nix/store/dy8vlsl18x439sbydss4bw0718gfdc7n-selinux-sandbox-2.7/bin/sandbox'...
/nix/store/dy8vlsl18x439sbydss4bw0718gfdc7n-selinux-sandbox-2.7

@xeji
Copy link
Contributor Author

xeji commented Mar 20, 2018

@GrahamcOfBorg build libsepol libselinux libsemanage policycoreutils checkpolicy

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: checkpolicy, libselinux, libsemanage, libsepol, policycoreutils, selinux-python, selinux-sandbox, setools

Partial log (click to expand)

moving /nix/store/mssq69yg4livphqx3ms1fqnyj6m8fman-selinux-sandbox-2.7/sbin/* to /nix/store/mssq69yg4livphqx3ms1fqnyj6m8fman-selinux-sandbox-2.7/bin
wrapping `/nix/store/mssq69yg4livphqx3ms1fqnyj6m8fman-selinux-sandbox-2.7/bin/sandbox'...
/nix/store/73ms89sm8kl67jf5fc5icrknmdby1n9r-checkpolicy-2.7
/nix/store/xrs3h0d8iby18mk0vr1wiiqmkrxnc9r3-libselinux-2.7
/nix/store/1prjv8gm5pydr2cpnhskq6738kccxnim-libsemanage-2.7
/nix/store/xvhmxmkx2jmis72nywgn5ha5qp20b8ba-libsepol-2.7
/nix/store/7749nh3bly19q38srw4yjv43wi2fw2am-policycoreutils-2.7
/nix/store/ajh6zd3l1w5vahl3hqhcbckakrrmb3rq-selinux-python-2.7
/nix/store/mssq69yg4livphqx3ms1fqnyj6m8fman-selinux-sandbox-2.7
/nix/store/61mk7sw3zbdd83sigax1qbdnik0zrbax-setools-2017-11-10

@dtzWill
Copy link
Member

dtzWill commented Mar 26, 2018

👍

@Mic92
Copy link
Member

Mic92 commented Mar 26, 2018

@xeji did you manage to get selinux running on nixos and if what flags where required? Otherwise I could test on fedora.

@xeji
Copy link
Contributor Author

xeji commented Mar 26, 2018

@Mic92 not yet - it's on my list for the next few days. Testing on fedora would be good anyway to confirm the tools work independent of nixos setup.

@xeji
Copy link
Contributor Author

xeji commented Mar 26, 2018

@Mic92 some quick first tests show you need boot.kernelParams = [ "security=selinux" "selinux=1" ]; to boot nixos with selinux. Then the logs look promising:

# dmesg | grep -i selinux
[    0.001588] SELinux:  Initializing.
[    0.001592] SELinux:  Starting in permissive mode
[    0.382732] SELinux:  Registering netfilter hooks
[    1.574033] systemd[1]: systemd 237 running in system mode. (+PAM +AUDIT -SELINUX +IMA +APPARMOR +SMACK -SYSVINIT +UTMP -LIBCRYPTSETUP +GCRYPT -GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID -ELFUTILS +KMOD +IDN2 -IDN -PCRE2 default-hierarchy=hybrid)

However, after boot selinux still shows as disabled:

# sestatus
SELinux status:                 disabled

I suspect the -SELINUX in systemd build config prevents it from working, so we would probably have to override and rebuild systemd. Don't know how to do that (it's a separate NixOS repo ?).
Anyway, this situation looks already better than selinux 2.4 which caused systemd-related kernel backtraces...

@dtzWill
Copy link
Member

dtzWill commented Mar 26, 2018

I suspect the -SELINUX in systemd build config prevents it from working, so we would probably have to override and rebuild systemd. Don't know how to do that (it's a separate NixOS repo ?).
Anyway, this situation looks already better than selinux 2.4 which caused systemd-related kernel backtraces...

I believe that means it wasn't available at compile-time (or that we forced it off with -Dselinux=false, which we don't)-- which seems like a good starting point. No clue what else might need changing, if anything, though.

Also, yay!

@Mic92
Copy link
Member

Mic92 commented Mar 26, 2018

@xeji looking at systemd is a good hint. It is possible to enable selinux in systemd without recompiling everything by loading a custom systemd with systemd.package = in configuration.nix. I will skim over the code to see if I can find something interesting.

@xeji
Copy link
Contributor Author

xeji commented Mar 26, 2018

Looking at the systemd expression, we don't disable selinux. But we don't list libselinux (that's what I guess it would be) as build input either. So if we're lucky, just adding that may hopefully configure systemd with +SELINUX. I'll give that a try when I have time for a lengthy build...

@Mic92
Copy link
Member

Mic92 commented Mar 26, 2018

selinux_init_load_policy seems to enable selinux globally:
https://github.com/systemd/systemd/blob/master/src/core/selinux-setup.c#L81

@xeji
Copy link
Contributor Author

xeji commented Mar 26, 2018

https://github.com/systemd/systemd/blob/ffb3c2bd705409ca5bbbb9ccef4c59349ea787cf/meson.build#L850
if libselinux is present, systemd builds with it

false by default, so no rebuild
@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: checkpolicy, libselinux, libsemanage, libsepol, policycoreutils, selinux-python, selinux-sandbox, setools, systemd

Partial log (click to expand)

wrapping `/nix/store/1wh7qmmwzgmqs0vsg8yzbnbd36gbxrag-selinux-sandbox-2.7/bin/sandbox'...
/nix/store/3igiz2cgimbqhc2fzka0p8crv8qlmqnv-checkpolicy-2.7
/nix/store/5gl66m6kgrpyy8i80fmbyqvsfxvj9phg-libselinux-2.7
/nix/store/0jn58hb0k4zc3jnd79pj20nbng0910jf-libsemanage-2.7
/nix/store/6ri8425ij5f1bjmhr0wx722dhml1ir78-libsepol-2.7
/nix/store/n6lb7r5yxccgdq9z7wvp3v8pzbj3kv8w-policycoreutils-2.7
/nix/store/5hhzhs1z8dl2h09sm018ygvyg8nn7433-selinux-python-2.7
/nix/store/1wh7qmmwzgmqs0vsg8yzbnbd36gbxrag-selinux-sandbox-2.7
/nix/store/74vmcgkg3vk8siz7f58qp5bz9lyjwibp-setools-2017-11-10
/nix/store/aw6jabbci1k81j6hvyskkhb3va45wws2-systemd-237

@xeji
Copy link
Contributor Author

xeji commented Mar 27, 2018

The last commit adds a withSelinux option to systemd to build it with selinux support, false by default so this should not trigger a rebuild. Now nixos boots with selinux enabled using this config.
For a fully functional selinux-enabled system we might also have to rebuild other packages like coreutils and util-linux with selinux support according to the Arch wiki.

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: checkpolicy, libselinux, libsemanage, libsepol, policycoreutils, selinux-python, selinux-sandbox, setools, systemd

Partial log (click to expand)

wrapping `/nix/store/mssq69yg4livphqx3ms1fqnyj6m8fman-selinux-sandbox-2.7/bin/sandbox'...
/nix/store/73ms89sm8kl67jf5fc5icrknmdby1n9r-checkpolicy-2.7
/nix/store/xrs3h0d8iby18mk0vr1wiiqmkrxnc9r3-libselinux-2.7
/nix/store/1prjv8gm5pydr2cpnhskq6738kccxnim-libsemanage-2.7
/nix/store/xvhmxmkx2jmis72nywgn5ha5qp20b8ba-libsepol-2.7
/nix/store/7749nh3bly19q38srw4yjv43wi2fw2am-policycoreutils-2.7
/nix/store/ajh6zd3l1w5vahl3hqhcbckakrrmb3rq-selinux-python-2.7
/nix/store/mssq69yg4livphqx3ms1fqnyj6m8fman-selinux-sandbox-2.7
/nix/store/61mk7sw3zbdd83sigax1qbdnik0zrbax-setools-2017-11-10
/nix/store/z7hj2mx7n4j6vpzqssr4bsc6anxdi58x-systemd-237

@Mic92
Copy link
Member

Mic92 commented Mar 27, 2018

@xeji I suppose this selinux snippet could become a module later. Thanks for making selinux work. I need this for testing some software.

@Mic92 Mic92 merged commit 00a4300 into NixOS:master Mar 27, 2018
@pbogdan
Copy link
Member

pbogdan commented Mar 27, 2018

Just a heads up - it seems libsepol doesn't build on i686-linux (https://hydra.nixos.org/build/72006419) which is holding up the build of the minimal iso for that platform (part of the unstable channel tested job). No idea how to fix it though :-(.

@xeji
Copy link
Contributor Author

xeji commented Mar 27, 2018

@pbogdan thanks. The error looks like it can be fixed by ignoring a warning, I'll give that a try later, cannot hurt. But I have no idea how to test a i686 build. Is there a way to cross-build this on a x86_64 machine? Never tried...

@pbogdan
Copy link
Member

pbogdan commented Mar 27, 2018

Yeah, at least for i686-linux you can build it with nix-build -A libsepol --argstr system i686-linux.

@xeji
Copy link
Contributor Author

xeji commented Mar 27, 2018

@Mic92 a selinux module would be nice, let's keep that in mind. Probably quite a bit of work since we need some sort of policy builder/patcher tool to create policies that fit a nixos system.

@xeji xeji deleted the selinux-2-7 branch March 27, 2018 20:10
@Mic92
Copy link
Member

Mic92 commented Mar 28, 2018

@xeji I think supporting containers/vms would be already useful. docker/lxc/systemd-nspawn already apply profiles.

substituteInPlace Makefile --replace "-m 4755" "-m 755"
substituteInPlace sandboxX.sh \
--replace "#!/bin/sh" "#!${bash}/bin/sh" \
--replace "/usr/share/sandbox/start" "${placeholder "out"}/share/sandbox/start" \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work for Nix 1.11 users, please correct this as seen in #37860

@xeji
Copy link
Contributor Author

xeji commented Mar 28, 2018 via email

@infinisil
Copy link
Member

The minimum version required is still 1.11, not 2.0: https://github.com/NixOS/nixpkgs/blob/master/lib/minver.nix

@jtojnar
Copy link
Contributor

jtojnar commented Mar 28, 2018

Fixed in 025881c

@jtojnar jtojnar mentioned this pull request Mar 28, 2018
8 tasks
@xeji
Copy link
Contributor Author

xeji commented Mar 28, 2018

Thanks @jtojnar !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants