Replace simple activationScripts #263203
Conversation
The activationScript does not seem to be necessary anymore as the paths are created anyways.
0b039b6 to
0c4ee3d
Compare
Create the wrappers via a separate systemd service.
nixos/modules/services/networking/strongswan-swanctl/module.nix
Outdated
Show resolved
Hide resolved
0c4ee3d to
c3018b4
Compare
The stage-2-init.sh script has the same functionality hardcoded so we do not need it in the activationScript again.
c3018b4 to
6b07cc2
Compare
l0b0
left a comment
There was a problem hiding this comment.
I've only reviewed the shell script parts of this PR.
I will not change the shell scripts themselves. I just move them into a systemd service or preStart. Improving the shell scripts is out of scope. Edit: Thank you for leaving these improvements here. I hope someone else can pick them up in a separate PR! |
The hostname is already set by systemd https://www.freedesktop.org/software/systemd/man/latest/hostname.html#Hostname%20semantics Create a separate service that registers the domainname.
138fe17 to
d300940
Compare
|
@ofborg test wrappers mysql.mysql80 iscsi-root strongswan-swanctl mattermost systemd-binfmt systemd-timesyncd opensearch.opensearch stunnel grafana.provision activcation-nix-channel activation-var The stargazer test seems to be broken on master |
|
@ElvishJerricco is this good to go now? |
ElvishJerricco
left a comment
There was a problem hiding this comment.
I think it looks good yea
|
a8f50f9 broke the installer tests. |
|
Reverting in #264200 |
Thank you for taking the time to only revert the offending commit! |
|
b5617e0 broke the MySQL auth module since it now depends on a local mysql database. Additionally, the script needs to run as root for the chown calls. |
| system.activationScripts.hostname = let | ||
| effectiveHostname = config.boot.kernel.sysctl."kernel.hostname" or cfg.hostName; | ||
| in optionalString (effectiveHostname != "") '' | ||
| hostname "${effectiveHostname}" |
There was a problem hiding this comment.
This is a slight regression in behaviour. Systemd refuses to set the transient hostname altogether if /etc/hostname exists. But I think that is harmless. gethostname will still return the correct thing I think
We want to get rid of specialFileSystems / earlyMountScript eventually and there is no need to run this before systemd anymore now that the wrappers themselves are set up in a systemd unit since NixOS#263203 Also this is needed to make soft-reboot work. We want to make sure that we remount /run/wrappers with the nosuid bit removed on soft-reboot but because @earlyMountScript@ happens in initrd, this wouldn't happen
Version 257.1 of systemd changed[1] the PrivateTmp setting for the systemd-timesyncd service from "yes" to "disconnected", which broke our systemd-timesyncd test. The reason for this is because the systemd-tmpfiles-setup.service is *only*[2] added as a dependency of systemd-timesyncd.service if PrivateTmp is set to "yes" but not when it is set to "disconnected" (which would make sense given that the tmpfiles.d mechanism was originally designed for temporary files). Commit 339a866 switched the activation script to using systemd-tmpfiles, but the commit in question doesn't provide an explanation why this was necessary in this particular case. However the pull request[3] lists an ongoing effort to get rid of Perl and in the future get also rid of BASH for activation. The reasons for doing this are outlined in the document[4]: > The simple presence of interpreters on a system pose a security risk. > An attacker that gains access to a system can abuse them to execute > arbitrary commands. Mitre lists this as technique T1059. The most > radical yet simple solution to mitigate this exploit is to remove all > interpreters from a system (Mitre M1042). This radical solution is > only really feasible and/or interesting for appliances (i.e. > non-interactive) systems. Especially for high-security solutions this > mitigtation is interesting. I personally don't think this is a very compelling reason, at least for our activation scripts, since an attacker could simply drop an executable binary. Nevertheless, getting rid of additional dependencies on eg. Perl or BASH is something worth pursuing to trim down moving parts. To address this, I decided to implement this as a normal systemd service unit, since we need to guarantee that it's started before systemd-timesyncd.service and with a dedicated unit we can ensure explicit ordering. This has the advantage that we don't interfere with the effort of getting rid of Perl/BASH for activation/boot and also don't risk running into race conditions (again) because it's very unlikely that systemd will change/deprecate explicit unit ordering in the near future. [1]: systemd/systemd@1f6e192 [2]: https://github.com/systemd/systemd/blob/30675a6ee98540a02bd1d6afcf80f0c0aa8c0910/src/core/unit.c#L1274 [3]: #263203 [4]: https://pad.lassul.us/nixos-perlless-activation Signed-off-by: aszlig <[email protected]>
This is one part of a series of PRs towards activation without Perl. See more about this larger project here: https://pad.lassul.us/nixos-perlless-activation#
This PR is part of step 1 of the larger project.
In this PR, I replace many of the simple activationScripts. I employed this strategy to remove activationScripts:
One of the immediate benefits of this work is that these activationScripts now actually run after the initrd when you use the systemd initrd. The systemd initrd calls stage-2-init.sh in the initrd as ./prepare-root
Things done
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)