-
Notifications
You must be signed in to change notification settings - Fork 3
Switch user and drop privileges #13
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nits, otherwise LGTM! 🚀
cmd/localstack/user.go
Outdated
func DropPrivileges(userToSwitchTo string) { | ||
// Lookup user and group IDs for the user we want to switch to. | ||
userInfo, err := user.Lookup(userToSwitchTo) | ||
if err != nil { | ||
log.Errorln("Error looking up user:", userToSwitchTo, err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func DropPrivileges(userToSwitchTo string) { | |
// Lookup user and group IDs for the user we want to switch to. | |
userInfo, err := user.Lookup(userToSwitchTo) | |
if err != nil { | |
log.Errorln("Error looking up user:", userToSwitchTo, err) | |
} | |
func DropPrivileges(userToSwitchTo string) error { | |
// Lookup user and group IDs for the user we want to switch to. | |
userInfo, err := user.Lookup(userToSwitchTo) | |
if err != nil { | |
log.Errorln("Error looking up user:", userToSwitchTo, err) | |
return err | |
} | |
... | |
return nil |
This is more of a general feedback for the methods in this file. It would generally be better to "fail" early and bubble up the error when receiving an error we don't plan to recover from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done for methods without a return value. Should we return a tuple for all methods with return values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switched to warn logging for recoverable errors for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only problem I have is the location of the privilege dropping, which should, in my opinion, be after binding port 53 and extracting the archives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now. We should however merge the other PR first, and might want to rebase this one to the localstack
branch.
Make `GetenvWithDefault` behave like `os.environ.get` in Python
As @dfangl pointed out: Binding port 53 might require root permissions for binding port < 1024 depending on the Docker version moby/moby#41030
df38614
to
95959e2
Compare
Using warning level for recoverable warnings rather than breaking errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Depends on #12
Switch to
sbx_user1051
user for runtime parity and drop root privileges.Limitations
DropPrivileges
breaks debugging aftersyscall
. Debugging before the syscall is possible and resuming (at least) a few lines before the syscall works but stepping over the syscall or any breakpoint beyond the syscalls breaks debugging. Hence, we need to disableDropPrivileges
for debugging:DropPriviledges
DropPriviledges