Skip to content

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

Merged
merged 8 commits into from
Mar 8, 2023

Conversation

joe4dev
Copy link
Member

@joe4dev joe4dev commented Mar 7, 2023

Depends on #12

Switch to sbx_user1051 user for runtime parity and drop root privileges.

Limitations

  • DropPrivileges breaks debugging after syscall. 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 disable DropPrivileges for debugging:
    • Manually comment DropPriviledges
    • Introduce an environment variable to conditionally skip DropPriviledges

@joe4dev joe4dev requested a review from dominikschubert March 7, 2023 12:33
@joe4dev joe4dev self-assigned this Mar 7, 2023
@joe4dev joe4dev requested a review from dfangl March 7, 2023 12:48
Copy link
Member

@dominikschubert dominikschubert left a 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! 🚀

Comment on lines 83 to 92
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)
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Member Author

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?

Copy link
Member Author

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

Copy link
Member

@dfangl dfangl left a 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.

Copy link
Member

@dfangl dfangl left a 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.

joe4dev added 6 commits March 8, 2023 14:34
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
@dfangl dfangl force-pushed the switch-user-and-drop-privileges branch from df38614 to 95959e2 Compare March 8, 2023 13:35
joe4dev added 2 commits March 8, 2023 15:14
Using warning level for recoverable warnings rather than breaking errors.
Copy link
Member

@dominikschubert dominikschubert left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@joe4dev joe4dev merged commit 6fbdf2e into localstack Mar 8, 2023
@joe4dev joe4dev deleted the switch-user-and-drop-privileges branch March 8, 2023 14:34
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

Successfully merging this pull request may close these issues.

3 participants