Skip to content

Commit 1aac323

Browse files
authored
Merge pull request #2 from jhawkwind/glibc-integration
Glibc integration and clean-up
2 parents 1e43d60 + a5569df commit 1aac323

13 files changed

+168
-98
lines changed

.gitmodules

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[submodule "glibc"]
2+
path = glibc
3+
url = git://sourceware.org/git/glibc.git
4+
branch = release/2.18/master
5+
[submodule "factorio-updater"]
6+
path = factorio-updater
7+
url = https://github.com/narc0tiq/factorio-updater.git

README.md

Lines changed: 98 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,24 @@ This is a fork of https://github.com/Bisa/factorio-init
1313
# Dependencies
1414
Among others:
1515
- cURL
16-
17-
## SELINUX Dependencies
16+
- git
17+
- glibc-devel
18+
- glibc
19+
- make
20+
- gcc-c++ - C++ component for glibc (optional)
21+
- texinfo - documentation output for glibc
22+
- libselinux-devel - SELINUX aware glibc
23+
- audit-libs-devel - SELINUX auditing aware
24+
- libcap-devel - root privileges partitioning for glibc
25+
26+
## SELINUX specific dependencies
1827
- **REQUIRED**
1928
- SELINUX installed and enabled.
2029
- `setenforce 1` - If you do not know what this command does, **STOP!** DO NOT PROCEED! Please read up on SELINUX Administration.
2130
- _coreutils_ package - Required in all cases.
2231
- _policycoreutils_ package - Required in all cases.
23-
- **REQUIRED if small changes or recompiling only**
32+
- **REQUIRED if small changes or recompiling only** - You will not need this if you use the RPM.
2433
- _policycoreutils-python_ package - Optional if using RPM. Required if compiling yourself.
25-
- gcc - Required to recompile.
26-
- make - Required to recompile.
2734
- _policycoreutils-devel_ package - Optional if using RPM or just making small adjustments. Required if debugging.
2835
- _setools-console_ package - Required if debugging, optional in other cases.
2936

@@ -32,128 +39,149 @@ This is a fork of https://github.com/Bisa/factorio-init
3239
If you find yourself wondering why stuff is not working the way you expect:
3340
- Check the logs, I suggest you `tail -f /opt/factorio/factorio-current.log` in a separate session
3441
- Enable debugging in the config and/or:
35-
- Try running the same commands as the factorio user (`/opt/factorio-init/factorio invocation` will tell you what the factorio user tries to run at start)
42+
- Try running the same commands as the factorio user (`/opt/factorio-SEinit/factorio invocation` will tell you what the factorio user tries to run at start)
3643

3744
```bash
38-
$ /opt/factorio-init/factorio invocation
45+
/opt/factorio-SEinit/factorio invocation
3946
# Run this as the factorio user, example:
40-
$ sudo -u factorio 'whatever invocation gave you'
47+
sudo -u factorio 'whatever invocation gave you'
4148
# You should see some output in your terminal here, hopefully giving
4249
# you a hint of what is going wrong
4350
```
4451

52+
- You may need to study the audit logs at `/var/log/audit/audit.log` and see what is being blocked.
53+
- You may need to disable the `dontaudit` flag and force auditing to get the output to the audit log with more answers: `semodule --disable_dontaudit --build`
54+
- If you followed hardening guides, you may need to adjust the *umask* temporarily back to `umask 022` which was the default, or run:
55+
```bash
56+
find /opt/glibc-2.18 -type d -exec chmod 755 {} \;
57+
find /opt/factorio-SEinit -type d -exec chmod 755 {} \;
58+
find /opt/factorio -type d -exec chmod 755 {} \;
59+
```
60+
4561
# Install
46-
- Create a directory where you want to store this script along with configuration. (either copy-paste the files or clone from github):
62+
- Create a directory where you want to store this script along with configuration. Cloning from github assuming **/opt/factorio-SEinit** as the directory:
4763

4864
```bash
49-
$ cd '/opt'
50-
$ git clone https://github.com/jhawkwind/factorio-SEinit
65+
yum install git
66+
cd '/opt'
67+
git clone --recurse-submodules https://github.com/jhawkwind/factorio-SEinit
5168
```
52-
- Rename config.example to config and modify the values within according to your setup.
69+
70+
- Rename **/opt/factorio-SEinit/config.example** to **/opt/factorio-SEinit/config** and modify the values within according to your setup.
71+
72+
## Install appropriate glibc version as required for CentOS 7
73+
74+
- The config has options for declaring an alternate glibc root, don't forget to configure it.
75+
- Compile the required GLIBC 2.18 and install it side-by-side with the OS version.
76+
```bash
77+
yum install glibc-devel glibc gcc make gcc-c++ autoconf texinfo libselinux-devel audit-libs-devel libcap-devel
78+
cd /opt/factorio-SEinit/glibc
79+
git apply ../patches/test-installation.pl.patch
80+
mkdir glibc-build
81+
cd glibc-build
82+
../configure --prefix='/opt/glibc-2.18' --with-selinux
83+
make
84+
make install
85+
```
5386

5487
## SELINUX Enablement
5588
- You must set `SELINUX=1` in the **config** file to have the init script change context into the **factorio_t** domain.
5689
- The policy expects you to have the INIT script, Factorio, and GLIBC-2.18 in either **/opt** or **/data**. If you put them
5790
anywhere else, you will need to modify **selinux/factorio.fc** and (of course) the **config** to tell it the new locations,
58-
and manually compilie and install the SELINUX policy modules.
91+
and manually compile and install the SELINUX policy modules.
5992
- File location format:
6093
* /opt (or /data)
6194
* /factorio/
62-
* /factorio-init/
95+
* /factorio-SEinit/
6396
* /glibc-2.18/
6497
* lib/
6598
* ld-2.18.so
66-
- Via the RPM, just run `rpm -Uvh Factorio-SEinit-1.1-0.el7.src.rpm`
67-
- Compiling the module by hand:
99+
- Via the RPM, just run:
68100
```bash
69-
[root@localhost]$ checkmodule -M -m -o factorio.mod factorio.te
70-
[root@localhost]$ semodule_package -o factorio.pp -m factorio.mod -f factorio.fc
71-
[root@localhost]$ semodule -i factorio.pp
72-
[root@localhost]$ restorecon -R -v /opt/factorio
73-
[root@localhost]$ restorecon -R -v /opt/factorio-init
74-
[root@localhost]$ restorecon -R -v /opt/glibc-2.18
101+
rpm -Uvh /opt/factorio-SEinit/selinux/Factorio-SEinit-1.1-0.el7.src.rpm
102+
restorecon -R -v /opt/factorio-SEinit
103+
restorecon -R -v /opt/glibc-2.18
104+
```
105+
- Compiling the module manually:
106+
```bash
107+
yum install policycoreutils-python policycoreutils-devel setools-console
108+
cd /opt/factorio-SEinit/selinux
109+
make -f /usr/share/selinux/devel/Makefile factorio.pp
110+
semodule -i factorio.pp
111+
restorecon -R -v /opt/factorio-SEinit
112+
restorecon -R -v /opt/glibc-2.18
75113
```
76-
77-
## Notes for users with CentOS 7 that has a older glibc version:
78-
79-
- The config has options for declaring a alternate glibc root. The user millisa over on the factorio forums has created a wonderful guide to follow on creating this alternate glibc root ( side by side ) here:
80-
https://forums.factorio.com/viewtopic.php?t=54654#p324493
81-
82-
```bash
83-
yum install glibc-devel glibc
84-
cd /tmp
85-
git clone git://sourceware.org/git/glibc.git
86-
cd glibc
87-
git checkout release/2.18/master
88-
mkdir glibc-build
89-
cd glibc-build
90-
../configure --prefix='/opt/glibc-2.18'
91-
```
92-
Fix the test script
93-
fix line 179 of the test install script:
94-
```
95-
vi ../scripts/test-installation.pl
96-
```
97-
change from
98-
```perl
99-
if (/$ld_so_name/) {
100-
```
101-
change to
102-
```
103-
if (/\Q$ld_so_name\E/) {
104-
```
105-
save the changes, then run the command to build and install
106-
```
107-
make
108-
make install
109-
```
110-
111114

112115
## First-run
113116
- If you don't have Factorio installed already, use the `install` command:
114117

115118
```bash
116-
$ /opt/factorio-init/factorio install # see help for options
119+
useradd -c "Factorio Server account" -d /opt/factorio -M -s /usr/sbin/nologin -r factorio
120+
/opt/factorio-SEinit/factorio install # see help for options
117121
```
118122

119123
- The installation routine creates Factorio's `config.ini` automatically.
120124

121-
- If you previously ran Factorio without this script, the existing `config.ini` should work fine.
125+
- If you previously ran Factorio without this script, the existing `config.ini` should work fine, just apply the security contexts:
126+
```bash
127+
restorecon -R -v /opt/factorio
128+
```
122129

123130
## Autocompletion
124131
- Copy/Symlink or source the bash_autocompletion file
125132

126133
```bash
127-
$ ln -s /opt/factorio-init/bash_autocomplete /etc/bash_completion.d/factorio
128-
# OR:
129-
$ echo "source /opt/factorio-init/bash_autocomplete" >> ~/.bashrc
134+
ln -s /opt/factorio-SEinit/bash_autocomplete /etc/bash_completion.d/factorio
135+
```
136+
OR:
137+
```bash
138+
echo "source /opt/factorio-SEinit/bash_autocomplete" >> ~/.bashrc
130139
# restart your shell to verify that it worked
131140
```
132141

133142
## Systemd
134143
- Copy the example service, adjust & reload
135144

136145
```bash
137-
$ cp /opt/factorio-init/factorio.service.example /etc/systemd/system/factorio.service
146+
cp /opt/factorio-SEinit/factorio.service.example /etc/systemd/system/factorio.service
138147
# Edit the service file to suit your environment then reload systemd
139-
$ systemctl daemon-reload
148+
systemctl daemon-reload
140149
```
141150

142151
- Verify that the server starts
143152

144153
```bash
145-
$ systemctl start factorio
146-
$ systemctl status -l factorio
154+
systemctl start factorio
155+
systemctl status -l factorio
147156
# Remember to enable the service at startup if you want that:
148-
$ systemctl enable factorio
157+
systemctl enable factorio
158+
```
159+
160+
## Clean up
161+
- You know we just installed a bunch of stuff earlier? This yum command should remove everything we no longer need:
162+
```bash
163+
yum remove glibc-devel gcc gcc-c++ autoconf texinfo libselinux-devel audit-libs-devel libcap-devel libsepol-devel pcre-devel libstdc++-devel git setools-console policycoreutils-devel perl-Git mpfr libmpc kernel-headers glibc-headers cpp m4 selinux-policy-devel
164+
```
165+
- You can resecure the _umask_ with `umask 0077`
166+
167+
## Firewall
168+
- The following firewalld rules will come in handy. As a "TODO" is to automate this as part of the installation process.
169+
```bash
170+
firewall-cmd --new-service=factorio-multiplayer --permanent
171+
firewall-cmd --service=factorio-multiplayer --description="Factorio multi-player lock step sychronization replication protocol" --permanent
172+
firewall-cmd --service=factorio-multiplayer --add-port=34197/udp --permanent
173+
firewall-cmd --add-service=factorio-multiplayer --permanent
174+
firewall-cmd --reload
149175
```
150176

151177
# Thank You
152178
- To all who find this script useful in one way or the other
153179
- A big thank you to [Wube](https://www.factorio.com/team) for making [Factorio](https://www.factorio.com/)
154-
- A special thanks to NoPantsMcDance, Oxyd, HanziQ, TheFactorioCube and all other frequent users of the [#factorio](irc://irc.esper.net/#factorio) channel @ esper.net
155-
- Thank you to Salzig for pointing me in the right direction when it comes to input redirection
156-
- At last, but not least; Thank you to all [contributors](https://github.com/Bisa/factorio-init/graphs/contributors) and users posting [issues](https://github.com/Bisa/factorio-init/issues) in my [github](https://github.com/Bisa/factorio-init/) project or on the [factorio forums](https://forums.factorio.com/viewtopic.php?f=133&t=13874)
180+
- A special thanks to NoPantsMcDance, Oxyd, HanziQ, TheFactorioCube and all other frequent users of the [**#factorio**](irc://irc.esper.net/#factorio) channel @ esper.net
181+
- Thank you to Salzig for pointing Bisa in the right direction when it comes to input redirection
182+
- The user _millisa_ over on the [factorio forums](https://forums.factorio.com/viewtopic.php?t=54654#p324493) for creating a wonderful guide to follow on making an alternate glibc root.
183+
- Please report any [(SE)init issues](https://github.com/jhawkwind/factorio-SEinit/issues) you find.
184+
- At last, but not least; Thank you to all [(SE)init contributors](https://github.com/jhawkwind/factorio-SEinit/graphs/contributors) and users posting [mainline issues](https://github.com/Bisa/factorio-init/issues) in Bisa's original [github](https://github.com/Bisa/factorio-init/) project or on the [factorio forums](https://forums.factorio.com/viewtopic.php?f=133&t=13874)
157185

158186
You are all a great source of motivation, thank you.
159187

config.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
DEBUG=0
66

77
# Enable alternative glibc directory for systems using older glibc versions ( ie RHEL CentOS and others )
8-
ALT_GLIBC=0
8+
ALT_GLIBC=1
99
# Put the Absolute path to the side by side glibc root here
1010
ALT_GLIBC_DIR="/opt/glibc-2.18"
1111
#Version of alt glibc goes here (i.e 2.18)
@@ -54,8 +54,8 @@ PACKAGE_DIR_NAME=factorio
5454
# git clone https://github.com/narc0tiq/factorio-updater
5555
#
5656

57-
# absolute path to the factorio-updater script
58-
UPDATE_SCRIPT=/path/to/update_factorio.py
57+
# absolute path to the factorio-updater script. Change as necessary.
58+
UPDATE_SCRIPT=/opt/factorio-SEinit/factorio-updater/update_factorio.py
5959
# Note that if you set HEADLESS=1 the username/token will not be used as the headless
6060
# download is provided free of charge
6161
HEADLESS=1

factorio

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,31 @@ test_deps(){
363363
return 0 # TODO: Implement ldd check on $BINARY
364364
}
365365

366+
set_perms(){
367+
echo "Applying file ownership ..."
368+
result=$(chown -R ${USERNAME}:${USERGROUP} ${FACTORIO_PATH})
369+
if [[ ${result} -ne 0 ]]; then
370+
echo "Failed to apply ownership ${USERNAME}:${USERGROUP} for ${FACTORIO_PATH}"
371+
exit 1
372+
fi
373+
374+
echo "Applying file permission ..."
375+
result=$(find ${FACTORIO_PATH} -type d -exec chmod 755 {} \;)
376+
if [[ ${result} -ne 0 ]]; then
377+
echo "Failed to apply permission for ${FACTORIO_PATH}"
378+
exit 1
379+
fi
380+
381+
if [[ ${SELINUX} -eq 1 ]]; then
382+
echo "Applying SELINUX security contexts ..."
383+
result=$(restorecon -R -v ${FACTORIO_PATH})
384+
if [[ ${result} -ne 0 ]]; then
385+
echo "Failed to apply SELINUX security contexts for ${FACTORIO_PATH}"
386+
exit 1
387+
fi
388+
fi
389+
}
390+
366391
install(){
367392
# Factorio comes packaged in a directory named "factorio"
368393
# Unless overriden in the config we will presume this is also the
@@ -420,12 +445,8 @@ install(){
420445
exit 1
421446
fi
422447
fi
423-
424-
echo "Applying file ownership ..."
425-
if ! chown -R ${USERNAME}:${USERGROUP} ${FACTORIO_PATH}; then
426-
echo "Failed to apply ownership ${USERNAME}:${USERGROUP} for ${FACTORIO_PATH}"
427-
exit 1
428-
fi
448+
449+
set_perms; # Set file permissions
429450

430451
# Generate default config.ini by creating a save
431452
as_user "${BINARY} --create ${FACTORIO_PATH}/saves/server-save ${EXE_ARGS_GLIBC}"

factorio-updater

Submodule factorio-updater added at 08797d0

factorio.service.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ PIDFile=/opt/factorio/server.pid
1313

1414
Type=forking
1515
TimeoutStartSec=20
16-
ExecStart=/opt/factorio-init/factorio start
16+
ExecStart=/opt/factorio-SEinit/factorio start
1717
TimeoutStopSec=20
18-
ExecStop=/opt/factorio-init/factorio stop
18+
ExecStop=/opt/factorio-SEinit/factorio stop
1919
RestartSec=20
2020
Restart=on-failure
2121

glibc

Submodule glibc added at 715e7fe

patches/test-installation.pl.patch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/test-installation.pl b/test-installation.pl
2+
index e01d60bd2b..b0c7eed225 100755
3+
--- a/scripts/test-installation.pl
4+
+++ b/scripts/test-installation.pl
5+
@@ -176,7 +176,7 @@ while (<LDD>) {
6+
$ok = 0;
7+
}
8+
}
9+
- if (/$ld_so_name/) {
10+
+ if (/\Q$ld_so_name\E/) {
11+
($version1) = /$ld_so_name\.so\.([0-9\.]*)/;
12+
if ($version1 ne $ld_so_version) {
13+
print "The dynamic linker $ld_so_name.so is not correctly installed.\n";
-20.4 KB
Binary file not shown.
20.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)