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

coturn: allow use of ports < 1024 #26632

Merged
merged 1 commit into from Jul 23, 2017
Merged

coturn: allow use of ports < 1024 #26632

merged 1 commit into from Jul 23, 2017

Conversation

jazmit
Copy link
Contributor

@jazmit jazmit commented Jun 16, 2017

Motivation for this change

Using ports 80 and 443 for STUN/TURN has the best chance of passing through strict firewalls. CoTURN needs to start as root in order to bind to these roots

Things done
  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Linux
  • 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.

@joachifm
Copy link
Contributor

What about adding NET_BIND_SERVICE to the ambient capabilities instead?

@joachifm
Copy link
Contributor

Ah, I take it coturn does its own privsep so it's not like it'll end up running as root, right?

@jazmit
Copy link
Contributor Author

jazmit commented Jun 16, 2017

I'm not sure what the best practice is here, but I've tested and the server does end up running as turnserver.

@joachifm
Copy link
Contributor

I wonder about the ownership of RuntimeDirectory though. Does the privsep fixup the ownership of that directory (to the extent that it is used at all, I've not looked very closely)? Otherwise, this change could introduce a regression wrt. to RuntimeDirectory ownership.

@jazmit
Copy link
Contributor Author

jazmit commented Jun 16, 2017

find /run -iname turnserver doesn't turn up anything, and after deleting the RuntimeDirectory directive and redeploying everything still works fine. Perhaps I could remove the directive as part of this PR?

@joachifm
Copy link
Contributor

Just to be sure: did you check that while the service was running? The runtime directory is supposed to be tied to the lifetime of the service.

@joachifm
Copy link
Contributor

Anyway, I think @Ralith is better suited to review this

@Ralith
Copy link
Contributor

Ralith commented Jun 17, 2017

The RuntimeDirectory is used to store the service's PID file, and absolutely does get touched. I don't have any knowledge of whether it's needed; if you've verified that it works fine without, then it should probably be removed from the config file, too (and tested again).

I'm also in favor of a capability approach rather than the big hammer that is root, unless there's some reason that won't work.

@jazmit
Copy link
Contributor Author

jazmit commented Jun 19, 2017

My bad, the RuntimeDirectory is of course created. I've updated the PR to use ambient capabilities as you suggest, and tested to confirm that port binding succeeeds. I only just read up on the linux capability saga, so let me know if there's anything else I need to do here.

@joachifm
Copy link
Contributor

A possible improvement is to augment ambient capabilities only when configured to use a privileged port.

@jazmit
Copy link
Contributor Author

jazmit commented Jun 19, 2017

Great suggestion @joachifm, I've updated the PR to do this. BTW I'm loving nixops, this kind of thing would have been a pain with ansible!

@jazmit
Copy link
Contributor Author

jazmit commented Jun 19, 2017

Would you prefer that I squished the commits together?

Copy link
Contributor

@Ralith Ralith left a comment

Choose a reason for hiding this comment

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

Looks good, modulo a couple tweaks.

@@ -320,6 +320,11 @@ in {
RuntimeDirectory = "turnserver";
User = "turnserver";
Group = "turnserver";
AmbientCapabilities =
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like a tab snuck into the indentation here.

AmbientCapabilities =
mkIf (
cfg.listening-port < 1024 || cfg.alt-listening-port < 1024
|| cfg.tls-listening-port < 1024 || cfg.alt-tls-listening-port < 1024
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this check cfg.min-port too?

@jazmit
Copy link
Contributor Author

jazmit commented Jun 19, 2017

Thanks, I've fixed both.

Copy link
Contributor

@Ralith Ralith left a comment

Choose a reason for hiding this comment

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

LGTM! You should probably squash, since the original commit is mooted by the new one.

@jazmit
Copy link
Contributor Author

jazmit commented Jun 20, 2017

OK, squashed and rebased to latest master

@joachifm
Copy link
Contributor

Sorry to mention this so late, but it just occurred to me that you could create the runtime dir with the appropriate ownership via preStart if you preferred to use the builtin privsep thing.

@jazmit
Copy link
Contributor Author

jazmit commented Jun 29, 2017

Actually, using AmbientCapabalities works great, and avoids using root so I think this is a good solution. Thanks for all the advice, I've definitely learned more about linux doing this PR!

@joachifm
Copy link
Contributor

Merging due to maintainer approval. Thank you.

@joachifm joachifm merged commit 1a768eb into NixOS:master Jul 23, 2017
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

4 participants