Skip to content

Commit 6fdef98

Browse files
Merge pull request #23 from AmedeeBulle/selinux
Image tools: Default SELinux to Enforcing
2 parents 5a2fe77 + 74a371c commit 6fdef98

File tree

7 files changed

+22
-8
lines changed

7 files changed

+22
-8
lines changed

oracle-linux-image-tools/bin/build-image.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ load_env() {
222222
[[ "${SETUP_SWAP,,}" =~ ^(yes)|(no)$ ]] || error "SETUP_SWAP must be yes or no"
223223
readonly SETUP_SWAP
224224

225+
[[ "${SELINUX,,}" =~ ^(enforcing)|(permissive)|(disabled)$ ]] || error "SELINUX must be enforcing, permissive or disabled"
226+
readonly SELINUX
227+
225228
[[ "${X2APIC,,}" =~ ^(on)|(off)$ ]] || error "X2APIC must be on or off"
226229
readonly X2APIC="${X2APIC,,}"
227230

oracle-linux-image-tools/cloud/vagrant-virtualbox/files/vagrant-common.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ EOF
9191
current_kernel=$(uname -r)
9292
${DRACUT_CMD} -f "/boot/initramfs-${current_kernel}.img" "${current_kernel}"
9393

94-
# Set SELinux to enforcing
95-
sed -i -e 's/^SELINUX\s*=.*/SELINUX=enforcing/' /etc/selinux/config
96-
9794
# Disabling firewalld on vagrant boxes
9895
if [[ "${ORACLE_RELEASE}" = "6" ]]; then
9996
service iptables stop

oracle-linux-image-tools/distr/ol7-slim/ol7-ks.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ rootpw --lock
3333

3434
# System services
3535
services --disabled="firewalld,kdump,rhsmcertd" --enabled="ip6tables,iptables,network,sshd,rsyslog,chronyd"
36-
selinux --permissive
36+
selinux --enforcing
3737
firewall --service=ssh
3838

3939
# System bootloader configuration

oracle-linux-image-tools/distr/ol7-slim/provision.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,12 @@ distr::common_cfg() {
173173
echo_message "Set rp_filter to loose mode"
174174
echo "net.ipv4.conf.default.rp_filter = 2" >> /etc/sysctl.conf
175175

176-
echo_message "Set SELinux to Permissive"
177-
sed -i -e 's/^SELINUX[ ]*=.*/SELINUX=permissive/' /etc/selinux/config
176+
echo_message "Set SELinux to ${SELINUX^^}"
177+
sed -i -e "s/^SELINUX[ ]*=.*/SELINUX=${SELINUX,,}/" /etc/selinux/config
178+
if [[ ${SELINUX,,} != "enforcing" ]]; then
179+
# Relax SELinux for the provisioning as well
180+
setenforce Permissive
181+
fi
178182

179183
echo_message "Clear network persistent data"
180184
rm -f /etc/udev/rules.d/70-persistent-net.rules

oracle-linux-image-tools/distr/ol8-slim/provision.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,12 @@ distr::common_cfg() {
160160
echo_message "Set rp_filter to loose mode"
161161
echo "net.ipv4.conf.default.rp_filter = 2" >> /etc/sysctl.conf
162162

163-
echo_message "Set SELinux to Permissive"
164-
sed -i -e 's/^SELINUX[ ]*=.*/SELINUX=permissive/' /etc/selinux/config
163+
echo_message "Set SELinux to ${SELINUX^^}"
164+
sed -i -e "s/^SELINUX[ ]*=.*/SELINUX=${SELINUX,,}/" /etc/selinux/config
165+
if [[ ${SELINUX,,} != "enforcing" ]]; then
166+
# Relax SELinux for the provisioning as well
167+
setenforce Permissive
168+
fi
165169

166170
echo_message "Clear network persistent data"
167171
rm -f /etc/udev/rules.d/70-persistent-net.rules

oracle-linux-image-tools/env.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ CLOUD="none"
4444
# Setup swap? (Yes/No, default is distribution / cloud specific)
4545
# SETUP_SWAP=
4646

47+
# SELinux state (enforcing, permissive, disabled)
48+
# SELINUX=
49+
4750
# Root filesystem: btrfs, xfs or lvm (Default: xfs)
4851
# ROOT_FS=
4952

oracle-linux-image-tools/env.properties.defaults

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ MEM_SIZE=8192
1717
# Setup swap?
1818
SETUP_SWAP="yes"
1919

20+
# SELinux state (enforcing, permissive, disabled)
21+
SELINUX="enforcing"
22+
2023
# Allocated disk size for the image.
2124
DISK_SIZE_GB=15
2225

0 commit comments

Comments
 (0)