Closed gopherbot closed 3 years ago
FWIW Both of the above issues are now fixed at HEAD.
Change https://golang.org/cl/285597 mentions this issue: doc/go1.16: mention syscall.AllThreadsSyscall
Just wanted to post an update. The following seems to work with go1.16.6 on Ubuntu linux which is pretty cool.
go build main.go
chmod 04755 main
./main 33 33
package main
import (
"os"
"time"
"syscall"
"fmt"
"strconv"
)
// https://storage.googleapis.com/go-attachment/1435/0/test.go
// https://github.com/golang/go/issues/1435
// $ sudo /sbin/setcap cap_setuid=ep ./prog
func printIds(ii int) {
for {
fmt.Printf(
"gorutine %d: uid=%d euid=%d gid=%d egid=%d\n", ii,
syscall.Getuid(), syscall.Geteuid(),
syscall.Getgid(), syscall.Getegid(),
)
time.Sleep(1e9)
}
}
func main() {
if len(os.Args) != 3 {
fmt.Printf("Usage: %s UID GID\n", os.Args[0])
os.Exit(1)
}
uid, err := strconv.Atoi(os.Args[1])
if err != nil {
fmt.Println("Wrong UID:", err)
os.Exit(1)
}
gid, err := strconv.Atoi(os.Args[2])
if err != nil {
fmt.Println("Wrong GID:", err)
os.Exit(1)
}
en := syscall.Setgid(gid)
if en != nil {
fmt.Println("Setgid error:",en.Error())
os.Exit(1)
}
en = syscall.Setuid(uid)
if en != nil {
fmt.Println("Setuid error:", en.Error())
os.Exit(1)
}
for ii := 1; ii < 10; ii++ {
go printIds(ii)
time.Sleep(1e8)
}
printIds(0)
}
Yes. I've also authored a native Go package for manipulating capabilities at runtime: "kernel.org/pub/linux/libs/security/libcap/cap"
. This worked example covers how to read/modify/drop runtime capabilities as well as manipulate UID
s etc.
@AndrewGMorgan thanks for sharing.
The Milestone
is "unplanned`, I guess it should be "1.16"?
Sorry, we don't try to set the milestone when we close an issue. But, yes, this was fixed in the 1.16 release.
by ziutek@Lnet.pl:
Attachments: