CentOS 6 kickstart 忽略“selinux --disabled”

Zyp*_*her 8 selinux kickstart centos

我一直在与这个问题斗争一段时间,似乎 CentOS 6 中出现了回归,就 anaconda 忽略该selinux --disabled指令而言。这似乎首先出现在RHEL 4.8 中,然后重新出现在RHEL 5.6 中

现在使用以前的版本,您只需将 sed 语句添加到您的%post指令中即可禁用它。

sed -i -e 's/\(^SELINUX=\).*$/\1permissive/' /etc/selinux/config
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是 RHEL/CentOS 6 中的新功能是它们默认设置文件系统属性,因此您现在必须清除这些属性。

我尝试运行以下命令来删除我%post部分中的这些属性,但没有任何效果。

find . -exec setfattr -x security.selinux {} \;
Run Code Online (Sandbox Code Playgroud)

如果您觉得有帮助,我的 kickstart 文件如下:

#version=RHEL6
install
url --url=http://ny-man01.ds.stackexchange.com/centos/6/os/x86_64
lang en_US.UTF-8
keyboard us
%include /tmp/nic-include
rootpw  --iscrypted <mmm no you don't even get the encrypted version>
firewall --service=ssh,ntp,snmp
authconfig --enableshadow --passalgo=sha512 --enablefingerprint --enablekrb5
selinux --disabled
timezone --utc Etc/UTC
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
clearpart --all --initlabel --drives=sda

part /boot --fstype=ext4 --size=500
part pv.M3dTcp-jomG-l0xc-Zl3I-wqR1-Gcwz-14jidB --grow --size=1
volgroup vg_test --pesize=4096 pv.M3dTcp-jomG-l0xc-Zl3I-wqR1-Gcwz-14jidB
logvol / --fstype=ext4 --name=lv_root --vgname=vg_test --grow --size=1024 --maxsize=51200
logvol swap --name=lv_swap --vgname=vg_test --grow --size=1024 --maxsize=6016

services --enabled ntpd,snmpd,puppet

reboot

repo --name="CentOS"  --baseurl=http://ny-man01.ds.stackexchange.com/centos/6/os/x86_64/ --                                                                                                                                                                                                                                  cost=100
repo --name="EPEL6" --baseurl=http://ny-man01.ds.stackexchange.com/epel/6/x86_64/
repo --name="SEI" --baseurl=http://ny-man01.ds.stackexchange.com/sei/

%packages
@base
@core
@hardware-monitoring
@perl-runtime
@server-policy
@system-admin-tools
pam_krb5
sgpio
perl-DBD-SQLite
epel-release-6-5
net-snmp
ntp
mercurial
puppet

%pre
echo "# `grep /proc/net/dev eth| cut -d: -f1 | cut -d' ' -f3` " >>/tmp/nic-include
echo "# auto generated nic setup" > /tmp/nic-include
for nic in `grep eth /proc/net/dev| cut -d: -f1 | cut -d' ' -f3`
do
        if [ "$nic" = "eth0" ]
        then
                echo "network --device $nic --bootproto dhcp " >> /tmp/nic-include
        else
                echo "network --device $nic --onboot no --bootproto dhcp" >> /tmp/nic-inclu                                                                                                                                                                                                                                  de
        fi
done


%post --log /root/ks-post.log
#sed -i -e 's/\(^SELINUX=\).*$/\1disabled/' /etc/selinux/config
#find / -exec setfattr -x security.selinux {} \;
wget -O- http://10.7.0.50/kickstart/generic-configs/get_files.sh | /bin/bash
cp /tmp/nic-include /root/
Run Code Online (Sandbox Code Playgroud)

Ril*_*ndo 6

CentOS 6 安装程序默认以许可模式加载策略(我在安装过程中通过运行 dmesg 确认了这一点)。这意味着在安装后步骤中,SELinux 已经处于活动状态。只要它正在运行,看起来您就无法删除这些属性。

您必须在安装开始之前的某个地方传递以下内容(就在内核引导加载程序行的末尾):

selinux=0
Run Code Online (Sandbox Code Playgroud)

所以像这样:

kernel /boot/vmlinuz-2.4.20-XXXXXXXXX ro root=/dev/hda1 nousb selinux=0
Run Code Online (Sandbox Code Playgroud)

这是当您尝试在许可模式下删除属性时发生的情况(请原谅格式,SF 似乎不满意):

[root@centos6dev test]# find . -exec setfattr -x security.selinux {} \;
setfattr: .: Permission denied
setfattr: ./test2: Permission denied
setfattr: ./test3: Permission denied
setfattr: ./test: Permission denied
Run Code Online (Sandbox Code Playgroud)

在启动时从 grub 禁用 selinux:

[root@centos6dev test]# ls -Z
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 test
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 test2
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 test3
[root@centos6dev test]# find . -exec setfattr -x security.selinux {} \;
[root@centos6dev test]# ls -la
total 8
drwxr-xr-x  2 root root 4096 Dec 13 22:27 .
dr-xr-x---. 4 root root 4096 Dec 13 22:27 ..
-rw-r--r--  1 root root    0 Dec 13 22:27 test
-rw-r--r--  1 root root    0 Dec 13 22:27 test2
-rw-r--r--  1 root root    0 Dec 13 22:27 test3
[root@centos6dev test]# ls -Z
-rw-r--r-- root root ?                                test
-rw-r--r-- root root ?                                test2
-rw-r--r-- root root ?                                test3
Run Code Online (Sandbox Code Playgroud)

基于此以及此错误报告,这可能意味着您将无法在安装后删除属性。因此,正如我所概述的,您需要在启动安装之前禁用 selinux。

(或者你可以不理会它,学会忍受它。:))。