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

Support privilege dropping? #74

Open
mperham opened this issue Apr 26, 2019 · 3 comments
Open

Support privilege dropping? #74

mperham opened this issue Apr 26, 2019 · 3 comments

Comments

@mperham
Copy link

mperham commented Apr 26, 2019

Since RubyDNS will often bind to privileged port 53, it will be run as root. Ideally it will drop after binding.

http://timetobleed.com/5-things-you-dont-know-about-user-ids-that-will-destroy-you/

uid = Etc.getpwnam("nobody").uid
Process::Sys.setuid(uid)

Pseudocode:

RubyDNS.run_server(INTERFACES, user: 'nobody') do
  ...
end
@ioquatix
Copy link
Member

https://github.com/socketry/rubydns/blob/master/examples/fortune-dns.rb has an example of how to do this.

@ioquatix
Copy link
Member

However, it's quite an old example. Maybe can be improved somewhat by combining it with a real command processor (e.g. samovar optimist, etc).

@fa11enangel
Copy link

fa11enangel commented Apr 17, 2020

I've launched rubydns on an un privileged port (5300) and added port forwarding through iptables from port 53. This way I don't need any privileges for the server to run/restart/update/...

This is an example for iptables rules:

iptables -t nat -I PREROUTING -p tcp --dport 53 -j REDIRECT --to-port 5300
iptables -t nat -I PREROUTING -p udp --dport 53 -j REDIRECT --to-port 5300

For UFW I've created a rule too:

#  /etc/ufw/before.rule
# Forward port 53 to 5300
*nat
:PREROUTING ACCEPT [0:0]
-A PREROUTING -p tcp --dport 53 -j REDIRECT --to-port 5300
:PREROUTING ACCEPT [0:0]
-A PREROUTING -p udp --dport 53 -j REDIRECT --to-port 5300
COMMIT

and for IPv6 in UFW:

# /etc/ufw/before6.rules
# Forward port 53 to 5300
*nat
:PREROUTING ACCEPT [0:0]
-A PREROUTING -p tcp --dport 53 -j REDIRECT --to-port 5300
:PREROUTING ACCEPT [0:0]
-A PREROUTING -p udp --dport 53 -j REDIRECT --to-port 5300
COMMIT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants