-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A much more lax approach to privelege separation (#816)
* A much more lax approach to privelege separation Compared to #814. * Correct ErrFailed for privdrop package * privdrop stubs for Windows * Assign *syscall.SysProcAttr instead of *syscall.Credential * chown(2) agent's binary when privelege dropping was requested * privdrop: expose Chown for both Windows and non-Windows * Clarify to which isolations does --user apply
- Loading branch information
Showing
8 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package privdrop | ||
|
||
type Chown struct { | ||
UID int | ||
GID int | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//go:build !windows | ||
|
||
package privdrop | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
userpkg "os/user" | ||
"strconv" | ||
"syscall" | ||
) | ||
|
||
var ErrFailed = errors.New("failed to initialize privilege dropping") | ||
|
||
var ( | ||
SysProcAttr *syscall.SysProcAttr | ||
ChownTo *Chown | ||
) | ||
|
||
func Initialize(username string) error { | ||
user, err := userpkg.Lookup(username) | ||
if err != nil { | ||
return fmt.Errorf("%w: failed to lookup username %q: %v", | ||
ErrFailed, username, err) | ||
} | ||
|
||
gid, err := strconv.Atoi(user.Gid) | ||
if err != nil { | ||
return fmt.Errorf("%w: failed to parse %s's group ID %q: %v", | ||
ErrFailed, user.Name, user.Gid, err) | ||
} | ||
|
||
uid, err := strconv.Atoi(user.Uid) | ||
if err != nil { | ||
return fmt.Errorf("%w: failed to parse %s's user ID %q: %v", | ||
ErrFailed, user.Name, user.Uid, err) | ||
} | ||
|
||
SysProcAttr = &syscall.SysProcAttr{ | ||
Credential: &syscall.Credential{ | ||
Uid: uint32(uid), | ||
Gid: uint32(gid), | ||
}, | ||
} | ||
ChownTo = &Chown{ | ||
UID: uid, | ||
GID: gid, | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//go:build windows | ||
|
||
package privdrop | ||
|
||
import ( | ||
"fmt" | ||
"syscall" | ||
) | ||
|
||
var ( | ||
SysProcAttr *syscall.SysProcAttr | ||
ChownTo *Chown | ||
) | ||
|
||
func Initialize(username string) error { | ||
return fmt.Errorf("privilege dropping is not supported on this platform") | ||
} |