Security: Difference between revisions

From NixOS Wiki
imported>Erdnaxe
Add link to Systemd_Hardening wiki page
imported>Vater
Line 109: Line 109:
=== Secure Boot ===
=== Secure Boot ===


Development of [https://en.wikipedia.org/wiki/Unified_Extensible_Firmware_Interface#Secure_Boot UEFI Secure Boot] support is [https://github.com/NixOS/nixpkgs/issues/42127 in flight]. Looking potential for release in 22.05.
Development of [https://en.wikipedia.org/wiki/Unified_Extensible_Firmware_Interface#Secure_Boot UEFI Secure Boot] support is [https://github.com/NixOS/nixpkgs/issues/42127 in flight]. Looking<ref>[https://nlnet.nl/project/NixOS-UEFI/ NLnet Foundation project ''UEFI Secure Boot support for NixOS'']</ref> potential for release in 22.11.


=== SELinux ===
=== SELinux ===

Revision as of 18:02, 25 September 2022

Overview

This page is a guide to securing NixOS. Topics like hardening, process isolation, virtualization, firewalls, SELinux, containers, sandboxes, encryption, VPNs, etc. are in scope.

Core Nix features

These are security elements that are core features of using Nix(OS).

Obscurity of Nix store

In a vanilla NixOS system, the typical Linux filesystem hierarchy is, in large part, replaced with the Nix store's user environments. This means that some malware which might rely on finding system tools in particular places might fail. This is a form of security through obscurity and is only a minor layer of protection.

Effort to isolate runtime search paths

In general, there is an effort to avoid rpath collisions across users [1].

Multi-user installation

NixOS is automatically installed in Multi-User mode. For standalone-Nix, the manual covers multi-user installs. This allows multiple users to have isolated store environments and to avoid them having access to root in order to install their personal applications (achieved by having build users which nix operations are delegated to).

Data integrity and authenticity

The core installation resources for Nix(OS) have SHA256 checksums which are GPG signed by the Nix team for authenticity. Within the installation data are all the SHA256 checksums for packages that were available within Nixpkgs at build time.

All packages which are pulled into your Nix system via Nixpkgs derivation builds are checked against SHA256 checksums which are already available on your local system (and should be traceable to the signed core Nix install materials).

Supported by Nix

These are features which are easily supported using Nix(OS).

Encryption

These are features which can protect data on a system.

Filesystem encryption

NixOS has LUKS partition-level disk encryption support.

Isolation

These are features which can limit a process or package's access to the host system.

Flatpaks

Flatpak'ed applications are sandboxed and require explicit privilege declaration for most access outside their own path. NixOS includes support for Flatpak. Note that, since Flatpak application dependencies are bundled/vendored, this introduces other security risks for the application . Also, most application flatpaks do no not make meaningful use of the sandbox.

Linux Containers

NixOS includes support for Linux Containers (LXC). Containers, by default, do not provide much security. They are, oversimplifying a lot, a chroot environment with some resource constraints (cgroups). The root user in a container would also be root on the whole system though. To avoid this, you must use unprivileged containers. There are some complications to this. The end of this post covers them well in brief.

References

Docker Containers

Docker is a system for building and running platform-independent virtual containers. On Linux, it is implemented similarly to LXC. Nix integrates tools to create Docker images (the templates for making Docker containers), documented in the Nixpkgs manual. Docker containers work with namespacing controls similar to unprivileged LXC containers by default.

Virtual machines

Virtual machines are generally one of the most robust tools available for process isolation. They come with performance penalties and resource overheads.

NixOS includes support for hosting virtual machines. The Nix store of the host machine is shared read-only with guest machines, making them lighter-weight in terms of storage use than typical VMs. Guest VMs are easily built from Nix configurations.

Test machines

NixOS integrates support for building test VMs to test configuration changes to your system.

NixOS also uses VMs to continuously validate functionality of the system. NixOS Manual - Writing Tests Chapter covers this.

References

Systemd Hardening

It is possible to increase the isolation of Systemd services by using hardening options. For example, adding PrivateNetwork=yes option in a Systemd unit removes access to the host network.

For more information, please see Systemd_Hardening.

Networking

These are features which improve system security in relation to the world outside of the system.

Firewall

NixOS includes a simple stateful firewall. It blocks incoming connections and other unexpected packets and is enabled by default.

Awaiting NixOS support

This section covers important security technologies which still need full NixOS support.

Secure Boot

Development of UEFI Secure Boot support is in flight. Looking[1] potential for release in 22.11.

SELinux

It is possible to use Security-Enhanced Linux (SELinux) in NixOS, but proper integration does not exist. This does not appear to have gotten much attention since 2019.

Nix official references

See also

NixOS

Projects leveraging Nix for security

  • Spectrum OS - Nix based, Spectrum is a project that aims to create a computer operating system, based on the principle of security by compartmentalization, that has a lower barrier to entry and is easier to use and maintain than other such systems.

General Linux hardening

  • The Practical Linux Hardening Guide
  • How To Secure A Linux Server - An evolving how-to guide for securing a Linux server that, hopefully, also teaches you a little about security and why it matters.
  • lynis - Security auditing tool for Linux, macOS, and UNIX-based systems. Assists with compliance testing (HIPAA/ISO27001/PCI DSS) and system hardening. Agentless, and installation optional.
  • DevSec Linux Baseline - InSpec profile to test Linux server security config

General systems hardening