Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/freeradius : init - Added freeradius service #34587

Merged
merged 1 commit into from Feb 17, 2018

Conversation

netixx
Copy link
Contributor

@netixx netixx commented Feb 4, 2018

Resubmit because of branch mixup

Inspired from the dhcpd service implementation
Only 2 configurations options at the moment:
enabled and path to configfile

folder networking has been chosen because radius is mainly used for network device and network authentication (e.g. WPA2 Entreprise)

Motivation for this change

Freeradius package is already supported by nix, but no service exists for nixos. This patch adds basic support to start the freeradius service.

Things done

I tested the service configuration in my personal nix installation successfully.

  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.


freeradiusConfig = {

enable = mkOption {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use mkEnableOption

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done :)


configDir = mkOption {
type = types.nullOr types.path;
default = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this allowed to be null? This could default to /var/lib/freeradius.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default value is set to /var/lib/freeradius. Without this parameter, the service will failed, so it makes sense to force default value. Default value for the radiusd command is /etc/raddb, should we use this ? I don't know about nixos policy on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably yes. I believe freeradius never writes to this directory, does it? If it doesn't, /etc makes sense.
It's always good to find inspiration in other distros: https://git.archlinux.org/svntogit/community.git/tree/trunk/freeradius.service?h=packages/freeradius
Depending on whether freeradius needs write access to the filesystem, you should consider ProtectSystem=strict and ReadWritePaths: https://www.freedesktop.org/software/systemd/man/systemd.exec.html

Btw, please amend/squash the commit(s) instead of adding new ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

I used ProtectSystem=full because I had difficulties with ReadWritePaths= :

  • the pre-start would fail freeradius.service: Failed at step NAMESPACE spawning /nix/store/z0ppd98vmw50pc2fj6ycc71ayxvzyqsr-unit-script/bin/freeradius-pre-start: No such file or directory
  • I added ReadOnlyPaths="/nix/store" but it didn't solve the issue
  • also, radius may need to write files (to /var/log/radius and maybe others), so it didn't seem wise (at least until we generate the freeradius configuration from nixos expressions).

after = ["network-online.target"];
requires = ["network-online.target"];
preStart = ''
${cfg.configDir}/certs/bootstrap
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the user supposed to provide that script?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some kind of typo that I forgot to remove.

@netixx
Copy link
Contributor Author

netixx commented Feb 4, 2018

I pushed fixes according to your very good suggestions. I only have a doubt on the default value for the config directory parameter (see comment).

Also, I changed the requires dependency to a wants dependency, following discussions is this PR

@andir
Copy link
Member

andir commented Feb 5, 2018

Are you able to construct a NixOS test that verifies that the module produces a working freeradius? Something with static username/password in the configuration would probably be sufficient.

@netixx
Copy link
Contributor Author

netixx commented Feb 6, 2018

What would the test consist on ? Doing an end to end test with a radius client ?

@andir
Copy link
Member

andir commented Feb 6, 2018 via email

@netixx
Copy link
Contributor Author

netixx commented Feb 7, 2018

In this case, we could do the following:
a. generate radius config (at least clients.conf and users files) with predefined keys
b. start the freeradius service
c. use the included radclient like so echo "User-Name=xxx,Password=xxx" | sudo radclient -s <your-server-ip> auth <shared secret> (example taken from here) and verify output/return code

However,

  1. The configuration for freeradius consists on multiples files and folders (currently, I have 284 files in my config, which I constructed from the vanilla freeradius config).
  2. I don't know which are strictly required.

What I suggest regarding tests is that we wait until we provide nixos configuration options (at least defining clients.conf and users) to generate a full working config (providing the other required files statically). With the complete configuration, we can start the server and perform tests.


cfg = config.services.freeradius;

freeradiusService = cfg: optionalAttrs cfg.enable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The optionalAttrs is not needed because you already guard the config below with mkIf. Also, returning the systemd service attrset is nicer than returning { freeradius = { ... }; } because the resulting service name can be chosen more elegantly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the indenten is slightly off, Should be on the same level as cfg.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

I moved the freeradius name to the config section (not sure if that's where it should go). And I tested it in my setup.

Inspired from the dhcpd service implementation
Only 2 configurations options at the moment:
- enabled
- path to config directory (defaults to /etc/raddb)

Implementation was also inspired from ArchLinux
systemd file and corrected with @dotlambda and
@fpletz help.
@joachifm joachifm merged commit 71a32c3 into NixOS:master Feb 17, 2018
@joachifm
Copy link
Contributor

Thank you

@netixx netixx deleted the add-freeradius-service branch February 17, 2018 10:03
netixx added a commit to netixx/nixpkgs that referenced this pull request Jun 22, 2018
The freeradius service was merged with NixOS#34587
but the module was not added to module-list.

This commit fixes that and enables the use of
services.freeradius in nixos configuration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants