How can I drop privileges in Perl?
-
05-09-2019 - |
Question
I created a server program that will be started as root. After it is started I want to drop privileges to another user. How can I do this securely?
Solution
See Privileges::Drop.
OTHER TIPS
You don't really need a module, although the one linked by Benji York looks pretty nice.
It's a simple matter of setting the UID via $<
and $>
. See perlvar for further information on these. You can also set the GID this way using $(
and $)
; note that you need to set $) = "$target_gid $target_gid"
if you want to drop supplemental groups. Don't forget to test for success afterwards.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow