mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
Use unveil(2) on OpenBSD
After #1175 removed ioctl(2) fallback code shelling out to ifconfig(8), there is no code left (compiled on OpenBSD) that would fork(2) or execve(2). Drop the ability to run any executable file to double down on this, thus reducing the attack surface of this this experimental, internet facing daemon running as root. pledge(2) is doable, but needs more polish. unveil(2), however, is as simple as it gets. On other systems, this code is a NOOP, but can still help to implement similar safety belts.
This commit is contained in:
parent
eef613993f
commit
b16a3b0d43
3 changed files with 19 additions and 0 deletions
|
@ -14,6 +14,8 @@ import (
|
|||
"strings"
|
||||
"syscall"
|
||||
|
||||
"suah.dev/protect"
|
||||
|
||||
"github.com/gologme/log"
|
||||
gsyslog "github.com/hashicorp/go-syslog"
|
||||
"github.com/hjson/hjson-go/v4"
|
||||
|
@ -39,6 +41,20 @@ type node struct {
|
|||
|
||||
// The main function is responsible for configuring and starting Yggdrasil.
|
||||
func main() {
|
||||
// Not all operations are coverable with pledge(2), so immediately
|
||||
// limit file system access with unveil(2), effectively preventing
|
||||
// "proc exec" promises right from the start:
|
||||
//
|
||||
// - read arbitrary config file
|
||||
// - create/write arbitrary log file
|
||||
// - read/write/chmod/remove admin socket, if at all
|
||||
if err := protect.Unveil("/", "rwc"); err != nil {
|
||||
panic(fmt.Sprintf("unveil /: %v", err))
|
||||
}
|
||||
if err := protect.UnveilBlock(); err != nil {
|
||||
panic(fmt.Sprintf("unveil: %v", err))
|
||||
}
|
||||
|
||||
genconf := flag.Bool("genconf", false, "print a new config to stdout")
|
||||
useconf := flag.Bool("useconf", false, "read HJSON/JSON config from stdin")
|
||||
useconffile := flag.String("useconffile", "", "read HJSON/JSON config from specified file path")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue