Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/sops/subcommand/exec/exec_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ func SwitchUser(username string) {
uid, _ := strconv.Atoi(user.Uid)
gid, _ := strconv.Atoi(user.Gid)

err = syscall.Setgroups([]int{gid})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are we looking to map the supplemental groups for the specified user or reset it so that it only contains the primary group?

Mapping could be accomplished by something similar to the following

	groupIds, _ := user.GroupIds()
	intGroupIds := make([]int, len(groupIds))
	for i, gid := range groupIds {
		intGroupIds[i], _ = strconv.Atoi(gid)
	}

	err = syscall.Setgroups(intGroupIds)
	if err != nil {
		log.Fatal(err)
	}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, I missed user.GroupIds(). Yeah, that makes sense. I've changed it slightly so that it falls back to []int{gid} if GroupIds() returns an error.

if err != nil {
log.Fatal(err)
}

err = syscall.Setgid(gid)
if err != nil {
log.Fatal(err)
Expand Down