mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-12-21 07:27:32 +00:00
genkeys, yggdrasilctl: Use pledge(2) on OpenBSD (#1193)
Restrict system operations of CLI tools with https://man.openbsd.org/pledge.2. https://pkg.go.dev/suah.dev/protect abstracts the OS specific code, i.e. is a NOOP on non-OpenBSD systems. This PR is to gauge upstream interest in this direction; my OpenBSD port of yggdrasil already pledges the daemon, resulting in minimal runtime privileges, but there are still a few rough edges: https://github.com/jasperla/openbsd-wip/blob/master/net/yggdrasil/patches/patch-cmd_yggdrasil_main_go#L80 --------- Co-authored-by: Neil <git@neilalexander.dev>
This commit is contained in:
parent
b2b0396d48
commit
2d587740c1
@ -18,6 +18,8 @@ import (
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"suah.dev/protect"
|
||||
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/address"
|
||||
)
|
||||
|
||||
@ -27,6 +29,10 @@ type keySet struct {
|
||||
}
|
||||
|
||||
func main() {
|
||||
if err := protect.Pledge("stdio"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
threads := runtime.GOMAXPROCS(0)
|
||||
fmt.Println("Threads:", threads)
|
||||
start := time.Now()
|
||||
|
@ -13,6 +13,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"suah.dev/protect"
|
||||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/admin"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/core"
|
||||
@ -22,6 +24,11 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
// read config, speak DNS/TCP and/or over a UNIX socket
|
||||
if err := protect.Pledge("stdio rpath inet unix dns"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// makes sure we can use defer and still return an error code to the OS
|
||||
os.Exit(run())
|
||||
}
|
||||
@ -78,6 +85,11 @@ func run() int {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// config and socket are done, work without unprivileges
|
||||
if err := protect.Pledge("stdio"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
logger.Println("Connected")
|
||||
defer conn.Close()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user